MyBatis-Spring DataSource Interaction

Spring side:

DataSourceUtils->getConnection(dataSource)->

TransactionSynchronizationManager.getResource(dataSource)

SpringManagedTransaction->getConnection()->this.connection = DataSourceUtils.getConnection(this.dataSource);

 

SqlSessionFactoryBean:
buildSqlSessionFactory():

this.transactionFactory = new SpringManagedTransactionFactory();--> newTransaction(dataSource,..., ...)

    Environment environment = new Environment(this.environment, this.transactionFactory, this.dataSource);
    configuration.setEnvironment(environment);

 
Configuration:
configuration.defaultExecutorType = ExecutorType.SIMPLE;
newExecutor(Transaction transaction, ExecutorType executorType);

DefaultSqlSessionFactory:
openSessionFromDataSource/openSessionFromConnection--return SqlSession-->
[
final Environment environment = configuration.getEnvironment();
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
final Executor executor = configuration.newExecutor(tx, execType);
return new DefaultSqlSession(configuration, executor, autoCommit);
]

你可能感兴趣的:(dataSource)