Skip to content

Commit 4989872

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 f48bbab commit 4989872

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
@@ -107,14 +107,14 @@ static class DialectSelectRenderContext implements SelectRenderContext {
107107

108108
private final Function<Select, ? extends CharSequence> afterFromTable;
109109
private final Function<Select, ? extends CharSequence> afterOrderBy;
110-
private final OrderByNullHandling orderByNullHandling;
110+
private final OrderByNullPrecedence orderByNullPrecedence;
111111

112112
DialectSelectRenderContext(Function<Select, ? extends CharSequence> afterFromTable,
113-
Function<Select, ? extends CharSequence> afterOrderBy, OrderByNullHandling orderByNullHandling) {
113+
Function<Select, ? extends CharSequence> afterOrderBy, OrderByNullPrecedence orderByNullPrecedence) {
114114

115115
this.afterFromTable = afterFromTable;
116116
this.afterOrderBy = afterOrderBy;
117-
this.orderByNullHandling = orderByNullHandling;
117+
this.orderByNullPrecedence = orderByNullPrecedence;
118118
}
119119

120120
/*
@@ -137,7 +137,7 @@ static class DialectSelectRenderContext implements SelectRenderContext {
137137

138138
@Override
139139
public String evaluateOrderByNullHandling(Sort.NullHandling nullHandling) {
140-
return orderByNullHandling.evaluate(nullHandling);
140+
return orderByNullPrecedence.evaluate(nullHandling);
141141
}
142142
}
143143

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
@@ -171,7 +171,7 @@ public Collection<Object> getConverters() {
171171
}
172172

173173
@Override
174-
public OrderByNullHandling orderByNullHandling() {
175-
return OrderByNullHandling.NONE;
174+
public OrderByNullPrecedence orderByNullHandling() {
175+
return OrderByNullPrecedence.NONE;
176176
}
177177
}
+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
@@ -158,7 +158,7 @@ public InsertRenderContext getInsertRenderContext() {
158158
}
159159

160160
@Override
161-
public OrderByNullHandling orderByNullHandling() {
162-
return OrderByNullHandling.NONE;
161+
public OrderByNullPrecedence orderByNullHandling() {
162+
return OrderByNullPrecedence.NONE;
163163
}
164164
}

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
@@ -61,14 +61,16 @@ Delegation enterMatched(OrderByField segment) {
6161
Delegation leaveMatched(OrderByField segment) {
6262

6363
if (segment.getDirection() != null) {
64+
6465
builder.append(" ") //
6566
.append(segment.getDirection());
6667
}
6768

68-
String nullHandling = context.getSelectRenderContext().evaluateOrderByNullHandling(segment.getNullHandling());
69-
if (!nullHandling.isEmpty()) {
69+
String nullPrecedence = context.getSelectRenderContext().evaluateOrderByNullHandling(segment.getNullHandling());
70+
if (!nullPrecedence.isEmpty()) {
71+
7072
builder.append(" ") //
71-
.append(nullHandling);
73+
.append(nullPrecedence);
7274
}
7375

7476
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)