|
16 | 16 | package com.baomidou.mybatisplus.core;
|
17 | 17 |
|
18 | 18 | import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
| 19 | +import com.baomidou.mybatisplus.core.executor.MybatisBatchExecutor; |
| 20 | +import com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor; |
| 21 | +import com.baomidou.mybatisplus.core.executor.MybatisReuseExecutor; |
| 22 | +import com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor; |
19 | 23 | import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
|
20 | 24 | import lombok.Getter;
|
21 | 25 | import lombok.Setter;
|
22 | 26 | import org.apache.ibatis.binding.MapperRegistry;
|
23 | 27 | import org.apache.ibatis.cache.Cache;
|
| 28 | +import org.apache.ibatis.executor.Executor; |
24 | 29 | import org.apache.ibatis.executor.keygen.KeyGenerator;
|
25 | 30 | import org.apache.ibatis.logging.Log;
|
26 | 31 | import org.apache.ibatis.logging.LogFactory;
|
|
31 | 36 | import org.apache.ibatis.parsing.XNode;
|
32 | 37 | import org.apache.ibatis.scripting.LanguageDriver;
|
33 | 38 | import org.apache.ibatis.session.Configuration;
|
| 39 | +import org.apache.ibatis.session.ExecutorType; |
34 | 40 | import org.apache.ibatis.session.SqlSession;
|
| 41 | +import org.apache.ibatis.transaction.Transaction; |
35 | 42 |
|
36 | 43 | import java.util.Collection;
|
37 | 44 | import java.util.HashMap;
|
@@ -69,6 +76,10 @@ public class MybatisConfiguration extends Configuration {
|
69 | 76 | @Getter
|
70 | 77 | private boolean useGeneratedShortKey = true;
|
71 | 78 |
|
| 79 | + @Setter |
| 80 | + @Getter |
| 81 | + private boolean useNewExecutor = true; |
| 82 | + |
72 | 83 | public MybatisConfiguration(Environment environment) {
|
73 | 84 | this();
|
74 | 85 | this.environment = environment;
|
@@ -297,6 +308,27 @@ public boolean hasStatement(String statementName, boolean validateIncompleteStat
|
297 | 308 | return mappedStatements.containsKey(statementName);
|
298 | 309 | }
|
299 | 310 |
|
| 311 | + @Override |
| 312 | + public Executor newExecutor(Transaction transaction, ExecutorType executorType) { |
| 313 | + if (useNewExecutor) { |
| 314 | + executorType = executorType == null ? defaultExecutorType : executorType; |
| 315 | + executorType = executorType == null ? ExecutorType.SIMPLE : executorType; |
| 316 | + Executor executor; |
| 317 | + if (ExecutorType.BATCH == executorType) { |
| 318 | + executor = new MybatisBatchExecutor(this, transaction); |
| 319 | + } else if (ExecutorType.REUSE == executorType) { |
| 320 | + executor = new MybatisReuseExecutor(this, transaction); |
| 321 | + } else { |
| 322 | + executor = new MybatisSimpleExecutor(this, transaction); |
| 323 | + } |
| 324 | + if (cacheEnabled) { |
| 325 | + executor = new MybatisCachingExecutor(executor); |
| 326 | + } |
| 327 | + executor = (Executor) interceptorChain.pluginAll(executor); |
| 328 | + return executor; |
| 329 | + } |
| 330 | + return super.newExecutor(transaction, executorType); |
| 331 | + } |
300 | 332 |
|
301 | 333 | // Slow but a one time cost. A better solution is welcome.
|
302 | 334 | protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
|
@@ -342,10 +374,12 @@ public StrictMap(String name) {
|
342 | 374 | super();
|
343 | 375 | this.name = name;
|
344 | 376 | }
|
| 377 | + |
345 | 378 | /**
|
346 | 379 | * Assign a function for producing a conflict error message when contains value with the same key.
|
347 | 380 | * <p>
|
348 | 381 | * function arguments are 1st is saved value and 2nd is target value.
|
| 382 | + * |
349 | 383 | * @param conflictMessageProducer A function for producing a conflict error message
|
350 | 384 | * @return a conflict error message
|
351 | 385 | * @since 3.5.0
|
|
0 commit comments