Skip to content

Commit 5061ca0

Browse files
committed
mybatis#101: Simplify main result handling loop and completely hide new functionality behind flag
1 parent 75a2e58 commit 5061ca0

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ public class DefaultResultSetHandler implements ResultSetHandler {
108108
private boolean useConstructorMappings;
109109

110110
private static class PendingRelation {
111+
111112
public MetaObject metaObject;
112113
public ResultMapping propertyMapping;
113114
}
114115

115116
private static class UnMappedColumnAutoMapping {
117+
116118
private final String column;
117119
private final String property;
118120
private final TypeHandler<?> typeHandler;
@@ -1047,42 +1049,35 @@ private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap r
10471049
final Object partialObject = nestedResultObjects.get(rowKey);
10481050
final boolean foundNewUniqueRow = partialObject == null;
10491051

1050-
// (issue #101) - found a new row, finish off the last creation
1051-
if (foundNewUniqueRow && lastHandledCreation != null) {
1052-
createAndStorePendingCreation(resultHandler, parentMapping, resultSet, resultContext, lastHandledCreation);
1053-
lastHandledCreation = null;
1054-
}
1052+
// issue #577, #542 && #101
1053+
if (useCollectionConstructorInjection) {
1054+
if (foundNewUniqueRow && lastHandledCreation != null) {
1055+
createAndStorePendingCreation(resultHandler, parentMapping, resultSet, resultContext, lastHandledCreation);
1056+
lastHandledCreation = null;
1057+
}
10551058

1056-
// issue #577 && #542
1057-
if (mappedStatement.isResultOrdered()) {
1059+
rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, null, partialObject);
1060+
if (rowValue instanceof PendingConstructorCreation) {
1061+
lastHandledCreation = (PendingConstructorCreation) rowValue;
1062+
}
1063+
} else if (mappedStatement.isResultOrdered()) {
10581064
if (foundNewUniqueRow && rowValue != null) {
10591065
nestedResultObjects.clear();
1060-
if (!useCollectionConstructorInjection) {
1061-
storeObject(resultHandler, resultContext, rowValue, parentMapping, resultSet);
1062-
}
1066+
storeObject(resultHandler, resultContext, rowValue, parentMapping, resultSet);
10631067
}
10641068
rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, null, partialObject);
10651069
} else {
10661070
rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, null, partialObject);
1067-
10681071
if (foundNewUniqueRow) {
1069-
if (!useCollectionConstructorInjection) {
1070-
storeObject(resultHandler, resultContext, rowValue, parentMapping, resultSet);
1071-
}
1072+
storeObject(resultHandler, resultContext, rowValue, parentMapping, resultSet);
10721073
}
10731074
}
1074-
1075-
if (useCollectionConstructorInjection && rowValue instanceof PendingConstructorCreation) {
1076-
lastHandledCreation = (PendingConstructorCreation) rowValue;
1077-
}
10781075
}
10791076

10801077
if (useCollectionConstructorInjection && lastHandledCreation != null) {
10811078
createAndStorePendingCreation(resultHandler, parentMapping, resultSet, resultContext, lastHandledCreation);
1082-
return;
1083-
}
1084-
1085-
if (rowValue != null && mappedStatement.isResultOrdered() && shouldProcessMoreRows(resultContext, rowBounds)) {
1079+
} else if (rowValue != null && mappedStatement.isResultOrdered()
1080+
&& shouldProcessMoreRows(resultContext, rowBounds)) {
10861081
storeObject(resultHandler, resultContext, rowValue, parentMapping, resultSet);
10871082
previousRowValue = null;
10881083
} else if (rowValue != null) {

0 commit comments

Comments
 (0)