O'Reilly logo

Beginning Spring Framework 2 by Christian Dupuis, Naveen Balani, Thomas Van de Velde, Anne Horton, Sing Li, Bruce Snyder

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required