0
点赞
收藏
分享

微信扫一扫

SqlSession的创建过程

上一篇 <<<SqlSessionFactory的创建过程原理
下一篇 >>>sqlSession如何获得具体的Mapper接口信息


原理

核心源码

// 从configuration中获得环境
Environment environment = this.configuration.getEnvironment();
// 取得事务工厂并创建事务
TransactionFactory transactionFactory = this.getTransactionFactoryFromEnvironment(environment);
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
//通过事务创建执行器
Executor executor = this.configuration.newExecutor(tx, execType);---》
// 然后封装到DefaultSqlSession返回
// SqlSession这个接口帮我们封装了CRUD的方法,便于我们操作,Mybatis默认最多能查到Integer的最大值21亿。
var8 = new DefaultSqlSession(this.configuration, executor, autoCommit);

if (this.cacheEnabled) {
executor = new CachingExecutor((Executor)executor);
}

执行器的类型与作用

Object 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);
}

为什么CachingExecutor要找SimpleExecutor创建缓存key?


推荐阅读:
<<<Mybatis的整体执行原理图解
<<<SqlSessionFactory的创建过程原理
<<<sqlSession如何获得具体的Mapper接口信息
<<<userMapper.getUser(1);底层实现原理
<<<sqlSession.selectOne底层实现原理
<<<Mybatis一级缓存知识汇总
<<<Mybatis二级缓存知识汇总
<<<Springboot整合Mybatis二级缓存
<<<Mybatis常见面试题

举报

相关推荐

0 条评论