Refactoring.
Clarified nullabillity for Identifier. Removed usage of deprecated constructor for StringBasedJdbcQuery. Original pull request #1901
This commit is contained in:
committed by
Jens Schauder
parent
95a9f64c3e
commit
08daf47842
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.data.relational.core.sql.SqlIdentifier;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -60,17 +61,16 @@ public final class Identifier {
|
||||
* Creates an {@link Identifier} from {@code name}, {@code value}, and a {@link Class target type}.
|
||||
*
|
||||
* @param name must not be {@literal null} or empty.
|
||||
* @param value
|
||||
* @param value must not be null
|
||||
* @param targetType must not be {@literal null}.
|
||||
* @return the {@link Identifier} for {@code name}, {@code value}, and a {@link Class target type}.
|
||||
*/
|
||||
public static Identifier of(SqlIdentifier name, Object value, Class<?> targetType) {
|
||||
|
||||
Assert.notNull(name, "Name must not be empty");
|
||||
Assert.notNull(value, "Value must not be empty");
|
||||
Assert.notNull(targetType, "Target type must not be null");
|
||||
|
||||
// TODO: Is value allowed to be null? SingleIdentifierValue says so, but this type doesn't allows it and
|
||||
// SqlParametersFactory.lambda$forQueryByIdentifier$1 fails with a NPE.
|
||||
return new Identifier(Collections.singletonList(new SingleIdentifierValue(name, value, targetType)));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,8 @@ public final class Identifier {
|
||||
|
||||
map.forEach((k, v) -> {
|
||||
|
||||
values.add(new SingleIdentifierValue(k, v, v != null ? ClassUtils.getUserClass(v) : Object.class));
|
||||
Assert.notNull(v, "The source map for identifier cannot contain null values");
|
||||
values.add(new SingleIdentifierValue(k, v, ClassUtils.getUserClass(v)));
|
||||
});
|
||||
|
||||
return new Identifier(Collections.unmodifiableList(values));
|
||||
@@ -199,9 +200,10 @@ public final class Identifier {
|
||||
private final Object value;
|
||||
private final Class<?> targetType;
|
||||
|
||||
private SingleIdentifierValue(SqlIdentifier name, @Nullable Object value, Class<?> targetType) {
|
||||
private SingleIdentifierValue(SqlIdentifier name, Object value, Class<?> targetType) {
|
||||
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(value, "Name must not be null");
|
||||
Assert.notNull(targetType, "TargetType must not be null");
|
||||
|
||||
this.name = name;
|
||||
|
||||
@@ -40,8 +40,7 @@ public class JdbcIdentifierBuilder {
|
||||
/**
|
||||
* Creates ParentKeys with backreference for the given path and value of the parents id.
|
||||
*/
|
||||
public static JdbcIdentifierBuilder forBackReferences(JdbcConverter converter, AggregatePath path,
|
||||
@Nullable Object value) {
|
||||
public static JdbcIdentifierBuilder forBackReferences(JdbcConverter converter, AggregatePath path, Object value) {
|
||||
|
||||
Identifier identifier = Identifier.of( //
|
||||
path.getTableInfo().reverseColumnInfo().name(), //
|
||||
|
||||
@@ -92,7 +92,7 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
|
||||
public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
|
||||
@Nullable RowMapper<?> defaultRowMapper, JdbcConverter converter,
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider) {
|
||||
this(queryMethod, operations, result -> (RowMapper<Object>) defaultRowMapper, converter, evaluationContextProvider);
|
||||
this(queryMethod.getRequiredQuery(), queryMethod, operations, result -> (RowMapper<Object>) defaultRowMapper, converter, evaluationContextProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,14 +50,16 @@ public class IdentifierUnitTests {
|
||||
public void parametersWithStringKeysUseObjectAsTypeForNull() {
|
||||
|
||||
HashMap<SqlIdentifier, Object> parameters = new HashMap<>();
|
||||
parameters.put(unquoted("one"), null);
|
||||
Object value = new Object();
|
||||
|
||||
parameters.put(unquoted("one"), value);
|
||||
|
||||
Identifier identifier = Identifier.from(parameters);
|
||||
|
||||
assertThat(identifier.getParts()) //
|
||||
.extracting("name", "value", "targetType") //
|
||||
.containsExactly( //
|
||||
Assertions.tuple(unquoted("one"), null, Object.class) //
|
||||
Assertions.tuple(unquoted("one"), value, Object.class) //
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -397,7 +397,7 @@ class StringBasedJdbcQueryUnitTests {
|
||||
mock(RelationResolver.class))
|
||||
: this.converter;
|
||||
|
||||
StringBasedJdbcQuery query = new StringBasedJdbcQuery(method, operations, result -> mock(RowMapper.class),
|
||||
StringBasedJdbcQuery query = new StringBasedJdbcQuery(method.getDeclaredQuery(), method, operations, result -> mock(RowMapper.class),
|
||||
converter, evaluationContextProvider);
|
||||
|
||||
query.execute(arguments);
|
||||
|
||||
Reference in New Issue
Block a user