From 634b7f5c302e39a012e5900bfbdea6a1ecc609a5 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Thu, 29 Dec 2022 12:12:35 +0100 Subject: [PATCH] [#1557] Add BlazeCriteriaQuery.applyToCriteriaBuilder to allow using a JPA Criteria query as set operand --- CHANGELOG.md | 2 +- .../criteria/BlazeCriteriaQuery.java | 10 ++++++++++ .../criteria/impl/BlazeCriteriaQueryImpl.java | 6 ++++++ .../criteria/impl/InternalQuery.java | 18 ++---------------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28f7e937a0..02a0d31f7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Changes that happened in releases ### New features -None yet +* Add `BlazeCriteriaQuery.applyToCriteriaBuilder` to allow using a JPA Criteria query as set operand ### Bug fixes diff --git a/jpa-criteria/api/src/main/java/com/blazebit/persistence/criteria/BlazeCriteriaQuery.java b/jpa-criteria/api/src/main/java/com/blazebit/persistence/criteria/BlazeCriteriaQuery.java index 1379cddd35..575952adb9 100644 --- a/jpa-criteria/api/src/main/java/com/blazebit/persistence/criteria/BlazeCriteriaQuery.java +++ b/jpa-criteria/api/src/main/java/com/blazebit/persistence/criteria/BlazeCriteriaQuery.java @@ -16,6 +16,8 @@ package com.blazebit.persistence.criteria; +import com.blazebit.persistence.BaseCriteriaBuilder; +import com.blazebit.persistence.BaseQueryBuilder; import com.blazebit.persistence.CriteriaBuilder; import javax.persistence.EntityManager; @@ -43,6 +45,14 @@ public interface BlazeCriteriaQuery extends CriteriaQuery, BlazeAbstractQu */ public CriteriaBuilder createCriteriaBuilder(EntityManager entityManager); + /** + * Applies this criteria query onto an existing Blaze-Persistence Core {@link BaseCriteriaBuilder}. + * + * @param criteriaBuilder The criteria builder to apply this criteria query onto + * @since 1.6.9 + */ + public void applyToCriteriaBuilder(BaseCriteriaBuilder criteriaBuilder); + /** * The extended JPA {@link javax.persistence.criteria.CriteriaBuilder} associated with this query. * diff --git a/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/BlazeCriteriaQueryImpl.java b/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/BlazeCriteriaQueryImpl.java index f2612599ca..58b3316416 100644 --- a/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/BlazeCriteriaQueryImpl.java +++ b/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/BlazeCriteriaQueryImpl.java @@ -16,6 +16,8 @@ package com.blazebit.persistence.criteria.impl; +import com.blazebit.persistence.BaseCriteriaBuilder; +import com.blazebit.persistence.BaseQueryBuilder; import com.blazebit.persistence.CriteriaBuilder; import com.blazebit.persistence.criteria.BlazeCriteriaBuilder; import com.blazebit.persistence.criteria.BlazeCriteriaQuery; @@ -280,4 +282,8 @@ public CriteriaBuilder createCriteriaBuilder(EntityManager entityManager) { return query.render(cb); } + @Override + public void applyToCriteriaBuilder(BaseCriteriaBuilder criteriaBuilder) { + query.render(criteriaBuilder); + } } diff --git a/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/InternalQuery.java b/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/InternalQuery.java index 3005a3d8d7..54619dcd56 100644 --- a/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/InternalQuery.java +++ b/jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/InternalQuery.java @@ -16,21 +16,7 @@ package com.blazebit.persistence.criteria.impl; -import com.blazebit.persistence.BaseSubqueryBuilder; -import com.blazebit.persistence.CriteriaBuilder; -import com.blazebit.persistence.FromBuilder; -import com.blazebit.persistence.FullQueryBuilder; -import com.blazebit.persistence.GroupByBuilder; -import com.blazebit.persistence.HavingBuilder; -import com.blazebit.persistence.JoinOnBuilder; -import com.blazebit.persistence.JoinType; -import com.blazebit.persistence.MultipleSubqueryInitiator; -import com.blazebit.persistence.OrderByBuilder; -import com.blazebit.persistence.SelectBuilder; -import com.blazebit.persistence.SelectObjectBuilder; -import com.blazebit.persistence.SubqueryBuilder; -import com.blazebit.persistence.SubqueryInitiator; -import com.blazebit.persistence.WhereBuilder; +import com.blazebit.persistence.*; import com.blazebit.persistence.criteria.BlazeAbstractQuery; import com.blazebit.persistence.criteria.BlazeJoin; import com.blazebit.persistence.criteria.BlazeOrder; @@ -271,7 +257,7 @@ public BlazeSubquery subquery(Class subqueryType) { /* Rendering */ - public CriteriaBuilder render(CriteriaBuilder cb) { + public > X render(X cb) { if (distinct) { cb.distinct(); }