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

Sun Microsystem Inc

Application Assembler’s responsibilities

Enterprise JavaBeans v1.1, Final Release

Support for Transactions

For example, an AccountTransfer bean which debits one account and credits another account could mark a transaction for rollback if it successfully performs the debit operation, but encounters a failure during the credit operation.

11.3.4.3 javax.ejb.EJBContext.getRollbackOnly() method

An enterprise bean with container-managed transaction demarcation can use the getRollbackOnly() method of its EJBContext object to test if the current transaction has been marked for rollback. The transaction might have been marked for rollback by the enterprise bean itself, by other enterprise beans, or by other components (outside of the EJB specification scope) of the transaction processing infrastructure.

11.3.5 Declaration in deployment descriptor

The Bean Provider of a Session Bean must use the transaction-type element to declare whether the Session Bean is of the bean-managed or container-managed transaction demarcation type. (See Chapter 16 for information about the deployment descriptor.)

The transaction-type element is not supported for Entity beans because all Entity beans must use con- tainer-managed transaction demarcation.

The Bean Provider of an enterprise bean with container-managed transaction demarcation may optionally specify the transaction attributes for the enterprise bean’s methods. See Subsection 11.4.1.

11.4 Application Assembler’s responsibilities

This section describes the view and responsibilities of the Application Assembler.

There is no mechanism for an Application Assembler to affect enterprise beans with bean-managed transaction demarcation. The Application Assembler must not define transaction attributes for an enterprise bean with bean-managed transaction demarcation.

The Application Assembler can use the transaction attribute mechanism described below to manage transaction demarcation for enterprise beans using container-managed transaction demarcation.

11.4.1 Transaction attributes

Note: The transaction attributes may be specified either by the Bean Provider or by the Application Assembler.

A transaction attribute is a value associated with a method of an enterprise bean’s remote or home interface. The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the business method via the enterprise bean home or remote interface.

169

11/24/99

Sun Microsystems Inc.

Support for Transactions

Enterprise JavaBeans v1.1, Final Release

Application Assembler’s responsibilities

The transaction attribute must be specified for the following remote and home interface methods:

For a session bean, the transaction attributes must be specified for the methods defined in the bean’s remote interface and all the direct and indirect superinterfaces of the remote interface, excluding the methods of the javax.ejb.EJBObject interface. Transaction attributes must not be specified for the methods of a session bean’s home interface.

For an entity bean, the transaction attributes must be specified for the methods defined in the bean’s remote interface and all the direct and indirect superinterfaces of the remote interface, excluding the getEJBHome, getHandle, getPrimaryKey, and isIdentical methods; and for the methods defined in the bean’s home interface and all the direct and indirect superinterfaces of the home interface, excluding the getEJBMetaData and getHomeHandle methods.

Providing the transaction attributes for an enterprise bean is an optional requirement for the Application Assembler, because, for a given enterprise bean, the Application Assembler must either specify a value of the transaction attribute for all the methods of the remote and home interfaces for which a transaction attribute must be specified, or the Assembler must specify none. If the transaction attributes are not specified for the methods of an enterprise bean, the Deployer will have to specify them.

Enterprise JavaBeans defines the following values for the transaction attribute:

NotSupported

Required

Supports

RequiresNew

Mandatory

Never

Refer to Subsection 11.6.2 for the specification of how the value of the transaction attribute affects the transaction management performed by the Container.

If an enterprise bean implements the javax.ejb.SessionSynchronization interface, the Application Assembler can specify only the following values for the transaction attributes of the bean’s methods: Required, RequiresNew, or Mandatory.

The above restriction is necessary to ensure that the enterprise bean is invoked only in a transaction. If the bean were invoked without a transaction, the Container would not be able to send the transaction synchronization calls.

The tools used by the Application Assembler can determine if the bean implements the javax.ejb.SessionSynchronization interface, for example, by using the Java reflection API on the enterprise bean’s class.

11/24/99

170

Sun Microsystem Inc

Application Assembler’s responsibilities

Enterprise JavaBeans v1.1, Final Release

Support for Transactions

The following is the description of the deployment descriptor rules that the Application Assembler uses to specify transaction attributes for the methods of the enterprise beans’ remote and home interfaces. (See Section 16.5 for the complete syntax of the deployment descriptor.)

The Application Assembler uses the container-transaction elements to define the transaction attributes for the methods of the enterprise beans’ remote and home interfaces. Each con- tainer-transaction element consists of a list of one or more method elements, and the trans-attribute element. The container-transaction element specifies that all the listed methods are assigned the specified transaction attribute value. It is required that all the methods specified in a single container-transaction element be methods of the same enterprise bean.

The method element uses the ejb-name, method-name, and method-params elements to denote one or more methods of an enterprise bean’s home and remote interfaces. There are three legal styles of composing the method element:

Style 1:

<method> <ejb-name>EJBNAME</ejb-name> <method-name>*</method-name>

</method>

This style is used to specify a default value of the transaction attribute for the methods for which there is no Style 2 or Style 3 element specified. There must be at most one con- tainer-transaction element that uses the Style 1 method element for a given enterprise bean.

Style 2:

<method> <ejb-name>EJBNAME</ejb-name>

<method-name>METHOD</method-name> </method>

This style is used for referring to a specified method of the remote or home interface of the specified enterprise bean. If there are multiple methods with the same overloaded name, this style refers to all the methods with the same name. There must be at most one con- tainer-transaction element that uses the Style 2 method element for a given method name. If there is also a container-transaction element that uses Style 1 element for the same bean, the value specified by the Style 2 element takes precedence.

Style 3:

<method> <ejb-name>EJBNAME</ejb-name>

<method-name>METHOD</method-name> <method-params>

<method-param>PARAMETER_1</method-param>

...

<method-param>PARAMETER_N</method-param> </method-params>

</method>

171

11/24/99