Skip to content

Commit b5aa7de

Browse files
committed
Polishing.
Refine temporal literal handling. Update documentation. See #3172 Original pull request: #3187
1 parent 648371b commit b5aa7de

File tree

6 files changed

+339
-126
lines changed

6 files changed

+339
-126
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java

+21-18
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
import jakarta.persistence.metamodel.Attribute;
1919
import 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-
2521
import java.io.Serial;
2622
import java.util.ArrayList;
2723
import java.util.Arrays;
2824
import java.util.Collection;
2925
import java.util.Collections;
3026
import 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
@@ -43,7 +46,7 @@ public class JpaSort extends Sort {
4346
@Serial private static final long serialVersionUID = 1L;
4447

4548
private JpaSort(Direction direction, List<Path<?, ?>> paths) {
46-
this(Collections.<Order>emptyList(), direction, paths);
49+
this(Collections.<Order> emptyList(), direction, paths);
4750
}
4851

4952
private JpaSort(List<Order> orders, @Nullable Direction direction, List<Path<?, ?>> paths) {
@@ -75,7 +78,7 @@ public static JpaSort of(JpaSort.Path<?, ?>... paths) {
7578
/**
7679
* Creates a new {@link JpaSort} for the given direction and attributes.
7780
*
78-
* @param direction the sorting direction.
81+
* @param direction the sorting direction.
7982
* @param attributes must not be {@literal null} or empty.
8083
*/
8184
public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
@@ -86,7 +89,7 @@ public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
8689
* Creates a new {@link JpaSort} for the given direction and {@link Path}s.
8790
*
8891
* @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.
9093
*/
9194
public static JpaSort of(Direction direction, Path<?, ?>... paths) {
9295
return new JpaSort(direction, Arrays.asList(paths));
@@ -95,7 +98,7 @@ public static JpaSort of(Direction direction, Path<?, ?>... paths) {
9598
/**
9699
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
97100
*
98-
* @param direction can be {@literal null}.
101+
* @param direction can be {@literal null}.
99102
* @param attributes must not be {@literal null}.
100103
* @return
101104
*/
@@ -110,7 +113,7 @@ public JpaSort and(@Nullable Direction direction, Attribute<?, ?>... attributes)
110113
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
111114
*
112115
* @param direction can be {@literal null}.
113-
* @param paths must not be {@literal null}.
116+
* @param paths must not be {@literal null}.
114117
* @return
115118
*/
116119
public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
@@ -129,7 +132,7 @@ public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
129132
/**
130133
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
131134
*
132-
* @param direction can be {@literal null}.
135+
* @param direction can be {@literal null}.
133136
* @param properties must not be {@literal null} or empty.
134137
* @return
135138
*/
@@ -147,7 +150,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
147150
orders.add(new JpaOrder(direction, property));
148151
}
149152

150-
return new JpaSort(orders, direction, Collections.<Path<?, ?>>emptyList());
153+
return new JpaSort(orders, direction, Collections.<Path<?, ?>> emptyList());
151154
}
152155

153156
/**
@@ -218,7 +221,7 @@ public static JpaSort unsafe(String... properties) {
218221
/**
219222
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
220223
*
221-
* @param direction must not be {@literal null}.
224+
* @param direction must not be {@literal null}.
222225
* @param properties must not be {@literal null} or empty.
223226
* @return
224227
*/
@@ -234,7 +237,7 @@ public static JpaSort unsafe(Direction direction, String... properties) {
234237
/**
235238
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
236239
*
237-
* @param direction must not be {@literal null}.
240+
* @param direction must not be {@literal null}.
238241
* @param properties must not be {@literal null} or empty.
239242
* @return
240243
*/
@@ -326,7 +329,7 @@ public static class JpaOrder extends Order {
326329
* {@link Sort#DEFAULT_DIRECTION}
327330
*
328331
* @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}.
330333
*/
331334
private JpaOrder(@Nullable Direction direction, String property) {
332335
this(direction, property, NullHandling.NATIVE);
@@ -336,16 +339,16 @@ private JpaOrder(@Nullable Direction direction, String property) {
336339
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
337340
* {@link Sort#DEFAULT_DIRECTION}.
338341
*
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}.
341344
* @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
342345
*/
343346
private JpaOrder(@Nullable Direction direction, String property, NullHandling nullHandlingHint) {
344347
this(direction, property, false, nullHandlingHint, true);
345348
}
346349

347350
private JpaOrder(@Nullable Direction direction, String property, boolean ignoreCase, NullHandling nullHandling,
348-
boolean unsafe) {
351+
boolean unsafe) {
349352

350353
super(direction, property, ignoreCase, nullHandling);
351354
this.unsafe = unsafe;

0 commit comments

Comments
 (0)