Skip to content

Commit d722dd5

Browse files
committed
avoid introspecting the resultset
1 parent 075f0bd commit d722dd5

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private CacheKey createRowKey(ResultMap resultMap, ResultSet rs, String columnPr
252252
createRowKeyForUnmappedProperties(resultMap, rs, cacheKey, columnPrefix, resultColumnCache);
253253
}
254254
} else {
255-
createRowKeyForMappedProperties(rs, cacheKey, resultMappings, columnPrefix);
255+
createRowKeyForMappedProperties(resultMap, rs, cacheKey, resultMappings, columnPrefix, resultColumnCache);
256256
}
257257
if (cacheKey.getUpdateCount() < 2) {
258258
return CacheKey.NULL_CACHE_KEY;
@@ -277,16 +277,17 @@ private List<ResultMapping> getResultMappingsForRowKey(ResultMap resultMap) {
277277
return resultMappings;
278278
}
279279

280-
private void createRowKeyForMappedProperties(ResultSet rs, CacheKey cacheKey, List<ResultMapping> resultMappings, String columnPrefix) throws SQLException {
280+
private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSet rs, CacheKey cacheKey, List<ResultMapping> resultMappings, String columnPrefix, ResultColumnCache resultColumnCache) throws SQLException {
281281
for (ResultMapping resultMapping : resultMappings) {
282282
if (resultMapping.getNestedResultMapId() != null) {
283-
final ResultMap myResultMap = configuration.getResultMap(resultMapping.getNestedResultMapId());
284-
createRowKeyForMappedProperties(rs, cacheKey, myResultMap.getConstructorResultMappings(),
285-
prependPrefix(resultMapping.getColumnPrefix(), columnPrefix));
283+
final ResultMap nestedResultMap = configuration.getResultMap(resultMapping.getNestedResultMapId());
284+
createRowKeyForMappedProperties(nestedResultMap, rs, cacheKey, nestedResultMap.getConstructorResultMappings(),
285+
prependPrefix(resultMapping.getColumnPrefix(), columnPrefix), resultColumnCache);
286286
} else if (resultMapping.getNestedQueryId() == null) {
287287
final String column = prependPrefix(resultMapping.getColumn(), columnPrefix);
288288
final TypeHandler<?> th = resultMapping.getTypeHandler();
289-
if (column != null && resultSetHasColumn(rs, column)) { // issue #114
289+
List<String> mappedColumnNames = resultColumnCache.getMappedColumnNames(resultMap, columnPrefix);
290+
if (column != null && mappedColumnNames.contains(column.toUpperCase(Locale.ENGLISH))) { // issue #114
290291
final Object value = th.getResult(rs, column);
291292
if (value != null) {
292293
cacheKey.update(column);
@@ -334,20 +335,4 @@ private void createRowKeyForMap(ResultSet rs, CacheKey cacheKey) throws SQLExcep
334335
}
335336
}
336337

337-
protected boolean resultSetHasColumn(final ResultSet rs, final String column) {
338-
try {
339-
final ResultSetMetaData rsmd = rs.getMetaData();
340-
final int columnCount = rsmd.getColumnCount();
341-
for (int i = 1; i <= columnCount; i++) {
342-
final String label = rsmd.getColumnLabel(i);
343-
if (column.equalsIgnoreCase(label)) {
344-
return true;
345-
}
346-
}
347-
} catch (final SQLException e) {
348-
// ignore
349-
}
350-
return false;
351-
}
352-
353338
}

0 commit comments

Comments
 (0)