读mybatis源码之五:执行器Executor创建
2014-06-21 20:22
246 查看
在sqlsession中主要是执行都是通过executor来处理的:
看configuration里面怎么构建执行器的:
executor = (Executor) interceptorChain.pluginAll(executor);
是将执行器添加到拦截器中,这个很重要,为后续写插件提供时机。
具体为session指定执行器可以使用类似这种方式sessionFactory.openSession(ExecutorType.BATCH,
false);
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);
是将执行器添加到拦截器中,这个很重要,为后续写插件提供时机。
具体为session指定执行器可以使用类似这种方式sessionFactory.openSession(ExecutorType.BATCH,
false);
相关文章推荐
- 读mybatis源码之六:执行器Executor之基类BaseExecutor
- Myeclipse 10 使用mybatis-generator自动创建代码总结,附源码
- Mybatis3源码分析(09)-SqlSession创建及简要说明
- Mybatis3.3.x技术内幕(四):五鼠闹东京之执行器Executor设计原本
- Mybatis源码阅读之SqlSession创建
- Mybatis源码分析-BaseExecutor
- mybatis源码分析3 - sqlSession的创建
- mybatis源码学习之执行过程分析(1)——SqlSessionFactory及SqlSession的创建
- Spark1.3从创建到提交:6)Executor和Driver互动源码分析
- 线程执行器的创建:Executor及其子类
- myBatis源码之SimpleExecutor
- Mybatis源码之SimpleExecutor
- Mybatis源码之SimpleExecutor
- Elastic-Job项目源码分析4--核心执行器AbstractElasticJobExecutor
- myBatis源码之BatchExecutor
- MyBATIS原理第三篇: SqlSession下的四大对象之一——执行器(executor)
- Mybatis源码之SimpleExecutor
- myBatis源码之BatchExecutor
- Mybatis 源码分析一、 SqlSessionFactory的创建过程
- MyBATIS原理第三篇: SqlSession下的四大对象之一——执行器(executor)