18
18
import jakarta .persistence .metamodel .Attribute ;
19
19
import jakarta .persistence .metamodel .PluralAttribute ;
20
20
21
- import org .springframework .data .domain .Sort ;
22
- import org .springframework .lang .Nullable ;
23
- import org .springframework .util .Assert ;
24
-
25
21
import java .io .Serial ;
26
22
import java .util .ArrayList ;
27
23
import java .util .Arrays ;
28
24
import java .util .Collection ;
29
25
import java .util .Collections ;
30
26
import java .util .List ;
31
27
28
+ import org .springframework .data .domain .Sort ;
29
+ import org .springframework .lang .Nullable ;
30
+ import org .springframework .util .Assert ;
31
+
32
32
/**
33
- * Sort option for queries that wraps JPA meta-model {@link Attribute}s for sorting.
33
+ * Sort option for queries that wraps JPA metamodel {@link Attribute}s for sorting.
34
+ * <p>
35
+ * {@link JpaSort#unsafe} accepts unsafe sort expressions, i. e. the String provided is not necessarily a property but
36
+ * can be an arbitrary expression piped into the query execution.
34
37
*
35
38
* @author Thomas Darimont
36
39
* @author Oliver Gierke
@@ -44,7 +47,7 @@ public class JpaSort extends Sort {
44
47
@ Serial private static final long serialVersionUID = 1L ;
45
48
46
49
private JpaSort (Direction direction , List <Path <?, ?>> paths ) {
47
- this (Collections .<Order >emptyList (), direction , paths );
50
+ this (Collections .<Order > emptyList (), direction , paths );
48
51
}
49
52
50
53
private JpaSort (List <Order > orders , @ Nullable Direction direction , List <Path <?, ?>> paths ) {
@@ -76,7 +79,7 @@ public static JpaSort of(JpaSort.Path<?, ?>... paths) {
76
79
/**
77
80
* Creates a new {@link JpaSort} for the given direction and attributes.
78
81
*
79
- * @param direction the sorting direction.
82
+ * @param direction the sorting direction.
80
83
* @param attributes must not be {@literal null} or empty.
81
84
*/
82
85
public static JpaSort of (Direction direction , Attribute <?, ?>... attributes ) {
@@ -87,7 +90,7 @@ public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
87
90
* Creates a new {@link JpaSort} for the given direction and {@link Path}s.
88
91
*
89
92
* @param direction the sorting direction.
90
- * @param paths must not be {@literal null} or empty.
93
+ * @param paths must not be {@literal null} or empty.
91
94
*/
92
95
public static JpaSort of (Direction direction , Path <?, ?>... paths ) {
93
96
return new JpaSort (direction , Arrays .asList (paths ));
@@ -96,7 +99,7 @@ public static JpaSort of(Direction direction, Path<?, ?>... paths) {
96
99
/**
97
100
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
98
101
*
99
- * @param direction can be {@literal null}.
102
+ * @param direction can be {@literal null}.
100
103
* @param attributes must not be {@literal null}.
101
104
* @return
102
105
*/
@@ -111,7 +114,7 @@ public JpaSort and(@Nullable Direction direction, Attribute<?, ?>... attributes)
111
114
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
112
115
*
113
116
* @param direction can be {@literal null}.
114
- * @param paths must not be {@literal null}.
117
+ * @param paths must not be {@literal null}.
115
118
* @return
116
119
*/
117
120
public JpaSort and (@ Nullable Direction direction , Path <?, ?>... paths ) {
@@ -130,7 +133,7 @@ public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
130
133
/**
131
134
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
132
135
*
133
- * @param direction can be {@literal null}.
136
+ * @param direction can be {@literal null}.
134
137
* @param properties must not be {@literal null} or empty.
135
138
* @return
136
139
*/
@@ -148,7 +151,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
148
151
orders .add (new JpaOrder (direction , property ));
149
152
}
150
153
151
- return new JpaSort (orders , direction , Collections .<Path <?, ?>>emptyList ());
154
+ return new JpaSort (orders , direction , Collections .<Path <?, ?>> emptyList ());
152
155
}
153
156
154
157
/**
@@ -219,7 +222,7 @@ public static JpaSort unsafe(String... properties) {
219
222
/**
220
223
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
221
224
*
222
- * @param direction must not be {@literal null}.
225
+ * @param direction must not be {@literal null}.
223
226
* @param properties must not be {@literal null} or empty.
224
227
* @return
225
228
*/
@@ -235,7 +238,7 @@ public static JpaSort unsafe(Direction direction, String... properties) {
235
238
/**
236
239
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
237
240
*
238
- * @param direction must not be {@literal null}.
241
+ * @param direction must not be {@literal null}.
239
242
* @param properties must not be {@literal null} or empty.
240
243
* @return
241
244
*/
@@ -327,7 +330,7 @@ public static class JpaOrder extends Order {
327
330
* {@link Sort#DEFAULT_DIRECTION}
328
331
*
329
332
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
330
- * @param property must not be {@literal null}.
333
+ * @param property must not be {@literal null}.
331
334
*/
332
335
private JpaOrder (@ Nullable Direction direction , String property ) {
333
336
this (direction , property , NullHandling .NATIVE );
@@ -337,16 +340,16 @@ private JpaOrder(@Nullable Direction direction, String property) {
337
340
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
338
341
* {@link Sort#DEFAULT_DIRECTION}.
339
342
*
340
- * @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
341
- * @param property must not be {@literal null}.
343
+ * @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
344
+ * @param property must not be {@literal null}.
342
345
* @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
343
346
*/
344
347
private JpaOrder (@ Nullable Direction direction , String property , NullHandling nullHandlingHint ) {
345
348
this (direction , property , false , nullHandlingHint , true );
346
349
}
347
350
348
351
private JpaOrder (@ Nullable Direction direction , String property , boolean ignoreCase , NullHandling nullHandling ,
349
- boolean unsafe ) {
352
+ boolean unsafe ) {
350
353
351
354
super (direction , property , ignoreCase , nullHandling );
352
355
this .unsafe = unsafe ;
0 commit comments