Java Reference
In-Depth Information
<tx:advice ...>
<tx:attributes>
<tx:method name= " ... "
rollback-for= " java.io.IOException "
no-rollback-for= " java.lang.ArithmeticException " />
...
</tx:attributes>
</tx:advice>
In classic Spring AOP, the rollback rule can be specified in the transaction attributes of
TransactionInterceptor and TransactionProxyFactoryBean . The minus sign indicates an exception
to cause a transaction to roll back, while the plus sign indicates an exception to cause a transaction to
commit.
<property name= " transactionAttributes " >
<props>
<prop key= " ... " >
PROPAGATION_REQUIRED, -java.io.IOException,
+java.lang.ArithmeticException
</prop>
</props>
</property>
In Spring's transaction management API, the rollback rule can be specified in a
RuleBasedTransactionAttribute object. Because it implements the TransactionDefinition interface,
it can be passed to a transaction manager's getTransaction() method or a transaction template's
constructor.
RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute();
attr.getRollbackRules().add(
new RollbackRuleAttribute( IOException.class));
attr.getRollbackRules().add(
new NoRollbackRuleAttribute( SendFailedException.class));
4-10. Setting the Timeout and Read-Only Transaction Attributes
Problem
Because a transaction may acquire locks on rows and tables, a long transaction will tie up resources and
have an impact on overall performance. Besides, if a transaction only reads but does not update data,
the database engine could optimize this transaction. You can specify these attributes to increase the
performance of your application.
 
Search WWH ::




Custom Search