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

mybatis / mybatis-3 / #3198

27 Aug 2023 08:39PM UTC coverage: 86.703% (-0.9%) from 87.632%
#3198

push

github

web-flow
Merge pull request #2944 from hazendaz/copyright

Update maven and github actions

9305 of 10732 relevant lines covered (86.7%)

0.87 hits per line

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

91.82
/src/main/java/org/apache/ibatis/mapping/MappedStatement.java
1
/*
2
 *    Copyright 2009-2023 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.List;
21

22
import org.apache.ibatis.cache.Cache;
23
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
24
import org.apache.ibatis.executor.keygen.KeyGenerator;
25
import org.apache.ibatis.executor.keygen.NoKeyGenerator;
26
import org.apache.ibatis.logging.Log;
27
import org.apache.ibatis.logging.LogFactory;
28
import org.apache.ibatis.scripting.LanguageDriver;
29
import org.apache.ibatis.session.Configuration;
30

31
/**
32
 * @author Clinton Begin
33
 */
34
public final class MappedStatement {
35

36
  private String resource;
37
  private Configuration configuration;
38
  private String id;
39
  private Integer fetchSize;
40
  private Integer timeout;
41
  private StatementType statementType;
42
  private ResultSetType resultSetType;
43
  private SqlSource sqlSource;
44
  private Cache cache;
45
  private ParameterMap parameterMap;
46
  private List<ResultMap> resultMaps;
47
  private boolean flushCacheRequired;
48
  private boolean useCache;
49
  private boolean resultOrdered;
50
  private SqlCommandType sqlCommandType;
51
  private KeyGenerator keyGenerator;
52
  private String[] keyProperties;
53
  private String[] keyColumns;
54
  private boolean hasNestedResultMaps;
55
  private String databaseId;
56
  private Log statementLog;
57
  private LanguageDriver lang;
58
  private String[] resultSets;
59
  private boolean dirtySelect;
60

61
  MappedStatement() {
1✔
62
    // constructor disabled
63
  }
1✔
64

65
  public static class Builder {
1✔
66
    private final MappedStatement mappedStatement = new MappedStatement();
1✔
67

68
    public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlCommandType sqlCommandType) {
1✔
69
      mappedStatement.configuration = configuration;
1✔
70
      mappedStatement.id = id;
1✔
71
      mappedStatement.sqlSource = sqlSource;
1✔
72
      mappedStatement.statementType = StatementType.PREPARED;
1✔
73
      mappedStatement.resultSetType = ResultSetType.DEFAULT;
1✔
74
      mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null,
1✔
75
          new ArrayList<>()).build();
1✔
76
      mappedStatement.resultMaps = new ArrayList<>();
1✔
77
      mappedStatement.sqlCommandType = sqlCommandType;
1✔
78
      mappedStatement.keyGenerator = configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType)
1✔
79
          ? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE;
1✔
80
      String logId = id;
1✔
81
      if (configuration.getLogPrefix() != null) {
1✔
82
        logId = configuration.getLogPrefix() + id;
×
83
      }
84
      mappedStatement.statementLog = LogFactory.getLog(logId);
1✔
85
      mappedStatement.lang = configuration.getDefaultScriptingLanguageInstance();
1✔
86
    }
1✔
87

88
    public Builder resource(String resource) {
89
      mappedStatement.resource = resource;
1✔
90
      return this;
1✔
91
    }
92

93
    public String id() {
94
      return mappedStatement.id;
×
95
    }
96

97
    public Builder parameterMap(ParameterMap parameterMap) {
98
      mappedStatement.parameterMap = parameterMap;
1✔
99
      return this;
1✔
100
    }
101

102
    public Builder resultMaps(List<ResultMap> resultMaps) {
103
      mappedStatement.resultMaps = resultMaps;
1✔
104
      for (ResultMap resultMap : resultMaps) {
1✔
105
        mappedStatement.hasNestedResultMaps = mappedStatement.hasNestedResultMaps || resultMap.hasNestedResultMaps();
1✔
106
      }
1✔
107
      return this;
1✔
108
    }
109

110
    public Builder fetchSize(Integer fetchSize) {
111
      mappedStatement.fetchSize = fetchSize;
1✔
112
      return this;
1✔
113
    }
114

115
    public Builder timeout(Integer timeout) {
116
      mappedStatement.timeout = timeout;
1✔
117
      return this;
1✔
118
    }
119

120
    public Builder statementType(StatementType statementType) {
121
      mappedStatement.statementType = statementType;
1✔
122
      return this;
1✔
123
    }
124

125
    public Builder resultSetType(ResultSetType resultSetType) {
126
      mappedStatement.resultSetType = resultSetType == null ? ResultSetType.DEFAULT : resultSetType;
1✔
127
      return this;
1✔
128
    }
129

130
    public Builder cache(Cache cache) {
131
      mappedStatement.cache = cache;
1✔
132
      return this;
1✔
133
    }
134

135
    public Builder flushCacheRequired(boolean flushCacheRequired) {
136
      mappedStatement.flushCacheRequired = flushCacheRequired;
1✔
137
      return this;
1✔
138
    }
139

140
    public Builder useCache(boolean useCache) {
141
      mappedStatement.useCache = useCache;
1✔
142
      return this;
1✔
143
    }
144

145
    public Builder resultOrdered(boolean resultOrdered) {
146
      mappedStatement.resultOrdered = resultOrdered;
1✔
147
      return this;
1✔
148
    }
149

150
    public Builder keyGenerator(KeyGenerator keyGenerator) {
151
      mappedStatement.keyGenerator = keyGenerator;
1✔
152
      return this;
1✔
153
    }
154

155
    public Builder keyProperty(String keyProperty) {
156
      mappedStatement.keyProperties = delimitedStringToArray(keyProperty);
1✔
157
      return this;
1✔
158
    }
159

160
    public Builder keyColumn(String keyColumn) {
161
      mappedStatement.keyColumns = delimitedStringToArray(keyColumn);
1✔
162
      return this;
1✔
163
    }
164

165
    public Builder databaseId(String databaseId) {
166
      mappedStatement.databaseId = databaseId;
1✔
167
      return this;
1✔
168
    }
169

170
    public Builder lang(LanguageDriver driver) {
171
      mappedStatement.lang = driver;
1✔
172
      return this;
1✔
173
    }
174

175
    public Builder resultSets(String resultSet) {
176
      mappedStatement.resultSets = delimitedStringToArray(resultSet);
1✔
177
      return this;
1✔
178
    }
179

180
    public Builder dirtySelect(boolean dirtySelect) {
181
      mappedStatement.dirtySelect = dirtySelect;
1✔
182
      return this;
1✔
183
    }
184

185
    /**
186
     * Resul sets.
187
     *
188
     * @param resultSet
189
     *          the result set
190
     *
191
     * @return the builder
192
     *
193
     * @deprecated Use {@link #resultSets}
194
     */
195
    @Deprecated
196
    public Builder resulSets(String resultSet) {
197
      mappedStatement.resultSets = delimitedStringToArray(resultSet);
×
198
      return this;
×
199
    }
200

201
    public MappedStatement build() {
202
      assert mappedStatement.configuration != null;
1✔
203
      assert mappedStatement.id != null;
1✔
204
      assert mappedStatement.sqlSource != null;
1✔
205
      assert mappedStatement.lang != null;
1✔
206
      mappedStatement.resultMaps = Collections.unmodifiableList(mappedStatement.resultMaps);
1✔
207
      return mappedStatement;
1✔
208
    }
209
  }
210

211
  public KeyGenerator getKeyGenerator() {
212
    return keyGenerator;
1✔
213
  }
214

215
  public SqlCommandType getSqlCommandType() {
216
    return sqlCommandType;
1✔
217
  }
218

219
  public String getResource() {
220
    return resource;
1✔
221
  }
222

223
  public Configuration getConfiguration() {
224
    return configuration;
1✔
225
  }
226

227
  public String getId() {
228
    return id;
1✔
229
  }
230

231
  public boolean hasNestedResultMaps() {
232
    return hasNestedResultMaps;
×
233
  }
234

235
  public Integer getFetchSize() {
236
    return fetchSize;
1✔
237
  }
238

239
  public Integer getTimeout() {
240
    return timeout;
1✔
241
  }
242

243
  public StatementType getStatementType() {
244
    return statementType;
1✔
245
  }
246

247
  public ResultSetType getResultSetType() {
248
    return resultSetType;
1✔
249
  }
250

251
  public SqlSource getSqlSource() {
252
    return sqlSource;
1✔
253
  }
254

255
  public ParameterMap getParameterMap() {
256
    return parameterMap;
1✔
257
  }
258

259
  public List<ResultMap> getResultMaps() {
260
    return resultMaps;
1✔
261
  }
262

263
  public Cache getCache() {
264
    return cache;
1✔
265
  }
266

267
  public boolean isFlushCacheRequired() {
268
    return flushCacheRequired;
1✔
269
  }
270

271
  public boolean isUseCache() {
272
    return useCache;
1✔
273
  }
274

275
  public boolean isResultOrdered() {
276
    return resultOrdered;
1✔
277
  }
278

279
  public String getDatabaseId() {
280
    return databaseId;
1✔
281
  }
282

283
  public String[] getKeyProperties() {
284
    return keyProperties;
1✔
285
  }
286

287
  public String[] getKeyColumns() {
288
    return keyColumns;
1✔
289
  }
290

291
  public Log getStatementLog() {
292
    return statementLog;
1✔
293
  }
294

295
  public LanguageDriver getLang() {
296
    return lang;
1✔
297
  }
298

299
  public String[] getResultSets() {
300
    return resultSets;
1✔
301
  }
302

303
  public boolean isDirtySelect() {
304
    return dirtySelect;
1✔
305
  }
306

307
  /**
308
   * Gets the resul sets.
309
   *
310
   * @return the resul sets
311
   *
312
   * @deprecated Use {@link #getResultSets()}
313
   */
314
  @Deprecated
315
  public String[] getResulSets() {
316
    return resultSets;
×
317
  }
318

319
  public BoundSql getBoundSql(Object parameterObject) {
320
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
1✔
321
    List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
1✔
322
    if (parameterMappings == null || parameterMappings.isEmpty()) {
1✔
323
      boundSql = new BoundSql(configuration, boundSql.getSql(), parameterMap.getParameterMappings(), parameterObject);
1✔
324
    }
325

326
    // check for nested result maps in parameter mappings (issue #30)
327
    for (ParameterMapping pm : boundSql.getParameterMappings()) {
1✔
328
      String rmId = pm.getResultMapId();
1✔
329
      if (rmId != null) {
1✔
330
        ResultMap rm = configuration.getResultMap(rmId);
×
331
        if (rm != null) {
×
332
          hasNestedResultMaps |= rm.hasNestedResultMaps();
×
333
        }
334
      }
335
    }
1✔
336

337
    return boundSql;
1✔
338
  }
339

340
  private static String[] delimitedStringToArray(String in) {
341
    if (in == null || in.trim().length() == 0) {
1✔
342
      return null;
1✔
343
    }
344
    return in.split(",");
1✔
345
  }
346

347
}
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

© 2026 Coveralls, Inc