Mybatis process:
2. Get The SqlSession
- Remove Exceutor (actuator) from the configuration file, call openSessionFromDataSource ()
- New types of actuators default: SIMPLE
- There are three types of actuators:
- note:
executor = (Executor) interceptorChain.pluginAll(executor);
Executor to intercept enhanced design patterns used here was the decorator pattern
- Then return: DefaultSqlSession (configuratioin, Executor, affairs issues)
Executor execution of CRUD configuratioin
Summary: The process of obtaining the SqlSession
- First SqlSessionFactory call openSession ()
SqlSession session = sessionFactory.openSession();
- Then openSession () call openSessionFromDataSource ()
@Override public SqlSession openSession() { return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false); }
- Return DefaultSqlSession objects , note DefaultSqlSession include: (the Configuration, Executor, affairs)
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { Transaction tx = null; try { final Environment environment = configuration.getEnvironment(); final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit); //创建一个新的执行器,类型为execType final Executor executor = configuration.newExecutor(tx, execType); return new DefaultSqlSession(configuration, executor, autoCommit); } catch (Exception e) { closeTransaction(tx); // may have fetched a connection so lets call close() throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }