Spring 声明式事务管理核心代码分析
来源:互联网 发布:react.js主要功能 编辑:程序博客网 时间:2024/04/27 22:29
org.springframework.transaction.interceptor.TransactionInterceptor.invoke();
public Object invoke(final MethodInvocation invocation) throws Throwable {// Work out the target class: may be <code>null</code>.// The TransactionAttributeSource should be passed the target class// as well as the method, which may be from an interface.Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);// If the transaction attribute is null, the method is non-transactional.final TransactionAttribute txAttr =getTransactionAttributeSource().getTransactionAttribute(invocation.getMethod(), targetClass);final PlatformTransactionManager tm = determineTransactionManager(txAttr);final String joinpointIdentification = methodIdentification(invocation.getMethod());if (txAttr == null || !(tm instanceof CallbackPreferringPlatformTransactionManager)) {// Standard transaction demarcation with getTransaction and commit/rollback calls.TransactionInfo txInfo = createTransactionIfNecessary(tm, txAttr, joinpointIdentification);Object retVal = null;try {// This is an around advice: Invoke the next interceptor in the chain.// This will normally result in a target object being invoked.retVal = invocation.proceed();}catch (Throwable ex) {// target invocation exceptioncompleteTransactionAfterThrowing(txInfo, ex);throw ex;}finally {cleanupTransactionInfo(txInfo);}commitTransactionAfterReturning(txInfo);return retVal;}else {// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.try {Object result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr,new TransactionCallback<Object>() {public Object doInTransaction(TransactionStatus status) {TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status);try {return invocation.proceed();}catch (Throwable ex) {if (txAttr.rollbackOn(ex)) {// A RuntimeException: will lead to a rollback.if (ex instanceof RuntimeException) {throw (RuntimeException) ex;}else {throw new ThrowableHolderException(ex);}}else {// A normal return value: will lead to a commit.return new ThrowableHolder(ex);}}finally {cleanupTransactionInfo(txInfo);}}});// Check result: It might indicate a Throwable to rethrow.if (result instanceof ThrowableHolder) {throw ((ThrowableHolder) result).getThrowable();}else {return result;}}catch (ThrowableHolderException ex) {throw ex.getCause();}}}
- Spring 声明式事务管理核心代码分析
- Spring--声明式事务管理
- 声明式事务管理--Spring
- Spring声明式事务管理
- Spring声明式事务管理
- Spring声明式事务管理
- Spring声明式事务管理
- Spring声明式事务管理
- spring声明式事务管理
- Spring声明式事务管理
- spring声明式事务管理
- spring声明式事务管理
- Spring 声明式事务管理
- Spring声明式事务管理
- spring声明式事务管理
- Spring声明式事务管理
- Spring 声明式事务管理
- 【Spring】声明式事务管理
- 关于单例模式
- 求100之内的素数
- 针对于QT5下找不到QApplication头文件的问题界解决
- st build后自动将项目deploy到android project的asset/www目录的方法
- ios开发(四):基本语法 Objects, Classes, and Messaging
- Spring 声明式事务管理核心代码分析
- 揭开正则表达式的神秘面纱
- 初识Javascript
- eclipse最实用快捷键
- Fragments 基础使用技术详解
- 【IOS 之愤怒的小鸟】使用Lua语言:Wax框架详解
- iOS 关于音频开发
- hive与hbase整合
- Linux Support for ARM LPAE 分析