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

Sun Microsystems Inc.

Session Bean Component Contract

Enterprise JavaBeans 2.0, Public Draft Object interaction diagrams for a STATEFUL

If the session bean instance allocates resources in the ejbCreate<METHOD>(...) method and/or in the business methods, and normally releases the resources in the ejbRemove() method, these resources will not be automatically released in the above scenarios. The application using the session bean should provide some clean up mechanism to periodically clean up the unreleased resources.

For example, if a shopping cart component is implemented as a session bean, and the session bean stores the shopping cart content in a database, the application should provide a program that runs periodically and removes “abandoned” shopping carts from the database.

6.6.4 Restrictions for transactions

The state diagram implies the following restrictions on transaction scoping of the client invoked business methods. The restrictions are enforced by the container and must be observed by the client programmer.

A session bean instance can participate in at most a single transaction at a time.

If a session bean instance is participating in a transaction, it is an error for a client to invoke a method on the session object such that the transaction attribute in the deployment descriptor would cause the container to execute the method in a different transaction context or in an unspecified transaction context. The container throws the java.rmi.RemoteException to the client in such a case.

If a session bean instance is participating in a transaction, it is an error for a client to invoke the remove method on the session object’s remote or home interface object. The container must detect such an attempt and throw the javax.ejb.RemoveException to the client. The container should not mark the client’s transaction for rollback, thus allowing the client to recover.

6.7Object interaction diagrams for a STATEFUL session bean

This section contains object interaction diagrams (OID) that illustrates the interaction of the classes.

6.7.1 Notes

The object interaction diagrams illustrate a box labeled “container-provided classes.” These are either classes that are part of the container, or classes that were generated by the container tools. These classes communicate with each other through protocols that are container-implementation specific. Therefore, the communication between these classes is not shown in the diagrams.

The classes shown in the diagrams should be considered as an illustrative implementation rather than as a prescriptive one.

5/31/00

70

Sun Microsystems Inc

Object interaction diagrams for a STATEFUL session beanEnterprise JavaBeans 2.0, Public Draft Session Bean Component Contract

6.7.2 Creating a session object

The following diagram illustrates the creation of a session object.

Figure 6 OID for Creation of a session object

container provided classes

client

EJB

EJB

container session

synchro-

instance transaction

 

Home

Object

context

nization

service

 

 

 

 

 

 

create(args)

new

new

new

setSessionContext()

ejbCreate(args)

6.7.3 Starting a transaction

The following diagram illustrates the protocol performed at the beginning of a transaction.

71

5/31/00

Sun Microsystems Inc.

Session Bean Component Contract

Enterprise JavaBeans 2.0, Public Draft Object interaction diagrams for a STATEFUL

Figure 7

OID for session object at start of a transaction.

 

 

 

 

container provided classes

 

 

 

 

 

 

 

 

 

 

client

EJB

EJB

container session

synchro-

instance transaction database

 

 

Home

Object

context

nization

service

 

 

 

 

 

 

 

javax.transaction.UserTransaction.begin()

business method

If the instance was passivated it is reactivated

new

registerSynchronization(synchronization)

afterBegin

read some data

register resource manager

business method

business method

business method

6.7.4 Committing a transaction

The following diagram illustrates the transaction synchronization protocol for a session object.

5/31/00

72

Sun Microsystems Inc

Object interaction diagrams for a STATEFUL session beanEnterprise JavaBeans 2.0, Public Draft Session Bean Component Contract

Figure 8

 

OID for session object transaction synchronization

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

container provided classes

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

client

EJB

EJB

container session

synchro-

instance transaction database

 

 

 

Home

Object

context

nization

 

 

service

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UserTransaction.commit()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

beforeCompletion()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

beforeCompletion()

 

 

 

 

 

 

 

 

 

 

 

 

 

write updates

to DB

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

prepare

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

commit

 

 

 

 

 

 

 

 

 

 

afterCompletion(status)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

afterCompletion(status)

6.7.5 Passivating and activating an instance between transactions

The following diagram illustrates the passivation and reactivation of a session bean instance. Passivation typically happens spontaneously based on the needs of the container. Activation typically occurs when a client calls a method.

73

5/31/00