MyBatis源码分析_获取openSession 方法

SqlSession openSession = sqlSessionFactory.openSession();

MyBatis源码分析_获取openSession 方法_第1张图片

 

 

MyBatis源码分析_获取openSession 方法_第2张图片 

根据配置文件创建不同的  Executor  默认为 

public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
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) {
  executor = new CachingExecutor(executor);
}
executor = (Executor) interceptorChain.pluginAll(executor);
return executor;
}

 

MyBatis源码分析_获取openSession 方法_第3张图片

 


返回SqlSession的实现类DefaultSqlSession对象,他里面包含了ExecutorConfiguration,Executor会在这一步被创建

MyBatis源码分析_获取openSession 方法_第4张图片 

你可能感兴趣的:(MyBatis)