Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overload where(), having(), and(), and or() to accept List<Predicate> #442

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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