Spring 声明式事务的传播性
2011-08-09 17:45
197 查看
spring中设置事务的传播属性有如下7种:
1. 判断当前是否在一个事务中;isTransactionExist 2. 把方法加入当前事务中; putInCurTransaction 3. 挂起原有方法,创建新的事务; suspendCurAndNewTra 4. 事务嵌套,内部回滚; nestTransaction isTransactionExist(){ 当前线程启动事务时记录当前事务; 所以本线程可以知道自己是否在一个事务中; } putInCurTransaction{ 什么也不做,直接在当前连接下运行函数; } suspendCurAndNewTra{ 新建一个连接,SET autocommit=0;自然就使用了新的事务; } nestTransaction{ SAVEPOINT `SAVEPOINT_1`; 执行函数; 成功 commit ;失败则 ROLLBACK TO SAVEPOINT `SAVEPOINT_1`; } 有了这几个函数, 则上述7类传播属性都可以实现: REQUIRED{ isTransactionExist(){ putInCurTransaction() }else{ SET autocommit=1; 执行函数; commit; } } SUPPORTS{ putInCurTransaction(); } MANDATORY{ isTransactionExist(){ putInCurTransaction(); }else{ throw Exception(); } } REQUIRES_NEW{ con2=suspendCurAndNewTra(); con2.commit(); } NOT_SUPPORTED{ 建立连接,SET autocommit=0;执行函数; } NEVER{ isTransactionExist(){ throw Exception(); }else{ 建立连接,SET autocommit=0;执行函数; } } NESTED{ isTransactionExist(){ nestTransaction(); }else{ REQUIRED(); } } |
相关文章推荐
- Spring声明式事务注意点,以及不生效情况
- 全面分析 Spring 的编程式事务管理及声明式事务管理
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- Spring学习之Spring的声明式事务管理详解
- 全面分析 Spring 的编程式事务管理及声明式事务管理
- 对Spring声明式事务的理解
- Spring的声明式事务管理(3)
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- spring 5.0 声明式事务 09
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- 全面分析 Spring 的编程式事务管理及声明式事务管理--转
- Spring 声明式事务管理配置
- Spring 声明式事务的配置方式(三)
- 【第九章】 Spring的事务 之 9.4 声明式事务 ——跟我学spring3
- Spring事务传播性与隔离级别
- spring声明式事务管理的两种方式
- Spring之AOP声明式事务管理(采用xml的配置方式更好)
- Spring声明式事务管理与配置介绍
- spring 声明式事务处理及测试用类,其他未列出。
- 使用Spring的声明式事务----Annotation注解方式