Java Reference
In-Depth Information
system returning to its original unmodified state. A task in the context of EJB refers to an
SQL statement or the processing of a JMS message. To put this in perspective, when you
transfer money from a checking account to a savings account, you want both operations to
succeed. If the deposit in the savings account fails for any reason, such as power loss, disk
failure, or networking failure, the withdrawal of money to the checking account should be
rescinded. Transactions are thus an integral part of your daily life whether you realize it or
not. You don't want to arrive at the airport to discover that although you've paid for a flight
and have a printed boarding pass, the airline has no reservation.
Transaction support is an integral component of the EJB architecture. As you'll see, you
have the choice of two transaction models when working with EJBs: programmatic and de-
clarative. Programmatic transactions, known as bean-managed transactions (BMTs), place
the onus on the developer to explicitly start, commit, and roll back transactions. Declarative
transactions, known as container-managed transactions (CMTs), manage the commit and
rollback transactions with configuration settings specified by the developer. Both models
can be used within the same application, although there are certain situations where they're
incompatible; these will be covered later in the chapter. If not specified, the default for a
bean is CMTs.
Stateful, stateless, singleton, and message-driven beans all support both BMTs and CMTs.
Note the inclusion of BMTs—transaction support also extends to JMS messaging. It's pos-
sible to implement Java Connector Architecture (JCA) connectors that talk to Enterprise
information systems as well as legacy systems and also participate in transactions. Systems
such as databases, JMS message queues, and external systems accessed via JCA are all re-
sources, and a resource manager controls access. To put everything in context, let's review
the basic properties of transactions and then work our way from Java SE to Java EE.
6.1.1. Transaction basics
Transactions are an exceedingly complex subject and are the focal point of much ongoing
research. Entire topics have been devoted to the subject and for good reason. In this section
we'll give you a brief overview of the core concepts. This overview will be enough to make
you dangerous if you're new to transactions and give you a foundation on which to dive
into the subject further. If you're already familiar with transactions, this section can either
be skipped or used as a basic refresher.
Search WWH ::




Custom Search