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

Sun Microsystems Inc.

Support for Transactions

Enterprise JavaBeans 2.0, Public Draft

Application Assembler’s responsibilities

16.5 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.

16.5.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 a session or entity bean’s remote or home interface or with the onMessage method of a message-driven bean. The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean’s home or remote interface or when the method is invoked as the result of the arrival of a JMS message.

The transaction attribute must be specified for the following 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.

For a message-driven bean, the transaction attribute must be specified for the bean’s onMessage method.

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 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

5/31/00

322

Sun Microsystems Inc

Application Assembler’s responsibilities

Enterprise JavaBeans 2.0, Public Draft

Support for Transactions

Required

Supports

RequiresNew

Mandatory

Never

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

For message-driven beans, only the Required and NotSupported transaction attributes may be used.

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.

The following is the description of the deployment descriptor rules that the Application Assembler uses to specify transaction attributes for the methods of the session and entity beans’ remote and home interfaces and message-driven beans’ onMessage methods. (See Section 21.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 session and entity bean remote and home interfaces and for the onMessage methods of message-driven beans. Each container-transaction element consists of a list of one or more method elements, and the trans-attribute element. The container-trans- action 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>

323

5/31/00

Sun Microsystems Inc.

Support for Transactions

Enterprise JavaBeans 2.0, Public Draft

Application Assembler’s responsibilities

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>

This style is used to refer to a single method within a set of methods with an overloaded name. The method must be one defined in the remote or home interface of the specified enterprise bean. If there is also a container-transaction element that uses the Style 2 element for the method name, or the Style 1 element for the bean, the value specified by the Style 3 element takes precedence.

The optional method-intf element can be used to differentiate between methods with the same name and signature that are defined in both the remote and home interfaces.

5/31/00

324