diff --git a/pom.xml b/pom.xml
index 2c64717780..591db97aca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-relational-parent
- 2.4.0-SNAPSHOT
+ 2.4.0-1089-sql-type-SNAPSHOT
pom
Spring Data Relational Parent
diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml
index 0646c2846d..78f1788fe2 100644
--- a/spring-data-jdbc-distribution/pom.xml
+++ b/spring-data-jdbc-distribution/pom.xml
@@ -14,7 +14,7 @@
org.springframework.data
spring-data-relational-parent
- 2.4.0-SNAPSHOT
+ 2.4.0-1089-sql-type-SNAPSHOT
../pom.xml
diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml
index 11114a795e..9bea548bf9 100644
--- a/spring-data-jdbc/pom.xml
+++ b/spring-data-jdbc/pom.xml
@@ -6,7 +6,7 @@
4.0.0
spring-data-jdbc
- 2.4.0-SNAPSHOT
+ 2.4.0-1089-sql-type-SNAPSHOT
Spring Data JDBC
Spring Data module for JDBC repositories.
@@ -15,7 +15,7 @@
org.springframework.data
spring-data-relational-parent
- 2.4.0-SNAPSHOT
+ 2.4.0-1089-sql-type-SNAPSHOT
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java
index 312eb8bab2..1d076d0e6e 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java
@@ -19,6 +19,7 @@
import java.sql.JDBCType;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.SQLType;
import java.util.Map;
import java.util.Optional;
@@ -170,10 +171,15 @@ private Class> getReferenceColumnType(RelationalPersistentProperty property) {
* @see org.springframework.data.jdbc.core.convert.JdbcConverter#getSqlType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty)
*/
@Override
+ public SQLType getTargetSqlType(RelationalPersistentProperty property) {
+ return JdbcUtil.targetSqlTypeFor(getColumnType(property));
+ }
+
+ @Override
+ @Deprecated
public int getSqlType(RelationalPersistentProperty property) {
return JdbcUtil.sqlTypeFor(getColumnType(property));
}
-
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.convert.JdbcConverter#getColumnType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty)
@@ -282,12 +288,19 @@ private boolean canWriteAsJdbcValue(@Nullable Object value) {
return customWriteTarget.isPresent() && customWriteTarget.get().isAssignableFrom(JdbcValue.class);
}
- /*
+ @Override
+ @Deprecated
+ public JdbcValue writeJdbcValue(@Nullable Object value, Class> columnType, int sqlType) {
+ return writeJdbcValue(value, columnType, JdbcUtil.jdbcTypeFor(sqlType));
+ }
+
+
+ /*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.convert.JdbcConverter#writeValue(java.lang.Object, java.lang.Class, int)
*/
@Override
- public JdbcValue writeJdbcValue(@Nullable Object value, Class> columnType, int sqlType) {
+ public JdbcValue writeJdbcValue(@Nullable Object value, Class> columnType, SQLType sqlType) {
JdbcValue jdbcValue = tryToConvertToJdbcValue(value);
if (jdbcValue != null) {
@@ -297,7 +310,8 @@ public JdbcValue writeJdbcValue(@Nullable Object value, Class> columnType, int
Object convertedValue = writeValue(value, ClassTypeInformation.from(columnType));
if (convertedValue == null || !convertedValue.getClass().isArray()) {
- return JdbcValue.of(convertedValue, JdbcUtil.jdbcTypeFor(sqlType));
+
+ return JdbcValue.of(convertedValue, sqlType);
}
Class> componentType = convertedValue.getClass().getComponentType();
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
index a5f1eab953..151c77027a 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
@@ -17,8 +17,8 @@
import static org.springframework.data.jdbc.core.convert.SqlGenerator.*;
-import java.sql.JDBCType;
import java.sql.ResultSet;
+import java.sql.SQLType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -546,17 +546,17 @@ private IdentifierProcessing getIdentifierProcessing() {
private void addConvertedPropertyValue(SqlIdentifierParameterSource parameterSource,
RelationalPersistentProperty property, @Nullable Object value, SqlIdentifier name) {
- addConvertedValue(parameterSource, value, name, converter.getColumnType(property), converter.getSqlType(property));
+ addConvertedValue(parameterSource, value, name, converter.getColumnType(property), converter.getTargetSqlType(property));
}
private void addConvertedPropertyValue(SqlIdentifierParameterSource parameterSource, SqlIdentifier name, Object value,
Class> javaType) {
- addConvertedValue(parameterSource, value, name, javaType, JdbcUtil.sqlTypeFor(javaType));
+ addConvertedValue(parameterSource, value, name, javaType, JdbcUtil.targetSqlTypeFor(javaType));
}
private void addConvertedValue(SqlIdentifierParameterSource parameterSource, @Nullable Object value,
- SqlIdentifier paramName, Class> javaType, int sqlType) {
+ SqlIdentifier paramName, Class> javaType, SQLType sqlType) {
JdbcValue jdbcValue = converter.writeJdbcValue( //
value, //
@@ -567,7 +567,7 @@ private void addConvertedValue(SqlIdentifierParameterSource parameterSource, @Nu
parameterSource.addValue( //
paramName, //
jdbcValue.getValue(), //
- JdbcUtil.sqlTypeFor(jdbcValue.getJdbcType()));
+ jdbcValue.getJdbcType().getVendorTypeNumber());
}
private void addConvertedPropertyValuesAsList(SqlIdentifierParameterSource parameterSource,
@@ -578,7 +578,7 @@ private void addConvertedPropertyValuesAsList(SqlIdentifierParameterSource param
for (Object id : values) {
Class> columnType = converter.getColumnType(property);
- int sqlType = converter.getSqlType(property);
+ SQLType sqlType = converter.getTargetSqlType(property);
jdbcValue = converter.writeJdbcValue(id, columnType, sqlType);
convertedIds.add(jdbcValue.getValue());
@@ -586,7 +586,7 @@ private void addConvertedPropertyValuesAsList(SqlIdentifierParameterSource param
Assert.state(jdbcValue != null, "JdbcValue must be not null at this point. Please report this as a bug.");
- JDBCType jdbcType = jdbcValue.getJdbcType();
+ SQLType jdbcType = jdbcValue.getJdbcType();
int typeNumber = jdbcType == null ? JdbcUtils.TYPE_UNKNOWN : jdbcType.getVendorTypeNumber();
parameterSource.addValue(paramName, convertedIds, typeNumber);
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultJdbcTypeFactory.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultJdbcTypeFactory.java
index c70287d1ba..09f5627f3e 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultJdbcTypeFactory.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultJdbcTypeFactory.java
@@ -16,7 +16,7 @@
package org.springframework.data.jdbc.core.convert;
import java.sql.Array;
-import java.sql.JDBCType;
+import java.sql.SQLType;
import org.springframework.data.jdbc.core.dialect.JdbcArrayColumns;
import org.springframework.data.jdbc.support.JdbcUtil;
@@ -68,7 +68,7 @@ public Array createArray(Object[] value) {
Class> componentType = arrayColumns.getArrayType(value.getClass());
- JDBCType jdbcType = JdbcUtil.jdbcTypeFor(componentType);
+ SQLType jdbcType = JdbcUtil.targetSqlTypeFor(componentType);
Assert.notNull(jdbcType, () -> String.format("Couldn't determine JDBCType for %s", componentType));
String typeName = arrayColumns.getArrayTypeName(jdbcType);
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java
index 31fc2e3726..6f4f1635ad 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java
@@ -16,6 +16,7 @@
package org.springframework.data.jdbc.core.convert;
import java.sql.ResultSet;
+import java.sql.SQLType;
import org.springframework.data.jdbc.core.mapping.JdbcValue;
import org.springframework.data.relational.core.conversion.RelationalConverter;
@@ -39,12 +40,24 @@ public interface JdbcConverter extends RelationalConverter {
* to JDBC parameters.
*
* @param value a value as it is used in the object model. May be {@code null}.
- * @param type {@link TypeInformation} into which the value is to be converted. Must not be {@code null}.
+ * @param type {@literal Class} into which the value is to be converted. Must not be {@code null}.
* @param sqlType the type constant from {@link java.sql.Types} to be used if non is specified by a converter.
* @return The converted value wrapped in a {@link JdbcValue}. Guaranteed to be not {@literal null}.
*/
JdbcValue writeJdbcValue(@Nullable Object value, Class> type, int sqlType);
+ /**
+ * Convert a property value into a {@link JdbcValue} that contains the converted value and information how to bind it
+ * to JDBC parameters.
+ *
+ * @param value a value as it is used in the object model. May be {@code null}.
+ * @param type {@literal Class} into which the value is to be converted. Must not be {@code null}.
+ * @param sqlType the {@link SQLType} to be used if non is specified by a converter.
+ * @return The converted value wrapped in a {@link JdbcValue}. Guaranteed to be not {@literal null}.
+ * @since 2.4
+ */
+ JdbcValue writeJdbcValue(@Nullable Object value, Class> type, SQLType sqlType);
+
/**
* Read the current row from {@link ResultSet} to an {@link RelationalPersistentEntity#getType() entity}.
*
@@ -73,7 +86,7 @@ public interface JdbcConverter extends RelationalConverter {
* top-level array type (e.g. {@code String[][]} returns {@code String[]}).
*
* @return a {@link Class} that is suitable for usage with JDBC drivers.
- * @see org.springframework.data.jdbc.support.JdbcUtil#sqlTypeFor(Class)
+ * @see org.springframework.data.jdbc.support.JdbcUtil#targetSqlTypeFor(Class)
* @since 2.0
*/
Class> getColumnType(RelationalPersistentProperty property);
@@ -85,5 +98,9 @@ public interface JdbcConverter extends RelationalConverter {
* @see java.sql.Types
* @since 2.0
*/
+ SQLType getTargetSqlType(RelationalPersistentProperty property);
+
+ @Deprecated
int getSqlType(RelationalPersistentProperty property);
+
}
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java
index c8c37b5323..e174ef44ef 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcValue.java
@@ -16,6 +16,7 @@
package org.springframework.data.jdbc.core.convert;
import java.sql.JDBCType;
+import java.sql.SQLType;
import java.util.Objects;
import org.springframework.lang.Nullable;
@@ -32,11 +33,11 @@
@Deprecated
public final class JdbcValue extends org.springframework.data.jdbc.core.mapping.JdbcValue {
- private JdbcValue(@Nullable Object value, @Nullable JDBCType jdbcType) {
+ private JdbcValue(@Nullable Object value, @Nullable SQLType jdbcType) {
super(value, jdbcType);
}
- public static JdbcValue of(@Nullable Object value, @Nullable JDBCType jdbcType) {
+ public static JdbcValue of(@Nullable Object value, @Nullable SQLType jdbcType) {
return new JdbcValue(value, jdbcType);
}
}
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcValue.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcValue.java
index 8e0dd48ba0..91f50417fd 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcValue.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcValue.java
@@ -16,6 +16,7 @@
package org.springframework.data.jdbc.core.mapping;
import java.sql.JDBCType;
+import java.sql.SQLType;
import java.util.Objects;
import org.springframework.lang.Nullable;
@@ -31,15 +32,15 @@
public class JdbcValue {
private final Object value;
- private final JDBCType jdbcType;
+ private final SQLType jdbcType;
- protected JdbcValue(@Nullable Object value, @Nullable JDBCType jdbcType) {
+ protected JdbcValue(@Nullable Object value, @Nullable SQLType jdbcType) {
this.value = value;
this.jdbcType = jdbcType;
}
- public static JdbcValue of(@Nullable Object value, @Nullable JDBCType jdbcType) {
+ public static JdbcValue of(@Nullable Object value, @Nullable SQLType jdbcType) {
return new JdbcValue(value, jdbcType);
}
@@ -49,7 +50,7 @@ public Object getValue() {
}
@Nullable
- public JDBCType getJdbcType() {
+ public SQLType getJdbcType() {
return this.jdbcType;
}
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/QueryMapper.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/QueryMapper.java
index 09b1138c21..33a3a4fad9 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/QueryMapper.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/QueryMapper.java
@@ -16,7 +16,7 @@
package org.springframework.data.jdbc.repository.query;
import java.sql.JDBCType;
-import java.sql.Types;
+import java.sql.SQLType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -27,6 +27,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.mapping.JdbcValue;
+import org.springframework.data.jdbc.support.JdbcUtil;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PropertyPath;
@@ -45,7 +46,6 @@
import org.springframework.data.util.Pair;
import org.springframework.data.util.TypeInformation;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -279,7 +279,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc
TypeInformation> actualType = propertyField.getTypeHint().getRequiredActualType();
Column column = table.column(propertyField.getMappedColumnName());
Object mappedValue;
- int sqlType;
+ SQLType sqlType;
if (criteria.getValue() instanceof JdbcValue) {
@@ -302,7 +302,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc
RelationalPersistentProperty property = ((MetadataBackedField) propertyField).property;
JdbcValue jdbcValue = convertToJdbcValue(property, criteria.getValue());
mappedValue = jdbcValue.getValue();
- sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType().getVendorTypeNumber()
+ sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType()
: propertyField.getSqlType();
} else {
@@ -339,7 +339,7 @@ private JdbcValue convertToJdbcValue(RelationalPersistentProperty property, @Nul
if (value instanceof Iterable) {
List