Browse Source

DATAJDBC-370 - Polishing.

Refactored code to better use existing code.

Original Pull Request: #151
pull/152/head
Jens Schauder 7 years ago committed by Christoph Strobl
parent
commit
bf3f99c585
  1. 22
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java

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

@ -351,31 +351,23 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
@Nullable @Nullable
private Object readEmbeddedEntityFrom(@Nullable Object idValue, RelationalPersistentProperty property) { private Object readEmbeddedEntityFrom(@Nullable Object idValue, RelationalPersistentProperty property) {
ReadingContext<?> ctx = extendBy(property); ReadingContext<?> newContext = extendBy(property);
return hasInstanceValues(property, ctx) ? ctx.createInstanceInternal(idValue) : null; return newContext.hasInstanceValues(idValue) ? newContext.createInstanceInternal(idValue) : null;
} }
private boolean hasInstanceValues(RelationalPersistentProperty property, ReadingContext<?> ctx) { private boolean hasInstanceValues(Object idValue) {
RelationalPersistentEntity<?> persistentEntity = getMappingContext() RelationalPersistentEntity<?> persistentEntity = path.getLeafEntity();
.getPersistentEntity(property.getTypeInformation());
PersistentPropertyPathExtension extension = ctx.path;
for (RelationalPersistentProperty embeddedProperty : persistentEntity) { for (RelationalPersistentProperty embeddedProperty : persistentEntity) {
// if the embedded contains Lists, Sets or Maps we consider it non-empty
if (embeddedProperty.isQualified() || embeddedProperty.isReference()) { if (embeddedProperty.isQualified() || embeddedProperty.isReference()) {
return true; return true;
} }
try { if (readOrLoadProperty(idValue, embeddedProperty) != null) {
if (ctx.getObjectFromResultSet(extension.extendBy(embeddedProperty).getColumnName()) != null) { return true;
return true;
}
} catch (MappingException e) {
if (ctx.getObjectFromResultSet(extension.extendBy(embeddedProperty).getReverseColumnNameAlias()) != null) {
return true;
}
} }
} }

Loading…
Cancel
Save