Skip to content

Commit 0a71449

Browse files
committed
overload where(), having(), and(), and or() to accept List<Predicate>
see jakartaee#137.
1 parent 4daf494 commit 0a71449

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

api/src/main/java/jakarta/persistence/criteria/CriteriaBuilder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ public interface CriteriaBuilder {
266266
*/
267267
Predicate and(Predicate... restrictions);
268268

269+
/**
270+
* Create a conjunction of the given restriction predicates.
271+
* A conjunction of zero predicates is true.
272+
* @param restrictions a list of zero or more restriction predicates
273+
* @return and predicate
274+
*/
275+
Predicate and(List<Predicate> restrictions);
276+
269277
/**
270278
* Create a disjunction of the given boolean expressions.
271279
* @param x boolean expression
@@ -282,6 +290,14 @@ public interface CriteriaBuilder {
282290
*/
283291
Predicate or(Predicate... restrictions);
284292

293+
/**
294+
* Create a disjunction of the given restriction predicates.
295+
* A disjunction of zero predicates is false.
296+
* @param restrictions a list of zero or more restriction predicates
297+
* @return or predicate
298+
*/
299+
Predicate or(List<Predicate> restrictions);
300+
285301
/**
286302
* Create a negation of the given restriction.
287303
* @param restriction restriction expression

api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
// Contributors:
14+
// Gavin King - 3.2
1415
// Linda DeMichiel - 2.1
1516
// Linda DeMichiel - 2.0
1617

@@ -204,6 +205,19 @@ public interface CriteriaQuery<T> extends AbstractQuery<T> {
204205
*/
205206
CriteriaQuery<T> where(Predicate... restrictions);
206207

208+
/**
209+
* Modify the query to restrict the query result according
210+
* to the conjunction of the specified restriction predicates.
211+
* Replaces the previously added restriction(s), if any.
212+
* If no restrictions are specified, any previously added
213+
* restrictions are simply removed.
214+
* This method only overrides the return type of the
215+
* corresponding <code>AbstractQuery</code> method.
216+
* @param restrictions a list of zero or more restriction predicates
217+
* @return the modified query
218+
*/
219+
CriteriaQuery<T> where(List<Predicate> restrictions);
220+
207221
/**
208222
* Specify the expressions that are used to form groups over
209223
* the query results.
@@ -254,6 +268,20 @@ public interface CriteriaQuery<T> extends AbstractQuery<T> {
254268
*/
255269
CriteriaQuery<T> having(Predicate... restrictions);
256270

271+
/**
272+
* Specify restrictions over the groups of the query
273+
* according the conjunction of the specified restriction
274+
* predicates.
275+
* Replaces the previously added having restriction(s), if any.
276+
* If no restrictions are specified, any previously added
277+
* restrictions are simply removed.
278+
* This method only overrides the return type of the
279+
* corresponding <code>AbstractQuery</code> method.
280+
* @param restrictions a list of zero or more restriction predicates
281+
* @return the modified query
282+
*/
283+
CriteriaQuery<T> having(List<Predicate> restrictions);
284+
257285
/**
258286
* Specify the ordering expressions that are used to
259287
* order the query results.

spec/src/main/asciidoc/appendixes.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ Added `||` string concatenation operator
110110

111111
Added _getSingleResultOrNull()_ to _Query_, _TypedQuery_, _StoredProcedureQuery_
112112

113-
Added _concat()_ overload accepting list of expressions to _CriteriaBuilder_
113+
Overload _concat()_ to accept list of expressions in _CriteriaBuilder_
114+
115+
Overload _where()_, _having()_, _and()_, and _or()_ to accept _List<Predicate>_ in _CriteriaQuery_ and _CriteriaBuilder_
114116

115117
Made the _name_ member of _TableGenerator_ and _SequenceGenerator_ optional
116118

0 commit comments

Comments
 (0)