Skip to content

Commit

Permalink
overload where(), having(), and(), and or() to accept List<Predicate> (
Browse files Browse the repository at this point in the history
…#442)

see #137.

Co-authored-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
gavinking and lukasj authored Aug 10, 2023
1 parent 2a40a58 commit 3d28b14
Show file tree
Hide file tree
Showing 3 changed files with 48 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
28 changes: 28 additions & 0 deletions api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

// Contributors:
// Gavin King - 3.2
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0

Expand Down Expand Up @@ -204,6 +205,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 Expand Up @@ -254,6 +268,20 @@ public interface CriteriaQuery<T> extends AbstractQuery<T> {
*/
CriteriaQuery<T> having(Predicate... restrictions);

/**
* Specify restrictions over the groups of the query
* according the conjunction of the specified restriction
* predicates.
* Replaces the previously added having 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> having(List<Predicate> restrictions);

/**
* Specify the ordering expressions that are used to
* order the query results.
Expand Down
4 changes: 4 additions & 0 deletions spec/src/main/asciidoc/appendixes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ Added `||` string concatenation operator

Added _getSingleResultOrNull()_ to _Query_, _TypedQuery_, _StoredProcedureQuery_

Overload _concat()_ to accept list of expressions in _CriteriaBuilder_

Overload _where()_, _having()_, _and()_, and _or()_ to accept _List<Predicate>_ in _CriteriaQuery_ and _CriteriaBuilder_

Added _equalTo()_ and _notEqualTo()_ to _Expression_

Added _concat()_ overload accepting list of expressions to _CriteriaBuilder_
Expand Down

0 comments on commit 3d28b14

Please sign in to comment.