Skip to content

Commit bf3f99c

Browse files
schauderchristophstrobl
authored andcommitted
DATAJDBC-370 - Polishing.
Refactored code to better use existing code. Original Pull Request: #151
1 parent 3a89ec0 commit bf3f99c

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -351,31 +351,23 @@ private Object readFrom(RelationalPersistentProperty property) {
351351
@Nullable
352352
private Object readEmbeddedEntityFrom(@Nullable Object idValue, RelationalPersistentProperty property) {
353353

354-
ReadingContext<?> ctx = extendBy(property);
355-
return hasInstanceValues(property, ctx) ? ctx.createInstanceInternal(idValue) : null;
354+
ReadingContext<?> newContext = extendBy(property);
355+
return newContext.hasInstanceValues(idValue) ? newContext.createInstanceInternal(idValue) : null;
356356
}
357357

358-
private boolean hasInstanceValues(RelationalPersistentProperty property, ReadingContext<?> ctx) {
358+
private boolean hasInstanceValues(Object idValue) {
359359

360-
RelationalPersistentEntity<?> persistentEntity = getMappingContext()
361-
.getPersistentEntity(property.getTypeInformation());
362-
363-
PersistentPropertyPathExtension extension = ctx.path;
360+
RelationalPersistentEntity<?> persistentEntity = path.getLeafEntity();
364361

365362
for (RelationalPersistentProperty embeddedProperty : persistentEntity) {
366363

364+
// if the embedded contains Lists, Sets or Maps we consider it non-empty
367365
if (embeddedProperty.isQualified() || embeddedProperty.isReference()) {
368366
return true;
369367
}
370368

371-
try {
372-
if (ctx.getObjectFromResultSet(extension.extendBy(embeddedProperty).getColumnName()) != null) {
373-
return true;
374-
}
375-
} catch (MappingException e) {
376-
if (ctx.getObjectFromResultSet(extension.extendBy(embeddedProperty).getReverseColumnNameAlias()) != null) {
377-
return true;
378-
}
369+
if (readOrLoadProperty(idValue, embeddedProperty) != null) {
370+
return true;
379371
}
380372
}
381373

0 commit comments

Comments
 (0)