DATAJDBC-428 - Polishing.
Code formatting.
This commit is contained in:
@@ -75,8 +75,8 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
|
||||
/**
|
||||
* Creates a new {@link BasicRelationalConverter} given {@link MappingContext} and a
|
||||
* {@link JdbcTypeFactory#unsupported() no-op type factory} throwing {@link UnsupportedOperationException} on type
|
||||
* creation. Use {@link #BasicJdbcConverter(MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and
|
||||
* large objects into JDBC-specific types.
|
||||
* creation. Use {@link #BasicJdbcConverter(MappingContext, RelationResolver, CustomConversions, JdbcTypeFactory)}
|
||||
* (MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.
|
||||
*
|
||||
* @param context must not be {@literal null}.
|
||||
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
|
||||
@@ -131,6 +131,7 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
|
||||
}
|
||||
|
||||
if (AggregateReference.class.isAssignableFrom(type.getType())) {
|
||||
|
||||
if (type.getType().isAssignableFrom(value.getClass())) {
|
||||
return value;
|
||||
}
|
||||
@@ -297,7 +298,7 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
|
||||
}
|
||||
|
||||
private <S> ReadingContext<S> extendBy(RelationalPersistentProperty property) {
|
||||
return new ReadingContext<S>(
|
||||
return new ReadingContext<>(
|
||||
(RelationalPersistentEntity<S>) getMappingContext().getRequiredPersistentEntity(property.getActualType()),
|
||||
resultSet, rootPath.extendBy(property), path.extendBy(property), identifier, key);
|
||||
}
|
||||
@@ -382,7 +383,7 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
|
||||
|
||||
ReadingContext<?> newContext = extendBy(property);
|
||||
|
||||
if(shouldCreateEmptyEmbeddedInstance(property) || newContext.hasInstanceValues(idValue)) {
|
||||
if (shouldCreateEmptyEmbeddedInstance(property) || newContext.hasInstanceValues(idValue)) {
|
||||
return newContext.createInstanceInternal(idValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.junit.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
@@ -131,19 +130,19 @@ public class EntityRowMapperUnitTests {
|
||||
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha");
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-427
|
||||
@Test // DATAJDBC-427
|
||||
public void simpleWithReferenceGetProperlyExtracted() throws SQLException {
|
||||
|
||||
ResultSet rs = mockResultSet(asList("id", "name", "trivial_id"), //
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 100L);
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 100L);
|
||||
rs.next();
|
||||
|
||||
WithReference extracted = createRowMapper(WithReference.class).mapRow(rs, 1);
|
||||
|
||||
assertThat(extracted) //
|
||||
.isNotNull() //
|
||||
.extracting(e -> e.id, e -> e.name, e -> e.trivialId) //
|
||||
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", AggregateReference.to(100L));
|
||||
.isNotNull() //
|
||||
.extracting(e -> e.id, e -> e.name, e -> e.trivialId) //
|
||||
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", AggregateReference.to(100L));
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-113
|
||||
@@ -176,19 +175,19 @@ public class EntityRowMapperUnitTests {
|
||||
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 24L, "beta");
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-427
|
||||
@Test // DATAJDBC-427
|
||||
public void immutableWithReferenceGetsProperlyExtracted() throws SQLException {
|
||||
|
||||
ResultSet rs = mockResultSet(asList("id", "name", "trivial_id"), //
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 100L);
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 100L);
|
||||
rs.next();
|
||||
|
||||
WithReferenceImmutable extracted = createRowMapper(WithReferenceImmutable.class).mapRow(rs, 1);
|
||||
|
||||
assertThat(extracted) //
|
||||
.isNotNull() //
|
||||
.extracting(e -> e.id, e -> e.name, e -> e.trivialId) //
|
||||
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", AggregateReference.to(100L));
|
||||
.isNotNull() //
|
||||
.extracting(e -> e.id, e -> e.name, e -> e.trivialId) //
|
||||
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", AggregateReference.to(100L));
|
||||
}
|
||||
|
||||
// TODO add additional test for multilevel embeddables
|
||||
@@ -334,7 +333,8 @@ public class EntityRowMapperUnitTests {
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, "ru'Ha'");
|
||||
rs.next();
|
||||
|
||||
WithNullableEmbeddedImmutableValue extracted = createRowMapper(WithNullableEmbeddedImmutableValue.class).mapRow(rs, 1);
|
||||
WithNullableEmbeddedImmutableValue extracted = createRowMapper(WithNullableEmbeddedImmutableValue.class) //
|
||||
.mapRow(rs, 1);
|
||||
|
||||
assertThat(extracted) //
|
||||
.isNotNull() //
|
||||
@@ -365,7 +365,8 @@ public class EntityRowMapperUnitTests {
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, 24);
|
||||
rs.next();
|
||||
|
||||
WithEmbeddedPrimitiveImmutableValue extracted = createRowMapper(WithEmbeddedPrimitiveImmutableValue.class).mapRow(rs, 1);
|
||||
WithEmbeddedPrimitiveImmutableValue extracted = createRowMapper(WithEmbeddedPrimitiveImmutableValue.class)
|
||||
.mapRow(rs, 1);
|
||||
|
||||
assertThat(extracted) //
|
||||
.isNotNull() //
|
||||
@@ -380,7 +381,8 @@ public class EntityRowMapperUnitTests {
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, null);
|
||||
rs.next();
|
||||
|
||||
WithNullableEmbeddedImmutableValue extracted = createRowMapper(WithNullableEmbeddedImmutableValue.class).mapRow(rs, 1);
|
||||
WithNullableEmbeddedImmutableValue extracted = createRowMapper(WithNullableEmbeddedImmutableValue.class) //
|
||||
.mapRow(rs, 1);
|
||||
|
||||
assertThat(extracted) //
|
||||
.isNotNull() //
|
||||
@@ -428,7 +430,8 @@ public class EntityRowMapperUnitTests {
|
||||
ID_FOR_ENTITY_NOT_REFERENCING_MAP, null);
|
||||
rs.next();
|
||||
|
||||
WithEmbeddedPrimitiveImmutableValue extracted = createRowMapper(WithEmbeddedPrimitiveImmutableValue.class).mapRow(rs, 1);
|
||||
WithEmbeddedPrimitiveImmutableValue extracted = createRowMapper(WithEmbeddedPrimitiveImmutableValue.class)
|
||||
.mapRow(rs, 1);
|
||||
|
||||
assertThat(extracted) //
|
||||
.isNotNull() //
|
||||
|
||||
Reference in New Issue
Block a user