background image

What Is a Transaction

<< ant clean Command | Container-Managed Transactions >>
<< ant clean Command | Container-Managed Transactions >>

What Is a Transaction

Transactions
A typical enterprise application accesses and stores information in one or more databases.
Because this information is critical for business operations, it must be accurate, current, and
reliable. Data integrity would be lost if multiple programs were allowed to update the same
information simultaneously. It would also be lost if a system that failed while processing a
business transaction were to leave the affected data only partially updated. By preventing both
of these scenarios, software transactions ensure data integrity. Transactions control the
concurrent access of data by multiple programs. In the event of a system failure, transactions
make sure that after recovery the data will be in a consistent state.
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 using
the steps listed in the following pseudocode:
begin transaction
debit checking account
credit savings account
update history log
commit transaction
Either 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 with 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 pseudocode, for example, if a disk drive were to crash during the credit
33
C H A P T E R
3 3
997