`
gsvince
  • 浏览: 53670 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

TransactionAttributeSource,TransactionAttribute

阅读更多
[/b][b]每一个方法执行都会应用事务,它回传的transactionAttribute实例的默认传播行为是PROPAGATION_REQUIRED,隔离层级为ISOLATION_REFAULE

<bean id="informationDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  		  <property name="proxyInterfaces">
		  	<list>
		  		<value>
		  			com.gsvince.hibernate.Idao.IInformationDAO
		  		</value>
		  	</list>
		  </property>
		  <property name="transactionManager">
		   <ref bean="transactionManager" />
		  </property>
		  <property name="target">
		   <ref local="informationDAO" />
		  </property>
		  <property name="transactionAttributeSource">
		   <ref bean="transactionAttributeSource"/>
		  </property>
	</bean>
	
	<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
	</bean>


也可以使用org.springframework.transaction.interceptor.DefaultTransactionAttribute,并设置自己的事务策略,之后设置给transactionAttributeSource,例如:

<bean id="myTransactionAttribute" class="org.springframework.transaction.interceptor.DefaultTransactionAttribute">
		<property name="propagationBehaviorName" 
				value="PROPAGATION_REQUIRES_NEW"/>
		<property name="isolationLevelName" 
				value="ISOLATION_REPEATABLE_READ"/>
	</bean>
	
	<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
		<property name="transactionAttribute" 
				ref="myTransactionAttribute"/>
	</bean>

	<bean id="informationDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  		  <property name="proxyInterfaces">
		  	<list>
		  		<value>
		  			com.gsvince.hibernate.Idao.IInformationDAO
		  		</value>
		  	</list>
		  </property>
		  <property name="transactionManager">
		   <ref bean="transactionManager" />
		  </property>
		  <property name="target">
		   <ref local="informationDAO" />
		  </property>
		  <property name="transactionAttributeSource"
		   		ref="transactionAttributeSource"/>
	</bean>


也可以使用org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource来指定某些方法要应用事务,以及要应用的事务策略,例如:

<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
		<property name="properties">
			<props>
				<prop key="edit*">PROPAGATION_REQUIRED</prop>
			    <prop key="insert*">PROPAGATION_REQUIRED</prop>
			    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
			    <prop key="delete*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	
	<bean id="informationDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  		  <property name="proxyInterfaces">
		  	<list>
		  		<value>
		  			com.gsvince.hibernate.Idao.IInformationDAO
		  		</value>
		  	</list>
		  </property>
		  <property name="transactionManager">
		   <ref bean="transactionManager" />
		  </property>
		  <property name="target">
		   <ref local="informationDAO" />
		  </property>
		  <property name="transactionAttributeSource"
		   		ref="transactionAttributeSource"/>
	</bean>	

在NameMatchTransactionAttributeSource的"properties"属性上,可以指定方法名称与事务策略,方法名称的指定可以指定全名,也可以使用Wildcard来指定,例如上面的指定中,只要方法名以insert开头的都会应用相对应的事务策略。
分享到:
评论

相关推荐

    EJB_transaction(EJB事物)

    EJB事物详细讲解:TransactionAttributeType.MANDATORY;TransactionAttributeType.REQUIRED;TransactionAttributeType.REQUIRES_NEW;TransactionAttributeType.SUPPORTS;TransactionAttributeType.NOT_SUPPORTED...

    开源框架 Spring Gossip

    Spring 对交易的支援 JDBC 编程式交易管理 JDBC 宣告式交易管理 交易的属性介绍 TransactionAttributeSource、 TransactionAttribute Hibernate 支援 Spring 整合了对 Hibernate 的设定...

    SPRING API 2.0.CHM

    All Classes AbstractAdvisorAutoProxyCreator AbstractApplicationContext AbstractApplicationEventMulticaster AbstractAspectJAdvice AbstractAspectJAdvisorFactory AbstractAspectJAdvisorFactory....

    javax.ejb.jar下载

    javax.ejb.TransactionAttribute.class javax.ejb.TransactionAttributeType.class javax.ejb.TransactionManagement.class javax.ejb.TransactionManagementType.class javax.ejb....

    javax.ejb.jar

    javax.ejb.TransactionAttribute.class javax.ejb.TransactionAttributeType.class javax.ejb.TransactionManagement.class javax.ejb.TransactionManagementType.class javax.ejb....

    javax.ejb.rar

    javax.ejb.TransactionAttribute.class javax.ejb.TransactionAttributeType.class javax.ejb.TransactionManagement.class javax.ejb.TransactionManagementType.class javax.ejb....

    Apache Geronimo 2.1_ Quick Reference.pdf

    TransactionAttribute 144 Bean-managed transactions 144 Support in Geronimo 145 Setting transaction timeout 145 Transaction isolation levels 145 Transactions in web applications 146 Summary 148 ...

Global site tag (gtag.js) - Google Analytics