Skip to content

Commit

Permalink
overload where(), and(), and or() to accept List<Predicate>
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Aug 9, 2023
1 parent 4daf494 commit aa8fe5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ public interface CriteriaBuilder {
*/
Predicate and(Predicate... restrictions);

/**
* Create a conjunction of the given restriction predicates.
* A conjunction of zero predicates is true.
* @param restrictions a list of zero or more restriction predicates
* @return and predicate
*/
Predicate and(List<Predicate> restrictions);

/**
* Create a disjunction of the given boolean expressions.
* @param x boolean expression
Expand All @@ -282,6 +290,14 @@ public interface CriteriaBuilder {
*/
Predicate or(Predicate... restrictions);

/**
* Create a disjunction of the given restriction predicates.
* A disjunction of zero predicates is false.
* @param restrictions a list of zero or more restriction predicates
* @return or predicate
*/
Predicate or(List<Predicate> restrictions);

/**
* Create a negation of the given restriction.
* @param restriction restriction expression
Expand Down
13 changes: 13 additions & 0 deletions api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ public interface CriteriaQuery<T> extends AbstractQuery<T> {
*/
CriteriaQuery<T> where(Predicate... restrictions);

/**
* Modify the query to restrict the query result according
* to the conjunction of the specified restriction predicates.
* Replaces the previously added restriction(s), if any.
* If no restrictions are specified, any previously added
* restrictions are simply removed.
* This method only overrides the return type of the
* corresponding <code>AbstractQuery</code> method.
* @param restrictions a list of zero or more restriction predicates
* @return the modified query
*/
CriteriaQuery<T> where(List<Predicate> restrictions);

/**
* Specify the expressions that are used to form groups over
* the query results.
Expand Down

0 comments on commit aa8fe5b

Please sign in to comment.