127127import org .hibernate .query .sqm .tree .predicate .SqmNullnessPredicate ;
128128import org .hibernate .query .sqm .tree .predicate .SqmPredicate ;
129129import org .hibernate .query .sqm .tree .select .SqmDynamicInstantiation ;
130- import org .hibernate .query .sqm .tree .select .SqmDynamicInstantiationArgument ;
131130import org .hibernate .query .sqm .tree .select .SqmJpaCompoundSelection ;
132131import org .hibernate .query .sqm .tree .select .SqmOrderByClause ;
133132import org .hibernate .query .sqm .tree .select .SqmQueryGroup ;
169168import static org .hibernate .internal .util .collections .CollectionHelper .determineProperSizing ;
170169import static org .hibernate .query .internal .QueryHelper .highestPrecedenceType ;
171170import static org .hibernate .query .sqm .TrimSpec .fromCriteriaTrimSpec ;
171+ import static org .hibernate .query .sqm .tree .select .SqmDynamicInstantiation .classInstantiation ;
172+ import static org .hibernate .query .sqm .tree .select .SqmDynamicInstantiation .listInstantiation ;
173+ import static org .hibernate .query .sqm .tree .select .SqmDynamicInstantiation .mapInstantiation ;
172174
173175/**
174176 * Acts as a JPA {@link jakarta.persistence.criteria.CriteriaBuilder} by
@@ -374,7 +376,7 @@ public <T> SqmInsertSelectStatement<T> createCriteriaInsertSelect(Class<T> targe
374376
375377 @ Override
376378 public SqmValues values (Expression <?>... expressions ) {
377- return values ( Arrays . asList ( expressions ) );
379+ return values ( asList ( expressions ) );
378380 }
379381
380382 @ Override
@@ -873,15 +875,14 @@ public JpaSearchOrder desc(JpaCteCriteriaAttribute x, boolean nullsFirst) {
873875
874876 @ Override
875877 public JpaCompoundSelection <Tuple > tuple (Selection <?>... selections ) {
876- return tuple ( Arrays . asList ( selections ) );
878+ return tuple ( asList ( selections ) );
877879 }
878880
879881 @ Override
880882 public JpaCompoundSelection <Tuple > tuple (List <Selection <?>> selections ) {
881883 checkMultiselect ( selections );
882- //noinspection unchecked,rawtypes
883884 return new SqmJpaCompoundSelection <>(
884- ( List ) selections ,
885+ selections . stream (). map ( selection -> ( SqmSelectableNode <?>) selection ). toList () ,
885886 getTypeConfiguration ().getJavaTypeRegistry ().getDescriptor ( Tuple .class ),
886887 this
887888 );
@@ -892,6 +893,11 @@ public <R> SqmTuple<R> tuple(Class<R> tupleType, SqmExpression<?>... expressions
892893 return tuple ( tupleType , asList ( expressions ) );
893894 }
894895
896+ @ Override
897+ public <R > SqmTuple <R > tuple (SqmExpressible <R > tupleType , SqmExpression <?>... expressions ) {
898+ return tuple ( tupleType , asList ( expressions ) );
899+ }
900+
895901 @ Override @ SuppressWarnings ("unchecked" )
896902 public <R > SqmTuple <R > tuple (Class <R > tupleType , List <? extends SqmExpression <?>> expressions ) {
897903 final SqmExpressible <R > expressibleType =
@@ -901,11 +907,6 @@ public <R> SqmTuple<R> tuple(Class<R> tupleType, List<? extends SqmExpression<?>
901907 return tuple ( expressibleType , expressions );
902908 }
903909
904- @ Override
905- public <R > SqmTuple <R > tuple (SqmExpressible <R > tupleType , SqmExpression <?>... expressions ) {
906- return tuple ( tupleType , asList ( expressions ) );
907- }
908-
909910 @ Override
910911 public <R > SqmTuple <R > tuple (SqmExpressible <R > tupleType , List <? extends SqmExpression <?>> sqmExpressions ) {
911912 if ( tupleType == null ) {
@@ -957,63 +958,51 @@ public <Y> JpaCompoundSelection<Y> construct(Class<Y> resultClass, List<? extend
957958 arguments .stream ().map ( arg -> (SqmSelectableNode <?>) arg ).toList () );
958959 }
959960
961+ @ SuppressWarnings ("unchecked" )
960962 private <Y > JpaCompoundSelection <Y > constructInternal (Class <Y > resultClass , List <? extends SqmSelectableNode <?>> arguments ) {
961963 checkMultiselect ( arguments );
962- final SqmDynamicInstantiation <Y > instantiation = createInstantiation ( resultClass );
963- for ( SqmSelectableNode <?> argument : arguments ) {
964- final SqmDynamicInstantiationArgument <?> arg =
965- new SqmDynamicInstantiationArgument <>( argument , argument .getAlias (), this );
966- instantiation .addArgument ( arg );
967- }
968- return instantiation ;
969- }
970-
971- @ SuppressWarnings ("unchecked" )
972- private <Y > SqmDynamicInstantiation <Y > createInstantiation (Class <Y > resultClass ) {
973964 if ( List .class .equals ( resultClass ) ) {
974- return (SqmDynamicInstantiation <Y >) SqmDynamicInstantiation . forListInstantiation ( this );
965+ return (SqmDynamicInstantiation <Y >) listInstantiation ( arguments , this );
975966 }
976967 else if ( Map .class .equals ( resultClass ) ) {
977- return (SqmDynamicInstantiation <Y >) SqmDynamicInstantiation . forMapInstantiation ( this );
968+ return (SqmDynamicInstantiation <Y >) mapInstantiation ( arguments , this );
978969 }
979970 else {
980- return SqmDynamicInstantiation . forClassInstantiation ( resultClass , this );
971+ return classInstantiation ( resultClass , arguments , this );
981972 }
982973 }
983974
984975 /**
985- * Package-protected method to centralize checking of criteria query multi-selects as defined by the
986- * {@link CriteriaQuery#multiselect(List)} method.
976+ * Check the arguments of {@link jakarta.persistence.criteria.CriteriaBuilder#array},
977+ * {@link jakarta.persistence.criteria.CriteriaBuilder#construct}, or
978+ * {@link jakarta.persistence.criteria.CriteriaBuilder#tuple}.
987979 *
988980 * @param selections The selection varargs to check
989981 *
990- * @throws IllegalArgumentException If the selection items are not valid per {@link CriteriaQuery#multiselect}
991- * documentation.
992- * <i>"An argument to the multiselect method must not be a tuple-
993- * or array-valued compound selection item."</i>
982+ * @throws IllegalArgumentException If the selection items are not valid per
983+ * according to {@linkplain CriteriaQuery#multiselect this documentation} .
984+ * <i>"An argument to the multiselect method must not be a tuple-
985+ * or array-valued compound selection item."</i>
994986 */
995- void checkMultiselect (List <? extends Selection <?>> selections ) {
987+ private void checkMultiselect (List <? extends Selection <?>> selections ) {
996988 final HashSet <String > aliases = new HashSet <>( determineProperSizing ( selections .size () ) );
997-
998- for ( Selection <?> it : selections ) {
999- final JpaSelection <?> selection = (JpaSelection <?>) it ;
989+ for ( Selection <?> selection : selections ) {
1000990 if ( selection .isCompoundSelection () ) {
1001- if ( selection .getJavaType ().isArray () ) {
991+ final Class <?> javaType = selection .getJavaType ();
992+ if ( javaType .isArray () ) {
1002993 throw new IllegalArgumentException (
1003- "Selection items in a multi-select cannot contain compound array-valued elements"
994+ "Selection item in a multi-select cannot contain compound array-valued elements"
1004995 );
1005996 }
1006- if ( Tuple .class .isAssignableFrom ( selection . getJavaType () ) ) {
997+ if ( Tuple .class .isAssignableFrom ( javaType ) ) {
1007998 throw new IllegalArgumentException (
1008- "Selection items in a multi-select cannot contain compound tuple-valued elements"
999+ "Selection item in a multi-select cannot contain compound tuple-valued elements"
10091000 );
10101001 }
10111002 }
1012- if ( StringHelper .isNotEmpty ( selection .getAlias () ) ) {
1013- boolean added = aliases .add ( selection .getAlias () );
1014- if ( ! added ) {
1015- throw new IllegalArgumentException ( "Multi-select expressions defined duplicate alias : " + selection .getAlias () );
1016- }
1003+ final String alias = selection .getAlias ();
1004+ if ( StringHelper .isNotEmpty ( alias ) && !aliases .add ( alias ) ) {
1005+ throw new IllegalArgumentException ( "Multi-select expressions have duplicate alias '" + alias + "'" );
10171006 }
10181007 }
10191008 }
@@ -1161,7 +1150,7 @@ public JpaExpression<Double> ln(Expression<? extends Number> x) {
11611150 @ Override
11621151 public JpaExpression <Double > power (Expression <? extends Number > x , Expression <? extends Number > y ) {
11631152 return getFunctionDescriptor ( "power" ).generateSqmExpression (
1164- Arrays . asList ( (SqmExpression <?>) x , (SqmExpression <?>) y ),
1153+ asList ( (SqmExpression <?>) x , (SqmExpression <?>) y ),
11651154 null ,
11661155 queryEngine
11671156 );
@@ -1170,7 +1159,7 @@ public JpaExpression<Double> power(Expression<? extends Number> x, Expression<?
11701159 @ Override
11711160 public JpaExpression <Double > power (Expression <? extends Number > x , Number y ) {
11721161 return getFunctionDescriptor ( "power" ).generateSqmExpression (
1173- Arrays . asList ( (SqmExpression <?>) x , value ( y ) ),
1162+ asList ( (SqmExpression <?>) x , value ( y ) ),
11741163 null ,
11751164 queryEngine
11761165 );
@@ -1179,7 +1168,7 @@ public JpaExpression<Double> power(Expression<? extends Number> x, Number y) {
11791168 @ Override
11801169 public <T extends Number > JpaExpression <T > round (Expression <T > x , Integer n ) {
11811170 return getFunctionDescriptor ( "round" ).generateSqmExpression (
1182- Arrays . asList ( (SqmExpression <?>) x , value ( n ) ),
1171+ asList ( (SqmExpression <?>) x , value ( n ) ),
11831172 null ,
11841173 queryEngine
11851174 );
@@ -1188,7 +1177,7 @@ public <T extends Number> JpaExpression<T> round(Expression<T> x, Integer n) {
11881177 @ Override
11891178 public <T extends Number > JpaExpression <T > truncate (Expression <T > x , Integer n ) {
11901179 return getFunctionDescriptor ( "truncate" ).generateSqmExpression (
1191- Arrays . asList ( (SqmExpression <?>) x , value ( n ) ),
1180+ asList ( (SqmExpression <?>) x , value ( n ) ),
11921181 null ,
11931182 queryEngine
11941183 );
@@ -5532,7 +5521,7 @@ private SqmExpression<String> jsonArrayAgg(
55325521 return getFunctionDescriptor ( "json_arrayagg" ).generateOrderedSetAggregateSqmExpression (
55335522 nullBehavior == null
55345523 ? Collections .singletonList ( value )
5535- : Arrays . asList ( value , SqmJsonNullBehavior .NULL ),
5524+ : asList ( value , SqmJsonNullBehavior .NULL ),
55365525 filterPredicate ,
55375526 orderByClause ,
55385527 null ,
@@ -5712,7 +5701,7 @@ public <T> SqmExpression<T> named(Expression<T> expression, String name) {
57125701
57135702 @ Override
57145703 public SqmExpression <String > xmlforest (Expression <?>... elements ) {
5715- return xmlforest ( Arrays . asList ( elements ) );
5704+ return xmlforest ( asList ( elements ) );
57165705 }
57175706
57185707 @ Override
@@ -5741,7 +5730,7 @@ public SqmExpression<String> xmlforest(List<? extends Expression<?>> elements) {
57415730
57425731 @ Override
57435732 public SqmExpression <String > xmlconcat (Expression <?>... elements ) {
5744- return xmlconcat ( Arrays . asList ( elements ) );
5733+ return xmlconcat ( asList ( elements ) );
57455734 }
57465735
57475736 @ Override
0 commit comments