Skip to content

Commit dc535e9

Browse files
lseekerschauder
authored andcommitted
DATAJDBC-349 - Apply JdbcConverter on reference ids.
Original pull request: #248.
1 parent 1b1395a commit dc535e9

10 files changed

+47
-7
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* @author Tyler Van Gorder
6767
* @author Milan Milanov
6868
* @author Myeonghyeon Lee
69+
* @author Yunyoung LEE
6970
* @since 1.1
7071
*/
7172
public class DefaultDataAccessStrategy implements DataAccessStrategy {
@@ -227,7 +228,12 @@ public void delete(Object rootId, PersistentPropertyPath<RelationalPersistentPro
227228
String delete = sql(rootEntity.getType()).createDeleteByPath(propertyPath);
228229

229230
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(getIdentifierProcessing());
230-
parameters.addValue(ROOT_ID_PARAMETER, rootId);
231+
addConvertedPropertyValue( //
232+
parameters, //
233+
rootEntity.getRequiredIdProperty(), //
234+
rootId, //
235+
ROOT_ID_PARAMETER //
236+
);
231237
operations.update(delete, parameters);
232238
}
233239

@@ -367,7 +373,8 @@ private SqlParameterSource createParameterSource(Identifier identifier, Identifi
367373

368374
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(identifierProcessing);
369375

370-
identifier.toMap().forEach(parameterSource::addValue);
376+
identifier.toMap()
377+
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass()));
371378

372379
return parameterSource;
373380
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import java.time.ZoneOffset;
3030
import java.util.Collections;
3131
import java.util.Date;
32+
import java.util.Set;
3233

3334
import org.assertj.core.api.Condition;
3435
import org.assertj.core.api.SoftAssertions;
3536
import org.junit.Test;
3637
import org.junit.runner.RunWith;
37-
3838
import org.springframework.beans.factory.annotation.Autowired;
3939
import org.springframework.context.ApplicationListener;
4040
import org.springframework.context.annotation.Bean;
@@ -45,6 +45,7 @@
4545
import org.springframework.data.jdbc.testing.AssumeFeatureRule;
4646
import org.springframework.data.jdbc.testing.EnabledOnFeature;
4747
import org.springframework.data.jdbc.testing.TestConfiguration;
48+
import org.springframework.data.relational.core.mapping.MappedCollection;
4849
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
4950
import org.springframework.data.repository.CrudRepository;
5051
import org.springframework.test.context.ContextConfiguration;
@@ -58,6 +59,7 @@
5859
*
5960
* @author Jens Schauder
6061
* @author Thomas Lang
62+
* @author Yunyung LEE
6163
*/
6264
@ContextConfiguration
6365
@Transactional
@@ -77,6 +79,9 @@ private static EntityWithColumnsRequiringConversions createDummyEntity() {
7779
entity.setBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
7880
entity.setDate(Date.from(getNow().toInstant(ZoneOffset.UTC)));
7981
entity.setLocalDateTime(getNow());
82+
EntityWithColumnsRequiringConversionsRelation relation = new EntityWithColumnsRequiringConversionsRelation();
83+
relation.setData("DUMMY");
84+
entity.setRelation(singleton(relation));
8085

8186
return entity;
8287
}
@@ -194,5 +199,13 @@ static class EntityWithColumnsRequiringConversions {
194199
// ensures conversion on id querying
195200
@Id private LocalDateTime idTimestamp;
196201

202+
@MappedCollection(idColumn = "ID_TIMESTAMP") Set<EntityWithColumnsRequiringConversionsRelation> relation;
203+
}
204+
205+
// DATAJDBC-349
206+
@Data
207+
static class EntityWithColumnsRequiringConversionsRelation {
208+
@Id private LocalDateTime idTimestamp;
209+
String data;
197210
}
198211
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
12
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
23

34
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
@@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
1011
local_Date_Time DATETIME,
1112
zoned_Date_Time VARCHAR(30)
1213
);
14+
15+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION (
16+
id_Timestamp DATETIME NOT NULL PRIMARY KEY,
17+
data VARCHAR(100),
18+
);
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
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))
1+
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));
2+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
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))
1+
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));
2+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
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))
1+
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));
2+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
12
DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
23
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));
4+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
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))
1+
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));
2+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
12
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
23

34
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
@@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
1011
LOCAL_DATE_TIME TIMESTAMP,
1112
ZONED_DATE_TIME VARCHAR2(30)
1213
);
14+
15+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION (
16+
ID_TIMESTAMP TIMESTAMP PRIMARY KEY,
17+
DATA VARCHAR2(100),
18+
);
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
12
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;
23
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))
4+
CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));

0 commit comments

Comments
 (0)