60
60
/**
61
61
* @author Clinton Begin
62
62
* @author Eduardo Macarron
63
+ * @author Iwao AVE!
63
64
*/
64
65
public class DefaultResultSetHandler implements ResultSetHandler {
65
66
@@ -78,7 +79,7 @@ public class DefaultResultSetHandler implements ResultSetHandler {
78
79
79
80
// nested resultmaps
80
81
private final Map <CacheKey , Object > nestedResultObjects = new HashMap <CacheKey , Object >();
81
- private final Map <CacheKey , Object > ancestorObjects = new HashMap <CacheKey , Object >();
82
+ private final Map <String , Object > ancestorObjects = new HashMap <String , Object >();
82
83
private final Map <String , String > ancestorColumnPrefix = new HashMap <String , String >();
83
84
84
85
// multiple resultsets
@@ -755,9 +756,9 @@ private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap r
755
756
nestedResultObjects .clear ();
756
757
storeObject (resultHandler , resultContext , rowValue , parentMapping , rsw .getResultSet ());
757
758
}
758
- rowValue = getRowValue (rsw , discriminatedResultMap , rowKey , rowKey , null , partialObject );
759
+ rowValue = getRowValue (rsw , discriminatedResultMap , rowKey , null , partialObject );
759
760
} else {
760
- rowValue = getRowValue (rsw , discriminatedResultMap , rowKey , rowKey , null , partialObject );
761
+ rowValue = getRowValue (rsw , discriminatedResultMap , rowKey , null , partialObject );
761
762
if (partialObject == null ) {
762
763
storeObject (resultHandler , resultContext , rowValue , parentMapping , rsw .getResultSet ());
763
764
}
@@ -772,14 +773,14 @@ private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap r
772
773
// GET VALUE FROM ROW FOR NESTED RESULT MAP
773
774
//
774
775
775
- private Object getRowValue (ResultSetWrapper rsw , ResultMap resultMap , CacheKey combinedKey , CacheKey absoluteKey , String columnPrefix , Object partialObject ) throws SQLException {
776
+ private Object getRowValue (ResultSetWrapper rsw , ResultMap resultMap , CacheKey combinedKey , String columnPrefix , Object partialObject ) throws SQLException {
776
777
final String resultMapId = resultMap .getId ();
777
778
Object resultObject = partialObject ;
778
779
if (resultObject != null ) {
779
780
final MetaObject metaObject = configuration .newMetaObject (resultObject );
780
- putAncestor (absoluteKey , resultObject , resultMapId , columnPrefix );
781
+ putAncestor (resultObject , resultMapId , columnPrefix );
781
782
applyNestedResultMappings (rsw , resultMap , metaObject , columnPrefix , combinedKey , false );
782
- ancestorObjects .remove (absoluteKey );
783
+ ancestorObjects .remove (resultMapId );
783
784
} else {
784
785
final ResultLoaderMap lazyLoader = new ResultLoaderMap ();
785
786
resultObject = createResultObject (rsw , resultMap , lazyLoader , columnPrefix );
@@ -790,9 +791,9 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, CacheKey c
790
791
foundValues = applyAutomaticMappings (rsw , resultMap , metaObject , columnPrefix ) || foundValues ;
791
792
}
792
793
foundValues = applyPropertyMappings (rsw , resultMap , metaObject , lazyLoader , columnPrefix ) || foundValues ;
793
- putAncestor (absoluteKey , resultObject , resultMapId , columnPrefix );
794
+ putAncestor (resultObject , resultMapId , columnPrefix );
794
795
foundValues = applyNestedResultMappings (rsw , resultMap , metaObject , columnPrefix , combinedKey , true ) || foundValues ;
795
- ancestorObjects .remove (absoluteKey );
796
+ ancestorObjects .remove (resultMapId );
796
797
foundValues = lazyLoader .size () > 0 || foundValues ;
797
798
resultObject = foundValues ? resultObject : null ;
798
799
}
@@ -803,11 +804,11 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, CacheKey c
803
804
return resultObject ;
804
805
}
805
806
806
- private void putAncestor (CacheKey rowKey , Object resultObject , String resultMapId , String columnPrefix ) {
807
+ private void putAncestor (Object resultObject , String resultMapId , String columnPrefix ) {
807
808
if (!ancestorColumnPrefix .containsKey (resultMapId )) {
808
809
ancestorColumnPrefix .put (resultMapId , columnPrefix );
809
810
}
810
- ancestorObjects .put (rowKey , resultObject );
811
+ ancestorObjects .put (resultMapId , resultObject );
811
812
}
812
813
813
814
//
@@ -822,24 +823,19 @@ private boolean applyNestedResultMappings(ResultSetWrapper rsw, ResultMap result
822
823
try {
823
824
final String columnPrefix = getColumnPrefix (parentPrefix , resultMapping );
824
825
final ResultMap nestedResultMap = getNestedResultMap (rsw .getResultSet (), nestedResultMapId , columnPrefix );
825
- CacheKey rowKey = null ;
826
- Object ancestorObject = null ;
827
- if (ancestorColumnPrefix .containsKey (nestedResultMapId )) {
828
- rowKey = createRowKey (nestedResultMap , rsw , ancestorColumnPrefix .get (nestedResultMapId ));
829
- ancestorObject = ancestorObjects .get (rowKey );
830
- }
826
+ Object ancestorObject = ancestorObjects .get (nestedResultMapId );
831
827
if (ancestorObject != null ) {
832
828
if (newObject ) {
833
829
linkObjects (metaObject , resultMapping , ancestorObject ); // issue #385
834
830
}
835
831
} else {
836
- rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
832
+ final CacheKey rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
837
833
final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
838
834
Object rowValue = nestedResultObjects .get (combinedKey );
839
835
boolean knownValue = (rowValue != null );
840
836
instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject ); // mandatory
841
837
if (anyNotNullColumnHasValue (resultMapping , columnPrefix , rsw .getResultSet ())) {
842
- rowValue = getRowValue (rsw , nestedResultMap , combinedKey , rowKey , columnPrefix , rowValue );
838
+ rowValue = getRowValue (rsw , nestedResultMap , combinedKey , columnPrefix , rowValue );
843
839
if (rowValue != null && !knownValue ) {
844
840
linkObjects (metaObject , resultMapping , rowValue );
845
841
foundValues = true ;
@@ -903,6 +899,9 @@ private CacheKey createRowKey(ResultMap resultMap, ResultSetWrapper rsw, String
903
899
} else {
904
900
createRowKeyForMappedProperties (resultMap , rsw , cacheKey , resultMappings , columnPrefix );
905
901
}
902
+ if (cacheKey .getUpdateCount () < 2 ) {
903
+ return CacheKey .NULL_CACHE_KEY ;
904
+ }
906
905
return cacheKey ;
907
906
}
908
907
0 commit comments