|
|
|
@ -61,9 +61,9 @@ import org.springframework.data.util.TypeInformation; |
|
|
|
class MappingJdbcConverterUnitTests { |
|
|
|
class MappingJdbcConverterUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
private static final UUID UUID = java.util.UUID.fromString("87a48aa8-a071-705e-54a9-e52fe3a012f1"); |
|
|
|
private static final UUID UUID = java.util.UUID.fromString("87a48aa8-a071-705e-54a9-e52fe3a012f1"); |
|
|
|
private static final byte[] BYTES_REPRESENTING_UUID = { -121, -92, -118, -88, -96, 113, 112, 94, 84, -87, -27, 47, |
|
|
|
private static final byte[] BYTES_REPRESENTING_UUID = {-121, -92, -118, -88, -96, 113, 112, 94, 84, -87, -27, 47, |
|
|
|
-29, |
|
|
|
-29, |
|
|
|
-96, 18, -15 }; |
|
|
|
-96, 18, -15}; |
|
|
|
|
|
|
|
|
|
|
|
private JdbcMappingContext context = new JdbcMappingContext(); |
|
|
|
private JdbcMappingContext context = new JdbcMappingContext(); |
|
|
|
private StubbedJdbcTypeFactory typeFactory = new StubbedJdbcTypeFactory(); |
|
|
|
private StubbedJdbcTypeFactory typeFactory = new StubbedJdbcTypeFactory(); |
|
|
|
@ -79,31 +79,32 @@ class MappingJdbcConverterUnitTests { |
|
|
|
context.setSimpleTypeHolder(converter.getConversions().getSimpleTypeHolder()); |
|
|
|
context.setSimpleTypeHolder(converter.getConversions().getSimpleTypeHolder()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-104, DATAJDBC-1384
|
|
|
|
@Test |
|
|
|
|
|
|
|
// DATAJDBC-104, DATAJDBC-1384
|
|
|
|
void testTargetTypesForPropertyType() { |
|
|
|
void testTargetTypesForPropertyType() { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
|
|
|
|
|
|
|
|
SoftAssertions softly = new SoftAssertions(); |
|
|
|
SoftAssertions.assertSoftly(softly -> { |
|
|
|
|
|
|
|
|
|
|
|
checkTargetType(softly, entity, "someEnum", String.class); |
|
|
|
checkTargetType(softly, entity, "someEnum", String.class); |
|
|
|
checkTargetType(softly, entity, "localDateTime", LocalDateTime.class); |
|
|
|
checkTargetType(softly, entity, "localDateTime", LocalDateTime.class); |
|
|
|
checkTargetType(softly, entity, "localDate", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "localDate", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "localTime", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "localTime", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "zonedDateTime", String.class); |
|
|
|
checkTargetType(softly, entity, "zonedDateTime", String.class); |
|
|
|
checkTargetType(softly, entity, "offsetDateTime", OffsetDateTime.class); |
|
|
|
checkTargetType(softly, entity, "offsetDateTime", OffsetDateTime.class); |
|
|
|
checkTargetType(softly, entity, "instant", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "instant", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "date", Date.class); |
|
|
|
checkTargetType(softly, entity, "date", Date.class); |
|
|
|
checkTargetType(softly, entity, "timestamp", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "timestamp", Timestamp.class); |
|
|
|
checkTargetType(softly, entity, "uuid", UUID.class); |
|
|
|
checkTargetType(softly, entity, "uuid", UUID.class); |
|
|
|
checkTargetType(softly, entity, "reference", Long.class); |
|
|
|
checkTargetType(softly, entity, "reference", Long.class); |
|
|
|
checkTargetType(softly, entity, "enumIdReference", String.class); |
|
|
|
checkTargetType(softly, entity, "enumIdReference", String.class); |
|
|
|
checkTargetType(softly, entity, "customIdReference", Long.class); |
|
|
|
checkTargetType(softly, entity, "customIdReference", Long.class); |
|
|
|
|
|
|
|
}); |
|
|
|
softly.assertAll(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-259
|
|
|
|
@Test |
|
|
|
|
|
|
|
// DATAJDBC-259
|
|
|
|
void classificationOfCollectionLikeProperties() { |
|
|
|
void classificationOfCollectionLikeProperties() { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
@ -119,22 +120,24 @@ class MappingJdbcConverterUnitTests { |
|
|
|
softly.assertAll(); |
|
|
|
softly.assertAll(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-221
|
|
|
|
@Test |
|
|
|
|
|
|
|
// DATAJDBC-221
|
|
|
|
void referencesAreNotEntitiesAndGetStoredAsTheirId() { |
|
|
|
void referencesAreNotEntitiesAndGetStoredAsTheirId() { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
|
|
|
|
|
|
|
|
SoftAssertions softly = new SoftAssertions(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentProperty reference = entity.getRequiredPersistentProperty("reference"); |
|
|
|
RelationalPersistentProperty reference = entity.getRequiredPersistentProperty("reference"); |
|
|
|
|
|
|
|
|
|
|
|
softly.assertThat(reference.isEntity()).isFalse(); |
|
|
|
SoftAssertions.assertSoftly(softly -> { |
|
|
|
softly.assertThat(converter.getColumnType(reference)).isEqualTo(Long.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
softly.assertAll(); |
|
|
|
softly.assertThat(reference.isEntity()).isFalse(); |
|
|
|
|
|
|
|
softly.assertThat(converter.getColumnType(reference)).isEqualTo(Long.class); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-637
|
|
|
|
@Test |
|
|
|
|
|
|
|
// DATAJDBC-637
|
|
|
|
void conversionOfDateLikeValueAndBackYieldsOriginalValue() { |
|
|
|
void conversionOfDateLikeValueAndBackYieldsOriginalValue() { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class); |
|
|
|
@ -150,17 +153,19 @@ class MappingJdbcConverterUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-945
|
|
|
|
@Test |
|
|
|
|
|
|
|
// GH-945
|
|
|
|
void conversionOfPrimitiveArrays() { |
|
|
|
void conversionOfPrimitiveArrays() { |
|
|
|
|
|
|
|
|
|
|
|
int[] ints = { 1, 2, 3, 4, 5 }; |
|
|
|
int[] ints = {1, 2, 3, 4, 5}; |
|
|
|
JdbcValue converted = converter.writeJdbcValue(ints, ints.getClass(), JdbcUtil.targetSqlTypeFor(ints.getClass())); |
|
|
|
JdbcValue converted = converter.writeJdbcValue(ints, ints.getClass(), JdbcUtil.targetSqlTypeFor(ints.getClass())); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(converted.getValue()).isInstanceOf(Array.class); |
|
|
|
assertThat(converted.getValue()).isInstanceOf(Array.class); |
|
|
|
assertThat(typeFactory.arraySource).containsExactly(1, 2, 3, 4, 5); |
|
|
|
assertThat(typeFactory.arraySource).containsExactly(1, 2, 3, 4, 5); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-1684
|
|
|
|
@Test |
|
|
|
|
|
|
|
// GH-1684
|
|
|
|
void accessesCorrectValuesForOneToOneRelationshipWithIdenticallyNamedIdProperties() { |
|
|
|
void accessesCorrectValuesForOneToOneRelationshipWithIdenticallyNamedIdProperties() { |
|
|
|
|
|
|
|
|
|
|
|
RowDocument rowdocument = new RowDocument(Map.of("ID", "one", "REFERENCED_ID", 23)); |
|
|
|
RowDocument rowdocument = new RowDocument(Map.of("ID", "one", "REFERENCED_ID", 23)); |
|
|
|
@ -170,7 +175,8 @@ class MappingJdbcConverterUnitTests { |
|
|
|
assertThat(result).isEqualTo(new WithOneToOne("one", new Referenced(23L))); |
|
|
|
assertThat(result).isEqualTo(new WithOneToOne("one", new Referenced(23L))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-1750
|
|
|
|
@Test |
|
|
|
|
|
|
|
// GH-1750
|
|
|
|
void readByteArrayToNestedUuidWithCustomConverter() { |
|
|
|
void readByteArrayToNestedUuidWithCustomConverter() { |
|
|
|
|
|
|
|
|
|
|
|
JdbcMappingContext context = new JdbcMappingContext(); |
|
|
|
JdbcMappingContext context = new JdbcMappingContext(); |
|
|
|
@ -194,7 +200,7 @@ class MappingJdbcConverterUnitTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void checkReadConversion(SoftAssertions softly, MappingJdbcConverter converter, String propertyName, |
|
|
|
private static void checkReadConversion(SoftAssertions softly, MappingJdbcConverter converter, String propertyName, |
|
|
|
Object expected) { |
|
|
|
Object expected) { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentProperty property = converter.getMappingContext().getRequiredPersistentEntity(DummyEntity.class) |
|
|
|
RelationalPersistentProperty property = converter.getMappingContext().getRequiredPersistentEntity(DummyEntity.class) |
|
|
|
.getRequiredPersistentProperty(propertyName); |
|
|
|
.getRequiredPersistentProperty(propertyName); |
|
|
|
@ -205,7 +211,7 @@ class MappingJdbcConverterUnitTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkConversionToTimestampAndBack(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity, |
|
|
|
private void checkConversionToTimestampAndBack(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity, |
|
|
|
String propertyName, Object value) { |
|
|
|
String propertyName, Object value) { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName); |
|
|
|
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName); |
|
|
|
|
|
|
|
|
|
|
|
@ -216,7 +222,7 @@ class MappingJdbcConverterUnitTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity, |
|
|
|
private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity, |
|
|
|
String propertyName, Class<?> expected) { |
|
|
|
String propertyName, Class<?> expected) { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName); |
|
|
|
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName); |
|
|
|
|
|
|
|
|
|
|
|
@ -240,100 +246,12 @@ class MappingJdbcConverterUnitTests { |
|
|
|
AggregateReference<ReferencedByUuid, UUID> uuidRef, |
|
|
|
AggregateReference<ReferencedByUuid, UUID> uuidRef, |
|
|
|
Optional<UUID> optionalUuid, |
|
|
|
Optional<UUID> optionalUuid, |
|
|
|
|
|
|
|
|
|
|
|
// DATAJDBC-259
|
|
|
|
// DATAJDBC-259
|
|
|
|
private final List<String> listOfString; |
|
|
|
List<String> listOfString, |
|
|
|
private final String[] arrayOfString; |
|
|
|
String[] arrayOfString, |
|
|
|
private final List<OtherEntity> listOfEntity; |
|
|
|
List<OtherEntity> listOfEntity, |
|
|
|
private final OtherEntity[] arrayOfEntity; |
|
|
|
OtherEntity[] arrayOfEntity |
|
|
|
|
|
|
|
) { |
|
|
|
private DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, LocalDate localDate, |
|
|
|
|
|
|
|
LocalTime localTime, ZonedDateTime zonedDateTime, OffsetDateTime offsetDateTime, Instant instant, Date date, |
|
|
|
|
|
|
|
Timestamp timestamp, AggregateReference<DummyEntity, Long> reference, UUID uuid, |
|
|
|
|
|
|
|
AggregateReference<ReferencedByUuid, UUID> uuidRef, Optional<java.util.UUID> optionalUUID, List<String> listOfString, String[] arrayOfString, |
|
|
|
|
|
|
|
List<OtherEntity> listOfEntity, OtherEntity[] arrayOfEntity) { |
|
|
|
|
|
|
|
this.id = id; |
|
|
|
|
|
|
|
this.someEnum = someEnum; |
|
|
|
|
|
|
|
this.localDateTime = localDateTime; |
|
|
|
|
|
|
|
this.localDate = localDate; |
|
|
|
|
|
|
|
this.localTime = localTime; |
|
|
|
|
|
|
|
this.zonedDateTime = zonedDateTime; |
|
|
|
|
|
|
|
this.offsetDateTime = offsetDateTime; |
|
|
|
|
|
|
|
this.instant = instant; |
|
|
|
|
|
|
|
this.date = date; |
|
|
|
|
|
|
|
this.timestamp = timestamp; |
|
|
|
|
|
|
|
this.reference = reference; |
|
|
|
|
|
|
|
this.uuid = uuid; |
|
|
|
|
|
|
|
this.uuidRef = uuidRef; |
|
|
|
|
|
|
|
this.optionalUuid = optionalUUID; |
|
|
|
|
|
|
|
this.listOfString = listOfString; |
|
|
|
|
|
|
|
this.arrayOfString = arrayOfString; |
|
|
|
|
|
|
|
this.listOfEntity = listOfEntity; |
|
|
|
|
|
|
|
this.arrayOfEntity = arrayOfEntity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Long getId() { |
|
|
|
|
|
|
|
return this.id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SomeEnum getSomeEnum() { |
|
|
|
|
|
|
|
return this.someEnum; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LocalDateTime getLocalDateTime() { |
|
|
|
|
|
|
|
return this.localDateTime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LocalDate getLocalDate() { |
|
|
|
|
|
|
|
return this.localDate; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LocalTime getLocalTime() { |
|
|
|
|
|
|
|
return this.localTime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ZonedDateTime getZonedDateTime() { |
|
|
|
|
|
|
|
return this.zonedDateTime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public OffsetDateTime getOffsetDateTime() { |
|
|
|
|
|
|
|
return this.offsetDateTime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Instant getInstant() { |
|
|
|
|
|
|
|
return this.instant; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Date getDate() { |
|
|
|
|
|
|
|
return this.date; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Timestamp getTimestamp() { |
|
|
|
|
|
|
|
return this.timestamp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AggregateReference<DummyEntity, Long> getReference() { |
|
|
|
|
|
|
|
return this.reference; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UUID getUuid() { |
|
|
|
|
|
|
|
return this.uuid; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> getListOfString() { |
|
|
|
|
|
|
|
return this.listOfString; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String[] getArrayOfString() { |
|
|
|
|
|
|
|
return this.arrayOfString; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<OtherEntity> getListOfEntity() { |
|
|
|
|
|
|
|
return this.listOfEntity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public OtherEntity[] getArrayOfEntity() { |
|
|
|
|
|
|
|
return this.arrayOfEntity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
@ -342,7 +260,8 @@ class MappingJdbcConverterUnitTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
private static class OtherEntity {} |
|
|
|
private static class OtherEntity { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class EnumIdEntity { |
|
|
|
private static class EnumIdEntity { |
|
|
|
@Id SomeEnum id; |
|
|
|
@Id SomeEnum id; |
|
|
|
|