本站首页
管理页面
写新日志
退出
[QQ:172832876] [MSN:lanlanq@hotmail.com]
麒麟在天欢迎您
.:
日期
«
September 2025
»
日
一
二
三
四
五
六
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.:
我的分类
首页(64)
J2EE(27)
架构设计(1)
休闲时刻(8)
C++/C#(DotNet)(9)
项目管理(8)
Lotus Notes(6)
.:
最新日志
继承ConfigurationSecti
做正确的事,正确的做事[续1]
c# 数据库连接管理类
做正确的事,正确的做事
摄像头控件(C#)选像,拍照,保存不同数
从网上找的 content-type 类
引发类型为“System.Windows
java.security 类 Acc
instanceof
计算日期
.:
显示信息
blog名称:
日志总数:64
评论数量:34
留言数量:3
访问次数:342778
建立时间:2006年3月10日
.:
留言板
签写新留言
我也向往美好的生活
.:
链接
奕友软件
宋传芳的Blog
公告
在属于自己的一片天空中,敲打着键盘,记录下自己感兴趣和认为自己因该回忆的碎片,可能是财富,也可能是不足,过后你会发现你的进步,这就足够。
[J2EE]
spring事务继续学习。。
网上资源
,
随笔
,
读书笔记
,
心得体会
,
软件技术
luckystar
发表于 2006/3/16 15:12:55
Spring提供了几个关于事务处理的类: TransactionDefinition //事务属性定义 TranscationStatus //代表了当前的事务,可以提交,回滚。 PlatformTransactionManager这个是spring提供的用于管理事务的基础接口,其下有一个实现的抽象类 AbstractPlatformTransactionManager,我们使用的事务管理类例如 DataSourceTransactionManager等都是这个类的子类。 我们使用编程式的事务管理流程可能如下:: 1、数据源 2、声明一个事务管理类,例如DataSourceTransactionManager,HibernateTransactionManger,JTATransactionManager等 3 在我们的代码中加入事务处理代码: TransactionDefinition td = new TransactionDefinition();TransactionStatus ts = transactionManager.getTransaction(td);try{ //do sth transactionManager.commit(ts);}catch(Exception e){transactionManager.rollback(ts);} 使用spring提供的事务模板TransactionTemplate void add(){ transactionTemplate.execute( new TransactionCallback(){ pulic Object doInTransaction(TransactionStatus ts) { //do sth} }} Spring声明式事务处理 Spring声明式事务处理也主要使用了ioc,aop思想,提供了TransactionInterceptor拦截器和常用的代理类TransactionProxyFactoryBean,可以直接对组件进行事务代理。 使用TransactionInterceptor步骤 1.定义数据源,事务管理类 2.定义事务拦截器,such as: <bean id = "transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"><property name="transactionManager"><ref bean="transactionManager"/></property><property name="transactionAttributeSource"><value>com.test.UserManager.*r=PROPAGATION_REQUIRED</value></property></bean> 3.为组件声明一个代理类:ProxyFactoryBean <bean id="userManager" class="org.springframework.aop.framework.ProxyFactoryBean"><property name="proxyInterfaces"><value>com.test.UserManager</value></property><property name="interceptorNames"><list><idref local="transactionInterceptor"/></list></property></bean> 使用TransactionProxyFactoryBean: <bean id="userManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"><property name="transactionManager"><ref bean="transactionManager"/></property><property name="target"><ref local="userManagerTarget"/></property><property name="transactionAttributes"><props><prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="update*">PROPAGATION_REQUIRED</prop><prop key="*">PROPAGATION_REQUIRED,readOnly</prop></props></property></bean> TransactionProxyFactoryBean只是为组件的事务代理,如果我们要给组件添加一些业务方面的验证等,可以使用 TransactionTemplate加拦截器方式,为组件添加多个拦截器,spring AOP中提供了三类Advice,即前增强,后增强,抛出异常时的增强,可以灵活使用。 (网上摘录)
阅读全文(4291)
|
回复(0)
|
编辑
|
精华
发表评论:
昵称:
密码:
主页:
标题:
验证码:
(不区分大小写,请仔细填写,输错需重写评论内容!)
站点首页
|
联系我们
|
博客注册
|
博客登陆
Sponsored By
W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144769863 times.
《全国人大常委会关于维护互联网安全的决定》
《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号