Skip to content

Commit

Permalink
Merge pull request #2837 from SeasonPanPan/Optimize-Configuration-che…
Browse files Browse the repository at this point in the history
…ckResultMaps

Optimize the loop of resultMaps in Configuration
  • Loading branch information
hazendaz authored Mar 6, 2023
2 parents acb63bf + 5ae537c commit b83c0f2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/apache/ibatis/session/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -990,14 +990,14 @@ protected String extractNamespace(String statementId) {
// Slow but a one time cost. A better solution is welcome.
protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
if (rm.hasNestedResultMaps()) {
for (Map.Entry<String, ResultMap> entry : resultMaps.entrySet()) {
Object value = entry.getValue();
if (value instanceof ResultMap) {
ResultMap entryResultMap = (ResultMap) value;
final String resultMapId = rm.getId();
for (Object resultMapObject : resultMaps.values()) {
if (resultMapObject instanceof ResultMap) {
ResultMap entryResultMap = (ResultMap) resultMapObject;
if (!entryResultMap.hasNestedResultMaps() && entryResultMap.getDiscriminator() != null) {
Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator().getDiscriminatorMap()
.values();
if (discriminatedResultMapNames.contains(rm.getId())) {
if (discriminatedResultMapNames.contains(resultMapId)) {
entryResultMap.forceNestedResultMaps();
}
}
Expand All @@ -1009,8 +1009,7 @@ protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
// Slow but a one time cost. A better solution is welcome.
protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
if (!rm.hasNestedResultMaps() && rm.getDiscriminator() != null) {
for (Map.Entry<String, String> entry : rm.getDiscriminator().getDiscriminatorMap().entrySet()) {
String discriminatedResultMapName = entry.getValue();
for (String discriminatedResultMapName : rm.getDiscriminator().getDiscriminatorMap().values()) {
if (hasResultMap(discriminatedResultMapName)) {
ResultMap discriminatedResultMap = resultMaps.get(discriminatedResultMapName);
if (discriminatedResultMap.hasNestedResultMaps()) {
Expand Down

0 comments on commit b83c0f2

Please sign in to comment.