The life of an entity bean
There are three
distinct states in the life cycle of an entity enterprise bean:
v
Nonexistent
v
Pooled
v
Ready
The
nonexistent state
At first the
entity bean instance doesn't exist. The EJB container creates an instance of an
entity bean and then it calls the setEntityContext() method on the entity bean
to pass the instance a reference to its context; that is, a reference to the
EntityContext interface. The EntityContext interface gives the instance access
to container provided services and allows it to obtain information about its
clients. The entity bean is now in the pooled state.
The
pooled state
Each type of
entity bean has its own pool. None of the instances in the pool are associated
with data. Because none of their instance variables have been set, the
instances have no identity and they are all equivalent.
The container
is free to assign any instance to a client that requests such an entity bean.
When a client application calls one of the entity bean's finder methods, the
container executes the corresponding ejbFind() method on an arbitrary instance
in the pool. The instance remains in the pooled state during the execution of a
finder method. When the container selects an instance to service a client's
requests to an entity object, that instance moves from the pooled to the ready
state.
There are two
ways that an entity instance moves from the pooled state to the ready state:
v Through the ejbCreate() and ejbPostCreate()
methods.
v Through the ejbActivate() method.
The container
selects the instance to handle a client's request on the bean's home interface.
In response to the create() call , the container creates an entity object and
calls the ejbCreates() and ejbPostCreate() methods when the instance is
assigned to the entity object. The container calls the ejbActivate() method to
activate an instance so that it can respond an invocation on an existing entity
object. Usually the container calls ejbActivate() when there is no suitable
instance in the ready state to handle the client's calls.
The
ready state
When the
instance is in the ready state, it is associated with a specific primary key.
Clients can call the application specific methods on the entity bean. The
container calls the ejbLoad() and ejbStore() methods to tell the bean to load
and store its data. They also enable the bean instance to synchronize its state
with that of the underlying data entity.
Returning
to the pooled state
When an entity
bean instance moves back to the pooled state , the instance is decoupled from
the data represented by the entity. The container can now assign the instance
of any entity object within the same entity bean home. There are two ways a
entity bean instance moves from the ready state back to the pooled state:
ü The
container calls the ejbPassivate() methods to disassociate the instance from
its primary key without removing the underlying entity object.
ü The container calls the ejbRemove() method
to remove the entity object. It calls ejbRemove() when the client application
calls the bean's home or remote remove() method.
To remove an
unassociated instance from the pool, the container calls the instance's
unsetEntityContext() method.

No comments:
Post a Comment