1818import jakarta .persistence .metamodel .Attribute ;
1919import jakarta .persistence .metamodel .PluralAttribute ;
2020
21- import org .springframework .data .domain .Sort ;
22- import org .springframework .lang .Nullable ;
23- import org .springframework .util .Assert ;
24-
2521import java .io .Serial ;
2622import java .util .ArrayList ;
2723import java .util .Arrays ;
2824import java .util .Collection ;
2925import java .util .Collections ;
3026import java .util .List ;
3127
28+ import org .springframework .data .domain .Sort ;
29+ import org .springframework .lang .Nullable ;
30+ import org .springframework .util .Assert ;
31+
3232/**
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.
3437 *
3538 * @author Thomas Darimont
3639 * @author Oliver Gierke
@@ -44,7 +47,7 @@ public class JpaSort extends Sort {
4447 @ Serial private static final long serialVersionUID = 1L ;
4548
4649 private JpaSort (Direction direction , List <Path <?, ?>> paths ) {
47- this (Collections .<Order >emptyList (), direction , paths );
50+ this (Collections .<Order > emptyList (), direction , paths );
4851 }
4952
5053 private JpaSort (List <Order > orders , @ Nullable Direction direction , List <Path <?, ?>> paths ) {
@@ -76,7 +79,7 @@ public static JpaSort of(JpaSort.Path<?, ?>... paths) {
7679 /**
7780 * Creates a new {@link JpaSort} for the given direction and attributes.
7881 *
79- * @param direction the sorting direction.
82+ * @param direction the sorting direction.
8083 * @param attributes must not be {@literal null} or empty.
8184 */
8285 public static JpaSort of (Direction direction , Attribute <?, ?>... attributes ) {
@@ -87,7 +90,7 @@ public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
8790 * Creates a new {@link JpaSort} for the given direction and {@link Path}s.
8891 *
8992 * @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.
9194 */
9295 public static JpaSort of (Direction direction , Path <?, ?>... paths ) {
9396 return new JpaSort (direction , Arrays .asList (paths ));
@@ -96,7 +99,7 @@ public static JpaSort of(Direction direction, Path<?, ?>... paths) {
9699 /**
97100 * Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
98101 *
99- * @param direction can be {@literal null}.
102+ * @param direction can be {@literal null}.
100103 * @param attributes must not be {@literal null}.
101104 * @return
102105 */
@@ -111,7 +114,7 @@ public JpaSort and(@Nullable Direction direction, Attribute<?, ?>... attributes)
111114 * Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
112115 *
113116 * @param direction can be {@literal null}.
114- * @param paths must not be {@literal null}.
117+ * @param paths must not be {@literal null}.
115118 * @return
116119 */
117120 public JpaSort and (@ Nullable Direction direction , Path <?, ?>... paths ) {
@@ -130,7 +133,7 @@ public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
130133 /**
131134 * Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
132135 *
133- * @param direction can be {@literal null}.
136+ * @param direction can be {@literal null}.
134137 * @param properties must not be {@literal null} or empty.
135138 * @return
136139 */
@@ -148,7 +151,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
148151 orders .add (new JpaOrder (direction , property ));
149152 }
150153
151- return new JpaSort (orders , direction , Collections .<Path <?, ?>>emptyList ());
154+ return new JpaSort (orders , direction , Collections .<Path <?, ?>> emptyList ());
152155 }
153156
154157 /**
@@ -219,7 +222,7 @@ public static JpaSort unsafe(String... properties) {
219222 /**
220223 * Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
221224 *
222- * @param direction must not be {@literal null}.
225+ * @param direction must not be {@literal null}.
223226 * @param properties must not be {@literal null} or empty.
224227 * @return
225228 */
@@ -235,7 +238,7 @@ public static JpaSort unsafe(Direction direction, String... properties) {
235238 /**
236239 * Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
237240 *
238- * @param direction must not be {@literal null}.
241+ * @param direction must not be {@literal null}.
239242 * @param properties must not be {@literal null} or empty.
240243 * @return
241244 */
@@ -327,7 +330,7 @@ public static class JpaOrder extends Order {
327330 * {@link Sort#DEFAULT_DIRECTION}
328331 *
329332 * @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}.
331334 */
332335 private JpaOrder (@ Nullable Direction direction , String property ) {
333336 this (direction , property , NullHandling .NATIVE );
@@ -337,16 +340,16 @@ private JpaOrder(@Nullable Direction direction, String property) {
337340 * Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
338341 * {@link Sort#DEFAULT_DIRECTION}.
339342 *
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}.
342345 * @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
343346 */
344347 private JpaOrder (@ Nullable Direction direction , String property , NullHandling nullHandlingHint ) {
345348 this (direction , property , false , nullHandlingHint , true );
346349 }
347350
348351 private JpaOrder (@ Nullable Direction direction , String property , boolean ignoreCase , NullHandling nullHandling ,
349- boolean unsafe ) {
352+ boolean unsafe ) {
350353
351354 super (direction , property , ignoreCase , nullHandling );
352355 this .unsafe = unsafe ;
0 commit comments