46
46
import org .apache .ibatis .mapping .ResultMapping ;
47
47
import org .apache .ibatis .reflection .MetaClass ;
48
48
import org .apache .ibatis .reflection .MetaObject ;
49
+ import org .apache .ibatis .reflection .ReflectorFactory ;
49
50
import org .apache .ibatis .reflection .factory .ObjectFactory ;
50
51
import org .apache .ibatis .session .AutoMappingBehavior ;
51
52
import org .apache .ibatis .session .Configuration ;
@@ -72,6 +73,7 @@ public class DefaultResultSetHandler implements ResultSetHandler {
72
73
private final BoundSql boundSql ;
73
74
private final TypeHandlerRegistry typeHandlerRegistry ;
74
75
private final ObjectFactory objectFactory ;
76
+ private final ReflectorFactory reflectorFactory ;
75
77
76
78
// nested resultmaps
77
79
private final Map <CacheKey , Object > nestedResultObjects = new HashMap <CacheKey , Object >();
@@ -81,12 +83,12 @@ public class DefaultResultSetHandler implements ResultSetHandler {
81
83
// multiple resultsets
82
84
private final Map <String , ResultMapping > nextResultMaps = new HashMap <String , ResultMapping >();
83
85
private final Map <CacheKey , List <PendingRelation >> pendingRelations = new HashMap <CacheKey , List <PendingRelation >>();
84
-
86
+
85
87
private static class PendingRelation {
86
88
public MetaObject metaObject ;
87
89
public ResultMapping propertyMapping ;
88
90
}
89
-
91
+
90
92
public DefaultResultSetHandler (Executor executor , MappedStatement mappedStatement , ParameterHandler parameterHandler , ResultHandler <?> resultHandler , BoundSql boundSql ,
91
93
RowBounds rowBounds ) {
92
94
this .executor = executor ;
@@ -97,6 +99,7 @@ public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatemen
97
99
this .boundSql = boundSql ;
98
100
this .typeHandlerRegistry = configuration .getTypeHandlerRegistry ();
99
101
this .objectFactory = configuration .getObjectFactory ();
102
+ this .reflectorFactory = configuration .getReflectorFactory ();
100
103
this .resultHandler = resultHandler ;
101
104
}
102
105
@@ -142,7 +145,7 @@ private void handleRefCursorOutputParameter(ResultSet rs, ParameterMapping param
142
145
@ Override
143
146
public List <Object > handleResultSets (Statement stmt ) throws SQLException {
144
147
ErrorContext .instance ().activity ("handling results" ).object (mappedStatement .getId ());
145
-
148
+
146
149
final List <Object > multipleResults = new ArrayList <Object >();
147
150
148
151
int resultSetCount = 0 ;
@@ -268,7 +271,7 @@ private void handleRowValues(ResultSetWrapper rsw, ResultMap resultMap, ResultHa
268
271
} else {
269
272
handleRowValuesForSimpleResultMap (rsw , resultMap , resultHandler , rowBounds , parentMapping );
270
273
}
271
- }
274
+ }
272
275
273
276
private void ensureNoRowBounds () {
274
277
if (configuration .isSafeRowBoundsEnabled () && rowBounds != null && (rowBounds .getLimit () < RowBounds .NO_ROW_LIMIT || rowBounds .getOffset () > RowBounds .NO_ROW_OFFSET )) {
@@ -280,10 +283,10 @@ private void ensureNoRowBounds() {
280
283
protected void checkResultHandler () {
281
284
if (resultHandler != null && configuration .isSafeResultHandlerEnabled () && !mappedStatement .isResultOrdered ()) {
282
285
throw new ExecutorException ("Mapped Statements with nested result mappings cannot be safely used with a custom ResultHandler. "
283
- + "Use safeResultHandlerEnabled=false setting to bypass this check "
286
+ + "Use safeResultHandlerEnabled=false setting to bypass this check "
284
287
+ "or ensure your statement returns ordered data and set resultOrdered=true on it." );
285
288
}
286
- }
289
+ }
287
290
288
291
private void handleRowValuesForSimpleResultMap (ResultSetWrapper rsw , ResultMap resultMap , ResultHandler <?> resultHandler , RowBounds rowBounds , ResultMapping parentMapping )
289
292
throws SQLException {
@@ -336,7 +339,7 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap) throws SQL
336
339
if (resultObject != null && !typeHandlerRegistry .hasTypeHandler (resultMap .getType ())) {
337
340
final MetaObject metaObject = configuration .newMetaObject (resultObject );
338
341
boolean foundValues = !resultMap .getConstructorResultMappings ().isEmpty ();
339
- if (shouldApplyAutomaticMappings (resultMap , false )) {
342
+ if (shouldApplyAutomaticMappings (resultMap , false )) {
340
343
foundValues = applyAutomaticMappings (rsw , resultMap , metaObject , null ) || foundValues ;
341
344
}
342
345
foundValues = applyPropertyMappings (rsw , resultMap , metaObject , lazyLoader , null ) || foundValues ;
@@ -373,9 +376,9 @@ private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap,
373
376
if (propertyMapping .getNestedResultMapId () != null ) {
374
377
// the user added a column attribute to a nested result map, ignore it
375
378
column = null ;
376
- }
377
- if (propertyMapping .isCompositeResult ()
378
- || (column != null && mappedColumnNames .contains (column .toUpperCase (Locale .ENGLISH )))
379
+ }
380
+ if (propertyMapping .isCompositeResult ()
381
+ || (column != null && mappedColumnNames .contains (column .toUpperCase (Locale .ENGLISH )))
379
382
|| propertyMapping .getResultSet () != null ) {
380
383
Object value = getPropertyMappingValue (rsw .getResultSet (), metaObject , propertyMapping , lazyLoader , columnPrefix );
381
384
// issue #541 make property optional
@@ -548,7 +551,7 @@ private Object createResultObject(ResultSetWrapper rsw, ResultMap resultMap, Res
548
551
private Object createResultObject (ResultSetWrapper rsw , ResultMap resultMap , List <Class <?>> constructorArgTypes , List <Object > constructorArgs , String columnPrefix )
549
552
throws SQLException {
550
553
final Class <?> resultType = resultMap .getType ();
551
- final MetaClass metaType = MetaClass .forClass (resultType );
554
+ final MetaClass metaType = MetaClass .forClass (resultType , reflectorFactory );
552
555
final List <ResultMapping > constructorMappings = resultMap .getConstructorResultMappings ();
553
556
if (typeHandlerRegistry .hasTypeHandler (resultType )) {
554
557
return createPrimitiveResultObject (rsw , resultMap , columnPrefix );
@@ -785,7 +788,7 @@ private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap r
785
788
storeObject (resultHandler , resultContext , rowValue , parentMapping , rsw .getResultSet ());
786
789
}
787
790
}
788
-
791
+
789
792
//
790
793
// GET VALUE FROM ROW FOR NESTED RESULT MAP
791
794
//
@@ -806,7 +809,7 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, CacheKey c
806
809
boolean foundValues = !resultMap .getConstructorResultMappings ().isEmpty ();
807
810
if (shouldApplyAutomaticMappings (resultMap , true )) {
808
811
foundValues = applyAutomaticMappings (rsw , resultMap , metaObject , columnPrefix ) || foundValues ;
809
- }
812
+ }
810
813
foundValues = applyPropertyMappings (rsw , resultMap , metaObject , lazyLoader , columnPrefix ) || foundValues ;
811
814
putAncestor (absoluteKey , resultObject , resultMapId , columnPrefix );
812
815
foundValues = applyNestedResultMappings (rsw , resultMap , metaObject , columnPrefix , combinedKey , true ) || foundValues ;
@@ -846,16 +849,16 @@ private boolean applyNestedResultMappings(ResultSetWrapper rsw, ResultMap result
846
849
rowKey = createRowKey (nestedResultMap , rsw , ancestorColumnPrefix .get (nestedResultMapId ));
847
850
ancestorObject = ancestorObjects .get (rowKey );
848
851
}
849
- if (ancestorObject != null ) {
852
+ if (ancestorObject != null ) {
850
853
if (newObject ) {
851
854
metaObject .setValue (resultMapping .getProperty (), ancestorObject );
852
855
}
853
856
} else {
854
857
rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
855
- final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
858
+ final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
856
859
Object rowValue = nestedResultObjects .get (combinedKey );
857
860
boolean knownValue = (rowValue != null );
858
- final Object collectionProperty = instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject );
861
+ final Object collectionProperty = instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject );
859
862
if (anyNotNullColumnHasValue (resultMapping , columnPrefix , rsw .getResultSet ())) {
860
863
rowValue = getRowValue (rsw , nestedResultMap , combinedKey , rowKey , columnPrefix , rowValue );
861
864
if (rowValue != null && !knownValue ) {
@@ -975,7 +978,7 @@ private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapp
975
978
}
976
979
977
980
private void createRowKeyForUnmappedProperties (ResultMap resultMap , ResultSetWrapper rsw , CacheKey cacheKey , String columnPrefix ) throws SQLException {
978
- final MetaClass metaType = MetaClass .forClass (resultMap .getType ());
981
+ final MetaClass metaType = MetaClass .forClass (resultMap .getType (), reflectorFactory );
979
982
List <String > unmappedColumnNames = rsw .getUnmappedColumnNames (resultMap , columnPrefix );
980
983
for (String column : unmappedColumnNames ) {
981
984
String property = column ;
0 commit comments