Support NullHandling in QueryUtils.
Closes #3811 Signed-off-by: Alim <alim.naizabek@gmail.com>
This commit is contained in:
@@ -85,6 +85,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Pranav HS
|
||||
* @author Eduard Dudar
|
||||
* @author Yanming Zhou
|
||||
* @author Alim Naizabek
|
||||
*/
|
||||
public abstract class QueryUtils {
|
||||
|
||||
@@ -428,7 +429,13 @@ public abstract class QueryUtils {
|
||||
}
|
||||
|
||||
private static String toJpaDirection(Order order) {
|
||||
return order.getDirection().name().toLowerCase(Locale.US);
|
||||
String direction = order.getDirection().name().toLowerCase(Locale.US);
|
||||
if (order.getNullHandling() == Sort.NullHandling.NULLS_FIRST) {
|
||||
direction += " nulls first";
|
||||
} else if (order.getNullHandling() == Sort.NullHandling.NULLS_LAST) {
|
||||
direction += " nulls last";
|
||||
}
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,4 +48,14 @@ public class DefaultQueryEnhancerUnitTests extends QueryEnhancerTckTests {
|
||||
|
||||
assertThat(sql).isEqualTo("SELECT e FROM Employee e order by e.foo asc, e.bar asc");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldApplySortingWithNullHandling() {
|
||||
|
||||
QueryEnhancer enhancer = createQueryEnhancer(DeclaredQuery.of("SELECT e FROM Employee e", true));
|
||||
|
||||
String sql = enhancer.applySorting(Sort.by(Sort.Order.asc("foo").nullsFirst(), Sort.Order.asc("bar").nullsLast()));
|
||||
|
||||
assertThat(sql).isEqualTo("SELECT e FROM Employee e order by e.foo asc nulls first, e.bar asc nulls last");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user