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

Sun Microsystems Inc

Use of resource manager local transactions as an optimizationEnterprise JavaBeans 2.0, Public Draft

Support for Transactions

If a message-driven bean is configured with the Required transaction attribute, the container behaves as follows: Because there is never a client transaction context available for a message-driven bean, the container automatically starts a new transaction before the dequeuing of the JMS message and, hence, before the invocation of the message-driven bean’s onMessage method. The Container automatically enlists the resource manager associated with the arriving message and all the resource managers accessed by the onMessage method with the transaction.

16.2.6 Bean-managed demarcation

A session Bean can use the javax.transaction.UserTransaction interface to programmatically demarcate transactions.

Note: When a message-driven bean uses the javax.transaction.UserTransaction interface to demarcate transactions, the dequeuing of the JMS message and the invocation of the bean’s onMessage method is not part of the transaction.

16.3Use of resource manager local transactions as an optimization

Many applications consist of one or more enterprise beans that all use a single resource manager. This section describes an optimization that allows the EJB container to use, transparently to the enterprise beans, a resource manager local transaction instead of a distributed (JTA) transaction. The optimization consists of the following elements:

The Bean Provider indicates in the deployment descriptor that the container is allowed to use a resource manager local transaction instead of a distributed transaction when starting a transaction on behalf of a particular enterprise bean. The deployment descriptor identifies whether a local or distributed transaction is needed for methods of the enterprise bean.

If the deployment descriptor indicates that the local transaction optimization is allowed, the container may, but is not required to, use resource manager local transactions instead of distributed transactions when executing the methods of the enterprise bean. If the container chooses to perform the optimization, the container must arrange that the enterprise bean and all beans that it calls will share a single resource manager connection in a transaction. The container collaborates with the resource adaptor (e.g., JDBC driver) to achieve the sharing.

16.3.1 Sample scenario: updates to a database by multiple beans in a local transaction

The Container, relying upon deployment descriptor hints by the Bean Provider, may use a local transaction as an optimization technique when access to only a single resource manager is involved.

In the following figure, a client invokes the enterprise Bean X. Bean X updates data in database A, and then calls another enterprise Bean Y. Bean Y also updates data in database A. The Bean Provider has specified in the deployment descriptor that Beans X and Y have the same local transaction scope. The Enterprise JavaBeans architecture makes it possible to perform the updates to database A by both X and Y in a single local transaction.

307

5/31/00