Package io.ran

Class CrudRepoBaseQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>

java.lang.Object
io.ran.CrudRepoBaseQuery<T,Z>
All Implemented Interfaces:
CrudRepository.InlineQuery<T,Z>
Direct Known Subclasses:
BaseValqueriesQuery, TestDoubleQuery

public abstract class CrudRepoBaseQuery<T,Z extends CrudRepository.InlineQuery<T,Z>> extends Object implements CrudRepository.InlineQuery<T,Z>
  • Field Details

  • Constructor Details

  • Method Details

    • eq

      public <X> Z eq(Function<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field equals the specified value. If you want to match null values, you have to use CrudRepository.InlineQuery.isNull(Function).

      Example:

      
       query.eq(Person::getName, "Bob")
       

      This will match people with the name "Bob".

      Specified by:
      eq in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the getter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • eq

      public <X> Z eq(BiConsumer<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field equals the specified value. If you want to match null values, you have to use CrudRepository.InlineQuery.isNull(BiConsumer).

      Example:

      
       query.eq(Person::setName, "Bob")
       

      This will match people with the name "Bob".

      Specified by:
      eq in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the setter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • notEq

      public <X> Z notEq(Function<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is not equal to the specified value.

      Example:

      
       query.notEq(Person::getName, "Bob")
       

      This will match people with a name other than "Bob".

      Specified by:
      notEq in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the getter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • notEq

      public <X> Z notEq(BiConsumer<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is not equal to the specified value.

      Example:

      
       query.notEq(Person::setName, "Bob")
       

      This will match people with a name other than "Bob".

      Specified by:
      notEq in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the setter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • gt

      public <X extends Comparable<? super X>> Z gt(Function<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is greater than the specified value.

      Example:

      
       query.gt(Person::getAge, 18)
       

      This will match people older than 18.

      Specified by:
      gt in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the getter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • gt

      public <X extends Comparable<? super X>> Z gt(BiConsumer<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is greater than the specified value.

      Example:

      
       query.gt(Person::setAge, 18)
       

      This will match people older than 18.

      Specified by:
      gt in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the setter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • gte

      public <X extends Comparable<? super X>> Z gte(Function<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is greater than or equal to the specified value.

      Example:

      
       query.gte(Person::getAge, 18)
       

      This will match people that are 18 or older.

      Specified by:
      gte in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the getter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • gte

      public <X extends Comparable<? super X>> Z gte(BiConsumer<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is greater than or equal to the specified value.

      Example:

      
       query.gte(Person::setAge, 18)
       

      This will match people that are 18 or older.

      Specified by:
      gte in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the setter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • lt

      public <X extends Comparable<? super X>> Z lt(Function<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is less than the specified value.

      Example:

      
       query.lt(Person::getAge, 18)
       

      This will match people younger than 18.

      Specified by:
      lt in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the getter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • lt

      public <X extends Comparable<? super X>> Z lt(BiConsumer<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is less than the specified value.

      Example:

      
       query.lt(Person::setAge, 18)
       

      This will match people younger than 18.

      Specified by:
      lt in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the setter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • lte

      public <X extends Comparable<? super X>> Z lte(Function<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is less than or equal to the specified value.

      Example:

      
       query.lte(Person::getAge, 18)
       

      This will match people that are 18 or younger.

      Specified by:
      lte in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the getter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • lte

      public <X extends Comparable<? super X>> Z lte(BiConsumer<T,X> field, X value)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is less than or equal to the specified value.

      Example:

      
       query.lte(Person::setAge, 18)
       

      This will match people that are 18 or younger.

      Specified by:
      lte in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field and value
      Parameters:
      field - a method reference to the setter of the field
      value - the value to check against
      Returns:
      the query, for chaining
    • isNull

      public Z isNull(Function<T,?> field)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is null.

      Example:

      
           query.isNull(Person::getEmail)
           

      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 CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Parameters:
      field - a method reference to the getter of the field
      Returns:
      the query, for chaining
    • isNull

      public Z isNull(BiConsumer<T,?> field)
      Description copied from interface: CrudRepository.InlineQuery
      Match if the value of a field is null.

      Example:

      
       query.isNull(Person::setEmail)
       

      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 CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Parameters:
      field - a method reference to the setter of the field
      Returns:
      the query, for chaining
    • sortAscending

      public <X extends Comparable<? super X>> Z sortAscending(Function<T,X> field)
      Description copied from interface: CrudRepository.InlineQuery
      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.

      Specified by:
      sortAscending in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field
      Parameters:
      field - a method reference to the getter of the field
      Returns:
      the query, for chaining
    • sortAscending

      public <X extends Comparable<? super X>> Z sortAscending(BiConsumer<T,X> field)
      Description copied from interface: CrudRepository.InlineQuery
      Sort the results by the given field in ascending order.

      Meant to be used with a setter method reference.

      Example:

      
       query.sortAscending(Person::setAge)
       

      This will sort the results by age in ascending order.

      Specified by:
      sortAscending in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field
      Parameters:
      field - a method reference to the setter of the field
      Returns:
      the query, for chaining
    • sortDescending

      public <X extends Comparable<? super X>> Z sortDescending(Function<T,X> field)
      Description copied from interface: CrudRepository.InlineQuery
      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.

      Specified by:
      sortDescending in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field
      Parameters:
      field - a method reference to the getter of the field
      Returns:
      the query, for chaining
    • sortDescending

      public <X extends Comparable<? super X>> Z sortDescending(BiConsumer<T,X> field)
      Description copied from interface: CrudRepository.InlineQuery
      Sort the results by the given field in descending order.

      Meant to be used with a setter method reference.

      Example:

      
       query.sortDescending(Person::setAge)
       

      This will sort the results by age in descending order.

      Specified by:
      sortDescending in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field
      Parameters:
      field - a method reference to the setter of the field
      Returns:
      the query, for chaining
    • withEager

      public Z withEager(Function<T,?> field)
      Description copied from interface: CrudRepository.InlineQuery
      Causes a Relation field to be eagerly fetched. Useful to avoid multiple queries if you know that you will access the relation.

      Eagerness is defined by the implementation, but it generally means that the field will be fetched in the same query as the parent object, rather than in a separate query when the field is accessed (lazy loading).

      Example, returning a stream of all phones of people that are 18:

      
       query.eq(Person::getAge, 18).withEager(Person::getPhone).execute().map(Person::getPhone)
       

      This will result in one query to the database, instead of creating a separate query to get each phone.

      Specified by:
      withEager in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Parameters:
      field - a method reference to the getter of the field
      Returns:
      the query, for chaining
    • withEager

      public Z withEager(BiConsumer<T,?> field)
      Description copied from interface: CrudRepository.InlineQuery
      Causes a Relation field to be eagerly fetched. Useful to avoid multiple queries if you know that you will access the relation.

      Eagerness is defined by the implementation, but it generally means that the field will be fetched in the same query as the parent object, rather than in a separate query when the field is accessed (lazy loading).

      Example, returning a stream of all phones of people that are 18:

      
       query.eq(Person::setAge, 18).withEager(Person::getPhone).execute().map(Person::getPhone)
       

      This will result in one query to the database, instead of creating a separate query to get each phone.

      Specified by:
      withEager in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Parameters:
      field - a method reference to the setter of the field
      Returns:
      the query, for chaining
    • distinct

      public <X> Stream<X> distinct(Function<T,X> field)
      Description copied from interface: CrudRepository.InlineQuery
      Execute the query and return all distinct values of a field that match the query.

      This is useful if you need just a single field from an object, as it will only transfer that column over the network and will only deserialize that field.

      Sorting can be used, but only on the same column that is being selected.

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

      The resulting Stream from the operation may be a lazy stream, meaning that the results are not fetched from the database until they are accessed. As such it is important that a terminal operation is performed on the stream within a reasonable time frame to avoid holding database connections open.

      Specified by:
      distinct in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field
      Parameters:
      field - a method reference to the getter of the field
      Returns:
      a Stream of distinct values of the field
    • selectField

      public <X> Stream<X> selectField(Function<T,X> field)
      Description copied from interface: CrudRepository.InlineQuery
      Execute the query and return all values of a field that match the query.

      This is useful if you need just a single field from an object, as it will only transfer that column over the network and will only deserialize that field.

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

      The resulting Stream from the operation may be a lazy stream, meaning that the results are not fetched from the database until they are accessed. As such it is important that a terminal operation is performed on the stream within a reasonable time frame to avoid holding database connections open.

      Specified by:
      selectField in interface CrudRepository.InlineQuery<T,Z extends CrudRepository.InlineQuery<T,Z>>
      Type Parameters:
      X - the type of the field
      Parameters:
      field - a method reference to the getter of the field
      Returns:
      a Stream of values of the field