Skip to content

Commit

Permalink
mybatis#101 Do not calculate flag everywhere, do it only once while b…
Browse files Browse the repository at this point in the history
…uilding the resultMap
  • Loading branch information
willie committed Mar 21, 2024
1 parent 70dfaa9 commit d5e0167
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main/java/org/apache/ibatis/mapping/ResultMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ResultMap {
private Set<String> mappedColumns;
private Set<String> mappedProperties;
private Discriminator discriminator;
private boolean hasResultMapsUsingConstructorCollection;
private boolean hasNestedResultMaps;
private boolean hasNestedQueries;
private Boolean autoMapping;
Expand All @@ -63,7 +64,7 @@ public Builder(Configuration configuration, String id, Class<?> type, List<Resul
}

public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings,
Boolean autoMapping) {
Boolean autoMapping) {
resultMap.configuration = configuration;
resultMap.id = id;
resultMap.type = type;
Expand Down Expand Up @@ -111,6 +112,14 @@ public ResultMap build() {
}
if (resultMapping.getFlags().contains(ResultFlag.CONSTRUCTOR)) {
resultMap.constructorResultMappings.add(resultMapping);

//#101
if (resultMap.configuration.isExperimentalConstructorCollectionMappingEnabled()) {
Class<?> javaType = resultMapping.getJavaType();
resultMap.hasResultMapsUsingConstructorCollection = resultMap.hasResultMapsUsingConstructorCollection
|| (javaType != null && resultMap.configuration.getObjectFactory().isCollection(javaType));
}

if (resultMapping.getProperty() != null) {
constructorArgNames.add(resultMapping.getProperty());
}
Expand All @@ -136,6 +145,12 @@ public ResultMap build() {
int paramIdx2 = actualArgNames.indexOf(o2.getProperty());
return paramIdx1 - paramIdx2;
});

//#101
if (resultMap.configuration.isExperimentalConstructorCollectionMappingEnabled()) {
resultMap.hasResultMapsUsingConstructorCollection = resultMap.constructorResultMappings.stream()
.map(ResultMapping::getJavaType).anyMatch(resultMap.configuration.getObjectFactory()::isCollection);
}
}
// lock down collections
resultMap.resultMappings = Collections.unmodifiableList(resultMap.resultMappings);
Expand Down Expand Up @@ -211,9 +226,7 @@ public String getId() {
}

public boolean hasResultMapsUsingConstructorCollection() {
return configuration.isExperimentalConstructorCollectionMappingEnabled()
&& this.constructorResultMappings.stream().filter(crm -> crm.getNestedQueryId() == null)
.map(ResultMapping::getJavaType).anyMatch(configuration.getObjectFactory()::isCollection);
return hasResultMapsUsingConstructorCollection;
}

public boolean hasNestedResultMaps() {
Expand Down

0 comments on commit d5e0167

Please sign in to comment.