Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc

Overview

Enterprise JavaBeans 2.0, Public Draft

Support for Transactions

Chapter 16 Support for Transactions

One of the key features of the Enterprise JavaBeans™ architecture is support for distributed transactions. The Enterprise JavaBeans architecture allows an application developer to write an application that atomically updates data in multiple databases which may be distributed across multiple sites. The sites may use EJB Servers from different vendors.

16.1 Overview

This section provides a brief overview of transactions and illustrates a number of transaction scenarios in EJB.

16.1.1 Transactions

Transactions are a proven technique for simplifying application programming. Transactions free the application programmer from dealing with the complex issues of failure recovery and multi-user programming. If the application programmer uses transactions, the programmer divides the application’s work into units called transactions. The transactional system ensures that a unit of work either fully completes, or the work is fully rolled back. Furthermore, transactions make it possible for the programmer to design the application as if it ran in an environment that executes units of work serially.

299

5/31/00

Sun Microsystems Inc.

Support for Transactions

Enterprise JavaBeans 2.0, Public Draft

Overview

Support for transactions is an essential component of the Enterprise JavaBeans architecture. The enterprise Bean Provider and the client application programmer are not exposed to the complexity of distributed transactions. The Bean Provider can choose between using programmatic transaction demarcation in the enterprise bean code (this style is called bean-managed transaction demarcation) or declarative transaction demarcation performed automatically by the EJB Container (this style is called con- tainer-managed transaction demarcation).

With bean-managed transaction demarcation, the enterprise bean code demarcates transactions using the javax.transaction.UserTransaction interface. All resource manager[22] accesses between the UserTransaction.begin and UserTransaction.commit calls are part of a transaction.

With container-managed transaction demarcation, the Container demarcates transactions per instructions provided by the Application Assembler in the deployment descriptor. These instructions, called transaction attributes, tell the container whether it should include the work performed by an enterprise bean method in a client’s transaction, run the enterprise bean method in a new transaction started by the Container, or run the method with “no transaction” (Refer to Subsection 16.7.5 for the description of the “no transaction” case).

Regardless whether an enterprise bean uses bean-managed or container-managed transaction demarcation, the burden of implementing transaction management is on the EJB Container and Server Provider. The EJB Container and Server implement the necessary low-level transaction protocols, such as the two-phase commit protocol between a transaction manager and a database system or JMS provider, transaction context propagation, and distributed two-phase commit.

Many applications will consist of one or several enterprise beans that all use a single resource manager (typically a relational database management system). The EJB Container can make use of resource manager local transactions as an optimization technique for enterprise beans for which distributed transactions are not needed and which are identified as such by the Bean Provider in the deployment descriptor. A resource manager local transaction does not involve control or coordination by an external transaction manager. The use of local transactions for enterprise beans with either container managed transaction demarcation or bean managed transaction demarcation is discussed in Section 16.3. For a more general discussion of resource manager local transactions and the javax.resource.LocalTransaction interface, refer to [ 11 ]. For resource adaptors, such as JDBC drivers, that do not support the javax.resource.LocalTransaction interface, this specification permits the EJB Container to use resource-adaptor specific APIs for local transaction management.

16.1.2 Transaction model

The Enterprise JavaBeans architecture supports flat transactions. A flat transaction cannot have any child (nested) transactions.

[22]The terms resource and resource manager used in this chapter refer to the resources declared in the enterprise bean’s deployment descriptor using the resource-ref element. This includes not only database resources, but also JMS Connections. These resources are considered to be “managed” by the Container.

5/31/00

300