Skip to content

Replaces java.sql.Types constants with java.sql.SQLType values. #1142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0-1089-sql-type-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0-1089-sql-type-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0-1089-sql-type-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0-1089-sql-type-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, //
Expand All @@ -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,
Expand All @@ -578,15 +578,15 @@ 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());
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
*
Expand Down Expand Up @@ -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);
Expand All @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -49,7 +50,7 @@ public Object getValue() {
}

@Nullable
public JDBCType getJdbcType() {
public SQLType getJdbcType() {
return this.jdbcType;
}

Expand Down
Loading