From 3c2d4f9616866124802648c75fa7bc2759c0f831 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 27 Jun 2023 14:57:29 +0200 Subject: [PATCH] HHH-16814 add getRootList() The method getRoots() returning a Set is really inconvenient --- .../java/org/hibernate/query/criteria/JpaCriteriaQuery.java | 6 ++++++ .../org/hibernate/query/criteria/JpaQueryStructure.java | 2 ++ .../query/sqm/tree/select/AbstractSqmSelectQuery.java | 4 ++++ .../org/hibernate/query/sqm/tree/select/SqmQuerySpec.java | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaCriteriaQuery.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaCriteriaQuery.java index f33829f2a3..52a6dcd04a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaCriteriaQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaCriteriaQuery.java @@ -13,6 +13,7 @@ import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Order; import jakarta.persistence.criteria.ParameterExpression; import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Selection; import jakarta.persistence.metamodel.EntityType; @@ -49,6 +50,11 @@ public interface JpaCriteriaQuery extends CriteriaQuery, JpaQueryableCrite // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Accessors + /** + * Return the {@linkplain #getRoots() roots} as a list. + */ + List> getRootList(); + @Override @SuppressWarnings("unchecked") default List getOrderList() { diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java index 3d1f0cb0da..5dc2cd1554 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java @@ -46,6 +46,8 @@ public interface JpaQueryStructure extends JpaQueryPart { Set> getRoots(); + List> getRootList(); + JpaQueryStructure addRoot(JpaRoot root); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java index 9a7cb8df4b..8507a2c8e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java @@ -211,6 +211,10 @@ public abstract class AbstractSqmSelectQuery return (Set) getQuerySpec().getRoots(); } + public List> getRootList() { + return (List) getQuerySpec().getRootList(); + } + @Override public SqmRoot from(Class entityClass) { return addRoot( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java index 4a6a1540dd..01a7e1231e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmQuerySpec.java @@ -318,6 +318,12 @@ public class SqmQuerySpec extends SqmQueryPart return new HashSet<>( getFromClause().getRoots() ); } + @Override + public List> getRootList() { + assert getFromClause() != null; + return getFromClause().getRoots(); + } + @Override public SqmQuerySpec addRoot(JpaRoot root) { if ( getFromClause() == null ) {