6.4. Transaction Overview

Business transactions are frequently carried out in a series of separate steps. Consider the following example where a customer purchases an airline ticket online. Here we use pseudocode that shows the required steps in a transactional environment.

try {
  startTransaction();
    reserveFlight();
    payForFlight();
  commitTransaction();
} catch (Exception ex) {
    rollbackTransaction();
}

For this transaction to complete, all steps must be successful. Otherwise, data may be inconsistent. These separate steps make up a transaction context, which is viewed as a single operation.

A transaction that commits means that all steps in the transaction were successful and data is saved. A transaction that rolls back means that one or more ...

Get Enterprise JavaBeans™ Component Architecture: Designing and Coding Enterprise Applications 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.