47
47
import org .apache .ibatis .mapping .ResultMapping ;
48
48
import org .apache .ibatis .reflection .MetaClass ;
49
49
import org .apache .ibatis .reflection .MetaObject ;
50
+ import org .apache .ibatis .reflection .ReflectorFactory ;
50
51
import org .apache .ibatis .reflection .factory .ObjectFactory ;
51
52
import org .apache .ibatis .session .AutoMappingBehavior ;
52
53
import org .apache .ibatis .session .Configuration ;
@@ -73,6 +74,7 @@ public class DefaultResultSetHandler implements ResultSetHandler {
73
74
private final BoundSql boundSql ;
74
75
private final TypeHandlerRegistry typeHandlerRegistry ;
75
76
private final ObjectFactory objectFactory ;
77
+ private final ReflectorFactory reflectorFactory ;
76
78
77
79
// nested resultmaps
78
80
private final Map <CacheKey , Object > nestedResultObjects = new HashMap <CacheKey , Object >();
@@ -82,12 +84,12 @@ public class DefaultResultSetHandler implements ResultSetHandler {
82
84
// multiple resultsets
83
85
private final Map <String , ResultMapping > nextResultMaps = new HashMap <String , ResultMapping >();
84
86
private final Map <CacheKey , List <PendingRelation >> pendingRelations = new HashMap <CacheKey , List <PendingRelation >>();
85
-
87
+
86
88
private static class PendingRelation {
87
89
public MetaObject metaObject ;
88
90
public ResultMapping propertyMapping ;
89
91
}
90
-
92
+
91
93
public DefaultResultSetHandler (Executor executor , MappedStatement mappedStatement , ParameterHandler parameterHandler , ResultHandler <?> resultHandler , BoundSql boundSql ,
92
94
RowBounds rowBounds ) {
93
95
this .executor = executor ;
@@ -98,6 +100,7 @@ public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatemen
98
100
this .boundSql = boundSql ;
99
101
this .typeHandlerRegistry = configuration .getTypeHandlerRegistry ();
100
102
this .objectFactory = configuration .getObjectFactory ();
103
+ this .reflectorFactory = configuration .getReflectorFactory ();
101
104
this .resultHandler = resultHandler ;
102
105
}
103
106
@@ -143,7 +146,7 @@ private void handleRefCursorOutputParameter(ResultSet rs, ParameterMapping param
143
146
@ Override
144
147
public List <Object > handleResultSets (Statement stmt ) throws SQLException {
145
148
ErrorContext .instance ().activity ("handling results" ).object (mappedStatement .getId ());
146
-
149
+
147
150
final List <Object > multipleResults = new ArrayList <Object >();
148
151
149
152
int resultSetCount = 0 ;
@@ -269,7 +272,7 @@ private void handleRowValues(ResultSetWrapper rsw, ResultMap resultMap, ResultHa
269
272
} else {
270
273
handleRowValuesForSimpleResultMap (rsw , resultMap , resultHandler , rowBounds , parentMapping );
271
274
}
272
- }
275
+ }
273
276
274
277
private void ensureNoRowBounds () {
275
278
if (configuration .isSafeRowBoundsEnabled () && rowBounds != null && (rowBounds .getLimit () < RowBounds .NO_ROW_LIMIT || rowBounds .getOffset () > RowBounds .NO_ROW_OFFSET )) {
@@ -281,10 +284,10 @@ private void ensureNoRowBounds() {
281
284
protected void checkResultHandler () {
282
285
if (resultHandler != null && configuration .isSafeResultHandlerEnabled () && !mappedStatement .isResultOrdered ()) {
283
286
throw new ExecutorException ("Mapped Statements with nested result mappings cannot be safely used with a custom ResultHandler. "
284
- + "Use safeResultHandlerEnabled=false setting to bypass this check "
287
+ + "Use safeResultHandlerEnabled=false setting to bypass this check "
285
288
+ "or ensure your statement returns ordered data and set resultOrdered=true on it." );
286
289
}
287
- }
290
+ }
288
291
289
292
private void handleRowValuesForSimpleResultMap (ResultSetWrapper rsw , ResultMap resultMap , ResultHandler <?> resultHandler , RowBounds rowBounds , ResultMapping parentMapping )
290
293
throws SQLException {
@@ -337,7 +340,7 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap) throws SQL
337
340
if (resultObject != null && !typeHandlerRegistry .hasTypeHandler (resultMap .getType ())) {
338
341
final MetaObject metaObject = configuration .newMetaObject (resultObject );
339
342
boolean foundValues = !resultMap .getConstructorResultMappings ().isEmpty ();
340
- if (shouldApplyAutomaticMappings (resultMap , false )) {
343
+ if (shouldApplyAutomaticMappings (resultMap , false )) {
341
344
foundValues = applyAutomaticMappings (rsw , resultMap , metaObject , null ) || foundValues ;
342
345
}
343
346
foundValues = applyPropertyMappings (rsw , resultMap , metaObject , lazyLoader , null ) || foundValues ;
@@ -374,9 +377,9 @@ private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap,
374
377
if (propertyMapping .getNestedResultMapId () != null ) {
375
378
// the user added a column attribute to a nested result map, ignore it
376
379
column = null ;
377
- }
378
- if (propertyMapping .isCompositeResult ()
379
- || (column != null && mappedColumnNames .contains (column .toUpperCase (Locale .ENGLISH )))
380
+ }
381
+ if (propertyMapping .isCompositeResult ()
382
+ || (column != null && mappedColumnNames .contains (column .toUpperCase (Locale .ENGLISH )))
380
383
|| propertyMapping .getResultSet () != null ) {
381
384
Object value = getPropertyMappingValue (rsw .getResultSet (), metaObject , propertyMapping , lazyLoader , columnPrefix );
382
385
// issue #541 make property optional
@@ -518,7 +521,7 @@ private Object createResultObject(ResultSetWrapper rsw, ResultMap resultMap, Res
518
521
private Object createResultObject (ResultSetWrapper rsw , ResultMap resultMap , List <Class <?>> constructorArgTypes , List <Object > constructorArgs , String columnPrefix )
519
522
throws SQLException {
520
523
final Class <?> resultType = resultMap .getType ();
521
- final MetaClass metaType = MetaClass .forClass (resultType );
524
+ final MetaClass metaType = MetaClass .forClass (resultType , reflectorFactory );
522
525
final List <ResultMapping > constructorMappings = resultMap .getConstructorResultMappings ();
523
526
if (typeHandlerRegistry .hasTypeHandler (resultType )) {
524
527
return createPrimitiveResultObject (rsw , resultMap , columnPrefix );
@@ -761,7 +764,7 @@ private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap r
761
764
storeObject (resultHandler , resultContext , rowValue , parentMapping , rsw .getResultSet ());
762
765
}
763
766
}
764
-
767
+
765
768
//
766
769
// GET VALUE FROM ROW FOR NESTED RESULT MAP
767
770
//
@@ -782,7 +785,7 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, CacheKey c
782
785
boolean foundValues = !resultMap .getConstructorResultMappings ().isEmpty ();
783
786
if (shouldApplyAutomaticMappings (resultMap , true )) {
784
787
foundValues = applyAutomaticMappings (rsw , resultMap , metaObject , columnPrefix ) || foundValues ;
785
- }
788
+ }
786
789
foundValues = applyPropertyMappings (rsw , resultMap , metaObject , lazyLoader , columnPrefix ) || foundValues ;
787
790
putAncestor (absoluteKey , resultObject , resultMapId , columnPrefix );
788
791
foundValues = applyNestedResultMappings (rsw , resultMap , metaObject , columnPrefix , combinedKey , true ) || foundValues ;
@@ -822,13 +825,13 @@ private boolean applyNestedResultMappings(ResultSetWrapper rsw, ResultMap result
822
825
rowKey = createRowKey (nestedResultMap , rsw , ancestorColumnPrefix .get (nestedResultMapId ));
823
826
ancestorObject = ancestorObjects .get (rowKey );
824
827
}
825
- if (ancestorObject != null ) {
828
+ if (ancestorObject != null ) {
826
829
if (newObject ) {
827
830
linkObjects (metaObject , resultMapping , ancestorObject ); // issue #385
828
831
}
829
832
} else {
830
833
rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
831
- final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
834
+ final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
832
835
Object rowValue = nestedResultObjects .get (combinedKey );
833
836
boolean knownValue = (rowValue != null );
834
837
instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject ); // mandatory
@@ -946,7 +949,7 @@ private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapp
946
949
}
947
950
948
951
private void createRowKeyForUnmappedProperties (ResultMap resultMap , ResultSetWrapper rsw , CacheKey cacheKey , String columnPrefix ) throws SQLException {
949
- final MetaClass metaType = MetaClass .forClass (resultMap .getType ());
952
+ final MetaClass metaType = MetaClass .forClass (resultMap .getType (), reflectorFactory );
950
953
List <String > unmappedColumnNames = rsw .getUnmappedColumnNames (resultMap , columnPrefix );
951
954
for (String column : unmappedColumnNames ) {
952
955
String property = column ;
0 commit comments