@@ -94,6 +94,11 @@ public String getPropertyName() {
94
94
95
95
abstract boolean isNullable (int index );
96
96
97
+ boolean initiallyUnwrapped () {
98
+ return !isUsingEntityManager () // a TypedQuery from EntityManager is not a SelectionQuery
99
+ || isUsingSpecification () && !isReactive (); // SelectionSpecification.createQuery() returns SelectionQuery
100
+ }
101
+
97
102
List <String > parameterTypes () {
98
103
return paramTypes .stream ()
99
104
.map (paramType -> isOrderParam (paramType ) && paramType .endsWith ("[]" )
@@ -275,19 +280,6 @@ else if ( jakartaPageRequest ) {
275
280
}
276
281
}
277
282
278
- void handleSorting (
279
- StringBuilder declaration , List <String > paramTypes ,
280
- @ Nullable String containerType ) {
281
- if ( !isJakartaCursoredPage (containerType )
282
- && hasOrdering (paramTypes ) ) {
283
- if ( !isUsingSpecification () ) {
284
- throw new AssertionError ();
285
- }
286
- declaration
287
- .append ("\t _spec.resort(_orders);\n " );
288
- }
289
- }
290
-
291
283
void handlePageParameters (
292
284
StringBuilder declaration , List <String > paramTypes ,
293
285
@ Nullable String containerType ) {
@@ -547,22 +539,34 @@ private void totalResults(StringBuilder declaration, List<String> paramTypes) {
547
539
}
548
540
}
549
541
550
- void collectOrdering (StringBuilder declaration , List <String > paramTypes ) {
542
+ void collectOrdering (StringBuilder declaration , List <String > paramTypes , @ Nullable String containerType ) {
551
543
if ( hasOrdering (paramTypes ) ) {
552
544
if ( returnTypeName != null ) {
553
- declaration
554
- .append ("\t var _orders = new " )
555
- .append (annotationMetaEntity .importType ("java.util.ArrayList" ))
556
- .append ("<" )
557
- .append (annotationMetaEntity .importType (HIB_ORDER ))
558
- .append ("<? super " )
559
- .append (annotationMetaEntity .importType (returnTypeName ))
560
- .append (">>();\n " );
545
+ final boolean cursoredPage = isJakartaCursoredPage ( containerType );
546
+ final String add ;
547
+ if ( cursoredPage ) {
548
+ // we need to collect them together in a List
549
+ declaration
550
+ .append ("\t var _orders = new " )
551
+ .append (annotationMetaEntity .importType ("java.util.ArrayList" ))
552
+ .append ("<" )
553
+ .append (annotationMetaEntity .importType (HIB_ORDER ))
554
+ .append ("<? super " )
555
+ .append (annotationMetaEntity .importType (returnTypeName ))
556
+ .append (">>();\n " );
557
+ add = "_orders.add" ;
558
+ }
559
+ else {
560
+ add = "_spec.sort" ;
561
+ }
562
+
561
563
// static orders declared using @OrderBy must come first
562
564
for ( OrderBy orderBy : orderBys ) {
563
565
annotationMetaEntity .staticImport (HIB_SORT_DIRECTION , "*" );
564
566
declaration
565
- .append ("\t _orders.add(" )
567
+ .append ("\t " )
568
+ .append (add )
569
+ .append ('(' )
566
570
.append (annotationMetaEntity .staticImport (HIB_ORDER , orderBy .descending ? "desc" : "asc" ))
567
571
.append ('(' )
568
572
.append (annotationMetaEntity .importType (returnTypeName ))
@@ -585,28 +589,46 @@ void collectOrdering(StringBuilder declaration, List<String> paramTypes) {
585
589
.append ("\t for (var _sort : " )
586
590
.append (name )
587
591
.append (") {\n " )
588
- .append ("\t \t _orders.add(_sort);\n " )
592
+ .append ("\t \t " )
593
+ .append (add )
594
+ .append ("(_sort);\n " )
589
595
.append ("\t }\n " );
590
596
}
591
597
else if ( type .startsWith (HIB_ORDER ) ) {
592
598
declaration
593
- .append ("\t _orders.add(" )
599
+ .append ("\t " )
600
+ .append (add )
601
+ .append ('(' )
594
602
.append (name )
595
603
.append (");\n " );
596
604
}
597
605
else if ( type .startsWith (LIST + "<" + HIB_ORDER ) ) {
598
- declaration
599
- .append ("\t _orders.addAll(" )
600
- .append (name )
601
- .append (");\n " );
606
+ if ( cursoredPage ) {
607
+ declaration
608
+ .append ("\t _orders.addAll(" )
609
+ .append (name )
610
+ .append (");\n " );
611
+ }
612
+ else {
613
+ declaration
614
+ .append ("\t for (var _sort : " )
615
+ .append (name )
616
+ .append (") {\n " )
617
+ .append ("\t \t " )
618
+ .append (add )
619
+ .append ("(_sort);\n " )
620
+ .append ("\t }\n " );
621
+ }
602
622
}
603
623
else if ( type .startsWith (JD_ORDER ) ) {
604
624
annotationMetaEntity .staticImport (HIB_SORT_DIRECTION , "*" );
605
625
declaration
606
626
.append ("\t for (var _sort : " )
607
627
.append (name )
608
628
.append (".sorts()) {\n " )
609
- .append ("\t \t _orders.add(" )
629
+ .append ("\t \t " )
630
+ .append (add )
631
+ .append ('(' )
610
632
.append (annotationMetaEntity .staticImport (HIB_ORDER , "asc" ))
611
633
.append ('(' )
612
634
.append (annotationMetaEntity .importType (returnTypeName ))
@@ -624,7 +646,9 @@ else if ( type.startsWith(JD_SORT) && type.endsWith("...") ) {
624
646
.append ("\t for (var _sort : " )
625
647
.append (name )
626
648
.append (") {\n " )
627
- .append ("\t \t _orders.add(" )
649
+ .append ("\t \t " )
650
+ .append (add )
651
+ .append ('(' )
628
652
.append (annotationMetaEntity .staticImport (HIB_ORDER , "asc" ))
629
653
.append ('(' )
630
654
.append (annotationMetaEntity .importType (returnTypeName ))
@@ -638,7 +662,9 @@ else if ( type.startsWith(JD_SORT) && type.endsWith("...") ) {
638
662
else if ( type .startsWith (JD_SORT ) ) {
639
663
annotationMetaEntity .staticImport (HIB_SORT_DIRECTION , "*" );
640
664
declaration
641
- .append ("\t _orders.add(" )
665
+ .append ("\t " )
666
+ .append (add )
667
+ .append ('(' )
642
668
.append (annotationMetaEntity .staticImport (HIB_ORDER , "asc" ))
643
669
.append ('(' )
644
670
.append (annotationMetaEntity .importType (returnTypeName ))
0 commit comments