在sqlsession中主要是執行都是通過executor來處理的:
executor.query(ms, wrapCollection(parameter), rowBounds, handler);
executor.update(ms, wrapCollection(parameter));
執行器從哪裏來呢?在DefaultSqlSessionFactory裏面openSessionFromDataSource:
final Executor executor = configuration.newExecutor(tx, execType, autoCommit);
看configuration裏面怎麼構建執行器的:
public Executor newExecutor(Transaction transaction, ExecutorType executorType, boolean autoCommit) {
executorType = executorType == null ? defaultExecutorType : executorType;
executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
Executor executor;
if (ExecutorType.BATCH == executorType) {
executor = new BatchExecutor(this, transaction);
} else if (ExecutorType.REUSE == executorType) {
executor = new ReuseExecutor(this, transaction);
} else {
executor = new SimpleExecutor(this, transaction);
}
if (cacheEnabled) {
<span style="color:#ff0000;">executor = new CachingExecutor(executor, autoCommit);</span>
}
executor = (Executor) interceptorChain.pluginAll(executor);
return executor;
}
可以看到,默認是是簡單執行器,還有批量、重用執行器,下面這段話解釋不用的執行器使用方式:
executor = (Executor) interceptorChain.pluginAll(executor);