Class TokenQueryImpl
- All Implemented Interfaces:
TokenQuery,TokenSubQuery,Setter,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionTokenQueryImpl(TableToken tableToken, ITransactionContext transactionContext, SqlDialect dialect) -
Method Summary
Modifier and TypeMethodDescriptionand(Consumer<TokenSubQuery> andGroup) Add an AND group to your query.voidclose()longcount()Count the rows matching the querydelete()Delete the rows matching the query.Match if the value of a field equals the specified value.Match if the value of a field is greater than the specified value.Match if the value of a field is greater than or equal to the specified value.Match if the value of a field is in the specified collection of values.in(Token field, Collection<?> values) Match if the value of a field is in the specified collection of values.Match if the value of a field is not null.Match if the value of a field is null.Match if the value of a field matches the specified pattern.limit(int limit) Limit the results to the given number of rows.limit(int offset, int limit) Limit the results to the given number of rows, starting at the given offset.Match if the value of a field is less than the specified value.Match if the value of a field is less than or equal to the specified value.Match if the value of a field does not equal the specified value.Match if the value of a field does not match the specified pattern.or(Consumer<TokenSubQuery> orGroup) Add an OR group to your query.<R> List<R>select(IRowMapper<R> rowMapper) Select the rows matching the query.voidset(IStatement statement) sortAscending(Token field) Sort the results by the given field in ascending order.sortDescending(Token field) Sort the results by the given field in descending order.update(Consumer<TokenUpdate> updater) Update the rows matching the query.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.valqueries.automapper.TokenQuery
eq, gt, gte, in, in, isNotNull, isNull, like, lt, lte, notEq, notLike, sortAscending, sortDescending
-
Constructor Details
-
TokenQueryImpl
public TokenQueryImpl(TableToken tableToken, ITransactionContext transactionContext, SqlDialect dialect)
-
-
Method Details
-
or
Description copied from interface:TokenQueryAdd an OR group to your query. The statements in this group will be OR-ed together.Example:
Will result into the following SQL: `WHERE (name = 'Bob' OR age = 42)`query.or(or -> or.eq(Person::getName, "Bob").eq(Person::getAge, 42));- Specified by:
orin interfaceTokenQuery- Specified by:
orin interfaceTokenSubQuery- Parameters:
orGroup- uses temporaryTokenSubQueryto specify statements in the OR group- Returns:
- this query, for chaining
-
and
Description copied from interface:TokenQueryAdd an AND group to your query. The statements in this group will be AND-ed together. Note that statements are AND-ed by default, this method is meant to be used inside an OR group.Example:
Will result into the following SQL: `WHERE (name = 'Alice OR (name = 'Bob' AND age = 42))`.query.or(or -> or.eq(Person::getName, "Alice").and(and -> and.eq(Person::getName, "Bob").eq(Person::getAge, 42)));- Specified by:
andin interfaceTokenQuery- Specified by:
andin interfaceTokenSubQuery- Parameters:
andGroup- uses temporaryTokenSubQueryto specify statements in the AND group- Returns:
- this query, for chaining
-
eq
Description copied from interface:TokenQueryMatch if the value of a field equals the specified value. If you want to match null values, you have to useTokenQuery.isNull(Token).Example:
query.eq(Token.get("name"), "Bob")This will match people with the name "Bob".
- Specified by:
eqin interfaceTokenQuery- Specified by:
eqin interfaceTokenSubQuery- Parameters:
field- the field to matchvalue- the value to match- Returns:
- the query, for chaining
-
notEq
Description copied from interface:TokenQueryMatch if the value of a field does not equal the specified value. If you want to match non-null values, you have to useTokenQuery.isNotNull(Token).Example:
query.notEq(Token.get("name"), "Bob")This will match people whose name is not "Bob".
- Specified by:
notEqin interfaceTokenQuery- Specified by:
notEqin interfaceTokenSubQuery- Parameters:
field- the field to matchvalue- the value to match- Returns:
- the query, for chaining
-
in
Description copied from interface:TokenQueryMatch if the value of a field is in the specified collection of values.Example:
query.in(Token.get("name"), List.of("Bob", "Alice"))This will match people with the name "Bob" or "Alice".
- Specified by:
inin interfaceTokenQuery- Specified by:
inin interfaceTokenSubQuery- Parameters:
field- the field to matchvalues- the values to match- Returns:
- the query, for chaining
-
in
Description copied from interface:TokenQueryMatch if the value of a field is in the specified collection of values.Example:
query.in(Token.get("name"), "Bob", "Alice")This will match people with the name "Bob" or "Alice".
- Specified by:
inin interfaceTokenQuery- Specified by:
inin interfaceTokenSubQuery- Parameters:
field- the field to matchvalues- the values to match- Returns:
- the query, for chaining
-
like
Description copied from interface:TokenQueryMatch if the value of a field matches the specified pattern.Example:
query.like(Token.get("name"), "%ed")This will match people whose name ends with "ed".
- Specified by:
likein interfaceTokenQuery- Specified by:
likein interfaceTokenSubQuery- Parameters:
field- the field to matchvalue- the pattern to match- Returns:
- the query, for chaining
-
notLike
Description copied from interface:TokenQueryMatch if the value of a field does not match the specified pattern.Example:
query.notLike(Token.get("name"), "%ed")This will match people whose name does not end with "ed".
- Specified by:
notLikein interfaceTokenQuery- Specified by:
notLikein interfaceTokenSubQuery- Parameters:
field- the field to matchvalue- the pattern to match- Returns:
- the query, for chaining
-
gt
Description copied from interface:TokenQueryMatch if the value of a field is greater than the specified value.Example:
query.gt(Token.get("age"), 18)This will match people older than 18.
- Specified by:
gtin interfaceTokenQuery- Specified by:
gtin interfaceTokenSubQuery- Parameters:
field- the field to comparevalue- the value to compare to- Returns:
- the query, for chaining
-
gte
Description copied from interface:TokenQueryMatch if the value of a field is greater than or equal to the specified value.Example:
query.gte(Token.get("age"), 18)This will match people 18 or older.
- Specified by:
gtein interfaceTokenQuery- Specified by:
gtein interfaceTokenSubQuery- Parameters:
field- the field to comparevalue- the value to compare to- Returns:
- the query, for chaining
-
lt
Description copied from interface:TokenQueryMatch if the value of a field is less than the specified value.Example:
query.lt(Token.get("age"), 18)This will match people younger than 18.
- Specified by:
ltin interfaceTokenQuery- Specified by:
ltin interfaceTokenSubQuery- Parameters:
field- the field to comparevalue- the value to compare to- Returns:
- the query, for chaining
-
lte
Description copied from interface:TokenQueryMatch if the value of a field is less than or equal to the specified value.Example:
query.lte(Token.get("age"), 18)This will match people 18 or younger.
- Specified by:
ltein interfaceTokenQuery- Specified by:
ltein interfaceTokenSubQuery- Parameters:
field- the field to comparevalue- the value to compare to- Returns:
- the query, for chaining
-
isNull
Description copied from interface:TokenQueryMatch if the value of a field is null.Example:
query.isNull(Token.get("email"))This will match people whose email is null.
Note: if the model class has fields of primitive type, they won't be null, even if the database contains NULL values. In this case isNull will still match correctly based on the values in the database.
- Specified by:
isNullin interfaceTokenQuery- Specified by:
isNullin interfaceTokenSubQuery- Parameters:
field- the field to check- Returns:
- the query, for chaining
-
isNotNull
Description copied from interface:TokenQueryMatch if the value of a field is not null.Example:
query.isNotNull(Token.get("email"))This will match people whose email is not null.
Note: if the model class has fields of primitive type, they won't be null, even if the database contains NULL values. In this case isNotNull will still match correctly based on the values in the database.
- Specified by:
isNotNullin interfaceTokenQuery- Specified by:
isNotNullin interfaceTokenSubQuery- Parameters:
field- the field to check- Returns:
- the query, for chaining
-
sortAscending
Description copied from interface:TokenQuerySort the results by the given field in ascending order.Example:
query.sortAscending(Person::getAge)This will sort the results by age in ascending order.
- Specified by:
sortAscendingin interfaceTokenQuery- Parameters:
field- the filed to sort by- Returns:
- the query, for chaining
-
sortDescending
Description copied from interface:TokenQuerySort the results by the given field in descending order.Example:
query.sortDescending(Person::getAge)This will sort the results by age in descending order.
- Specified by:
sortDescendingin interfaceTokenQuery- Parameters:
field- the filed to sort by- Returns:
- the query, for chaining
-
limit
Description copied from interface:TokenQueryLimit the results to the given number of rows.Example:
query.limit(10)This will return the first 10 rows.
- Specified by:
limitin interfaceTokenQuery- Parameters:
limit- the number of rows to return- Returns:
- the query, for chaining
- See Also:
-
limit
Description copied from interface:TokenQueryLimit the results to the given number of rows, starting at the given offset.Offset is 0-based (the first row is 0).
Offset is inclusive, limit is the size of the returned collection.
Example:
query.limit(10, 20)This will return rows 10, 11, 12, ..., 29.
- Specified by:
limitin interfaceTokenQuery- Parameters:
offset- the offset to start atlimit- the number of rows to return- Returns:
- the query, for chaining
-
select
Description copied from interface:TokenQuerySelect the rows matching the query.This is a terminal operation. As such, the query should not be reused after this method is called.
- Specified by:
selectin interfaceTokenQuery- Type Parameters:
R- the type of the objects returned by the mapper- Parameters:
rowMapper- the mapper converting each row of the result into an object that will be returned- Returns:
- list of objects returned by the mapper
-
count
public long count()Description copied from interface:TokenQueryCount the rows matching the query- Specified by:
countin interfaceTokenQuery- Returns:
- the number of rows matching the query
-
update
Description copied from interface:TokenQueryUpdate the rows matching the query.This is a terminal operation. As such, the query should not be reused after this method is called.
- Specified by:
updatein interfaceTokenQuery- Parameters:
updater- uses theTokenUpdateto specify the update operation- Returns:
- a
CrudRepository.CrudUpdateResultwith the number of rows affected
-
delete
Description copied from interface:TokenQueryDelete the rows matching the query.This is a terminal operation. As such, the query should not be reused after this method is called.
- Specified by:
deletein interfaceTokenQuery- Returns:
- a
CrudRepository.CrudUpdateResultwith the number of rows affected
-
set
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-