- 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
WhereBuilder relies on preview features of the Java platform:
WhereBuilderrefers to one or more preview APIs:StringTemplate.
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract PredicateBuilder<T, R, ID> exists(QueryBuilder<?, ?, ?> subquery) Adds anEXISTScondition to the WHERE clause using the specified subquery.final PredicateBuilder<T, R, ID> FALSE()A predicate that always evaluates to false.abstract PredicateBuilder<T, R, ID> notExists(QueryBuilder<?, ?, ?> subquery) Adds anNOT EXISTScondition to the WHERE clause using the specified subquery.final PredicateBuilder<T, R, ID> TRUE()A predicate that always evaluates to true.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified records.abstract PredicateBuilder<T, R, ID> where(StringTemplatePREVIEW template) Appends a custom expression to the WHERE clause.final <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified records.abstract <V> PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph.final <V> PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph.abstract <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified ref.final <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified record.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified record.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified records.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified record.final <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified records.abstract <V> PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph or manually added joins.final <V> PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph or manually added joins.abstract <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified ref.final <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified record.abstract PredicateBuilder<T, R, ID> whereAnyRef(Iterable<? extends Ref<?>> it) Adds a condition to the WHERE clause that matches the specified primary keys of the table, expressed by a ref.abstract <V extends Data>
PredicateBuilder<T, R, ID> whereAnyRef(Metamodel<?, V> path, Iterable<? extends Ref<V>> it) Adds a condition to the WHERE clause that matches the specified refs.abstract PredicateBuilder<T, R, ID> whereAnyRef(Ref<?> ref) Adds a condition to the WHERE clause that matches the specified primary key of the table, expressed by a ref.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified primary key of the table.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified primary keys of the table.protected abstract <V> PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified objects at the specified path in the table graph or manually added joins.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified primary keys of the table, expressed by a ref.abstract <V extends Data>
PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified refs.abstract PredicateBuilder<T, R, ID> Adds a condition to the WHERE clause that matches the specified primary key of the table, expressed by a ref.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface st.orm.template.SubqueryTemplate
subquery, subquery, subquery
-
Constructor Details
-
WhereBuilder
public WhereBuilder()
-
-
Method Details
-
TRUE
A predicate that always evaluates to true. -
FALSE
A predicate that always evaluates to false. -
exists
Adds anEXISTScondition to the WHERE clause using the specified subquery.This method appends an
EXISTSclause 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
PredicateBuilderwith the EXISTS condition applied.
-
notExists
Adds anNOT EXISTScondition to the WHERE clause using the specified subquery.This method appends an
NOT EXISTSclause 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
PredicateBuilderwith the NOT EXISTS condition applied.
-
whereId
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
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
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
Adds a condition to the WHERE clause that matches the specified record.- Parameters:
record- the record to match.- Returns:
- the predicate builder.
-
whereAny
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
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
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
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
Adds a condition to the WHERE clause that matches the specified records.- Parameters:
it- the records to match.- Returns:
- the predicate builder.
-
whereAny
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, whereID> (@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, whereAnyID> (@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, whereID> (@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, whereAnyID> (@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, whereRefID> (@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, whereAnyRefID> (@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, whereID> (@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, whereAnyID> (@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, whereID> (@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, whereAnyID> (@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, whereID> (@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, whereAnyID> (@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
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, whereImplID> (@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
-
WhereBuilderwhen preview features are enabled.