- 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.
Methods named and/or are type-safe and restrict predicates to the root table's entity graph.
Methods named andAny/orAny accept predicates 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_.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<T, ?, ?> predicate) Adds a predicate to the WHERE clause using an AND condition.<TX extends Data,RX, IDX>
PredicateBuilder<TX, RX, IDX> andAny(PredicateBuilder<TX, RX, IDX> 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<T, ?, ?> predicate) Adds a predicate to the WHERE clause using an OR condition.<TX extends Data,RX, IDX>
PredicateBuilder<TX, RX, IDX> orAny(PredicateBuilder<TX, RX, IDX> 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.
- Parameters:
predicate- the predicate to add.- Returns:
- the predicate builder.
-
andAny
<TX extends Data,RX, PredicateBuilder<TX,IDX> RX, andAnyIDX> (@Nonnull PredicateBuilder<TX, RX, IDX> predicate) 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:
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.
- Parameters:
predicate- the predicate to add.- Returns:
- the predicate builder.
-
orAny
<TX extends Data,RX, PredicateBuilder<TX,IDX> RX, orAnyIDX> (@Nonnull PredicateBuilder<TX, RX, IDX> predicate) 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.
- 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.