本篇是mybatis执行sql的第二步,开启会话
调用DefaultSqlSessionFactory的openSession开启会话
//org.apache.ibatis.session.defaults.DefaultSqlSessionFactory#openSession()
public SqlSession openSession() {
//传入默认的执行器类型,Simple,共有Simple,Reuse,Batch三种
return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false);
}
//org.apache.ibatis.session.defaults.DefaultSqlSessionFactory#openSessionFromDataSource
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
//事务
Transaction tx = null;
try {
//从配置类获取环境
final Environment environment = configuration.getEnvironment();
//生成事务工厂
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
//创建事务