Browse Source

Polishing.

Original pull request #1901
pull/1905/head
Jens Schauder 1 year ago
parent
commit
4d5a382a73
No known key found for this signature in database
GPG Key ID: 74F6C554AE971567
  1. 12
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java
  2. 19
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java

12
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java

@ -24,7 +24,6 @@ import java.util.Map; @@ -24,7 +24,6 @@ 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,15 +59,15 @@ public final class Identifier { @@ -60,15 +59,15 @@ 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 must not be null
* @param name must not be {@literal null}.
* @param value must not be {@literal 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(name, "Name must not be null");
Assert.notNull(value, "Value must not be null");
Assert.notNull(targetType, "Target type must not be null");
return new Identifier(Collections.singletonList(new SingleIdentifierValue(name, value, targetType)));
@ -92,7 +91,8 @@ public final class Identifier { @@ -92,7 +91,8 @@ public final class Identifier {
map.forEach((k, v) -> {
Assert.notNull(v, "The source map for identifier cannot contain null values");
Assert.notNull(v, "The source map for identifier must not contain null values");
values.add(new SingleIdentifierValue(k, v, ClassUtils.getUserClass(v)));
});

19
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java

@ -47,19 +47,28 @@ public class IdentifierUnitTests { @@ -47,19 +47,28 @@ public class IdentifierUnitTests {
}
@Test // DATAJDBC-326
public void parametersWithStringKeysUseObjectAsTypeForNull() {
public void typeIsCalculatedCorrectly() {
HashMap<SqlIdentifier, Object> parameters = new HashMap<>();
Object value = new Object();
Object objectValue = new Object();
Object stringValue = "text";
Object intValue = 23;
Object integerValue = 42;
parameters.put(unquoted("one"), value);
parameters.put(unquoted("one"), objectValue);
parameters.put(unquoted("two"), stringValue);
parameters.put(unquoted("three"), intValue);
parameters.put(unquoted("four"), integerValue);
Identifier identifier = Identifier.from(parameters);
assertThat(identifier.getParts()) //
.extracting("name", "value", "targetType") //
.containsExactly( //
Assertions.tuple(unquoted("one"), value, Object.class) //
.containsExactlyInAnyOrder( //
Assertions.tuple(unquoted("one"), objectValue, Object.class), //
Assertions.tuple(unquoted("two"), stringValue, String.class), //
Assertions.tuple(unquoted("three"), intValue, Integer.class), //
Assertions.tuple(unquoted("four"), integerValue, Integer.class) //
);
}

Loading…
Cancel
Save