@@ -532,7 +532,7 @@ private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap,
532
532
final List <ResultMapping > propertyMappings = resultMap .getPropertyResultMappings ();
533
533
for (ResultMapping propertyMapping : propertyMappings ) {
534
534
String column = prependPrefix (propertyMapping .getColumn (), columnPrefix );
535
- if (propertyMapping .getNestedResultMapId () != null ) {
535
+ if (propertyMapping .getNestedResultMapId () != null && ! JdbcType . CURSOR . equals ( propertyMapping . getJdbcType ()) ) {
536
536
// the user added a column attribute to a nested result map, ignore it
537
537
column = null ;
538
538
}
@@ -568,6 +568,11 @@ private Object getPropertyMappingValue(ResultSet rs, MetaObject metaResultObject
568
568
if (propertyMapping .getNestedQueryId () != null ) {
569
569
return getNestedQueryMappingValue (rs , metaResultObject , propertyMapping , lazyLoader , columnPrefix );
570
570
}
571
+ if (JdbcType .CURSOR .equals (propertyMapping .getJdbcType ())) {
572
+ List <Object > results = getNestedCursorValue (rs , propertyMapping , columnPrefix );
573
+ linkObjects (metaResultObject , propertyMapping , results .get (0 ), true );
574
+ return metaResultObject .getValue (propertyMapping .getProperty ());
575
+ }
571
576
if (propertyMapping .getResultSet () != null ) {
572
577
addPendingChildRelation (rs , metaResultObject , propertyMapping ); // TODO is that OK?
573
578
return DEFERRED ;
@@ -578,6 +583,18 @@ private Object getPropertyMappingValue(ResultSet rs, MetaObject metaResultObject
578
583
}
579
584
}
580
585
586
+ private List <Object > getNestedCursorValue (ResultSet rs , ResultMapping propertyMapping , String parentColumnPrefix )
587
+ throws SQLException {
588
+ final String column = prependPrefix (propertyMapping .getColumn (), parentColumnPrefix );
589
+ ResultMap nestedResultMap = resolveDiscriminatedResultMap (rs ,
590
+ configuration .getResultMap (propertyMapping .getNestedResultMapId ()),
591
+ getColumnPrefix (parentColumnPrefix , propertyMapping ));
592
+ ResultSetWrapper rsw = new ResultSetWrapper (rs .getObject (column , ResultSet .class ), configuration );
593
+ List <Object > results = new ArrayList <>();
594
+ handleResultSet (rsw , nestedResultMap , results , null );
595
+ return results ;
596
+ }
597
+
581
598
private List <UnMappedColumnAutoMapping > createAutomaticMappings (ResultSetWrapper rsw , ResultMap resultMap ,
582
599
MetaObject metaObject , String columnPrefix ) throws SQLException {
583
600
final String mapKey = resultMap .getId () + ":" + columnPrefix ;
@@ -761,6 +778,15 @@ Object createParameterizedResultObject(ResultSetWrapper rsw, Class<?> resultType
761
778
try {
762
779
if (constructorMapping .getNestedQueryId () != null ) {
763
780
value = getNestedQueryConstructorValue (rsw .getResultSet (), constructorMapping , columnPrefix );
781
+ } else if (JdbcType .CURSOR .equals (constructorMapping .getJdbcType ())) {
782
+ List <?> result = (List <?>) getNestedCursorValue (rsw .getResultSet (), constructorMapping , columnPrefix ).get (0 );
783
+ if (objectFactory .isCollection (parameterType )) {
784
+ MetaObject collection = configuration .newMetaObject (objectFactory .create (parameterType ));
785
+ collection .addAll ((List <?>) result );
786
+ value = collection .getOriginalObject ();
787
+ } else {
788
+ value = toSingleObj (result );
789
+ }
764
790
} else if (constructorMapping .getNestedResultMapId () != null ) {
765
791
final String constructorColumnPrefix = getColumnPrefix (columnPrefix , constructorMapping );
766
792
final ResultMap resultMap = resolveDiscriminatedResultMap (rsw .getResultSet (),
@@ -1527,10 +1553,19 @@ private void createRowKeyForMap(ResultSetWrapper rsw, CacheKey cacheKey) throws
1527
1553
}
1528
1554
1529
1555
private void linkObjects (MetaObject metaObject , ResultMapping resultMapping , Object rowValue ) {
1556
+ linkObjects (metaObject , resultMapping , rowValue , false );
1557
+ }
1558
+
1559
+ private void linkObjects (MetaObject metaObject , ResultMapping resultMapping , Object rowValue ,
1560
+ boolean isNestedCursorResult ) {
1530
1561
final Object collectionProperty = instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject );
1531
1562
if (collectionProperty != null ) {
1532
1563
final MetaObject targetMetaObject = configuration .newMetaObject (collectionProperty );
1533
- targetMetaObject .add (rowValue );
1564
+ if (isNestedCursorResult ) {
1565
+ targetMetaObject .addAll ((List <?>) rowValue );
1566
+ } else {
1567
+ targetMetaObject .add (rowValue );
1568
+ }
1534
1569
1535
1570
// it is possible for pending creations to get set via property mappings,
1536
1571
// keep track of these, so we can rebuild them.
@@ -1543,10 +1578,16 @@ private void linkObjects(MetaObject metaObject, ResultMapping resultMapping, Obj
1543
1578
pendingPccRelations .put (originalObject , pendingRelation );
1544
1579
}
1545
1580
} else {
1546
- metaObject .setValue (resultMapping .getProperty (), rowValue );
1581
+ metaObject .setValue (resultMapping .getProperty (),
1582
+ isNestedCursorResult ? toSingleObj ((List <?>) rowValue ) : rowValue );
1547
1583
}
1548
1584
}
1549
1585
1586
+ private Object toSingleObj (List <?> list ) {
1587
+ // Even if there are multiple elements, silently returns the first one.
1588
+ return list .isEmpty () ? null : list .get (0 );
1589
+ }
1590
+
1550
1591
private Object instantiateCollectionPropertyIfAppropriate (ResultMapping resultMapping , MetaObject metaObject ) {
1551
1592
final String propertyName = resultMapping .getProperty ();
1552
1593
Object propertyValue = metaObject .getValue (propertyName );
0 commit comments