Java Reference
In-Depth Information
To see how to configure a TransactionInterceptor , let's imagine that the
TransferFacade from chapter 1 has the following interface:
public interface TransferFacade {
public BankingTransaction transfer(
String fromAccountId, String toAccountId,
double amount)
throws MoneyTransferException;
public void getBalance(String accountId);
}
The transfer() method transfers money from one account to another and throws
a MoneyTransferException if the transfer fails. We want this method to be executed
within a transaction that is rolled back if the MoneyTransferException is thrown.
The getBalance() method returns the balance of the specified account. It doesn't
need to be executed within a transaction because it does not update the database.
Here is the definition of a TransactionInterceptor that manages transactions
for the TransferFacade :
<beans>
<bean id="ExampleTransactionInterceptor"
class="org.springframework.transaction.interceptor.
b bbb b
TransactionInterceptor">
<property name="transactionAttributeSource">
<value>net.chrisrichardson.bankingExample.facade.
b bbb b
TransferFacade.transfer=PROPAGATION_REQUIRED,
b bbbbb b net.chrisrichardson.bankingExample.facade.
b bbbbb b MoneyTransferException
net.chrisrichardson.bankingExample.facade.TransferFacade.get*=
b b b PROPAGATION_SUPPORTS, readOnly
</value>
</property>
<property ref="transactionManager"/>
</bean>
</beans>
The transactionAttributesSource property specifies the transaction attribute for
each method. In this example, the transaction attributes for the transfer()
method are
PROPAGATION_REQUIRED,-net.chrisrichardson.bankingExample.facade.
b bbbbbbb b MoneyTransferException
 
Search WWH ::




Custom Search