Home TOC |
Search
Feedback |
What is a Transaction?
To emulate a business transaction, a program may need to perform several steps. A financial program, for example, might transfer funds from a checking account to a savings account with the steps listed in the following pseudo-code.
begin transaction debit checking account credit savings account update history log commit transactionEither all three of these steps must complete, or none of them at all. Otherwise, data integrity is lost. Because the steps within a transaction are a unified whole, a transaction is often defined as an indivisible unit of work.
A transaction can end in two ways: with a commit or a rollback. When a transaction commits, the data modifications made by its statements are saved. If a statement within a transaction fails, the transaction rolls back, undoing the effects of all statements in the transaction. In the pseudo-code, for example, if a disk drive crashed during the credit step, the transaction rolls back and undoes the data modifications made by the debit statement. Although the transaction failed, data integrity is intact because the accounts still balance.
In the preceding pseudo-code, the begin and commit statements mark the boundaries of the transaction. When deploying an enterprise bean, you determine how the boundaries are set by specifying either container-managed or bean-managed transactions.
Home TOC |
Search
Feedback |