Skip to content

DATAJDBC-349 - Use JdbcConverter on relation id property. #248

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 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* @author Tyler Van Gorder
* @author Milan Milanov
* @author Myeonghyeon Lee
* @author Yunyoung LEE
* @since 1.1
*/
public class DefaultDataAccessStrategy implements DataAccessStrategy {
Expand Down Expand Up @@ -227,7 +228,12 @@ public void delete(Object rootId, PersistentPropertyPath<RelationalPersistentPro
String delete = sql(rootEntity.getType()).createDeleteByPath(propertyPath);

SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(getIdentifierProcessing());
parameters.addValue(ROOT_ID_PARAMETER, rootId);
addConvertedPropertyValue( //
parameters, //
rootEntity.getRequiredIdProperty(), //
rootId, //
ROOT_ID_PARAMETER //
);
operations.update(delete, parameters);
}

Expand Down Expand Up @@ -367,7 +373,8 @@ private SqlParameterSource createParameterSource(Identifier identifier, Identifi

SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(identifierProcessing);

identifier.toMap().forEach(parameterSource::addValue);
identifier.toMap()
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass()));

return parameterSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import java.time.ZoneOffset;
import java.util.Collections;
import java.util.Date;
import java.util.Set;

import org.assertj.core.api.Condition;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
Expand All @@ -45,6 +45,7 @@
import org.springframework.data.jdbc.testing.AssumeFeatureRule;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
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.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -58,6 +59,7 @@
*
* @author Jens Schauder
* @author Thomas Lang
* @author Yunyung LEE
*/
@ContextConfiguration
@Transactional
Expand All @@ -77,6 +79,9 @@ private static EntityWithColumnsRequiringConversions createDummyEntity() {
entity.setBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
entity.setDate(Date.from(getNow().toInstant(ZoneOffset.UTC)));
entity.setLocalDateTime(getNow());
EntityWithColumnsRequiringConversionsRelation relation = new EntityWithColumnsRequiringConversionsRelation();
relation.setData("DUMMY");
entity.setRelation(singleton(relation));

return entity;
}
Expand Down Expand Up @@ -194,5 +199,13 @@ static class EntityWithColumnsRequiringConversions {
// ensures conversion on id querying
@Id private LocalDateTime idTimestamp;

@MappedCollection(idColumn = "ID_TIMESTAMP") Set<EntityWithColumnsRequiringConversionsRelation> relation;
}

// DATAJDBC-349
@Data
static class EntityWithColumnsRequiringConversionsRelation {
@Id private LocalDateTime idTimestamp;
String data;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;

CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
Expand All @@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
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),
);
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
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_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS;

CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
Expand All @@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS (
LOCAL_DATE_TIME TIMESTAMP,
ZONED_DATE_TIME VARCHAR2(30)
);

CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION (
ID_TIMESTAMP TIMESTAMP PRIMARY KEY,
DATA VARCHAR2(100),
);
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION;
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_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));