Interface TokenQuery

All Superinterfaces:
TokenSubQuery
All Known Implementing Classes:
TokenQueryImpl, TokenQueryJooq

public interface TokenQuery extends TokenSubQuery
Alternative to ValqueriesQuery that is not based on a specific model class. Useful for migrations.
  • Method Details

    • or

      Add an OR group to your query. The statements in this group will be OR-ed together.

      Example:

      
       query.or(or -> or.eq(Person::getName, "Bob").eq(Person::getAge, 42));
       
      Will result into the following SQL: `WHERE (name = 'Bob' OR age = 42)`

      Specified by:
      or in interface TokenSubQuery
      Parameters:
      orGroup - uses temporary TokenSubQuery to specify statements in the OR group
      Returns:
      this query, for chaining
    • and

      Add 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:

      
       query.or(or -> or.eq(Person::getName, "Alice").and(and -> and.eq(Person::getName, "Bob").eq(Person::getAge, 42)));
       
      Will result into the following SQL: `WHERE (name = 'Alice OR (name = 'Bob' AND age = 42))`.

      Specified by:
      and in interface TokenSubQuery
      Parameters:
      andGroup - uses temporary TokenSubQuery to specify statements in the AND group
      Returns:
      this query, for chaining
    • eq

      TokenQuery eq(Token field, Object value)
      Match if the value of a field equals the specified value. If you want to match null values, you have to use isNull(Token).

      Example:

      
       query.eq(Token.get("name"), "Bob")
       

      This will match people with the name "Bob".

      Specified by:
      eq in interface TokenSubQuery
      Parameters:
      field - the field to match
      value - the value to match
      Returns:
      the query, for chaining
    • eq

      default TokenQuery eq(String field, Object value)
      Match if the value of a field equals the specified value. If you want to match null values, you have to use isNull(String).

      Example:

      
       query.eq("name", "Bob")
       

      This will match people with the name "Bob".

      Note: to specify non-standard column names, use eq(Token, Object) with Token.literal(String)

      Specified by:
      eq in interface TokenSubQuery
      Parameters:
      field - the field to match, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the value to match
      Returns:
      the query, for chaining
    • notEq

      TokenQuery notEq(Token field, Object value)
      Match if the value of a field does not equal the specified value. If you want to match non-null values, you have to use isNotNull(Token).

      Example:

      
       query.notEq(Token.get("name"), "Bob")
       

      This will match people whose name is not "Bob".

      Specified by:
      notEq in interface TokenSubQuery
      Parameters:
      field - the field to match
      value - the value to match
      Returns:
      the query, for chaining
    • notEq

      default TokenQuery notEq(String field, Object value)
      Match if the value of a field does not equal the specified value. If you want to match non-null values, you have to use isNotNull(String).

      Example:

      
       query.notEq("name", "Bob")
       

      This will match people whose name is not "Bob".

      Note: to specify non-standard column names, use notEq(Token, Object) with Token.literal(String)

      Specified by:
      notEq in interface TokenSubQuery
      Parameters:
      field - the field to match, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the value to match
      Returns:
      the query, for chaining
    • in

      TokenQuery in(Token field, Collection<?> values)
      Match 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:
      in in interface TokenSubQuery
      Parameters:
      field - the field to match
      values - the values to match
      Returns:
      the query, for chaining
    • in

      default TokenQuery in(String field, Collection<?> values)
      Match if the value of a field is in the specified collection of values.

      Example:

      
       query.in("name", List.of("Bob", "Alice"))
       

      This will match people with the name "Bob" or "Alice".

      Note: to specify non-standard column names, use in(Token, Collection) with Token.literal(String)

      Specified by:
      in in interface TokenSubQuery
      Parameters:
      field - the field to match, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      values - the values to match
      Returns:
      the query, for chaining
    • in

      TokenQuery in(Token field, Object... values)
      Match 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:
      in in interface TokenSubQuery
      Parameters:
      field - the field to match
      values - the values to match
      Returns:
      the query, for chaining
    • in

      default TokenQuery in(String field, Object... values)
      Match if the value of a field is in the specified collection of values.

      Example:

      
       query.in("name", "Bob", "Alice")
       

      This will match people with the name "Bob" or "Alice".

      Note: to specify non-standard column names, use in(Token, Object...) with Token.literal(String)

      Specified by:
      in in interface TokenSubQuery
      Parameters:
      field - the field to match, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      values - the values to match
      Returns:
      the query, for chaining
    • like

      TokenQuery like(Token field, String value)
      Match 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:
      like in interface TokenSubQuery
      Parameters:
      field - the field to match
      value - the pattern to match
      Returns:
      the query, for chaining
    • like

      default TokenQuery like(String field, String value)
      Match if the value of a field matches the specified pattern.

      Example:

      
       query.like("name", "%ed")
       

      This will match people whose name ends with "ed".

      Note: to specify non-standard column names, use like(Token, String) with Token.literal(String)

      Specified by:
      like in interface TokenSubQuery
      Parameters:
      field - the field to match, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the pattern to match
      Returns:
      the query, for chaining
    • notLike

      TokenQuery notLike(Token field, String value)
      Match 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:
      notLike in interface TokenSubQuery
      Parameters:
      field - the field to match
      value - the pattern to match
      Returns:
      the query, for chaining
    • notLike

      default TokenQuery notLike(String field, String value)
      Match if the value of a field does not match the specified pattern.

      Example:

      
           query.notLike("name", "%ed")
           

      This will match people whose name does not end with "ed".

      Note: to specify non-standard column names, use notLike(Token, String) with Token.literal(String)

      Specified by:
      notLike in interface TokenSubQuery
      Parameters:
      field - the field to match, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the pattern to match
      Returns:
      the query, for chaining
    • gt

      TokenQuery gt(Token field, Object value)
      Match 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:
      gt in interface TokenSubQuery
      Parameters:
      field - the field to compare
      value - the value to compare to
      Returns:
      the query, for chaining
    • gt

      default TokenQuery gt(String field, Object value)
      Match if the value of a field is greater than the specified value.

      Example:

      
       query.gt("age", 18)
       

      This will match people older than 18.

      Note: to specify non-standard column names, use gt(Token, Object) with Token.literal(String)

      Specified by:
      gt in interface TokenSubQuery
      Parameters:
      field - the field to compare, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the value to compare to
      Returns:
      the query, for chaining
    • gte

      TokenQuery gte(Token field, Object value)
      Match 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:
      gte in interface TokenSubQuery
      Parameters:
      field - the field to compare
      value - the value to compare to
      Returns:
      the query, for chaining
    • gte

      default TokenQuery gte(String field, Object value)
      Match if the value of a field is greater than or equal to the specified value.

      Example:

      
       query.gte("age", 18)
       

      This will match people 18 or older.

      Note: to specify non-standard column names, use gte(Token, Object) with Token.literal(String)

      Specified by:
      gte in interface TokenSubQuery
      Parameters:
      field - the field to compare, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the value to compare to
      Returns:
      the query, for chaining
    • lt

      TokenQuery lt(Token field, Object value)
      Match 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:
      lt in interface TokenSubQuery
      Parameters:
      field - the field to compare
      value - the value to compare to
      Returns:
      the query, for chaining
    • lt

      default TokenQuery lt(String field, Object value)
      Match if the value of a field is less than the specified value.

      Example:

      
       query.lt("age", 18)
       

      This will match people younger than 18.

      Note: to specify non-standard column names, use lt(Token, Object) with Token.literal(String)

      Specified by:
      lt in interface TokenSubQuery
      Parameters:
      field - the field to compare, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the value to compare to
      Returns:
      the query, for chaining
    • lte

      TokenQuery lte(Token field, Object value)
      Match 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:
      lte in interface TokenSubQuery
      Parameters:
      field - the field to compare
      value - the value to compare to
      Returns:
      the query, for chaining
    • lte

      default TokenQuery lte(String field, Object value)
      Match if the value of a field is less than or equal to the specified value.

      Example:

      
       query.lte("age", 18)
       

      This will match people 18 or younger.

      Note: to specify non-standard column names, use lte(Token, Object) with Token.literal(String)

      Specified by:
      lte in interface TokenSubQuery
      Parameters:
      field - the field to compare, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      value - the value to compare to
      Returns:
      the query, for chaining
    • isNull

      TokenQuery isNull(Token field)
      Match 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:
      isNull in interface TokenSubQuery
      Parameters:
      field - the field to check
      Returns:
      the query, for chaining
    • isNull

      default TokenQuery isNull(String field)
      Match if the value of a field is null.

      Example:

      
       query.isNull("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.

      Note: to specify non-standard column names, use isNull(Token) with Token.literal(String)

      Specified by:
      isNull in interface TokenSubQuery
      Parameters:
      field - the field to check, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      Returns:
      the query, for chaining
    • isNotNull

      TokenQuery isNotNull(Token field)
      Match 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:
      isNotNull in interface TokenSubQuery
      Parameters:
      field - the field to check
      Returns:
      the query, for chaining
    • isNotNull

      default TokenQuery isNotNull(String field)
      Match if the value of a field is not null.

      Example:

      
       query.isNotNull("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.

      Note: to specify non-standard column names, use isNotNull(Token) with Token.literal(String)

      Specified by:
      isNotNull in interface TokenSubQuery
      Parameters:
      field - the field to check, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      Returns:
      the query, for chaining
    • sortAscending

      TokenQuery sortAscending(Token field)
      Sort the results by the given field in ascending order.

      Example:

      
       query.sortAscending(Person::getAge)
       

      This will sort the results by age in ascending order.

      Parameters:
      field - the filed to sort by
      Returns:
      the query, for chaining
    • sortAscending

      default TokenQuery sortAscending(String field)
      Sort the results by the given field in ascending order.

      Example:

      
       query.sortAscending("age")
       

      This will sort the results by age in ascending order.

      Note: to specify non-standard column names, use sortAscending(Token) with Token.literal(String)

      Parameters:
      field - the filed to sort by, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      Returns:
      the query, for chaining
    • sortDescending

      TokenQuery sortDescending(Token field)
      Sort the results by the given field in descending order.

      Example:

      
       query.sortDescending(Person::getAge)
       

      This will sort the results by age in descending order.

      Parameters:
      field - the filed to sort by
      Returns:
      the query, for chaining
    • sortDescending

      default TokenQuery sortDescending(String field)
      Sort the results by the given field in descending order.

      Example:

      
       query.sortDescending("age")
       

      This will sort the results by age in descending order.

      Note: to specify non-standard column names, use sortDescending(Token) with Token.literal(String)

      Parameters:
      field - the filed to sort by, will be tokenized, for example "fullName" will reference column "full_name" for MariaDb
      Returns:
      the query, for chaining
    • limit

      TokenQuery limit(int limit)
      Limit the results to the given number of rows.

      Example:

      
       query.limit(10)
       

      This will return the first 10 rows.

      Parameters:
      limit - the number of rows to return
      Returns:
      the query, for chaining
      See Also:
    • limit

      TokenQuery limit(int offset, int limit)
      Limit 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.

      Parameters:
      offset - the offset to start at
      limit - the number of rows to return
      Returns:
      the query, for chaining
    • select

      <R> List<R> select(IRowMapper<R> rowMapper)
      Select the rows matching the query.

      This is a terminal operation. As such, the query should not be reused after this method is called.

      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

      long count()
      Count the rows matching the query
      Returns:
      the number of rows matching the query
    • update

      Update the rows matching the query.

      This is a terminal operation. As such, the query should not be reused after this method is called.

      Parameters:
      updater - uses the TokenUpdate to specify the update operation
      Returns:
      a CrudRepository.CrudUpdateResult with the number of rows affected
    • delete

      Delete the rows matching the query.

      This is a terminal operation. As such, the query should not be reused after this method is called.

      Returns:
      a CrudRepository.CrudUpdateResult with the number of rows affected