From d0053fb49bfec4fd61cb1b38647c226a6b70244c Mon Sep 17 00:00:00 2001 From: Mikhail2048 Date: Sat, 28 Sep 2024 23:18:17 +0300 Subject: [PATCH 1/2] Polishing: Removed references to deprecated StringBasedJdbcQuery constructor --- .../data/jdbc/repository/query/StringBasedJdbcQuery.java | 2 +- .../jdbc/repository/query/StringBasedJdbcQueryUnitTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java index 7e8da647ee..9fe48069e7 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java @@ -93,7 +93,7 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery { public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations, @Nullable RowMapper defaultRowMapper, JdbcConverter converter, QueryMethodEvaluationContextProvider evaluationContextProvider) { - this(queryMethod, operations, result -> (RowMapper) defaultRowMapper, converter, evaluationContextProvider); + this(queryMethod.getRequiredQuery(), queryMethod, operations, result -> (RowMapper) defaultRowMapper, converter, evaluationContextProvider); } /** diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQueryUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQueryUnitTests.java index d5fabc8f7c..040beefe22 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQueryUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQueryUnitTests.java @@ -408,7 +408,7 @@ public SqlParameterSource extractParameterSource() { 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); From fb159b98f66b2f84502e4f86cf7da9bf3f3ec0cf Mon Sep 17 00:00:00 2001 From: Mikhail2048 Date: Sun, 29 Sep 2024 16:37:58 +0300 Subject: [PATCH 2/2] Polishing: Removed TODO for Identifier value --- .../data/jdbc/core/convert/Identifier.java | 12 +++++++----- .../jdbc/core/convert/JdbcIdentifierBuilder.java | 3 +-- .../data/jdbc/core/convert/IdentifierUnitTests.java | 6 ++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java index db751f6440..7a3dcc4ee8 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java @@ -24,6 +24,7 @@ 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 static Identifier empty() { * 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 static Identifier from(Map map) { 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 @@ static final class SingleIdentifierValue { 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; diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcIdentifierBuilder.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcIdentifierBuilder.java index b33a0dfce4..255ed7fa73 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcIdentifierBuilder.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcIdentifierBuilder.java @@ -40,8 +40,7 @@ public static JdbcIdentifierBuilder empty() { /** * 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(), // diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java index ee331cc939..cfde059ebe 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java @@ -50,14 +50,16 @@ public void getParametersByName() { public void parametersWithStringKeysUseObjectAsTypeForNull() { HashMap 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) // ); }