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
@@ -43,7 +46,7 @@ public class JpaSort extends Sort {
43
46
@ Serial private static final long serialVersionUID = 1L ;
44
47
45
48
private JpaSort (Direction direction , List <Path <?, ?>> paths ) {
46
- this (Collections .<Order >emptyList (), direction , paths );
49
+ this (Collections .<Order > emptyList (), direction , paths );
47
50
}
48
51
49
52
private JpaSort (List <Order > orders , @ Nullable Direction direction , List <Path <?, ?>> paths ) {
@@ -75,7 +78,7 @@ public static JpaSort of(JpaSort.Path<?, ?>... paths) {
75
78
/**
76
79
* Creates a new {@link JpaSort} for the given direction and attributes.
77
80
*
78
- * @param direction the sorting direction.
81
+ * @param direction the sorting direction.
79
82
* @param attributes must not be {@literal null} or empty.
80
83
*/
81
84
public static JpaSort of (Direction direction , Attribute <?, ?>... attributes ) {
@@ -86,7 +89,7 @@ public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
86
89
* Creates a new {@link JpaSort} for the given direction and {@link Path}s.
87
90
*
88
91
* @param direction the sorting direction.
89
- * @param paths must not be {@literal null} or empty.
92
+ * @param paths must not be {@literal null} or empty.
90
93
*/
91
94
public static JpaSort of (Direction direction , Path <?, ?>... paths ) {
92
95
return new JpaSort (direction , Arrays .asList (paths ));
@@ -95,7 +98,7 @@ public static JpaSort of(Direction direction, Path<?, ?>... paths) {
95
98
/**
96
99
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
97
100
*
98
- * @param direction can be {@literal null}.
101
+ * @param direction can be {@literal null}.
99
102
* @param attributes must not be {@literal null}.
100
103
* @return
101
104
*/
@@ -110,7 +113,7 @@ public JpaSort and(@Nullable Direction direction, Attribute<?, ?>... attributes)
110
113
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
111
114
*
112
115
* @param direction can be {@literal null}.
113
- * @param paths must not be {@literal null}.
116
+ * @param paths must not be {@literal null}.
114
117
* @return
115
118
*/
116
119
public JpaSort and (@ Nullable Direction direction , Path <?, ?>... paths ) {
@@ -129,7 +132,7 @@ public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
129
132
/**
130
133
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
131
134
*
132
- * @param direction can be {@literal null}.
135
+ * @param direction can be {@literal null}.
133
136
* @param properties must not be {@literal null} or empty.
134
137
* @return
135
138
*/
@@ -147,7 +150,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
147
150
orders .add (new JpaOrder (direction , property ));
148
151
}
149
152
150
- return new JpaSort (orders , direction , Collections .<Path <?, ?>>emptyList ());
153
+ return new JpaSort (orders , direction , Collections .<Path <?, ?>> emptyList ());
151
154
}
152
155
153
156
/**
@@ -218,7 +221,7 @@ public static JpaSort unsafe(String... properties) {
218
221
/**
219
222
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
220
223
*
221
- * @param direction must not be {@literal null}.
224
+ * @param direction must not be {@literal null}.
222
225
* @param properties must not be {@literal null} or empty.
223
226
* @return
224
227
*/
@@ -234,7 +237,7 @@ public static JpaSort unsafe(Direction direction, String... properties) {
234
237
/**
235
238
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
236
239
*
237
- * @param direction must not be {@literal null}.
240
+ * @param direction must not be {@literal null}.
238
241
* @param properties must not be {@literal null} or empty.
239
242
* @return
240
243
*/
@@ -326,7 +329,7 @@ public static class JpaOrder extends Order {
326
329
* {@link Sort#DEFAULT_DIRECTION}
327
330
*
328
331
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
329
- * @param property must not be {@literal null}.
332
+ * @param property must not be {@literal null}.
330
333
*/
331
334
private JpaOrder (@ Nullable Direction direction , String property ) {
332
335
this (direction , property , NullHandling .NATIVE );
@@ -336,16 +339,16 @@ private JpaOrder(@Nullable Direction direction, String property) {
336
339
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
337
340
* {@link Sort#DEFAULT_DIRECTION}.
338
341
*
339
- * @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
340
- * @param property must not be {@literal null}.
342
+ * @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
343
+ * @param property must not be {@literal null}.
341
344
* @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
342
345
*/
343
346
private JpaOrder (@ Nullable Direction direction , String property , NullHandling nullHandlingHint ) {
344
347
this (direction , property , false , nullHandlingHint , true );
345
348
}
346
349
347
350
private JpaOrder (@ Nullable Direction direction , String property , boolean ignoreCase , NullHandling nullHandling ,
348
- boolean unsafe ) {
351
+ boolean unsafe ) {
349
352
350
353
super (direction , property , ignoreCase , nullHandling );
351
354
this .unsafe = unsafe ;
0 commit comments