@@ -180,8 +180,7 @@ public SqmQuerySource getQuerySource() {
180
180
@ Override
181
181
public SqmQuerySpec <T > getQuerySpec () {
182
182
if ( querySource == CRITERIA ) {
183
- final SqmQueryPart <T > queryPart = getQueryPart ();
184
- if ( queryPart instanceof SqmQuerySpec <T > querySpec ) {
183
+ if ( getQueryPart () instanceof SqmQuerySpec <T > querySpec ) {
185
184
return querySpec ;
186
185
}
187
186
throw new IllegalStateException (
@@ -355,9 +354,8 @@ public SqmSelectStatement<T> multiselect(Selection<?>... selections) {
355
354
checkSelectionIsJpaCompliant ( selection );
356
355
}
357
356
}
358
-
359
- final Selection <? extends T > resultSelection = getResultSelection ( selections );
360
- getQuerySpec ().getSelectClause ().setSelection ( (SqmSelectableNode <?>) resultSelection );
357
+ getQuerySpec ().getSelectClause ()
358
+ .setSelection ( (SqmSelectableNode <?>) getResultSelection ( selections ) );
361
359
return this ;
362
360
}
363
361
@@ -368,32 +366,29 @@ public SqmSelectStatement<T> multiselect(List<Selection<?>> selectionList) {
368
366
checkSelectionIsJpaCompliant ( selection );
369
367
}
370
368
}
371
- final Selection <? extends T > resultSelection = getResultSelection ( selectionList );
372
- getQuerySpec (). getSelectClause (). setSelection ( (SqmSelectableNode <?>) resultSelection );
369
+ getQuerySpec (). getSelectClause ()
370
+ . setSelection ( (SqmSelectableNode <?>) getResultSelection ( selectionList ) );
373
371
return this ;
374
372
}
375
373
376
- @ SuppressWarnings ("unchecked" )
377
- private Selection <? extends T > getResultSelection (List <?> selections ) {
374
+ private JpaSelection <?> getResultSelection (List <Selection <?>> selections ) {
378
375
final Class <T > resultType = getResultType ();
379
376
if ( resultType == null || resultType == Object .class ) {
380
- switch ( selections .size () ) {
381
- case 0 :
382
- throw new IllegalArgumentException ( "Empty selections passed to criteria query typed as Object" );
383
- case 1 :
384
- return (Selection <? extends T >) selections .get ( 0 );
385
- default :
386
- return (Selection <? extends T >) nodeBuilder ().array ( (List <Selection <?>>) selections );
387
- }
377
+ return switch ( selections .size () ) {
378
+ case 0 -> throw new IllegalArgumentException (
379
+ "empty selections passed to criteria query typed as Object" );
380
+ case 1 -> (JpaSelection <?>) selections .get ( 0 );
381
+ default -> nodeBuilder ().array ( selections );
382
+ };
388
383
}
389
384
else if ( Tuple .class .isAssignableFrom ( resultType ) ) {
390
- return ( Selection <? extends T >) nodeBuilder ().tuple ( ( List < Selection <?>>) selections );
385
+ return nodeBuilder ().tuple ( selections );
391
386
}
392
387
else if ( resultType .isArray () ) {
393
- return nodeBuilder ().array ( resultType , ( List <? extends JpaSelection <?>>) selections );
388
+ return nodeBuilder ().array ( resultType , selections );
394
389
}
395
390
else {
396
- return nodeBuilder ().construct ( resultType , ( List <? extends JpaSelection <?>>) selections );
391
+ return nodeBuilder ().construct ( resultType , selections );
397
392
}
398
393
}
399
394
@@ -566,10 +561,12 @@ private <S> void aliasSelections(SqmQueryPart<S> queryPart) {
566
561
final SqmQuerySpec <S > querySpec = queryPart .getFirstQuerySpec ();
567
562
final LinkedHashSet <JpaSelection <?>> newSelections = new LinkedHashSet <>();
568
563
aliasSelection ( querySpec .getSelection (), newSelections );
564
+ final JpaSelection <?> selection =
565
+ newSelections .size () == 1
566
+ ? newSelections .iterator ().next ()
567
+ : nodeBuilder ().tuple ( newSelections .toArray ( new JpaSelection <?>[0 ] ) );
569
568
//noinspection unchecked
570
- querySpec .setSelection ( (JpaSelection <S >) ( newSelections .size () == 1 ?
571
- newSelections .iterator ().next () :
572
- nodeBuilder ().tuple ( newSelections .toArray ( new JpaSelection <?>[0 ] ) ) ) );
569
+ querySpec .setSelection ( (JpaSelection <S >) selection );
573
570
}
574
571
else {
575
572
( (SqmQueryGroup <?>) queryPart ).getQueryParts ().forEach ( this ::aliasSelections );
0 commit comments