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
see #137.
  • Loading branch information
gavinking committed Aug 10, 2023
1 parent 4daf494 commit 0a71449
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
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: 3 additions & 1 deletion spec/src/main/asciidoc/appendixes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ Added `||` string concatenation operator

Added _getSingleResultOrNull()_ to _Query_, _TypedQuery_, _StoredProcedureQuery_

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

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

Made the _name_ member of _TableGenerator_ and _SequenceGenerator_ optional

0 comments on commit 0a71449

Please sign in to comment.