127
127
import org .hibernate .query .sqm .tree .predicate .SqmNullnessPredicate ;
128
128
import org .hibernate .query .sqm .tree .predicate .SqmPredicate ;
129
129
import org .hibernate .query .sqm .tree .select .SqmDynamicInstantiation ;
130
- import org .hibernate .query .sqm .tree .select .SqmDynamicInstantiationArgument ;
131
130
import org .hibernate .query .sqm .tree .select .SqmJpaCompoundSelection ;
132
131
import org .hibernate .query .sqm .tree .select .SqmOrderByClause ;
133
132
import org .hibernate .query .sqm .tree .select .SqmQueryGroup ;
169
168
import static org .hibernate .internal .util .collections .CollectionHelper .determineProperSizing ;
170
169
import static org .hibernate .query .internal .QueryHelper .highestPrecedenceType ;
171
170
import 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 ;
172
174
173
175
/**
174
176
* Acts as a JPA {@link jakarta.persistence.criteria.CriteriaBuilder} by
@@ -374,7 +376,7 @@ public <T> SqmInsertSelectStatement<T> createCriteriaInsertSelect(Class<T> targe
374
376
375
377
@ Override
376
378
public SqmValues values (Expression <?>... expressions ) {
377
- return values ( Arrays . asList ( expressions ) );
379
+ return values ( asList ( expressions ) );
378
380
}
379
381
380
382
@ Override
@@ -873,15 +875,14 @@ public JpaSearchOrder desc(JpaCteCriteriaAttribute x, boolean nullsFirst) {
873
875
874
876
@ Override
875
877
public JpaCompoundSelection <Tuple > tuple (Selection <?>... selections ) {
876
- return tuple ( Arrays . asList ( selections ) );
878
+ return tuple ( asList ( selections ) );
877
879
}
878
880
879
881
@ Override
880
882
public JpaCompoundSelection <Tuple > tuple (List <Selection <?>> selections ) {
881
883
checkMultiselect ( selections );
882
- //noinspection unchecked,rawtypes
883
884
return new SqmJpaCompoundSelection <>(
884
- ( List ) selections ,
885
+ selections . stream (). map ( selection -> ( SqmSelectableNode <?>) selection ). toList () ,
885
886
getTypeConfiguration ().getJavaTypeRegistry ().getDescriptor ( Tuple .class ),
886
887
this
887
888
);
@@ -892,6 +893,11 @@ public <R> SqmTuple<R> tuple(Class<R> tupleType, SqmExpression<?>... expressions
892
893
return tuple ( tupleType , asList ( expressions ) );
893
894
}
894
895
896
+ @ Override
897
+ public <R > SqmTuple <R > tuple (SqmExpressible <R > tupleType , SqmExpression <?>... expressions ) {
898
+ return tuple ( tupleType , asList ( expressions ) );
899
+ }
900
+
895
901
@ Override @ SuppressWarnings ("unchecked" )
896
902
public <R > SqmTuple <R > tuple (Class <R > tupleType , List <? extends SqmExpression <?>> expressions ) {
897
903
final SqmExpressible <R > expressibleType =
@@ -901,11 +907,6 @@ public <R> SqmTuple<R> tuple(Class<R> tupleType, List<? extends SqmExpression<?>
901
907
return tuple ( expressibleType , expressions );
902
908
}
903
909
904
- @ Override
905
- public <R > SqmTuple <R > tuple (SqmExpressible <R > tupleType , SqmExpression <?>... expressions ) {
906
- return tuple ( tupleType , asList ( expressions ) );
907
- }
908
-
909
910
@ Override
910
911
public <R > SqmTuple <R > tuple (SqmExpressible <R > tupleType , List <? extends SqmExpression <?>> sqmExpressions ) {
911
912
if ( tupleType == null ) {
@@ -957,63 +958,51 @@ public <Y> JpaCompoundSelection<Y> construct(Class<Y> resultClass, List<? extend
957
958
arguments .stream ().map ( arg -> (SqmSelectableNode <?>) arg ).toList () );
958
959
}
959
960
961
+ @ SuppressWarnings ("unchecked" )
960
962
private <Y > JpaCompoundSelection <Y > constructInternal (Class <Y > resultClass , List <? extends SqmSelectableNode <?>> arguments ) {
961
963
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 ) {
973
964
if ( List .class .equals ( resultClass ) ) {
974
- return (SqmDynamicInstantiation <Y >) SqmDynamicInstantiation . forListInstantiation ( this );
965
+ return (SqmDynamicInstantiation <Y >) listInstantiation ( arguments , this );
975
966
}
976
967
else if ( Map .class .equals ( resultClass ) ) {
977
- return (SqmDynamicInstantiation <Y >) SqmDynamicInstantiation . forMapInstantiation ( this );
968
+ return (SqmDynamicInstantiation <Y >) mapInstantiation ( arguments , this );
978
969
}
979
970
else {
980
- return SqmDynamicInstantiation . forClassInstantiation ( resultClass , this );
971
+ return classInstantiation ( resultClass , arguments , this );
981
972
}
982
973
}
983
974
984
975
/**
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}.
987
979
*
988
980
* @param selections The selection varargs to check
989
981
*
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>
994
986
*/
995
- void checkMultiselect (List <? extends Selection <?>> selections ) {
987
+ private void checkMultiselect (List <? extends Selection <?>> selections ) {
996
988
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 ) {
1000
990
if ( selection .isCompoundSelection () ) {
1001
- if ( selection .getJavaType ().isArray () ) {
991
+ final Class <?> javaType = selection .getJavaType ();
992
+ if ( javaType .isArray () ) {
1002
993
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"
1004
995
);
1005
996
}
1006
- if ( Tuple .class .isAssignableFrom ( selection . getJavaType () ) ) {
997
+ if ( Tuple .class .isAssignableFrom ( javaType ) ) {
1007
998
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"
1009
1000
);
1010
1001
}
1011
1002
}
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 + "'" );
1017
1006
}
1018
1007
}
1019
1008
}
@@ -1161,7 +1150,7 @@ public JpaExpression<Double> ln(Expression<? extends Number> x) {
1161
1150
@ Override
1162
1151
public JpaExpression <Double > power (Expression <? extends Number > x , Expression <? extends Number > y ) {
1163
1152
return getFunctionDescriptor ( "power" ).generateSqmExpression (
1164
- Arrays . asList ( (SqmExpression <?>) x , (SqmExpression <?>) y ),
1153
+ asList ( (SqmExpression <?>) x , (SqmExpression <?>) y ),
1165
1154
null ,
1166
1155
queryEngine
1167
1156
);
@@ -1170,7 +1159,7 @@ public JpaExpression<Double> power(Expression<? extends Number> x, Expression<?
1170
1159
@ Override
1171
1160
public JpaExpression <Double > power (Expression <? extends Number > x , Number y ) {
1172
1161
return getFunctionDescriptor ( "power" ).generateSqmExpression (
1173
- Arrays . asList ( (SqmExpression <?>) x , value ( y ) ),
1162
+ asList ( (SqmExpression <?>) x , value ( y ) ),
1174
1163
null ,
1175
1164
queryEngine
1176
1165
);
@@ -1179,7 +1168,7 @@ public JpaExpression<Double> power(Expression<? extends Number> x, Number y) {
1179
1168
@ Override
1180
1169
public <T extends Number > JpaExpression <T > round (Expression <T > x , Integer n ) {
1181
1170
return getFunctionDescriptor ( "round" ).generateSqmExpression (
1182
- Arrays . asList ( (SqmExpression <?>) x , value ( n ) ),
1171
+ asList ( (SqmExpression <?>) x , value ( n ) ),
1183
1172
null ,
1184
1173
queryEngine
1185
1174
);
@@ -1188,7 +1177,7 @@ public <T extends Number> JpaExpression<T> round(Expression<T> x, Integer n) {
1188
1177
@ Override
1189
1178
public <T extends Number > JpaExpression <T > truncate (Expression <T > x , Integer n ) {
1190
1179
return getFunctionDescriptor ( "truncate" ).generateSqmExpression (
1191
- Arrays . asList ( (SqmExpression <?>) x , value ( n ) ),
1180
+ asList ( (SqmExpression <?>) x , value ( n ) ),
1192
1181
null ,
1193
1182
queryEngine
1194
1183
);
@@ -5532,7 +5521,7 @@ private SqmExpression<String> jsonArrayAgg(
5532
5521
return getFunctionDescriptor ( "json_arrayagg" ).generateOrderedSetAggregateSqmExpression (
5533
5522
nullBehavior == null
5534
5523
? Collections .singletonList ( value )
5535
- : Arrays . asList ( value , SqmJsonNullBehavior .NULL ),
5524
+ : asList ( value , SqmJsonNullBehavior .NULL ),
5536
5525
filterPredicate ,
5537
5526
orderByClause ,
5538
5527
null ,
@@ -5712,7 +5701,7 @@ public <T> SqmExpression<T> named(Expression<T> expression, String name) {
5712
5701
5713
5702
@ Override
5714
5703
public SqmExpression <String > xmlforest (Expression <?>... elements ) {
5715
- return xmlforest ( Arrays . asList ( elements ) );
5704
+ return xmlforest ( asList ( elements ) );
5716
5705
}
5717
5706
5718
5707
@ Override
@@ -5741,7 +5730,7 @@ public SqmExpression<String> xmlforest(List<? extends Expression<?>> elements) {
5741
5730
5742
5731
@ Override
5743
5732
public SqmExpression <String > xmlconcat (Expression <?>... elements ) {
5744
- return xmlconcat ( Arrays . asList ( elements ) );
5733
+ return xmlconcat ( asList ( elements ) );
5745
5734
}
5746
5735
5747
5736
@ Override
0 commit comments