DATAJDBC-229 - Added UUID.class as simple type.
Also made RelationalMappingContext actually use the JdbcSimpleTypes. In order for this to work the database needs to be able to handle parameters of type UUID and store them either as such or internally convert them. Currently no conversion by Spring Data JDBC happens. Original pull request: #76.
This commit is contained in:
@@ -66,6 +66,7 @@ public abstract class JdbcSimpleTypes {
|
||||
simpleTypes.add(Struct.class);
|
||||
simpleTypes.add(Time.class);
|
||||
simpleTypes.add(Timestamp.class);
|
||||
simpleTypes.add(UUID.class);
|
||||
|
||||
JDBC_SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
|
||||
}
|
||||
|
||||
@@ -17,17 +17,12 @@ package org.springframework.data.relational.core.mapping;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.jdbc.core.mapping.JdbcSimpleTypes;
|
||||
import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -39,7 +34,8 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RelationalMappingContext extends AbstractMappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> {
|
||||
public class RelationalMappingContext
|
||||
extends AbstractMappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> {
|
||||
|
||||
@Getter private final NamingStrategy namingStrategy;
|
||||
|
||||
@@ -61,7 +57,7 @@ public class RelationalMappingContext extends AbstractMappingContext<RelationalP
|
||||
|
||||
this.namingStrategy = namingStrategy;
|
||||
|
||||
setSimpleTypeHolder(new SimpleTypeHolder(Collections.emptySet(), true));
|
||||
setSimpleTypeHolder(JdbcSimpleTypes.HOLDER);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -78,8 +74,8 @@ public class RelationalMappingContext extends AbstractMappingContext<RelationalP
|
||||
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(org.springframework.data.mapping.model.Property, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder)
|
||||
*/
|
||||
@Override
|
||||
protected RelationalPersistentProperty createPersistentProperty(Property property, RelationalPersistentEntity<?> owner,
|
||||
SimpleTypeHolder simpleTypeHolder) {
|
||||
protected RelationalPersistentProperty createPersistentProperty(Property property,
|
||||
RelationalPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||
return new BasicRelationalPersistentProperty(property, owner, simpleTypeHolder, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,11 @@ import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link BasicRelationalPersistentProperty}.
|
||||
@@ -62,6 +59,21 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-104, DATAJDBC-1384
|
||||
public void testTargetTypesForPropertyType() {
|
||||
|
||||
SoftAssertions softly = new SoftAssertions();
|
||||
|
||||
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
|
||||
|
||||
checkTargetType(softly, persistentEntity, "someEnum", String.class);
|
||||
checkTargetType(softly, persistentEntity, "localDateTime", Date.class);
|
||||
checkTargetType(softly, persistentEntity, "zonedDateTime", String.class);
|
||||
checkTargetType(softly, persistentEntity, "uuid", UUID.class);
|
||||
|
||||
softly.assertAll();
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-106
|
||||
public void detectsAnnotatedColumnName() {
|
||||
|
||||
@@ -72,15 +84,23 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
.isEqualTo("dummy_last_updated_at");
|
||||
}
|
||||
|
||||
private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity,
|
||||
String propertyName, Class<?> expected) {
|
||||
|
||||
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName);
|
||||
|
||||
softly.assertThat(property.getColumnType()).describedAs(propertyName).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class DummyEntity {
|
||||
|
||||
private final SomeEnum someEnum;
|
||||
private final LocalDateTime localDateTime;
|
||||
private final ZonedDateTime zonedDateTime;
|
||||
private final UUID uuid;
|
||||
|
||||
// DATACMNS-106
|
||||
|
||||
private @Column("dummy_name") String name;
|
||||
|
||||
@Column("dummy_last_updated_at")
|
||||
|
||||
@@ -35,6 +35,7 @@ public class RelationalMappingContextUnitTests {
|
||||
RelationalMappingContext mappingContext = new RelationalMappingContext();
|
||||
RelationalPersistentEntity<?> entity = mappingContext.getPersistentEntity(EntityWithUuid.class);
|
||||
RelationalPersistentProperty uuidProperty = entity.getRequiredPersistentProperty("uuid");
|
||||
|
||||
assertThat(uuidProperty.isEntity()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user