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
This commit is contained in:
@@ -258,8 +258,8 @@ class JdbcAggregateTemplateIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // GH-821
|
||||
@EnabledOnFeature({SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_HANDLING})
|
||||
void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullHandling() {
|
||||
@EnabledOnFeature({SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_PRECEDENCE})
|
||||
void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullPrecedence() {
|
||||
|
||||
template.save(createLegoSet(null));
|
||||
template.save(createLegoSet("Star"));
|
||||
|
||||
@@ -84,7 +84,7 @@ public class TestDatabaseFeatures {
|
||||
assumeThat(database).isNotIn(Database.H2, Database.Hsql);
|
||||
}
|
||||
|
||||
private void supportsNullHandling() {
|
||||
private void supportsNullPrecedence() {
|
||||
assumeThat(database).isNotIn(Database.MySql, Database.MariaDb, Database.SqlServer);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class TestDatabaseFeatures {
|
||||
SUPPORTS_ARRAYS(TestDatabaseFeatures::supportsArrays), //
|
||||
SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES(TestDatabaseFeatures::supportsGeneratedIdsInReferencedEntities), //
|
||||
SUPPORTS_NANOSECOND_PRECISION(TestDatabaseFeatures::supportsNanosecondPrecision), //
|
||||
SUPPORTS_NULL_HANDLING(TestDatabaseFeatures::supportsNullHandling),
|
||||
SUPPORTS_NULL_PRECEDENCE(TestDatabaseFeatures::supportsNullPrecedence),
|
||||
IS_POSTGRES(f -> f.databaseIs(Database.PostgreSql)), //
|
||||
IS_HSQL(f -> f.databaseIs(Database.Hsql));
|
||||
|
||||
|
||||
@@ -103,14 +103,14 @@ public abstract class AbstractDialect implements Dialect {
|
||||
|
||||
private final Function<Select, ? extends CharSequence> afterFromTable;
|
||||
private final Function<Select, ? extends CharSequence> afterOrderBy;
|
||||
private final OrderByNullHandling orderByNullHandling;
|
||||
private final OrderByNullPrecedence orderByNullPrecedence;
|
||||
|
||||
DialectSelectRenderContext(Function<Select, ? extends CharSequence> afterFromTable,
|
||||
Function<Select, ? extends CharSequence> afterOrderBy, OrderByNullHandling orderByNullHandling) {
|
||||
Function<Select, ? extends CharSequence> afterOrderBy, OrderByNullPrecedence orderByNullPrecedence) {
|
||||
|
||||
this.afterFromTable = afterFromTable;
|
||||
this.afterOrderBy = afterOrderBy;
|
||||
this.orderByNullHandling = orderByNullHandling;
|
||||
this.orderByNullPrecedence = orderByNullPrecedence;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +125,7 @@ public abstract class AbstractDialect implements Dialect {
|
||||
|
||||
@Override
|
||||
public String evaluateOrderByNullHandling(Sort.NullHandling nullHandling) {
|
||||
return orderByNullHandling.evaluate(nullHandling);
|
||||
return orderByNullPrecedence.evaluate(nullHandling);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,11 +123,12 @@ public interface Dialect {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link OrderByNullHandling} used by this dialect.
|
||||
* Return the {@link OrderByNullPrecedence} used by this dialect.
|
||||
*
|
||||
* @return the {@link OrderByNullHandling} used by this dialect.
|
||||
* @return the {@link OrderByNullPrecedence} used by this dialect.
|
||||
* @since 2.4
|
||||
*/
|
||||
default OrderByNullHandling orderByNullHandling() {
|
||||
return OrderByNullHandling.SQL_STANDARD;
|
||||
default OrderByNullPrecedence orderByNullHandling() {
|
||||
return OrderByNullPrecedence.SQL_STANDARD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class MySqlDialect extends AbstractDialect {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderByNullHandling orderByNullHandling() {
|
||||
return OrderByNullHandling.NONE;
|
||||
public OrderByNullPrecedence orderByNullHandling() {
|
||||
return OrderByNullPrecedence.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,21 +21,22 @@ import org.springframework.data.domain.Sort;
|
||||
* Represents how the {@link Sort.NullHandling} option of an {@code ORDER BY} sort expression is to be evaluated.
|
||||
*
|
||||
* @author Chirag Tailor
|
||||
* @since 2.4
|
||||
*/
|
||||
public interface OrderByNullHandling {
|
||||
public interface OrderByNullPrecedence {
|
||||
/**
|
||||
* An {@link OrderByNullHandling} that can be used for databases conforming to the SQL standard which uses
|
||||
* An {@link OrderByNullPrecedence} that can be used for databases conforming to the SQL standard which uses
|
||||
* {@code NULLS FIRST} and {@code NULLS LAST} in {@code ORDER BY} sort expressions to make null values appear before
|
||||
* or after non-null values in the result set.
|
||||
*/
|
||||
OrderByNullHandling SQL_STANDARD = new SqlStandardOrderByNullHandling();
|
||||
OrderByNullPrecedence SQL_STANDARD = new SqlStandardOrderByNullPrecedence();
|
||||
|
||||
/**
|
||||
* An {@link OrderByNullHandling} that can be used for databases that do not support the SQL standard usage of
|
||||
* An {@link OrderByNullPrecedence} that can be used for databases that do not support the SQL standard usage of
|
||||
* {@code NULLS FIRST} and {@code NULLS LAST} in {@code ORDER BY} sort expressions to control where null values appear
|
||||
* respective to non-null values in the result set.
|
||||
*/
|
||||
OrderByNullHandling NONE = nullHandling -> "";
|
||||
OrderByNullPrecedence NONE = nullHandling -> "";
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
String evaluate(Sort.NullHandling nullHandling);
|
||||
|
||||
/**
|
||||
* An {@link OrderByNullHandling} implementation for databases conforming to the SQL standard which uses
|
||||
* An {@link OrderByNullPrecedence} implementation for databases conforming to the SQL standard which uses
|
||||
* {@code NULLS FIRST} and {@code NULLS LAST} in {@code ORDER BY} sort expressions to make null values appear before
|
||||
* or after non-null values in the result set.
|
||||
*
|
||||
* @author Chirag Tailor
|
||||
*/
|
||||
class SqlStandardOrderByNullHandling implements OrderByNullHandling {
|
||||
class SqlStandardOrderByNullPrecedence implements OrderByNullPrecedence {
|
||||
|
||||
private static final String NULLS_FIRST = "NULLS FIRST";
|
||||
private static final String NULLS_LAST = "NULLS LAST";
|
||||
@@ -118,7 +118,7 @@ public class SqlServerDialect extends AbstractDialect {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderByNullHandling orderByNullHandling() {
|
||||
return OrderByNullHandling.NONE;
|
||||
public OrderByNullPrecedence orderByNullHandling() {
|
||||
return OrderByNullPrecedence.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,14 +53,16 @@ class OrderByClauseVisitor extends TypedSubtreeVisitor<OrderByField> implements
|
||||
Delegation leaveMatched(OrderByField segment) {
|
||||
|
||||
if (segment.getDirection() != null) {
|
||||
|
||||
builder.append(" ") //
|
||||
.append(segment.getDirection());
|
||||
}
|
||||
|
||||
String nullHandling = context.getSelectRenderContext().evaluateOrderByNullHandling(segment.getNullHandling());
|
||||
if (!nullHandling.isEmpty()) {
|
||||
String nullPrecedence = context.getSelectRenderContext().evaluateOrderByNullHandling(segment.getNullHandling());
|
||||
if (!nullPrecedence.isEmpty()) {
|
||||
|
||||
builder.append(" ") //
|
||||
.append(nullHandling);
|
||||
.append(nullPrecedence);
|
||||
}
|
||||
|
||||
return Delegation.leave();
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.OptionalLong;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.relational.core.dialect.OrderByNullHandling;
|
||||
import org.springframework.data.relational.core.dialect.OrderByNullPrecedence;
|
||||
import org.springframework.data.relational.core.sql.LockMode;
|
||||
import org.springframework.data.relational.core.sql.Select;
|
||||
|
||||
@@ -95,8 +95,9 @@ public interface SelectRenderContext {
|
||||
*
|
||||
* @param nullHandling the {@link Sort.NullHandling} for the {@code ORDER BY} sort expression. Must not be {@literal null}.
|
||||
* @return render {@link String} SQL text to be included in an {@code ORDER BY} sort expression.
|
||||
* @since 2.4
|
||||
*/
|
||||
default String evaluateOrderByNullHandling(Sort.NullHandling nullHandling) {
|
||||
return OrderByNullHandling.NONE.evaluate(nullHandling);
|
||||
return OrderByNullPrecedence.NONE.evaluate(nullHandling);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class PostgresDialectRenderingUnitTests {
|
||||
}
|
||||
|
||||
@Test // GH-821
|
||||
void shouldRenderSelectOrderByWithNullHandling() {
|
||||
void shouldRenderSelectOrderByWithNullPrecedence() {
|
||||
|
||||
Table table = Table.create("foo");
|
||||
Select select = StatementBuilder.select(table.asterisk())
|
||||
|
||||
Reference in New Issue
Block a user