openSession获取sqlSession
这一节 我们看defaultSqlSessionFactory对象的openSession()方法的具体过程
调用的方法是openSessionFromDataSource()方法
首先从configuration中拿到默认的Executor类型
this.configuration.getDefaultExecutorType()
流程图
openSessionFromDataSource
openSessionFromDataSource方法先是获取了一些信息,然后创建了一个Executor
Executor的创建
openSessionFromDataSource方法通过这一句创建Executor
Executor executor = this.configuration.newExecutor(tx, execType);
newExecutor方法:
- 根据Executor在全局配置的类型(SIMPLE/REUSE/BATCH) 创建相应的Executor
- 如果有二级缓存则包装executor,但实际执行增删改查的还是包装之前的executor
- 用每一个拦截器重新包装executor并返回
Executor
Executor是一个接口,用来做增删改查的
获取DefaultSqlSession对象
得到executor后,通过下面这一句new一个DefaultSqlSession对象 返回。
DefaultSqlSession中包含了配置信息以及executor
var8 = new DefaultSqlSession(this.configuration, executor, autoCommit);
DefaultSqlSession是SqlSession的实现类,
来源:oschina
链接:https://my.oschina.net/u/4389078/blog/4760196