Module storm.java

Class WhereBuilder<T extends Data,R,ID>

java.lang.Object
st.orm.template.WhereBuilder<T,R,ID>
Type Parameters:
T - the type of the table being queried.
R - the type of the result.
ID - the type of the primary key.
All Implemented Interfaces:
SubqueryTemplate

public abstract class WhereBuilder<T extends Data,R,ID> extends Object implements SubqueryTemplate
WhereBuilder relies on preview features of the Java platform:
Programs can only use WhereBuilder when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A builder for constructing the WHERE clause of a query, providing type-safe predicate construction.

The WhereBuilder is passed to the lambda argument of QueryBuilder.where(java.util.function.Function) and offers methods for matching by primary key, record, ref, metamodel path, or custom string template expressions. Each method returns a PredicateBuilder that can be further composed using and() and or() combinators.

Methods named where are type-safe and restrict metamodel paths to the root table's entity graph. Methods named whereAny accept metamodel paths from any table, including manually added joins.

Example


 List<User> users = userRepository
         .select()
         .where(predicate -> predicate
             .where(User_.active, EQUALS, true)
             .and(predicate.where(User_.address.city.name, EQUALS, "Sunnyvale")))
         .getResultList();
 
See Also:
  • Constructor Details

    • WhereBuilder

      public WhereBuilder()
  • Method Details

    • TRUE

      public final PredicateBuilder<T,R,ID> TRUE()
      A predicate that always evaluates to true.
    • FALSE

      public final PredicateBuilder<T,R,ID> FALSE()
      A predicate that always evaluates to false.
    • exists

      public abstract PredicateBuilder<T,R,ID> exists(@Nonnull QueryBuilder<?,?,?> subquery)
      Adds an EXISTS condition to the WHERE clause using the specified subquery.

      This method appends an EXISTS clause to the current query's WHERE condition. It checks whether the provided subquery returns any rows, allowing you to filter results based on the existence of related data. This is particularly useful for constructing queries that need to verify the presence of certain records in a related table or subquery.

      Parameters:
      subquery - the subquery to check for existence.
      Returns:
      the updated PredicateBuilder with the EXISTS condition applied.
    • notExists

      public abstract PredicateBuilder<T,R,ID> notExists(@Nonnull QueryBuilder<?,?,?> subquery)
      Adds an NOT EXISTS condition to the WHERE clause using the specified subquery.

      This method appends an NOT EXISTS clause to the current query's WHERE condition. It checks whether the provided subquery returns any rows, allowing you to filter results based on the existence of related data. This is particularly useful for constructing queries that need to verify the absence of certain records in a related table or subquery.

      Parameters:
      subquery - the subquery to check for existence.
      Returns:
      the updated PredicateBuilder with the NOT EXISTS condition applied.
    • whereId

      public abstract PredicateBuilder<T,R,ID> whereId(@Nonnull ID id)
      Adds a condition to the WHERE clause that matches the specified primary key of the table.
      Parameters:
      id - the id to match.
      Returns:
      the predicate builder.
    • whereRef

      public abstract PredicateBuilder<T,R,ID> whereRef(@Nonnull Ref<T> ref)
      Adds a condition to the WHERE clause that matches the specified primary key of the table, expressed by a ref.
      Parameters:
      ref - the ref to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • whereAnyRef

      public abstract PredicateBuilder<T,R,ID> whereAnyRef(@Nonnull Ref<?> ref)
      Adds a condition to the WHERE clause that matches the specified primary key of the table, expressed by a ref. The ref can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      ref - the ref to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • where

      public abstract PredicateBuilder<T,R,ID> where(@Nonnull T record)
      Adds a condition to the WHERE clause that matches the specified record.
      Parameters:
      record - the record to match.
      Returns:
      the predicate builder.
    • whereAny

      public abstract PredicateBuilder<T,R,ID> whereAny(@Nonnull Data record)
      Adds a condition to the WHERE clause that matches the specified record. The record can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      record - the record to match.
      Returns:
      the predicate builder.
      Since:
      1.2
    • whereId

      public abstract PredicateBuilder<T,R,ID> whereId(@Nonnull Iterable<? extends ID> it)
      Adds a condition to the WHERE clause that matches the specified primary keys of the table.
      Parameters:
      it - the ids to match.
      Returns:
      the predicate builder.
      Since:
      1.2
    • whereRef

      public abstract PredicateBuilder<T,R,ID> whereRef(@Nonnull Iterable<? extends Ref<T>> it)
      Adds a condition to the WHERE clause that matches the specified primary keys of the table, expressed by a ref.
      Parameters:
      it - the refs to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • whereAnyRef

      public abstract PredicateBuilder<T,R,ID> whereAnyRef(@Nonnull Iterable<? extends Ref<?>> it)
      Adds a condition to the WHERE clause that matches the specified primary keys of the table, expressed by a ref. The ref can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      it - the refs to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • where

      public abstract PredicateBuilder<T,R,ID> where(@Nonnull Iterable<? extends T> it)
      Adds a condition to the WHERE clause that matches the specified records.
      Parameters:
      it - the records to match.
      Returns:
      the predicate builder.
    • whereAny

      public abstract PredicateBuilder<T,R,ID> whereAny(@Nonnull Iterable<? extends Data> it)
      Adds a condition to the WHERE clause that matches the specified records. The record can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      it - the records to match.
      Returns:
      the query builder.
    • where

      public final <V extends Data> PredicateBuilder<T,R,ID> where(@Nonnull Metamodel<T,V> path, @Nonnull V record)
      Adds a condition to the WHERE clause that matches the specified record. The record can represent any of the related tables in the table graph.
      Parameters:
      path - the path to the object in the table graph.
      record - the records to match.
      Returns:
      the predicate builder.
    • whereAny

      public final <V extends Data> PredicateBuilder<T,R,ID> whereAny(@Nonnull Metamodel<?,V> path, @Nonnull V record)
      Adds a condition to the WHERE clause that matches the specified record. The record can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      record - the records to match.
      Returns:
      the predicate builder.
    • where

      public abstract <V extends Data> PredicateBuilder<T,R,ID> where(@Nonnull Metamodel<T,V> path, @Nonnull Ref<V> ref)
      Adds a condition to the WHERE clause that matches the specified ref. The record can represent any of the related tables in the table graph.
      Parameters:
      path - the path to the object in the table graph.
      ref - the ref to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • whereAny

      public abstract <V extends Data> PredicateBuilder<T,R,ID> whereAny(@Nonnull Metamodel<?,V> path, @Nonnull Ref<V> ref)
      Adds a condition to the WHERE clause that matches the specified ref. The record can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      path - the path to the object in the table graph.
      ref - the ref to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • whereRef

      public abstract <V extends Data> PredicateBuilder<T,R,ID> whereRef(@Nonnull Metamodel<T,V> path, @Nonnull Iterable<? extends Ref<V>> it)
      Adds a condition to the WHERE clause that matches the specified refs. The refs can represent any of the related tables in the table graph.
      Parameters:
      path - the path to the ref in the table graph.
      it - the refs to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • whereAnyRef

      public abstract <V extends Data> PredicateBuilder<T,R,ID> whereAnyRef(@Nonnull Metamodel<?,V> path, @Nonnull Iterable<? extends Ref<V>> it)
      Adds a condition to the WHERE clause that matches the specified refs. The refs can represent any of the related tables in the table graph.
      Parameters:
      path - the path to the ref in the table graph.
      it - the refs to match.
      Returns:
      the predicate builder.
      Since:
      1.3
    • where

      public final <V extends Data> PredicateBuilder<T,R,ID> where(@Nonnull Metamodel<T,V> path, @Nonnull Iterable<V> it)
      Adds a condition to the WHERE clause that matches the specified records. The records can represent any of the related tables in the table graph.
      Parameters:
      path - the path to the object in the table graph.
      it - the records to match.
      Returns:
      the predicate builder.
    • whereAny

      public final <V extends Data> PredicateBuilder<T,R,ID> whereAny(@Nonnull Metamodel<?,V> path, @Nonnull Iterable<V> it)
      Adds a condition to the WHERE clause that matches the specified records. The records can represent any of the related tables in the table graph or manually added joins.
      Parameters:
      path - the path to the object in the table graph.
      it - the records to match.
      Returns:
      the predicate builder.
    • where

      public abstract <V> PredicateBuilder<T,R,ID> where(@Nonnull Metamodel<T,V> path, @Nonnull Operator operator, @Nonnull Iterable<? extends V> it)
      Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph.
      Type Parameters:
      V - the type of the object that the metamodel represents.
      Parameters:
      path - the path to the object in the table graph.
      operator - the operator to use for the comparison.
      it - the objects to match, which can be primary keys, records representing the table, or fields in the table graph.
      Returns:
      the query builder.
      Since:
      1.2
    • whereAny

      public abstract <V> PredicateBuilder<T,R,ID> whereAny(@Nonnull Metamodel<?,V> path, @Nonnull Operator operator, @Nonnull Iterable<? extends V> it)
      Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph or manually added joins.
      Type Parameters:
      V - the type of the object that the metamodel represents.
      Parameters:
      path - the path to the object in the table graph.
      operator - the operator to use for the comparison.
      it - the objects to match, which can be primary keys, records representing the table, or fields in the table graph.
      Returns:
      the query builder.
      Since:
      1.2
    • where

      @SafeVarargs public final <V> PredicateBuilder<T,R,ID> where(@Nonnull Metamodel<T,V> path, @Nonnull Operator operator, @Nonnull V... o)
      Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph.
      Type Parameters:
      V - the type of the object that the metamodel represents.
      Parameters:
      path - the path to the object in the table graph.
      operator - the operator to use for the comparison.
      o - the object(s) to match, which can be primary keys, records representing the table, or fields in the table graph.
      Returns:
      the query builder.
      Since:
      1.2
    • whereAny

      @SafeVarargs public final <V> PredicateBuilder<T,R,ID> whereAny(@Nonnull Metamodel<?,V> path, @Nonnull Operator operator, @Nonnull V... o)
      Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph or manually added joins.
      Type Parameters:
      V - the type of the object that the metamodel represents.
      Parameters:
      path - the path to the object in the table graph.
      operator - the operator to use for the comparison.
      o - the object(s) to match, which can be primary keys, records representing the table, or fields in the table graph.
      Returns:
      the query builder.
      Since:
      1.2
    • where

      public abstract PredicateBuilder<T,R,ID> where(@Nonnull StringTemplatePREVIEW template)
      Appends a custom expression to the WHERE clause.
      Parameters:
      template - the expression to add.
      Returns:
      the predicate builder.
    • whereImpl

      protected abstract <V> PredicateBuilder<T,R,ID> whereImpl(@Nonnull Metamodel<?,V> path, @Nonnull Operator operator, @Nonnull V[] o)
      Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph or manually added joins.
      Type Parameters:
      V - the type of the object that the metamodel represents.
      Parameters:
      path - the path to the object in the table graph.
      operator - the operator to use for the comparison.
      o - the object(s) to match, which can be primary keys, records representing the table, or fields in the table graph.
      Returns:
      the query builder.
      Since:
      1.2