Browse Source

DATAJDBC-349 - Apply JdbcConverter on reference ids.

Original pull request: #248.
pull/211/head
Yunyoung LEE 5 years ago committed by Jens Schauder
parent
commit
dc535e9791
No known key found for this signature in database
GPG Key ID: 996B1389BA0721C3
  1. 11
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
  2. 15
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java
  3. 6
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql
  4. 3
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-h2.sql
  5. 3
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-hsql.sql
  6. 3
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql
  7. 2
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mssql.sql
  8. 3
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mysql.sql
  9. 6
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-oracle.sql
  10. 2
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-postgres.sql

11
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

@ -66,6 +66,7 @@ import org.springframework.util.Assert;
* @author Tyler Van Gorder * @author Tyler Van Gorder
* @author Milan Milanov * @author Milan Milanov
* @author Myeonghyeon Lee * @author Myeonghyeon Lee
* @author Yunyoung LEE
* @since 1.1 * @since 1.1
*/ */
public class DefaultDataAccessStrategy implements DataAccessStrategy { public class DefaultDataAccessStrategy implements DataAccessStrategy {
@ -227,7 +228,12 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
String delete = sql(rootEntity.getType()).createDeleteByPath(propertyPath); String delete = sql(rootEntity.getType()).createDeleteByPath(propertyPath);
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(getIdentifierProcessing()); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(getIdentifierProcessing());
parameters.addValue(ROOT_ID_PARAMETER, rootId); addConvertedPropertyValue( //
parameters, //
rootEntity.getRequiredIdProperty(), //
rootId, //
ROOT_ID_PARAMETER //
);
operations.update(delete, parameters); operations.update(delete, parameters);
} }
@ -367,7 +373,8 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(identifierProcessing); SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(identifierProcessing);
identifier.toMap().forEach(parameterSource::addValue); identifier.toMap()
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass()));
return parameterSource; return parameterSource;
} }

15
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java

@ -29,12 +29,12 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Set;
import org.assertj.core.api.Condition; import org.assertj.core.api.Condition;
import org.assertj.core.api.SoftAssertions; import org.assertj.core.api.SoftAssertions;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -45,6 +45,7 @@ import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.testing.AssumeFeatureRule; import org.springframework.data.jdbc.testing.AssumeFeatureRule;
import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.EnabledOnFeature;
import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent; import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
@ -58,6 +59,7 @@ import org.springframework.transaction.annotation.Transactional;
* *
* @author Jens Schauder * @author Jens Schauder
* @author Thomas Lang * @author Thomas Lang
* @author Yunyung LEE
*/ */
@ContextConfiguration @ContextConfiguration
@Transactional @Transactional
@ -77,6 +79,9 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
entity.setBigInteger(BigInteger.valueOf(Long.MAX_VALUE)); entity.setBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
entity.setDate(Date.from(getNow().toInstant(ZoneOffset.UTC))); entity.setDate(Date.from(getNow().toInstant(ZoneOffset.UTC)));
entity.setLocalDateTime(getNow()); entity.setLocalDateTime(getNow());
EntityWithColumnsRequiringConversionsRelation relation = new EntityWithColumnsRequiringConversionsRelation();
relation.setData("DUMMY");
entity.setRelation(singleton(relation));
return entity; return entity;
} }
@ -194,5 +199,13 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
// ensures conversion on id querying // ensures conversion on id querying
@Id private LocalDateTime idTimestamp; @Id private LocalDateTime idTimestamp;
@MappedCollection(idColumn = "ID_TIMESTAMP") Set<EntityWithColumnsRequiringConversionsRelation> relation;
}
// DATAJDBC-349
@Data
static class EntityWithColumnsRequiringConversionsRelation {
@Id private LocalDateTime idTimestamp;
String data;
} }
} }

6
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql

@ -1,3 +1,4 @@
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
local_Date_Time DATETIME, local_Date_Time DATETIME,
zoned_Date_Time VARCHAR(30) zoned_Date_Time VARCHAR(30)
); );
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION (
id_Timestamp DATETIME NOT NULL PRIMARY KEY,
data VARCHAR(100),
);

3
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-h2.sql

@ -1 +1,2 @@
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30));
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

3
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-hsql.sql

@ -1 +1,2 @@
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30));
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

3
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql

@ -1 +1,2 @@
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30));
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

2
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mssql.sql

@ -1,2 +1,4 @@
DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool bit, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(38), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)); CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool bit, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(38), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30));
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

3
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mysql.sql

@ -1 +1,2 @@
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30));
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

6
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-oracle.sql

@ -1,3 +1,4 @@
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
LOCAL_DATE_TIME TIMESTAMP, LOCAL_DATE_TIME TIMESTAMP,
ZONED_DATE_TIME VARCHAR2(30) ZONED_DATE_TIME VARCHAR2(30)
); );
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION (
ID_TIMESTAMP TIMESTAMP PRIMARY KEY,
DATA VARCHAR2(100),
);

2
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-postgres.sql

@ -1,2 +1,4 @@
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp TIMESTAMP PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer BIGINT, date TIMESTAMP, local_Date_Time TIMESTAMP, zoned_Date_Time VARCHAR(30)) CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp TIMESTAMP PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer BIGINT, date TIMESTAMP, local_Date_Time TIMESTAMP, zoned_Date_Time VARCHAR(30))
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

Loading…
Cancel
Save