Skip to content

Commit 037dafd

Browse files
committed
code polish
1 parent 77eae66 commit 037dafd

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/main/java/org/apache/ibatis/executor/resultset/NestedResultSetHandler.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ private boolean applyNestedResultMappings(ResultSet rs, ResultMap resultMap, Met
135135
final String nestedResultMapId = resultMapping.getNestedResultMapId();
136136
if (nestedResultMapId != null) {
137137
try {
138-
final StringBuilder columnPrefixBuilder = new StringBuilder();
139-
if (parentPrefix != null) columnPrefixBuilder.append(parentPrefix);
140-
if (resultMapping.getColumnPrefix() != null) columnPrefixBuilder.append(resultMapping.getColumnPrefix());
141-
final String columnPrefix = columnPrefixBuilder.length() == 0 ? null : columnPrefixBuilder.toString().toUpperCase(Locale.ENGLISH);
138+
final String columnPrefix = getColumnPrefix(parentPrefix, resultMapping);
142139
final ResultMap nestedResultMap = getNestedResultMap(rs, nestedResultMapId, columnPrefix);
143140
final CacheKey rowKey = createRowKey(nestedResultMap, rs, columnPrefix, resultColumnCache);
144141
final Object ancestorObject = ancestorCache.get(rowKey);
@@ -149,7 +146,7 @@ private boolean applyNestedResultMappings(ResultSet rs, ResultMap resultMap, Met
149146
Object rowValue = objectCache.get(combinedKey);
150147
boolean knownValue = (rowValue != null);
151148
rowValue = getRowValue(rs, nestedResultMap, combinedKey, rowKey, columnPrefix, resultColumnCache, rowValue);
152-
final Object collectionProperty = instantiateCollectionPropertyIfAppropriate(resultMapping, metaObject); // even if there is no data an empty collection is set
149+
final Object collectionProperty = instantiateCollectionPropertyIfAppropriate(resultMapping, metaObject);
153150
if (rowValue != null && !knownValue && anyNotNullColumnHasValue(resultMapping, columnPrefix, rs)) {
154151
if (collectionProperty != null) {
155152
final MetaObject targetMetaObject = configuration.newMetaObject(collectionProperty);
@@ -171,21 +168,29 @@ private boolean applyNestedResultMappings(ResultSet rs, ResultMap resultMap, Met
171168
}
172169
return foundValues;
173170
}
171+
172+
private String getColumnPrefix(String parentPrefix, ResultMapping resultMapping) {
173+
final StringBuilder columnPrefixBuilder = new StringBuilder();
174+
if (parentPrefix != null) columnPrefixBuilder.append(parentPrefix);
175+
if (resultMapping.getColumnPrefix() != null) columnPrefixBuilder.append(resultMapping.getColumnPrefix());
176+
final String columnPrefix = columnPrefixBuilder.length() == 0 ? null : columnPrefixBuilder.toString().toUpperCase(Locale.ENGLISH);
177+
return columnPrefix;
178+
}
174179

175180
private boolean anyNotNullColumnHasValue(ResultMapping resultMapping, String columnPrefix, ResultSet rs) throws SQLException {
176181
Set<String> notNullColumns = resultMapping.getNotNullColumns();
177-
boolean anyNotNullColumnIsNotNull = true;
182+
boolean anyNotNullColumnHasValue = true;
178183
if (notNullColumns != null && !notNullColumns.isEmpty()) {
179-
anyNotNullColumnIsNotNull = false;
184+
anyNotNullColumnHasValue = false;
180185
for (String column: notNullColumns) {
181186
rs.getObject(prependPrefix(column, columnPrefix));
182187
if (!rs.wasNull()) {
183-
anyNotNullColumnIsNotNull = true;
188+
anyNotNullColumnHasValue = true;
184189
break;
185190
}
186191
}
187192
}
188-
return anyNotNullColumnIsNotNull;
193+
return anyNotNullColumnHasValue;
189194
}
190195

191196
private Object instantiateCollectionPropertyIfAppropriate(ResultMapping resultMapping, MetaObject metaObject) {

0 commit comments

Comments
 (0)