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);
]
SqlSessionTemplate:
Thread safe, Spring managed, -->Proxy-->
SqlSessionHolder holder = (SqlSessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
holder-->DefaultSqlSession:Executor:SIMPLE/BATCH->1:1
SqlSessionUtils.getSqlSession--> SqlSessionHolder[ResourceHolderSupport].requested++,released--,
if no holder, TransactionSynchronizationManager.registerSynchronization ->
SqlSessionSynchronization[TransactionSynchronization.beforeCommit--> SqlSession.commit-->executor.commit[...flushStatements...]
TransactionSynchronization.beforeCompletion if referenceCount<=0 TransactionSynchronizationManager.unbindResource(sessionFactory)]
BATCH: flushStatements before doSelect
mapper->select/insert/update/delete flushCache
Mybatis不允许在同一个事务并且是同一线程中并存2种执行模式。同一事务不同线程可以2种执行模式并存。
相关推荐
Spring provides the core container for managing beans and dependencies, Spring MVC handles the Model-View-Controller architecture, and MyBatis simplifies database interactions. The design of the ...
Spring provides the foundation for dependency injection and application structuring, SpringMVC handles the Model-View-Controller architecture for web applications, while MyBatis simplifies database ...
Spring provides the core dependency injection and AOP (Aspect-Oriented Programming) functionalities, while SpringMVC handles the presentation layer, and MyBatis simplifies database interactions....
Spring provides the foundation for dependency injection and overall application structure, SpringMVC handles the Model-View-Controller architecture, while MyBatis simplifies database interactions....
Spring provides dependency injection and a comprehensive application framework, Struts handles the Model-View-Controller (MVC) pattern for structuring applications, and MyBatis simplifies database ...
3. **MyBatis**: This ORM (Object-Relational Mapping) tool helps in managing database interactions, allowing developers to write SQL queries directly, reducing the complexity of data management. ...
The system follows a B/S (Browser/Server) three-tier architecture, enhancing the ease, speed, and convenience of user interactions. 关键词:在线考试系统;Spring Boot 架构;MyBatisPlus 框架;Vue 前端...
MyBatis, on the other hand, serves as an ORM (Object-Relational Mapping) tool, simplifying database interactions. In terms of the database, MySQL is chosen due to its popularity, performance, and ...
In addition, it employs the Spring and Mybatis framework technologies. The Sd球鞋销售平台系统 consists of two main components: a frontend designed specifically for users and a backend tailored for ...
The SSM (Spring, SpringMVC, MyBatis) framework is a popular choice for building enterprise-level applications. Spring provides dependency injection and a comprehensive framework for managing ...
The persistence layer (dao) deals with database interactions, abstracting away the details of database operations. It interacts with the MySQL database, performing CRUD (Create, Read, Update, Delete) ...
MyBatis, on the other hand, serves as an efficient ORM (Object-Relational Mapping) tool, facilitating interactions between Java code and databases like MySQL. In this specific project, the use of ...
The SSM (Spring, SpringMVC, MyBatis) framework is a popular choice for developing web applications due to its modularity, scalability, and ease of use. Spring provides dependency injection and manages...
The system is built using the SSM (Spring, SpringMVC, MyBatis) framework, a popular choice in Java web development, combined with MySQL as the database management system. SSM offers advantages such ...
MyBatis, on the other hand, serves as a persistence layer, simplifying database interactions by mapping SQL queries to Java methods. MySQL, a widely used open-source relational database management ...