• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / mybatis-3 / 3081

26 Dec 2025 06:25PM UTC coverage: 87.396% (+0.01%) from 87.382%
3081

Pull #3579

github

web-flow
Merge 1da72b86e into 17d9f882a
Pull Request #3579: Reduce the memory usage of inline ResultMap

3845 of 4659 branches covered (82.53%)

20 of 20 new or added lines in 4 files covered. (100.0%)

9 existing lines in 3 files now uncovered.

9957 of 11393 relevant lines covered (87.4%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/main/java/org/apache/ibatis/mapping/ResultMap.java
1
/*
2
 *    Copyright 2009-2025 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.apache.ibatis.mapping;
17

18
import java.util.ArrayList;
19
import java.util.Collections;
20
import java.util.HashSet;
21
import java.util.List;
22
import java.util.Locale;
23
import java.util.Set;
24

25
import org.apache.ibatis.session.Configuration;
26
import org.apache.ibatis.type.JdbcType;
27

28
/**
29
 * @author Clinton Begin
30
 */
31
public class ResultMap {
32
  private Configuration configuration;
33

34
  private String id;
35
  private Class<?> type;
36
  private List<ResultMapping> resultMappings;
37
  private List<ResultMapping> idResultMappings;
38
  private List<ResultMapping> constructorResultMappings;
39
  private List<ResultMapping> propertyResultMappings;
40
  private Set<String> mappedColumns;
41
  private Set<String> mappedProperties;
42
  private Discriminator discriminator;
43
  private boolean hasResultMapsUsingConstructorCollection;
44
  private boolean hasNestedResultMaps;
45
  private boolean hasNestedQueries;
46
  private Boolean autoMapping;
47

48
  private ResultMap() {
49
  }
50

51
  public static ResultMap inline(Configuration configuration, String statementId, Class<?> resultType) {
52
    ResultMap inlineResultMap = new ResultMap();
1✔
53
    inlineResultMap.configuration = configuration;
1✔
54
    inlineResultMap.id = statementId + "-Inline";
1✔
55
    inlineResultMap.type = resultType;
1✔
56
    // lock down collections
57
    inlineResultMap.resultMappings = Collections.emptyList();
1✔
58
    inlineResultMap.idResultMappings = Collections.emptyList();
1✔
59
    inlineResultMap.constructorResultMappings = Collections.emptyList();
1✔
60
    inlineResultMap.propertyResultMappings = Collections.emptyList();
1✔
61
    inlineResultMap.mappedColumns = Collections.emptySet();
1✔
62
    inlineResultMap.mappedProperties = Collections.emptySet();
1✔
63
    return inlineResultMap;
1✔
64
  }
65

66
  public static class Builder {
67
    private final ResultMap resultMap = new ResultMap();
1✔
68

69
    public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings) {
70
      this(configuration, id, type, resultMappings, null);
1✔
71
    }
1✔
72

73
    public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings,
74
        Boolean autoMapping) {
1✔
75
      resultMap.configuration = configuration;
1✔
76
      resultMap.id = id;
1✔
77
      resultMap.type = type;
1✔
78
      resultMap.resultMappings = resultMappings;
1✔
79
      resultMap.autoMapping = autoMapping;
1✔
80
    }
1✔
81

82
    public Builder discriminator(Discriminator discriminator) {
83
      resultMap.discriminator = discriminator;
1✔
84
      return this;
1✔
85
    }
86

87
    public Class<?> type() {
UNCOV
88
      return resultMap.type;
×
89
    }
90

91
    public ResultMap build() {
92
      if (resultMap.id == null) {
1!
UNCOV
93
        throw new IllegalArgumentException("ResultMaps must have an id");
×
94
      }
95

96
      resultMap.mappedColumns = new HashSet<>();
1✔
97
      resultMap.mappedProperties = new HashSet<>();
1✔
98
      resultMap.idResultMappings = new ArrayList<>();
1✔
99
      resultMap.constructorResultMappings = new ArrayList<>();
1✔
100
      resultMap.propertyResultMappings = new ArrayList<>();
1✔
101

102
      for (ResultMapping resultMapping : resultMap.resultMappings) {
1✔
103
        resultMap.hasNestedQueries = resultMap.hasNestedQueries || resultMapping.getNestedQueryId() != null;
1✔
104
        resultMap.hasNestedResultMaps = resultMap.hasNestedResultMaps || resultMapping.getNestedResultMapId() != null
1✔
105
            && resultMapping.getResultSet() == null && !JdbcType.CURSOR.equals(resultMapping.getJdbcType());
1!
106
        final String column = resultMapping.getColumn();
1✔
107
        if (column != null) {
1✔
108
          resultMap.mappedColumns.add(column.toUpperCase(Locale.ENGLISH));
1✔
109
        } else if (resultMapping.isCompositeResult()) {
1✔
110
          for (ResultMapping compositeResultMapping : resultMapping.getComposites()) {
1✔
111
            final String compositeColumn = compositeResultMapping.getColumn();
1✔
112
            if (compositeColumn != null) {
1!
113
              resultMap.mappedColumns.add(compositeColumn.toUpperCase(Locale.ENGLISH));
1✔
114
            }
115
          }
1✔
116
        }
117

118
        final String property = resultMapping.getProperty();
1✔
119
        if (property != null) {
1✔
120
          resultMap.mappedProperties.add(property);
1✔
121
        }
122

123
        if (resultMapping.getFlags().contains(ResultFlag.CONSTRUCTOR)) {
1✔
124
          resultMap.constructorResultMappings.add(resultMapping);
1✔
125

126
          // #101
127
          Class<?> javaType = resultMapping.getJavaType();
1✔
128
          resultMap.hasResultMapsUsingConstructorCollection = resultMap.hasResultMapsUsingConstructorCollection
1✔
129
              || (resultMapping.getNestedQueryId() == null && resultMapping.getTypeHandler() == null && javaType != null
1!
130
                  && resultMap.configuration.getObjectFactory().isCollection(javaType));
1✔
131
        } else {
1✔
132
          resultMap.propertyResultMappings.add(resultMapping);
1✔
133
        }
134

135
        if (resultMapping.getFlags().contains(ResultFlag.ID)) {
1✔
136
          resultMap.idResultMappings.add(resultMapping);
1✔
137
        }
138
      }
1✔
139

140
      if (resultMap.idResultMappings.isEmpty()) {
1✔
141
        resultMap.idResultMappings.addAll(resultMap.resultMappings);
1✔
142
      }
143

144
      // lock down collections
145
      resultMap.resultMappings = Collections.unmodifiableList(resultMap.resultMappings);
1✔
146
      resultMap.idResultMappings = Collections.unmodifiableList(resultMap.idResultMappings);
1✔
147
      resultMap.constructorResultMappings = Collections.unmodifiableList(resultMap.constructorResultMappings);
1✔
148
      resultMap.propertyResultMappings = Collections.unmodifiableList(resultMap.propertyResultMappings);
1✔
149
      resultMap.mappedColumns = Collections.unmodifiableSet(resultMap.mappedColumns);
1✔
150

151
      return resultMap;
1✔
152
    }
153
  }
154

155
  public String getId() {
156
    return id;
1✔
157
  }
158

159
  public boolean hasResultMapsUsingConstructorCollection() {
160
    return hasResultMapsUsingConstructorCollection;
1✔
161
  }
162

163
  public boolean hasNestedResultMaps() {
164
    return hasNestedResultMaps;
1✔
165
  }
166

167
  public boolean hasNestedQueries() {
168
    return hasNestedQueries;
×
169
  }
170

171
  public Class<?> getType() {
172
    return type;
1✔
173
  }
174

175
  public List<ResultMapping> getResultMappings() {
176
    return resultMappings;
1✔
177
  }
178

179
  public List<ResultMapping> getConstructorResultMappings() {
180
    return constructorResultMappings;
1✔
181
  }
182

183
  public List<ResultMapping> getPropertyResultMappings() {
184
    return propertyResultMappings;
1✔
185
  }
186

187
  public List<ResultMapping> getIdResultMappings() {
188
    return idResultMappings;
1✔
189
  }
190

191
  public Set<String> getMappedColumns() {
192
    return mappedColumns;
1✔
193
  }
194

195
  public Set<String> getMappedProperties() {
196
    return mappedProperties;
1✔
197
  }
198

199
  public Discriminator getDiscriminator() {
200
    return discriminator;
1✔
201
  }
202

203
  public void forceNestedResultMaps() {
204
    hasNestedResultMaps = true;
1✔
205
  }
1✔
206

207
  public Boolean getAutoMapping() {
208
    return autoMapping;
1✔
209
  }
210

211
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc