- Type Parameters:
T- the type of the table being queried.R- the type of the result.ID- the type of the primary key.
PredicateBuilder relies on preview features of the Java platform:
PredicateBuilderrefers to one or more preview APIs:StringTemplate.
AND and OR composition.
PredicateBuilder instances are returned by the methods on WhereBuilder and can be combined
using and(PredicateBuilder) and or(PredicateBuilder) to build compound conditions. Each
combinator returns a new PredicateBuilder that represents the combined expression.
Predicates combine within the query root. A join widens the root, after which the WhereBuilder
produces predicates that may reference 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_.email, IS_NOT_NULL))
.or(predicate.where(User_.role, EQUALS, "admin")))
.getResultList();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionand(StringTemplatePREVIEW template) Adds a predicate to the WHERE clause using an AND condition.and(PredicateBuilder<? extends T, ?, ?> predicate) Adds a predicate to the WHERE clause using an AND condition.or(StringTemplatePREVIEW template) Adds a predicate to the WHERE clause using an OR condition.or(PredicateBuilder<? extends T, ?, ?> predicate) Adds a predicate to the WHERE clause using an OR condition.
-
Method Details
-
and
Adds a predicate to the WHERE clause using an AND condition.This method combines the specified predicate with existing predicates using an AND operation, ensuring that all added conditions must be true. The predicate inherits the query root: a join widens the root, admitting predicates that reference any entity in the query.
- Parameters:
predicate- the predicate to add.- Returns:
- the predicate builder.
-
and
Adds a predicate to the WHERE clause using an AND condition.This method combines the specified predicate with existing predicates using an AND operation, ensuring that all added conditions must be true.
- Parameters:
template- the template string representing the predicate to add.- Returns:
- the predicate builder.
-
or
Adds a predicate to the WHERE clause using an OR condition.This method combines the specified predicate with existing predicates using an OR operation, allowing any of the added conditions to be true. The predicate inherits the query root: a join widens the root, admitting predicates that reference any entity in the query.
- Parameters:
predicate- the predicate to add.- Returns:
- the predicate builder.
-
or
Adds a predicate to the WHERE clause using an OR condition.This method combines the specified predicate with existing predicates using an OR operation, ensuring that all added conditions must be true.
- Parameters:
template- the template string representing the predicate to add.- Returns:
- the predicate builder.
-
PredicateBuilderwhen preview features are enabled.