Chapter 13. More AOP: Transactions
In the previous chapter you learned a great deal about AOP. One of most frequent uses of AOP in application design is in the area of transactions. In fact, transactions are a requirement in many business applications. Roughly speaking, transactions are sequences of activities that must be completed together. If any of the activities involved in the transaction fails, all the changes made by the sequence must be undone. Only if all the activities complete successfully will the transaction be considered successful.
In a business context, a common example of a transaction is the sequence of activities involved in an ATM cash withdrawal. Suppose you need to get a hundred dollars for dinner at the neighborhood ATM. You start by putting the ATM card in the machine, then enter your password and confirm it. After the ATM verifies your credentials, you select a withdrawal operation and enter $100 as the withdrawal amount. When you hit OK, the transaction begins. The ATM now needs to issue $100 in cash to you and deduct $100 from your account as a transaction. These two activities must be successfully completed together. If the dispenser jams and fails to provide you with the cash, you want to make sure that $100 are not deducted from your account. In that case, the transaction must be rolled back (undone) and your account balance must revert to the amount it contained before the transaction started.
There are typically two ways to use transactions in any ...
Get Beginning Spring Framework 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.