梦之天堂

我学故我知,我思故我在;java你我,happy你我——sylilzy

BlogJava 首页 新随笔 联系 聚合 管理
  3 Posts :: 8 Stories :: 2 Comments :: 0 Trackbacks
spring的事务处理详解:调用一个方法后的事务处理过程
 
sylilzy@163.com
版权所有,转载请注明出处
 
spring调用一个方法后的事务处理过程:
参照TransactionInterceptor的invoke方法:
 1 try   {
 2     //  This is an around advice.
 3     //  Invoke the next interceptor in the chain.
 4     //  This will normally result in a target object being invoked.
 5    retVal  =  invocation.proceed();
 6   }

 7    catch  (Throwable ex)  {
 8     //  target invocation exception
 9    doCloseTransactionAfterThrowing(txInfo, ex);
10     throw  ex;
11   }

12    finally   {
13    doFinally(txInfo);
14   }

15   doCommitTransactionAfterReturning(txInfo);
16    return  retVal;
17  }
 
调用目标方法时没有抛出异常时会调用:
doCommitTransactionAfterReturning(txInfo);
然后直接提交事务
 
如果抛异常则检查是否需要回滚事务(doCloseTransactionAfterThrowing方法会根据在spring中设备的Transaction Attribute),否则提交事务.

参考资料:
1.Spring Reference Manual:http://static.springframework.org/spring/docs/1.2.x/reference/index.html
2.Spring API doc:http://static.springframework.org/spring/docs/1.2.x/api/index.html
3.Spring 的源代码

作者简介:
    施祖阳,网名sylilzy,1979年生。
    2002年起从事软件开发工作,主要研究为JAVA、Linux及相关技术。
    你可通过 sylilzy@163.com 与作者联系。
posted on 2006-06-14 18:34 sylilzy 阅读(333) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: