- 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.
The where methods are type-safe and restrict metamodel paths to the root table's entity graph.
A join widens the query root, after which the where methods accept paths from any entity in the query;
a path on an entity outside the query fails when the query is built.
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 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
-
where
Adds a condition to the WHERE clause that matches the specified record.- Parameters:
record- the record to match.- Returns:
- the predicate builder.
-
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
-
where
Adds a condition to the WHERE clause that matches the specified records.- Parameters:
it- the records to match.- Returns:
- the predicate builder.
-
where
Appends a custom expression to the WHERE clause.- Parameters:
template- the expression to add.- Returns:
- the predicate builder.
-
WhereBuilderwhen preview features are enabled.