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

mybatis / mybatis-3 / 4017

02 Dec 2026 01:21PM UTC coverage: 87.564% (+0.1%) from 87.454%
4017

Pull #3809

github

web-flow
Merge de6182685 into 19b82e6ae
Pull Request #3809: Fix JDBC array cleanup when binding or extraction fails

3907 of 4711 branches covered (82.93%)

22 of 22 new or added lines in 1 file covered. (100.0%)

152 existing lines in 10 files now uncovered.

10034 of 11459 relevant lines covered (87.56%)

0.88 hits per line

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

88.94
/src/main/java/org/apache/ibatis/session/Configuration.java
1
/*
2
 *    Copyright 2009-2026 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.session;
17

18
import java.util.Arrays;
19
import java.util.Collection;
20
import java.util.HashMap;
21
import java.util.HashSet;
22
import java.util.Iterator;
23
import java.util.LinkedList;
24
import java.util.List;
25
import java.util.Map;
26
import java.util.Properties;
27
import java.util.Set;
28
import java.util.concurrent.ConcurrentHashMap;
29
import java.util.concurrent.locks.ReentrantLock;
30
import java.util.function.BiFunction;
31

32
import org.apache.ibatis.binding.MapperRegistry;
33
import org.apache.ibatis.builder.CacheRefResolver;
34
import org.apache.ibatis.builder.IncompleteElementException;
35
import org.apache.ibatis.builder.ResultMapResolver;
36
import org.apache.ibatis.builder.annotation.MethodResolver;
37
import org.apache.ibatis.builder.xml.XMLStatementBuilder;
38
import org.apache.ibatis.cache.Cache;
39
import org.apache.ibatis.cache.decorators.FifoCache;
40
import org.apache.ibatis.cache.decorators.LruCache;
41
import org.apache.ibatis.cache.decorators.SoftCache;
42
import org.apache.ibatis.cache.decorators.WeakCache;
43
import org.apache.ibatis.cache.impl.PerpetualCache;
44
import org.apache.ibatis.datasource.jndi.JndiDataSourceFactory;
45
import org.apache.ibatis.datasource.pooled.PooledDataSourceFactory;
46
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
47
import org.apache.ibatis.executor.BatchExecutor;
48
import org.apache.ibatis.executor.CachingExecutor;
49
import org.apache.ibatis.executor.Executor;
50
import org.apache.ibatis.executor.ReuseExecutor;
51
import org.apache.ibatis.executor.SimpleExecutor;
52
import org.apache.ibatis.executor.keygen.KeyGenerator;
53
import org.apache.ibatis.executor.loader.ProxyFactory;
54
import org.apache.ibatis.executor.loader.cglib.CglibProxyFactory;
55
import org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory;
56
import org.apache.ibatis.executor.parameter.ParameterHandler;
57
import org.apache.ibatis.executor.resultset.DefaultResultSetHandler;
58
import org.apache.ibatis.executor.resultset.ResultSetHandler;
59
import org.apache.ibatis.executor.statement.RoutingStatementHandler;
60
import org.apache.ibatis.executor.statement.StatementHandler;
61
import org.apache.ibatis.io.VFS;
62
import org.apache.ibatis.logging.Log;
63
import org.apache.ibatis.logging.LogFactory;
64
import org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl;
65
import org.apache.ibatis.logging.jdk14.Jdk14LoggingImpl;
66
import org.apache.ibatis.logging.log4j.Log4jImpl;
67
import org.apache.ibatis.logging.log4j2.Log4j2Impl;
68
import org.apache.ibatis.logging.nologging.NoLoggingImpl;
69
import org.apache.ibatis.logging.slf4j.Slf4jImpl;
70
import org.apache.ibatis.logging.stdout.StdOutImpl;
71
import org.apache.ibatis.mapping.BoundSql;
72
import org.apache.ibatis.mapping.Environment;
73
import org.apache.ibatis.mapping.MappedStatement;
74
import org.apache.ibatis.mapping.ParameterMap;
75
import org.apache.ibatis.mapping.ResultMap;
76
import org.apache.ibatis.mapping.ResultSetType;
77
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
78
import org.apache.ibatis.parsing.XNode;
79
import org.apache.ibatis.plugin.Interceptor;
80
import org.apache.ibatis.plugin.InterceptorChain;
81
import org.apache.ibatis.reflection.DefaultReflectorFactory;
82
import org.apache.ibatis.reflection.MetaObject;
83
import org.apache.ibatis.reflection.ReflectorFactory;
84
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
85
import org.apache.ibatis.reflection.factory.ObjectFactory;
86
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
87
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
88
import org.apache.ibatis.scripting.LanguageDriver;
89
import org.apache.ibatis.scripting.LanguageDriverRegistry;
90
import org.apache.ibatis.scripting.defaults.RawLanguageDriver;
91
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
92
import org.apache.ibatis.transaction.Transaction;
93
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
94
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
95
import org.apache.ibatis.type.JdbcType;
96
import org.apache.ibatis.type.TypeAliasRegistry;
97
import org.apache.ibatis.type.TypeHandler;
98
import org.apache.ibatis.type.TypeHandlerRegistry;
99

100
/**
101
 * @author Clinton Begin
102
 */
103
public class Configuration {
104

105
  protected Environment environment;
106

107
  protected boolean safeRowBoundsEnabled;
108
  protected boolean safeResultHandlerEnabled = true;
1 ✔
109
  protected boolean mapUnderscoreToCamelCase;
110
  protected boolean aggressiveLazyLoading;
111
  protected boolean useGeneratedKeys;
112
  protected boolean useColumnLabel = true;
1 ✔
113
  protected boolean cacheEnabled = true;
1 ✔
114
  protected boolean callSettersOnNulls;
115
  protected boolean useActualParamName = true;
1 ✔
116
  protected boolean returnInstanceForEmptyRow;
117
  protected boolean shrinkWhitespacesInSql;
118
  protected boolean nullableOnForEach;
119
  protected boolean argNameBasedConstructorAutoMapping;
120
  protected boolean ignoreParameterMetaData;
121

122
  protected String logPrefix;
123
  protected Class<? extends Log> logImpl;
124
  protected Class<? extends VFS> vfsImpl;
125
  protected Class<?> defaultSqlProviderType;
126
  protected LocalCacheScope localCacheScope = LocalCacheScope.SESSION;
1 ✔
127
  protected JdbcType jdbcTypeForNull = JdbcType.OTHER;
1 ✔
128
  protected Set<String> lazyLoadTriggerMethods = new HashSet<>(
1 ✔
129
      Arrays.asList("equals", "clone", "hashCode", "toString"));
1 ✔
130
  protected Integer defaultStatementTimeout;
131
  protected Integer defaultFetchSize;
132
  protected ResultSetType defaultResultSetType;
133
  protected ExecutorType defaultExecutorType = ExecutorType.SIMPLE;
1 ✔
134
  protected AutoMappingBehavior autoMappingBehavior = AutoMappingBehavior.PARTIAL;
1 ✔
135
  protected AutoMappingUnknownColumnBehavior autoMappingUnknownColumnBehavior = AutoMappingUnknownColumnBehavior.NONE;
1 ✔
136

137
  protected Properties variables = new Properties();
1 ✔
138
  protected ReflectorFactory reflectorFactory = new DefaultReflectorFactory();
1 ✔
139
  protected ObjectFactory objectFactory = new DefaultObjectFactory();
1 ✔
140
  protected ObjectWrapperFactory objectWrapperFactory = new DefaultObjectWrapperFactory();
1 ✔
141

142
  protected boolean lazyLoadingEnabled;
143
  protected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL
1 ✔
144

145
  protected String databaseId;
146
  /**
147
   * Configuration factory class. Used to create Configuration for loading deserialized unread properties.
148
   *
149
   * @see <a href='https://github.com/mybatis/old-google-code-issues/issues/300'>Issue 300 (google code)</a>
150
   */
151
  protected Class<?> configurationFactory;
152

153
  protected final MapperRegistry mapperRegistry = new MapperRegistry(this);
1 ✔
154
  protected final InterceptorChain interceptorChain = new InterceptorChain();
1 ✔
155
  protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry(this);
1 ✔
156
  protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();
1 ✔
157
  protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry();
1 ✔
158

159
  protected final Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>(
1 ✔
160
      "Mapped Statements collection")
161
          .conflictMessageProducer((savedValue, targetValue) -> ". please check " + savedValue.getResource() + " and "
1 ✔
162
              + targetValue.getResource());
1 ✔
163
  protected final Map<String, Cache> caches = new StrictMap<>("Caches collection");
1 ✔
164
  protected final Map<String, ResultMap> resultMaps = new StrictMap<>("Result Maps collection");
1 ✔
165
  protected final Map<String, ParameterMap> parameterMaps = new StrictMap<>("Parameter Maps collection");
1 ✔
166
  protected final Map<String, KeyGenerator> keyGenerators = new StrictMap<>("Key Generators collection");
1 ✔
167

168
  protected final Set<String> loadedResources = new HashSet<>();
1 ✔
169
  protected final Map<String, XNode> sqlFragments = new StrictMap<>("XML fragments parsed from previous mappers");
1 ✔
170
  protected final Collection<XMLStatementBuilder> incompleteStatements = new LinkedList<>();
1 ✔
171
  protected final Collection<CacheRefResolver> incompleteCacheRefs = new LinkedList<>();
1 ✔
172
  protected final Collection<ResultMapResolver> incompleteResultMaps = new LinkedList<>();
1 ✔
173
  protected final Collection<MethodResolver> incompleteMethods = new LinkedList<>();
1 ✔
174

175
  private final ReentrantLock incompleteResultMapsLock = new ReentrantLock();
1 ✔
176
  private final ReentrantLock incompleteCacheRefsLock = new ReentrantLock();
1 ✔
177
  private final ReentrantLock incompleteStatementsLock = new ReentrantLock();
1 ✔
178
  private final ReentrantLock incompleteMethodsLock = new ReentrantLock();
1 ✔
179

180
  /*
181
   * A map holds cache-ref relationship. The key is the namespace that references a cache bound to another namespace and
182
   * the value is the namespace which the actual cache is bound to.
183
   */
184
  protected final Map<String, String> cacheRefMap = new HashMap<>();
1 ✔
185

186
  public Configuration(Environment environment) {
187
    this();
1 ✔
188
    this.environment = environment;
1 ✔
189
  }
1 ✔
190

191
  public Configuration() {
1 ✔
192
    typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class);
1 ✔
193
    typeAliasRegistry.registerAlias("MANAGED", ManagedTransactionFactory.class);
1 ✔
194

195
    typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class);
1 ✔
196
    typeAliasRegistry.registerAlias("POOLED", PooledDataSourceFactory.class);
1 ✔
197
    typeAliasRegistry.registerAlias("UNPOOLED", UnpooledDataSourceFactory.class);
1 ✔
198

199
    typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class);
1 ✔
200
    typeAliasRegistry.registerAlias("FIFO", FifoCache.class);
1 ✔
201
    typeAliasRegistry.registerAlias("LRU", LruCache.class);
1 ✔
202
    typeAliasRegistry.registerAlias("SOFT", SoftCache.class);
1 ✔
203
    typeAliasRegistry.registerAlias("WEAK", WeakCache.class);
1 ✔
204

205
    typeAliasRegistry.registerAlias("DB_VENDOR", VendorDatabaseIdProvider.class);
1 ✔
206

207
    typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class);
1 ✔
208
    typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class);
1 ✔
209

210
    typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class);
1 ✔
211
    typeAliasRegistry.registerAlias("COMMONS_LOGGING", JakartaCommonsLoggingImpl.class);
1 ✔
212
    typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class);
1 ✔
213
    typeAliasRegistry.registerAlias("LOG4J2", Log4j2Impl.class);
1 ✔
214
    typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class);
1 ✔
215
    typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class);
1 ✔
216
    typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class);
1 ✔
217

218
    typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class);
1 ✔
219
    typeAliasRegistry.registerAlias("JAVASSIST", JavassistProxyFactory.class);
1 ✔
220

221
    languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class);
1 ✔
222
    languageRegistry.register(RawLanguageDriver.class);
1 ✔
223
  }
1 ✔
224

225
  public String getLogPrefix() {
226
    return logPrefix;
1 ✔
227
  }
228

229
  public void setLogPrefix(String logPrefix) {
230
    this.logPrefix = logPrefix;
1 ✔
231
  }
1 ✔
232

233
  public Class<? extends Log> getLogImpl() {
234
    return logImpl;
1 ✔
235
  }
236

237
  public void setLogImpl(Class<? extends Log> logImpl) {
238
    if (logImpl != null) {
1 ✔
239
      this.logImpl = logImpl;
1 ✔
240
      LogFactory.useCustomLogging(this.logImpl);
1 ✔
241
    }
242
  }
1 ✔
243

244
  public Class<? extends VFS> getVfsImpl() {
UNCOV
245
    return this.vfsImpl;
×
246
  }
247

248
  public void setVfsImpl(Class<? extends VFS> vfsImpl) {
249
    if (vfsImpl != null) {
×
250
      this.vfsImpl = vfsImpl;
×
UNCOV
251
      VFS.addImplClass(this.vfsImpl);
×
252
    }
UNCOV
253
  }
×
254

255
  /**
256
   * Gets an applying type when omit a type on sql provider annotation(e.g.
257
   * {@link org.apache.ibatis.annotations.SelectProvider}).
258
   *
259
   * @return the default type for sql provider annotation
260
   *
261
   * @since 3.5.6
262
   */
263
  public Class<?> getDefaultSqlProviderType() {
264
    return defaultSqlProviderType;
1 ✔
265
  }
266

267
  /**
268
   * Sets an applying type when omit a type on sql provider annotation(e.g.
269
   * {@link org.apache.ibatis.annotations.SelectProvider}).
270
   *
271
   * @param defaultSqlProviderType
272
   *          the default type for sql provider annotation
273
   *
274
   * @since 3.5.6
275
   */
276
  public void setDefaultSqlProviderType(Class<?> defaultSqlProviderType) {
277
    this.defaultSqlProviderType = defaultSqlProviderType;
1 ✔
278
  }
1 ✔
279

280
  public boolean isCallSettersOnNulls() {
281
    return callSettersOnNulls;
1 ✔
282
  }
283

284
  public void setCallSettersOnNulls(boolean callSettersOnNulls) {
285
    this.callSettersOnNulls = callSettersOnNulls;
1 ✔
286
  }
1 ✔
287

288
  public boolean isUseActualParamName() {
289
    return useActualParamName;
1 ✔
290
  }
291

292
  public void setUseActualParamName(boolean useActualParamName) {
293
    this.useActualParamName = useActualParamName;
1 ✔
294
  }
1 ✔
295

296
  public boolean isReturnInstanceForEmptyRow() {
297
    return returnInstanceForEmptyRow;
1 ✔
298
  }
299

300
  public void setReturnInstanceForEmptyRow(boolean returnEmptyInstance) {
301
    this.returnInstanceForEmptyRow = returnEmptyInstance;
1 ✔
302
  }
1 ✔
303

304
  public boolean isShrinkWhitespacesInSql() {
305
    return shrinkWhitespacesInSql;
1 ✔
306
  }
307

308
  public void setShrinkWhitespacesInSql(boolean shrinkWhitespacesInSql) {
309
    this.shrinkWhitespacesInSql = shrinkWhitespacesInSql;
1 ✔
310
  }
1 ✔
311

312
  /**
313
   * Sets the default value of 'nullable' attribute on 'foreach' tag.
314
   *
315
   * @param nullableOnForEach
316
   *          If nullable, set to {@code true}
317
   *
318
   * @since 3.5.9
319
   */
320
  public void setNullableOnForEach(boolean nullableOnForEach) {
321
    this.nullableOnForEach = nullableOnForEach;
1 ✔
322
  }
1 ✔
323

324
  /**
325
   * Returns the default value of 'nullable' attribute on 'foreach' tag.
326
   * <p>
327
   * Default is {@code false}.
328
   *
329
   * @return If nullable, set to {@code true}
330
   *
331
   * @since 3.5.9
332
   */
333
  public boolean isNullableOnForEach() {
334
    return nullableOnForEach;
1 ✔
335
  }
336

337
  public boolean isArgNameBasedConstructorAutoMapping() {
338
    return argNameBasedConstructorAutoMapping;
1 ✔
339
  }
340

341
  public void setArgNameBasedConstructorAutoMapping(boolean argNameBasedConstructorAutoMapping) {
342
    this.argNameBasedConstructorAutoMapping = argNameBasedConstructorAutoMapping;
1 ✔
343
  }
1 ✔
344

345
  /**
346
   * @since 3.6.1
347
   */
348
  public boolean isIgnoreParameterMetaData() {
349
    return ignoreParameterMetaData;
1 ✔
350
  }
351

352
  /**
353
   * @since 3.6.1
354
   */
355
  public void setIgnoreParameterMetaData(boolean ignoreParameterMetaData) {
356
    this.ignoreParameterMetaData = ignoreParameterMetaData;
1 ✔
357
  }
1 ✔
358

359
  public String getDatabaseId() {
360
    return databaseId;
1 ✔
361
  }
362

363
  public void setDatabaseId(String databaseId) {
364
    this.databaseId = databaseId;
1 ✔
365
  }
1 ✔
366

367
  public Class<?> getConfigurationFactory() {
368
    return configurationFactory;
1 ✔
369
  }
370

371
  public void setConfigurationFactory(Class<?> configurationFactory) {
372
    this.configurationFactory = configurationFactory;
1 ✔
373
  }
1 ✔
374

375
  public boolean isSafeResultHandlerEnabled() {
376
    return safeResultHandlerEnabled;
1 ✔
377
  }
378

379
  public void setSafeResultHandlerEnabled(boolean safeResultHandlerEnabled) {
380
    this.safeResultHandlerEnabled = safeResultHandlerEnabled;
1 ✔
381
  }
1 ✔
382

383
  public boolean isSafeRowBoundsEnabled() {
384
    return safeRowBoundsEnabled;
1 ✔
385
  }
386

387
  public void setSafeRowBoundsEnabled(boolean safeRowBoundsEnabled) {
388
    this.safeRowBoundsEnabled = safeRowBoundsEnabled;
1 ✔
389
  }
1 ✔
390

391
  public boolean isMapUnderscoreToCamelCase() {
392
    return mapUnderscoreToCamelCase;
1 ✔
393
  }
394

395
  public void setMapUnderscoreToCamelCase(boolean mapUnderscoreToCamelCase) {
396
    this.mapUnderscoreToCamelCase = mapUnderscoreToCamelCase;
1 ✔
397
  }
1 ✔
398

399
  public void addLoadedResource(String resource) {
400
    loadedResources.add(resource);
1 ✔
401
  }
1 ✔
402

403
  public boolean isResourceLoaded(String resource) {
404
    return loadedResources.contains(resource);
1 ✔
405
  }
406

407
  public Environment getEnvironment() {
408
    return environment;
1 ✔
409
  }
410

411
  public void setEnvironment(Environment environment) {
412
    this.environment = environment;
1 ✔
413
  }
1 ✔
414

415
  public AutoMappingBehavior getAutoMappingBehavior() {
416
    return autoMappingBehavior;
1 ✔
417
  }
418

419
  public void setAutoMappingBehavior(AutoMappingBehavior autoMappingBehavior) {
420
    this.autoMappingBehavior = autoMappingBehavior;
1 ✔
421
  }
1 ✔
422

423
  /**
424
   * Gets the auto mapping unknown column behavior.
425
   *
426
   * @return the auto mapping unknown column behavior
427
   *
428
   * @since 3.4.0
429
   */
430
  public AutoMappingUnknownColumnBehavior getAutoMappingUnknownColumnBehavior() {
431
    return autoMappingUnknownColumnBehavior;
1 ✔
432
  }
433

434
  /**
435
   * Sets the auto mapping unknown column behavior.
436
   *
437
   * @param autoMappingUnknownColumnBehavior
438
   *          the new auto mapping unknown column behavior
439
   *
440
   * @since 3.4.0
441
   */
442
  public void setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior autoMappingUnknownColumnBehavior) {
443
    this.autoMappingUnknownColumnBehavior = autoMappingUnknownColumnBehavior;
1 ✔
444
  }
1 ✔
445

446
  public boolean isLazyLoadingEnabled() {
447
    return lazyLoadingEnabled;
1 ✔
448
  }
449

450
  public void setLazyLoadingEnabled(boolean lazyLoadingEnabled) {
451
    this.lazyLoadingEnabled = lazyLoadingEnabled;
1 ✔
452
  }
1 ✔
453

454
  public ProxyFactory getProxyFactory() {
455
    return proxyFactory;
1 ✔
456
  }
457

458
  public void setProxyFactory(ProxyFactory proxyFactory) {
459
    if (proxyFactory == null) {
1 ✔
460
      proxyFactory = new JavassistProxyFactory();
1 ✔
461
    }
462
    this.proxyFactory = proxyFactory;
1 ✔
463
  }
1 ✔
464

465
  public boolean isAggressiveLazyLoading() {
466
    return aggressiveLazyLoading;
1 ✔
467
  }
468

469
  public void setAggressiveLazyLoading(boolean aggressiveLazyLoading) {
470
    this.aggressiveLazyLoading = aggressiveLazyLoading;
1 ✔
471
  }
1 ✔
472

473
  /**
474
   * @deprecated You can safely remove the call to this method as this option had no effect.
475
   */
476
  @Deprecated
477
  public boolean isMultipleResultSetsEnabled() {
UNCOV
478
    return true;
×
479
  }
480

481
  /**
482
   * @deprecated You can safely remove the call to this method as this option had no effect.
483
   */
484
  @Deprecated
485
  public void setMultipleResultSetsEnabled(boolean multipleResultSetsEnabled) {
486
    // nop
UNCOV
487
  }
×
488

489
  public Set<String> getLazyLoadTriggerMethods() {
490
    return lazyLoadTriggerMethods;
1 ✔
491
  }
492

493
  public void setLazyLoadTriggerMethods(Set<String> lazyLoadTriggerMethods) {
494
    this.lazyLoadTriggerMethods = lazyLoadTriggerMethods;
1 ✔
495
  }
1 ✔
496

497
  public boolean isUseGeneratedKeys() {
498
    return useGeneratedKeys;
1 ✔
499
  }
500

501
  public void setUseGeneratedKeys(boolean useGeneratedKeys) {
502
    this.useGeneratedKeys = useGeneratedKeys;
1 ✔
503
  }
1 ✔
504

505
  public ExecutorType getDefaultExecutorType() {
506
    return defaultExecutorType;
1 ✔
507
  }
508

509
  public void setDefaultExecutorType(ExecutorType defaultExecutorType) {
510
    this.defaultExecutorType = defaultExecutorType;
1 ✔
511
  }
1 ✔
512

513
  public boolean isCacheEnabled() {
514
    return cacheEnabled;
1 ✔
515
  }
516

517
  public void setCacheEnabled(boolean cacheEnabled) {
518
    this.cacheEnabled = cacheEnabled;
1 ✔
519
  }
1 ✔
520

521
  public Integer getDefaultStatementTimeout() {
522
    return defaultStatementTimeout;
1 ✔
523
  }
524

525
  public void setDefaultStatementTimeout(Integer defaultStatementTimeout) {
526
    this.defaultStatementTimeout = defaultStatementTimeout;
1 ✔
527
  }
1 ✔
528

529
  /**
530
   * Gets the default fetch size.
531
   *
532
   * @return the default fetch size
533
   *
534
   * @since 3.3.0
535
   */
536
  public Integer getDefaultFetchSize() {
537
    return defaultFetchSize;
1 ✔
538
  }
539

540
  /**
541
   * Sets the default fetch size.
542
   *
543
   * @param defaultFetchSize
544
   *          the new default fetch size
545
   *
546
   * @since 3.3.0
547
   */
548
  public void setDefaultFetchSize(Integer defaultFetchSize) {
549
    this.defaultFetchSize = defaultFetchSize;
1 ✔
550
  }
1 ✔
551

552
  /**
553
   * Gets the default result set type.
554
   *
555
   * @return the default result set type
556
   *
557
   * @since 3.5.2
558
   */
559
  public ResultSetType getDefaultResultSetType() {
560
    return defaultResultSetType;
1 ✔
561
  }
562

563
  /**
564
   * Sets the default result set type.
565
   *
566
   * @param defaultResultSetType
567
   *          the new default result set type
568
   *
569
   * @since 3.5.2
570
   */
571
  public void setDefaultResultSetType(ResultSetType defaultResultSetType) {
572
    this.defaultResultSetType = defaultResultSetType;
1 ✔
573
  }
1 ✔
574

575
  public boolean isUseColumnLabel() {
576
    return useColumnLabel;
1 ✔
577
  }
578

579
  public void setUseColumnLabel(boolean useColumnLabel) {
580
    this.useColumnLabel = useColumnLabel;
1 ✔
581
  }
1 ✔
582

583
  public LocalCacheScope getLocalCacheScope() {
584
    return localCacheScope;
1 ✔
585
  }
586

587
  public void setLocalCacheScope(LocalCacheScope localCacheScope) {
588
    this.localCacheScope = localCacheScope;
1 ✔
589
  }
1 ✔
590

591
  public JdbcType getJdbcTypeForNull() {
592
    return jdbcTypeForNull;
1 ✔
593
  }
594

595
  public void setJdbcTypeForNull(JdbcType jdbcTypeForNull) {
596
    this.jdbcTypeForNull = jdbcTypeForNull;
1 ✔
597
  }
1 ✔
598

599
  public Properties getVariables() {
600
    return variables;
1 ✔
601
  }
602

603
  public void setVariables(Properties variables) {
604
    this.variables = variables;
1 ✔
605
  }
1 ✔
606

607
  public TypeHandlerRegistry getTypeHandlerRegistry() {
608
    return typeHandlerRegistry;
1 ✔
609
  }
610

611
  /**
612
   * Set a default {@link TypeHandler} class for {@link Enum}. A default {@link TypeHandler} is
613
   * {@link org.apache.ibatis.type.EnumTypeHandler}.
614
   *
615
   * @param typeHandler
616
   *          a type handler class for {@link Enum}
617
   *
618
   * @since 3.4.5
619
   */
620
  public void setDefaultEnumTypeHandler(Class<? extends TypeHandler> typeHandler) {
621
    if (typeHandler != null) {
1 !
UNCOV
622
      getTypeHandlerRegistry().setDefaultEnumTypeHandler(typeHandler);
×
623
    }
624
  }
1 ✔
625

626
  public TypeAliasRegistry getTypeAliasRegistry() {
627
    return typeAliasRegistry;
1 ✔
628
  }
629

630
  /**
631
   * Gets the mapper registry.
632
   *
633
   * @return the mapper registry
634
   *
635
   * @since 3.2.2
636
   */
637
  public MapperRegistry getMapperRegistry() {
638
    return mapperRegistry;
1 ✔
639
  }
640

641
  public ReflectorFactory getReflectorFactory() {
642
    return reflectorFactory;
1 ✔
643
  }
644

645
  public void setReflectorFactory(ReflectorFactory reflectorFactory) {
UNCOV
646
    this.reflectorFactory = reflectorFactory;
×
UNCOV
647
  }
×
648

649
  public ObjectFactory getObjectFactory() {
650
    return objectFactory;
1 ✔
651
  }
652

653
  public void setObjectFactory(ObjectFactory objectFactory) {
654
    this.objectFactory = objectFactory;
1 ✔
655
  }
1 ✔
656

657
  public ObjectWrapperFactory getObjectWrapperFactory() {
658
    return objectWrapperFactory;
1 ✔
659
  }
660

661
  public void setObjectWrapperFactory(ObjectWrapperFactory objectWrapperFactory) {
662
    this.objectWrapperFactory = objectWrapperFactory;
1 ✔
663
  }
1 ✔
664

665
  /**
666
   * Gets the interceptors.
667
   *
668
   * @return the interceptors
669
   *
670
   * @since 3.2.2
671
   */
672
  public List<Interceptor> getInterceptors() {
UNCOV
673
    return interceptorChain.getInterceptors();
×
674
  }
675

676
  public LanguageDriverRegistry getLanguageRegistry() {
677
    return languageRegistry;
1 ✔
678
  }
679

680
  public void setDefaultScriptingLanguage(Class<? extends LanguageDriver> driver) {
681
    if (driver == null) {
1 ✔
682
      driver = XMLLanguageDriver.class;
1 ✔
683
    }
684
    getLanguageRegistry().setDefaultDriverClass(driver);
1 ✔
685
  }
1 ✔
686

687
  public LanguageDriver getDefaultScriptingLanguageInstance() {
688
    return languageRegistry.getDefaultDriver();
1 ✔
689
  }
690

691
  /**
692
   * Gets the language driver.
693
   *
694
   * @param langClass
695
   *          the lang class
696
   *
697
   * @return the language driver
698
   *
699
   * @since 3.5.1
700
   */
701
  public LanguageDriver getLanguageDriver(Class<? extends LanguageDriver> langClass) {
702
    if (langClass == null) {
1 ✔
703
      return languageRegistry.getDefaultDriver();
1 ✔
704
    }
705
    languageRegistry.register(langClass);
1 ✔
706
    return languageRegistry.getDriver(langClass);
1 ✔
707
  }
708

709
  /**
710
   * Gets the default scripting language instance.
711
   *
712
   * @return the default scripting language instance
713
   *
714
   * @deprecated Use {@link #getDefaultScriptingLanguageInstance()}
715
   */
716
  @Deprecated
717
  public LanguageDriver getDefaultScriptingLanuageInstance() {
UNCOV
718
    return getDefaultScriptingLanguageInstance();
×
719
  }
720

721
  public MetaObject newMetaObject(Object object) {
722
    return MetaObject.forObject(object, objectFactory, objectWrapperFactory, reflectorFactory);
1 ✔
723
  }
724

725
  public ParameterHandler newParameterHandler(MappedStatement mappedStatement, Object parameterObject,
726
      BoundSql boundSql) {
727
    ParameterHandler parameterHandler = mappedStatement.getLang().createParameterHandler(mappedStatement,
1 ✔
728
        parameterObject, boundSql);
729
    return (ParameterHandler) interceptorChain.pluginAll(parameterHandler);
1 ✔
730
  }
731

732
  public ResultSetHandler newResultSetHandler(Executor executor, MappedStatement mappedStatement, RowBounds rowBounds,
733
      ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql) {
734
    ResultSetHandler resultSetHandler = new DefaultResultSetHandler(executor, mappedStatement, parameterHandler,
1 ✔
735
        resultHandler, boundSql, rowBounds);
736
    return (ResultSetHandler) interceptorChain.pluginAll(resultSetHandler);
1 ✔
737
  }
738

739
  public StatementHandler newStatementHandler(Executor executor, MappedStatement mappedStatement,
740
      Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
741
    StatementHandler statementHandler = new RoutingStatementHandler(executor, mappedStatement, parameterObject,
1 ✔
742
        rowBounds, resultHandler, boundSql);
743
    return (StatementHandler) interceptorChain.pluginAll(statementHandler);
1 ✔
744
  }
745

746
  public Executor newExecutor(Transaction transaction) {
UNCOV
747
    return newExecutor(transaction, defaultExecutorType);
×
748
  }
749

750
  public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
751
    executorType = executorType == null ? defaultExecutorType : executorType;
1 !
752
    Executor executor;
753
    if (ExecutorType.BATCH == executorType) {
1 ✔
754
      executor = new BatchExecutor(this, transaction);
1 ✔
755
    } else if (ExecutorType.REUSE == executorType) {
1 ✔
756
      executor = new ReuseExecutor(this, transaction);
1 ✔
757
    } else {
758
      executor = new SimpleExecutor(this, transaction);
1 ✔
759
    }
760
    if (cacheEnabled) {
1 !
761
      executor = new CachingExecutor(executor);
1 ✔
762
    }
763
    return (Executor) interceptorChain.pluginAll(executor);
1 ✔
764
  }
765

766
  public void addKeyGenerator(String id, KeyGenerator keyGenerator) {
767
    keyGenerators.put(id, keyGenerator);
1 ✔
768
  }
1 ✔
769

770
  public Collection<String> getKeyGeneratorNames() {
UNCOV
771
    return keyGenerators.keySet();
×
772
  }
773

774
  public Collection<KeyGenerator> getKeyGenerators() {
UNCOV
775
    return keyGenerators.values();
×
776
  }
777

778
  public KeyGenerator getKeyGenerator(String id) {
779
    return keyGenerators.get(id);
1 ✔
780
  }
781

782
  public boolean hasKeyGenerator(String id) {
783
    return keyGenerators.containsKey(id);
1 ✔
784
  }
785

786
  public void addCache(Cache cache) {
787
    caches.put(cache.getId(), cache);
1 ✔
788
  }
1 ✔
789

790
  public Collection<String> getCacheNames() {
UNCOV
791
    return caches.keySet();
×
792
  }
793

794
  public Collection<Cache> getCaches() {
UNCOV
795
    return caches.values();
×
796
  }
797

798
  public Cache getCache(String id) {
799
    return caches.get(id);
1 ✔
800
  }
801

802
  public boolean hasCache(String id) {
UNCOV
803
    return caches.containsKey(id);
×
804
  }
805

806
  public void addResultMap(ResultMap rm) {
807
    resultMaps.put(rm.getId(), rm);
1 ✔
808
    checkLocallyForDiscriminatedNestedResultMaps(rm);
1 ✔
809
    checkGloballyForDiscriminatedNestedResultMaps(rm);
1 ✔
810
  }
1 ✔
811

812
  public Collection<String> getResultMapNames() {
UNCOV
813
    return resultMaps.keySet();
×
814
  }
815

816
  public Collection<ResultMap> getResultMaps() {
817
    return resultMaps.values();
1 ✔
818
  }
819

820
  public ResultMap getResultMap(String id) {
821
    return resultMaps.get(id);
1 ✔
822
  }
823

824
  public boolean hasResultMap(String id) {
825
    return resultMaps.containsKey(id);
1 ✔
826
  }
827

828
  public void addParameterMap(ParameterMap pm) {
829
    parameterMaps.put(pm.getId(), pm);
1 ✔
830
  }
1 ✔
831

832
  public Collection<String> getParameterMapNames() {
UNCOV
833
    return parameterMaps.keySet();
×
834
  }
835

836
  public Collection<ParameterMap> getParameterMaps() {
UNCOV
837
    return parameterMaps.values();
×
838
  }
839

840
  public ParameterMap getParameterMap(String id) {
841
    return parameterMaps.get(id);
1 ✔
842
  }
843

844
  public boolean hasParameterMap(String id) {
UNCOV
845
    return parameterMaps.containsKey(id);
×
846
  }
847

848
  public void addMappedStatement(MappedStatement ms) {
849
    mappedStatements.put(ms.getId(), ms);
1 ✔
850
  }
1 ✔
851

852
  public Collection<String> getMappedStatementNames() {
853
    buildAllStatements();
1 ✔
854
    return mappedStatements.keySet();
1 ✔
855
  }
856

857
  public Collection<MappedStatement> getMappedStatements() {
UNCOV
858
    buildAllStatements();
×
UNCOV
859
    return mappedStatements.values();
×
860
  }
861

862
  /**
863
   * @deprecated call {@link #parsePendingStatements(boolean)}
864
   */
865
  @Deprecated
866
  public Collection<XMLStatementBuilder> getIncompleteStatements() {
UNCOV
867
    return incompleteStatements;
×
868
  }
869

870
  public void addIncompleteStatement(XMLStatementBuilder incompleteStatement) {
871
    incompleteStatementsLock.lock();
1 ✔
872
    try {
873
      incompleteStatements.add(incompleteStatement);
1 ✔
874
    } finally {
875
      incompleteStatementsLock.unlock();
1 ✔
876
    }
877
  }
1 ✔
878

879
  /**
880
   * @deprecated call {@link #parsePendingCacheRefs(boolean)}
881
   */
882
  @Deprecated
883
  public Collection<CacheRefResolver> getIncompleteCacheRefs() {
UNCOV
884
    return incompleteCacheRefs;
×
885
  }
886

887
  public void addIncompleteCacheRef(CacheRefResolver incompleteCacheRef) {
888
    incompleteCacheRefsLock.lock();
1 ✔
889
    try {
890
      incompleteCacheRefs.add(incompleteCacheRef);
1 ✔
891
    } finally {
892
      incompleteCacheRefsLock.unlock();
1 ✔
893
    }
894
  }
1 ✔
895

896
  /**
897
   * @deprecated call {@link #parsePendingResultMaps(boolean)}
898
   */
899
  @Deprecated
900
  public Collection<ResultMapResolver> getIncompleteResultMaps() {
UNCOV
901
    return incompleteResultMaps;
×
902
  }
903

904
  public void addIncompleteResultMap(ResultMapResolver resultMapResolver) {
905
    incompleteResultMapsLock.lock();
1 ✔
906
    try {
907
      incompleteResultMaps.add(resultMapResolver);
1 ✔
908
    } finally {
909
      incompleteResultMapsLock.unlock();
1 ✔
910
    }
911
  }
1 ✔
912

913
  public void addIncompleteMethod(MethodResolver builder) {
914
    incompleteMethodsLock.lock();
1 ✔
915
    try {
916
      incompleteMethods.add(builder);
1 ✔
917
    } finally {
918
      incompleteMethodsLock.unlock();
1 ✔
919
    }
920
  }
1 ✔
921

922
  /**
923
   * @deprecated call {@link #parsePendingMethods(boolean)}
924
   */
925
  @Deprecated
926
  public Collection<MethodResolver> getIncompleteMethods() {
UNCOV
927
    return incompleteMethods;
×
928
  }
929

930
  public MappedStatement getMappedStatement(String id) {
931
    return this.getMappedStatement(id, true);
1 ✔
932
  }
933

934
  public MappedStatement getMappedStatement(String id, boolean validateIncompleteStatements) {
935
    if (validateIncompleteStatements) {
1 ✔
936
      buildAllStatements();
1 ✔
937
    }
938
    return mappedStatements.get(id);
1 ✔
939
  }
940

941
  public Map<String, XNode> getSqlFragments() {
942
    return sqlFragments;
1 ✔
943
  }
944

945
  public void addInterceptor(Interceptor interceptor) {
946
    interceptorChain.addInterceptor(interceptor);
1 ✔
947
  }
1 ✔
948

949
  public void addMappers(String packageName, Class<?> superType) {
UNCOV
950
    mapperRegistry.addMappers(packageName, superType);
×
UNCOV
951
  }
×
952

953
  public void addMappers(String packageName) {
954
    mapperRegistry.addMappers(packageName);
1 ✔
955
  }
1 ✔
956

957
  public <T> void addMapper(Class<T> type) {
958
    mapperRegistry.addMapper(type);
1 ✔
959
  }
1 ✔
960

961
  public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
962
    return mapperRegistry.getMapper(type, sqlSession);
1 ✔
963
  }
964

965
  public boolean hasMapper(Class<?> type) {
966
    return mapperRegistry.hasMapper(type);
1 ✔
967
  }
968

969
  public boolean hasStatement(String statementName) {
970
    return hasStatement(statementName, true);
1 ✔
971
  }
972

973
  public boolean hasStatement(String statementName, boolean validateIncompleteStatements) {
974
    if (validateIncompleteStatements) {
1 ✔
975
      buildAllStatements();
1 ✔
976
    }
977
    return mappedStatements.containsKey(statementName);
1 ✔
978
  }
979

980
  public void addCacheRef(String namespace, String referencedNamespace) {
981
    cacheRefMap.put(namespace, referencedNamespace);
1 ✔
982
  }
1 ✔
983

984
  /*
985
   * Parses all the unprocessed statement nodes in the cache. It is recommended to call this method once all the mappers
986
   * are added as it provides fail-fast statement validation.
987
   */
988
  protected void buildAllStatements() {
989
    parsePendingResultMaps(true);
1 ✔
990
    parsePendingCacheRefs(true);
1 ✔
991
    parsePendingStatements(true);
1 ✔
992
    parsePendingMethods(true);
1 ✔
993
  }
1 ✔
994

995
  public void parsePendingMethods(boolean reportUnresolved) {
996
    if (incompleteMethods.isEmpty()) {
1 ✔
997
      return;
1 ✔
998
    }
999
    incompleteMethodsLock.lock();
1 ✔
1000
    try {
1001
      incompleteMethods.removeIf(x -> {
1 ✔
1002
        x.resolve();
1 ✔
1003
        return true;
1 ✔
1004
      });
1005
    } catch (IncompleteElementException e) {
1 ✔
1006
      if (reportUnresolved) {
1 !
UNCOV
1007
        throw e;
×
1008
      }
1009
    } finally {
1010
      incompleteMethodsLock.unlock();
1 ✔
1011
    }
1012
  }
1 ✔
1013

1014
  public void parsePendingStatements(boolean reportUnresolved) {
1015
    if (incompleteStatements.isEmpty()) {
1 ✔
1016
      return;
1 ✔
1017
    }
1018
    incompleteStatementsLock.lock();
1 ✔
1019
    try {
1020
      incompleteStatements.removeIf(x -> {
1 ✔
1021
        x.parseStatementNode();
1 ✔
1022
        return true;
1 ✔
1023
      });
1024
    } catch (IncompleteElementException e) {
1 ✔
1025
      if (reportUnresolved) {
1 ✔
1026
        throw e;
1 ✔
1027
      }
1028
    } finally {
1029
      incompleteStatementsLock.unlock();
1 ✔
1030
    }
1031
  }
1 ✔
1032

1033
  public void parsePendingCacheRefs(boolean reportUnresolved) {
1034
    if (incompleteCacheRefs.isEmpty()) {
1 ✔
1035
      return;
1 ✔
1036
    }
1037
    incompleteCacheRefsLock.lock();
1 ✔
1038
    try {
1039
      incompleteCacheRefs.removeIf(x -> x.resolveCacheRef() != null);
1 !
1040
    } catch (IncompleteElementException e) {
1 ✔
1041
      if (reportUnresolved) {
1 !
UNCOV
1042
        throw e;
×
1043
      }
1044
    } finally {
1045
      incompleteCacheRefsLock.unlock();
1 ✔
1046
    }
1047
  }
1 ✔
1048

1049
  public void parsePendingResultMaps(boolean reportUnresolved) {
1050
    if (incompleteResultMaps.isEmpty()) {
1 ✔
1051
      return;
1 ✔
1052
    }
1053
    incompleteResultMapsLock.lock();
1 ✔
1054
    try {
1055
      boolean resolved;
1056
      IncompleteElementException ex = null;
1 ✔
1057
      do {
1058
        resolved = false;
1 ✔
1059
        Iterator<ResultMapResolver> iterator = incompleteResultMaps.iterator();
1 ✔
1060
        while (iterator.hasNext()) {
1 ✔
1061
          try {
1062
            iterator.next().resolve();
1 ✔
1063
            iterator.remove();
1 ✔
1064
            resolved = true;
1 ✔
1065
          } catch (IncompleteElementException e) {
1 ✔
1066
            ex = e;
1 ✔
1067
          }
1 ✔
1068
        }
1069
      } while (resolved);
1 ✔
1070
      if (reportUnresolved && !incompleteResultMaps.isEmpty() && ex != null) {
1 !
1071
        // At least one result map is unresolvable.
UNCOV
1072
        throw ex;
×
1073
      }
1074
    } finally {
1075
      incompleteResultMapsLock.unlock();
1 ✔
1076
    }
1077
  }
1 ✔
1078

1079
  /**
1080
   * Extracts namespace from fully qualified statement id.
1081
   *
1082
   * @param statementId
1083
   *          the statement id
1084
   *
1085
   * @return namespace or null when id does not contain period.
1086
   */
1087
  protected String extractNamespace(String statementId) {
1088
    int lastPeriod = statementId.lastIndexOf('.');
×
UNCOV
1089
    return lastPeriod > 0 ? statementId.substring(0, lastPeriod) : null;
×
1090
  }
1091

1092
  // Slow but a one time cost. A better solution is welcome.
1093
  protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
1094
    if (rm.hasNestedResultMaps()) {
1 ✔
1095
      final String resultMapId = rm.getId();
1 ✔
1096
      for (Object resultMapObject : resultMaps.values()) {
1 ✔
1097
        if (resultMapObject instanceof ResultMap) {
1 ✔
1098
          ResultMap entryResultMap = (ResultMap) resultMapObject;
1 ✔
1099
          if (!entryResultMap.hasNestedResultMaps() && entryResultMap.getDiscriminator() != null) {
1 ✔
1100
            Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator().getDiscriminatorMap()
1 ✔
1101
                .values();
1 ✔
1102
            if (discriminatedResultMapNames.contains(resultMapId)) {
1 !
UNCOV
1103
              entryResultMap.forceNestedResultMaps();
×
1104
            }
1105
          }
1106
        }
1107
      }
1 ✔
1108
    }
1109
  }
1 ✔
1110

1111
  // Slow but a one time cost. A better solution is welcome.
1112
  protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
1113
    if (!rm.hasNestedResultMaps() && rm.getDiscriminator() != null) {
1 ✔
1114
      for (String discriminatedResultMapName : rm.getDiscriminator().getDiscriminatorMap().values()) {
1 ✔
1115
        if (hasResultMap(discriminatedResultMapName)) {
1 ✔
1116
          ResultMap discriminatedResultMap = resultMaps.get(discriminatedResultMapName);
1 ✔
1117
          if (discriminatedResultMap.hasNestedResultMaps()) {
1 ✔
1118
            rm.forceNestedResultMaps();
1 ✔
1119
            break;
1 ✔
1120
          }
1121
        }
1122
      }
1 ✔
1123
    }
1124
  }
1 ✔
1125

1126
  protected static class StrictMap<V> extends ConcurrentHashMap<String, V> {
1127

1128
    private static final long serialVersionUID = -4950446264854982944L;
1129
    private final String name;
1130
    private BiFunction<V, V, String> conflictMessageProducer;
1131
    private static final Object AMBIGUITY_INSTANCE = new Object();
1 ✔
1132

1133
    public StrictMap(String name, int initialCapacity, float loadFactor) {
1134
      super(initialCapacity, loadFactor);
×
1135
      this.name = name;
×
UNCOV
1136
    }
×
1137

1138
    public StrictMap(String name, int initialCapacity) {
UNCOV
1139
      super(initialCapacity);
×
UNCOV
1140
      this.name = name;
×
UNCOV
1141
    }
×
1142

1143
    public StrictMap(String name) {
1 ✔
1144
      this.name = name;
1 ✔
1145
    }
1 ✔
1146

1147
    public StrictMap(String name, Map<String, ? extends V> m) {
UNCOV
1148
      super(m);
×
UNCOV
1149
      this.name = name;
×
UNCOV
1150
    }
×
1151

1152
    /**
1153
     * Assign a function for producing a conflict error message when contains value with the same key.
1154
     * <p>
1155
     * function arguments are 1st is saved value and 2nd is target value.
1156
     *
1157
     * @param conflictMessageProducer
1158
     *          A function for producing a conflict error message
1159
     *
1160
     * @return a conflict error message
1161
     *
1162
     * @since 3.5.0
1163
     */
1164
    public StrictMap<V> conflictMessageProducer(BiFunction<V, V, String> conflictMessageProducer) {
1165
      this.conflictMessageProducer = conflictMessageProducer;
1 ✔
1166
      return this;
1 ✔
1167
    }
1168

1169
    @Override
1170
    @SuppressWarnings("unchecked")
1171
    public V put(String key, V value) {
1172
      if (containsKey(key)) {
1 ✔
1173
        throw new IllegalArgumentException(name + " already contains key " + key
1 ✔
1174
            + (conflictMessageProducer == null ? "" : conflictMessageProducer.apply(super.get(key), value)));
1 ✔
1175
      }
1176
      if (key.contains(".")) {
1 ✔
1177
        final String shortKey = getShortName(key);
1 ✔
1178
        if (super.get(shortKey) == null) {
1 ✔
1179
          super.put(shortKey, value);
1 ✔
1180
        } else {
1181
          super.put(shortKey, (V) AMBIGUITY_INSTANCE);
1 ✔
1182
        }
1183
      }
1184
      return super.put(key, value);
1 ✔
1185
    }
1186

1187
    @Override
1188
    public boolean containsKey(Object key) {
1189
      if (key == null) {
1 ✔
1190
        return false;
1 ✔
1191
      }
1192

1193
      return super.get(key) != null;
1 ✔
1194
    }
1195

1196
    @Override
1197
    public V get(Object key) {
1198
      V value = super.get(key);
1 ✔
1199
      if (value == null) {
1 ✔
1200
        throw new IllegalArgumentException(name + " does not contain value for " + key);
1 ✔
1201
      }
1202
      if (AMBIGUITY_INSTANCE == value) {
1 ✔
1203
        throw new IllegalArgumentException(key + " is ambiguous in " + name
1 ✔
1204
            + " (try using the full name including the namespace, or rename one of the entries)");
1205
      }
1206
      return value;
1 ✔
1207
    }
1208

1209
    private String getShortName(String key) {
1210
      final String[] keyParts = key.split("\\.");
1 ✔
1211
      return keyParts[keyParts.length - 1];
1 ✔
1212
    }
1213
  }
1214

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

© 2026 Coveralls, Inc