Class TQAssoc<T,R>

java.lang.Object
io.ebean.typequery.TQProperty<R,Object>
io.ebean.typequery.TQAssoc<T,R>
Type Parameters:
T - the entity bean type (normal entity bean type e.g. Customer)
R - the specific root query bean type (e.g. QCustomer)
All Implemented Interfaces:
io.ebean.Query.Property<Object>
Direct Known Subclasses:
TQAssocBean

public abstract class TQAssoc<T,R> extends TQProperty<R,Object>
Base type for associated beans.
  • Constructor Details

    • TQAssoc

      public TQAssoc(String name, R root)
      Construct with a property name and root instance.
      Parameters:
      name - the name of the property
      root - the root query bean instance
    • TQAssoc

      public TQAssoc(String name, R root, String prefix)
      Construct with additional path prefix.
  • Method Details

    • eq

      public final R eq(T other)
      Is equal to by ID property.
    • eqIfPresent

      public final R eqIfPresent(@Nullable T other)
      Is EQUAL TO if value is non-null and otherwise no expression is added to the query.

      This is effectively a helper method that allows a query to be built in fluid style where some predicates are effectively optional. We can use eqIfPresent() rather than having a separate if block.

    • equalTo

      public final R equalTo(T other)
      Is equal to by ID property.
    • ne

      public final R ne(T other)
      Is not equal to by ID property.
    • notEqualTo

      public final R notEqualTo(T other)
      Is not equal to by ID property.
    • in

      @SafeVarargs public final R in(T... values)
      Is in a list of values.
      Parameters:
      values - the list of values for the predicate
      Returns:
      the root query bean instance
    • in

      public final R in(Collection<T> values)
      Is in a list of values.
      Parameters:
      values - the list of values for the predicate
      Returns:
      the root query bean instance
    • inOrEmpty

      public final R inOrEmpty(Collection<T> values)
      In where null or empty values means that no predicate is added to the query.

      That is, only add the IN predicate if the values are not null or empty.

      Without this we typically need to code an if block to only add the IN predicate if the collection is not empty like:

      Without inOrEmpty()

      
      
         List<String> names = Arrays.asList("foo", "bar");
      
         QCustomer query = new QCustomer()
             .registered.before(LocalDate.now())
      
         // conditionally add the IN expression to the query
         if (names != null && !names.isEmpty()) {
             query.name.in(names)
         }
      
         query.findList();
      
       

      Using inOrEmpty()

      
      
         List<String> names = Arrays.asList("foo", "bar");
      
         new QCustomer()
             .registered.before(LocalDate.now())
             .name.inOrEmpty(names)
             .findList();
      
       
    • notIn

      public final R notIn(Collection<T> values)
      Is NOT in a list of values.
      Parameters:
      values - the list of values for the predicate
      Returns:
      the root query bean instance
    • notIn

      @SafeVarargs public final R notIn(T... values)
      Is NOT in a list of values.
      Parameters:
      values - the list of values for the predicate
      Returns:
      the root query bean instance