Skip to content

Commit 4066df9

Browse files
committed
Polishing.
Rename "null handling" to "null precedence". This is somewhat inconsistent with commons null handling, but more descriptive. Minor formatting. Original pull request #1156 See #821
1 parent 60a59b6 commit 4066df9

File tree

10 files changed

+34
-29
lines changed

10 files changed

+34
-29
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ void saveAndLoadManyEntitiesWithReferencedEntitySortedAndPaged() {
258258
}
259259

260260
@Test // GH-821
261-
@EnabledOnFeature({SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_HANDLING})
262-
void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullHandling() {
261+
@EnabledOnFeature({SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_PRECEDENCE})
262+
void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullPrecedence() {
263263

264264
template.save(createLegoSet(null));
265265
template.save(createLegoSet("Star"));

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/TestDatabaseFeatures.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void supportsMultiDimensionalArrays() {
8484
assumeThat(database).isNotIn(Database.H2, Database.Hsql);
8585
}
8686

87-
private void supportsNullHandling() {
87+
private void supportsNullPrecedence() {
8888
assumeThat(database).isNotIn(Database.MySql, Database.MariaDb, Database.SqlServer);
8989
}
9090

@@ -120,7 +120,7 @@ public enum Feature {
120120
SUPPORTS_ARRAYS(TestDatabaseFeatures::supportsArrays), //
121121
SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES(TestDatabaseFeatures::supportsGeneratedIdsInReferencedEntities), //
122122
SUPPORTS_NANOSECOND_PRECISION(TestDatabaseFeatures::supportsNanosecondPrecision), //
123-
SUPPORTS_NULL_HANDLING(TestDatabaseFeatures::supportsNullHandling),
123+
SUPPORTS_NULL_PRECEDENCE(TestDatabaseFeatures::supportsNullPrecedence),
124124
IS_POSTGRES(f -> f.databaseIs(Database.PostgreSql)), //
125125
IS_HSQL(f -> f.databaseIs(Database.Hsql));
126126

spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/AbstractDialect.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ static class DialectSelectRenderContext implements SelectRenderContext {
103103

104104
private final Function<Select, ? extends CharSequence> afterFromTable;
105105
private final Function<Select, ? extends CharSequence> afterOrderBy;
106-
private final OrderByNullHandling orderByNullHandling;
106+
private final OrderByNullPrecedence orderByNullPrecedence;
107107

108108
DialectSelectRenderContext(Function<Select, ? extends CharSequence> afterFromTable,
109-
Function<Select, ? extends CharSequence> afterOrderBy, OrderByNullHandling orderByNullHandling) {
109+
Function<Select, ? extends CharSequence> afterOrderBy, OrderByNullPrecedence orderByNullPrecedence) {
110110

111111
this.afterFromTable = afterFromTable;
112112
this.afterOrderBy = afterOrderBy;
113-
this.orderByNullHandling = orderByNullHandling;
113+
this.orderByNullPrecedence = orderByNullPrecedence;
114114
}
115115

116116
@Override
@@ -125,7 +125,7 @@ static class DialectSelectRenderContext implements SelectRenderContext {
125125

126126
@Override
127127
public String evaluateOrderByNullHandling(Sort.NullHandling nullHandling) {
128-
return orderByNullHandling.evaluate(nullHandling);
128+
return orderByNullPrecedence.evaluate(nullHandling);
129129
}
130130
}
131131

spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/Dialect.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ default InsertRenderContext getInsertRenderContext() {
123123
}
124124

125125
/**
126-
* Return the {@link OrderByNullHandling} used by this dialect.
126+
* Return the {@link OrderByNullPrecedence} used by this dialect.
127127
*
128-
* @return the {@link OrderByNullHandling} used by this dialect.
128+
* @return the {@link OrderByNullPrecedence} used by this dialect.
129+
* @since 2.4
129130
*/
130-
default OrderByNullHandling orderByNullHandling() {
131-
return OrderByNullHandling.SQL_STANDARD;
131+
default OrderByNullPrecedence orderByNullHandling() {
132+
return OrderByNullPrecedence.SQL_STANDARD;
132133
}
133134
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/MySqlDialect.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public Collection<Object> getConverters() {
135135
}
136136

137137
@Override
138-
public OrderByNullHandling orderByNullHandling() {
139-
return OrderByNullHandling.NONE;
138+
public OrderByNullPrecedence orderByNullHandling() {
139+
return OrderByNullPrecedence.NONE;
140140
}
141141
}
+8-7
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@
2121
* Represents how the {@link Sort.NullHandling} option of an {@code ORDER BY} sort expression is to be evaluated.
2222
*
2323
* @author Chirag Tailor
24+
* @since 2.4
2425
*/
25-
public interface OrderByNullHandling {
26+
public interface OrderByNullPrecedence {
2627
/**
27-
* An {@link OrderByNullHandling} that can be used for databases conforming to the SQL standard which uses
28+
* An {@link OrderByNullPrecedence} that can be used for databases conforming to the SQL standard which uses
2829
* {@code NULLS FIRST} and {@code NULLS LAST} in {@code ORDER BY} sort expressions to make null values appear before
2930
* or after non-null values in the result set.
3031
*/
31-
OrderByNullHandling SQL_STANDARD = new SqlStandardOrderByNullHandling();
32+
OrderByNullPrecedence SQL_STANDARD = new SqlStandardOrderByNullPrecedence();
3233

3334
/**
34-
* An {@link OrderByNullHandling} that can be used for databases that do not support the SQL standard usage of
35+
* An {@link OrderByNullPrecedence} that can be used for databases that do not support the SQL standard usage of
3536
* {@code NULLS FIRST} and {@code NULLS LAST} in {@code ORDER BY} sort expressions to control where null values appear
3637
* respective to non-null values in the result set.
3738
*/
38-
OrderByNullHandling NONE = nullHandling -> "";
39+
OrderByNullPrecedence NONE = nullHandling -> "";
3940

4041
/**
4142
* Converts a {@link Sort.NullHandling} option to the appropriate SQL text to be included an {@code ORDER BY} sort
@@ -44,13 +45,13 @@ public interface OrderByNullHandling {
4445
String evaluate(Sort.NullHandling nullHandling);
4546

4647
/**
47-
* An {@link OrderByNullHandling} implementation for databases conforming to the SQL standard which uses
48+
* An {@link OrderByNullPrecedence} implementation for databases conforming to the SQL standard which uses
4849
* {@code NULLS FIRST} and {@code NULLS LAST} in {@code ORDER BY} sort expressions to make null values appear before
4950
* or after non-null values in the result set.
5051
*
5152
* @author Chirag Tailor
5253
*/
53-
class SqlStandardOrderByNullHandling implements OrderByNullHandling {
54+
class SqlStandardOrderByNullPrecedence implements OrderByNullPrecedence {
5455

5556
private static final String NULLS_FIRST = "NULLS FIRST";
5657
private static final String NULLS_LAST = "NULLS LAST";

spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/SqlServerDialect.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public InsertRenderContext getInsertRenderContext() {
118118
}
119119

120120
@Override
121-
public OrderByNullHandling orderByNullHandling() {
122-
return OrderByNullHandling.NONE;
121+
public OrderByNullPrecedence orderByNullHandling() {
122+
return OrderByNullPrecedence.NONE;
123123
}
124124
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/OrderByClauseVisitor.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ Delegation enterMatched(OrderByField segment) {
5353
Delegation leaveMatched(OrderByField segment) {
5454

5555
if (segment.getDirection() != null) {
56+
5657
builder.append(" ") //
5758
.append(segment.getDirection());
5859
}
5960

60-
String nullHandling = context.getSelectRenderContext().evaluateOrderByNullHandling(segment.getNullHandling());
61-
if (!nullHandling.isEmpty()) {
61+
String nullPrecedence = context.getSelectRenderContext().evaluateOrderByNullHandling(segment.getNullHandling());
62+
if (!nullPrecedence.isEmpty()) {
63+
6264
builder.append(" ") //
63-
.append(nullHandling);
65+
.append(nullPrecedence);
6466
}
6567

6668
return Delegation.leave();

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/SelectRenderContext.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.function.Function;
2020

2121
import org.springframework.data.domain.Sort;
22-
import org.springframework.data.relational.core.dialect.OrderByNullHandling;
22+
import org.springframework.data.relational.core.dialect.OrderByNullPrecedence;
2323
import org.springframework.data.relational.core.sql.LockMode;
2424
import org.springframework.data.relational.core.sql.Select;
2525

@@ -95,8 +95,9 @@ public interface SelectRenderContext {
9595
*
9696
* @param nullHandling the {@link Sort.NullHandling} for the {@code ORDER BY} sort expression. Must not be {@literal null}.
9797
* @return render {@link String} SQL text to be included in an {@code ORDER BY} sort expression.
98+
* @since 2.4
9899
*/
99100
default String evaluateOrderByNullHandling(Sort.NullHandling nullHandling) {
100-
return OrderByNullHandling.NONE.evaluate(nullHandling);
101+
return OrderByNullPrecedence.NONE.evaluate(nullHandling);
101102
}
102103
}

spring-data-relational/src/test/java/org/springframework/data/relational/core/dialect/PostgresDialectRenderingUnitTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void shouldRenderSelectOrderByWithDirection() {
181181
}
182182

183183
@Test // GH-821
184-
void shouldRenderSelectOrderByWithNullHandling() {
184+
void shouldRenderSelectOrderByWithNullPrecedence() {
185185

186186
Table table = Table.create("foo");
187187
Select select = StatementBuilder.select(table.asterisk())

0 commit comments

Comments
 (0)