org.objectweb.jonas_ejb.container
Class JEntityContext

java.lang.Object
  |
  +--org.objectweb.jonas_ejb.container.JContext
        |
        +--org.objectweb.jonas_ejb.container.JEntityContext
All Implemented Interfaces:
javax.ejb.EJBContext, javax.ejb.EntityContext, javax.transaction.Synchronization
Direct Known Subclasses:
JEntityContext

public class JEntityContext
extends JContext
implements javax.ejb.EntityContext, javax.transaction.Synchronization

This class implements javax.ejb.EntityContext interface. An Entitycontext is bound to a bean instance. To be used, it must be associated to a JEntitySwitch, and possibly to a Transaction. In case the Context is used inside a Transaction, we use the Synchronization interface to be aware of transaction demarcations.

Author:
Philippe Coq, Philippe Durieux

Fields inherited from class org.objectweb.jonas_ejb.container.JContext
bf, cont, home, instance, localhome, roleGuard, tm
 
Constructor Summary
JEntityContext(JEntityFactory bf, javax.ejb.EntityBean eb)
          Constructs an EntityContext the Context has to be initialized after this.
 
Method Summary
 void activate(boolean doactivate)
          Activate instance.
 void afterCompletion(int status)
          The afterCompletion method is called by the transaction manager after the transaction is committed or rolled back.
 void beforeCompletion()
          This beforeCompletion method is called by the transaction manager prior to the start of the transaction completion process.
 javax.ejb.EJBLocalObject getEJBLocalObject()
          Obtain a reference to the EJB local object that is currently associated with the instance.
 javax.ejb.EJBObject getEJBObject()
          Obtains a reference to the EJB object that is currently associated with the instance.
 JEntityFactory getEntityFactory()
          JEntityFactory accessor
 JEntitySwitch getEntitySwitch()
          JEntitySwitch accessor
 javax.ejb.EntityBean getInstance()
          Returns the bean instance of this context Used in the generated classes to retrieve the instance
 java.lang.Object getPrimaryKey()
          Obtains the primary key of the EJB object that is currently associated with this instance.
 void initEntityContext(JEntitySwitch bs, javax.transaction.Transaction tx)
          Reinit Context for reuse
 boolean isMarkedRemoved()
          Check if context has been marked removed
 void passivate()
          passivate this instance
 void razEntityContext()
          Raz Context before freeing it.
 void reuseEntityContext(javax.transaction.Transaction tx)
          reuse EntityContext for another transaction. optimization: don't pass it by the pool.
 void setEntitySwitch(JEntitySwitch bs)
          set the EntitySwitch
 void setNewInstance()
          Set new instance flag
 void setRemoved()
          Mark this context as removed.
 void storeIfModified()
          Persistence: write data on storage
 
Methods inherited from class org.objectweb.jonas_ejb.container.JContext
getCallerIdentity, getCallerPrincipal, getEJBHome, getEJBLocalHome, getEnvironment, getRollbackOnly, getUserTransaction, isCallerInRole, isCallerInRole, setRollbackOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ejb.EJBContext
getCallerIdentity, getCallerPrincipal, getEJBHome, getEJBLocalHome, getEnvironment, getRollbackOnly, getUserTransaction, isCallerInRole, isCallerInRole, setRollbackOnly
 

Constructor Detail

JEntityContext

public JEntityContext(JEntityFactory bf,
                      javax.ejb.EntityBean eb)
Constructs an EntityContext the Context has to be initialized after this.
Parameters:
bf - - the JEntityFactory
eb - - the Enterprise Bean instance
Method Detail

getEJBObject

public javax.ejb.EJBObject getEJBObject()
                                 throws java.lang.IllegalStateException
Obtains a reference to the EJB object that is currently associated with the instance.
Specified by:
getEJBObject in interface javax.ejb.EntityContext
Returns:
The EJB object currently associated with the instance.
Throws:
IllegalStateException: - Thrown if the instance invokes this method while the instance is in a state that does not allow the instance to invoke this method.

getEJBLocalObject

public javax.ejb.EJBLocalObject getEJBLocalObject()
                                           throws java.lang.IllegalStateException
Obtain a reference to the EJB local object that is currently associated with the instance.
Specified by:
getEJBLocalObject in interface javax.ejb.EntityContext
Returns:
The EJB local object currently associated with the instance.
Throws:
java.lang.IllegalStateException - - if the instance invokes this method while the instance is in a state that does not allow the instance to invoke this method, or if the instance does not have a local interface.

getPrimaryKey

public java.lang.Object getPrimaryKey()
                               throws java.lang.IllegalStateException
Obtains the primary key of the EJB object that is currently associated with this instance.
Specified by:
getPrimaryKey in interface javax.ejb.EntityContext
Returns:
The EJB object currently associated with the instance.
Throws:
java.lang.IllegalStateException - Thrown if the instance invokes this method while the instance is in a state that does not allow the instance to invoke this method.

beforeCompletion

public void beforeCompletion()
This beforeCompletion method is called by the transaction manager prior to the start of the transaction completion process. This method executes in the transaction context of the calling thread. The Bean's state must be stored on the persistent storage before the completion of the transaction.
Specified by:
beforeCompletion in interface javax.transaction.Synchronization

afterCompletion

public void afterCompletion(int status)
The afterCompletion method is called by the transaction manager after the transaction is committed or rolled back. This method executes without a transaction context.
Specified by:
afterCompletion in interface javax.transaction.Synchronization
Parameters:
status - The status of the transaction completion.

razEntityContext

public void razEntityContext()
Raz Context before freeing it. This is mainly for garbage collector.

initEntityContext

public void initEntityContext(JEntitySwitch bs,
                              javax.transaction.Transaction tx)
Reinit Context for reuse
Parameters:
bs - - The Bean Switch this Context belongs to.
tx - - the Transaction where this instance will be used

reuseEntityContext

public void reuseEntityContext(javax.transaction.Transaction tx)
reuse EntityContext for another transaction. optimization: don't pass it by the pool.
Parameters:
tx - - the Transaction where this instance will be used

setNewInstance

public void setNewInstance()
Set new instance flag

setRemoved

public void setRemoved()
                throws java.rmi.RemoteException,
                       javax.ejb.RemoveException
Mark this context as removed. Complete removing will be achieved at the end of the transaction.

isMarkedRemoved

public boolean isMarkedRemoved()
Check if context has been marked removed
Returns:
true when instance is marked removed.

getInstance

public javax.ejb.EntityBean getInstance()
                                 throws java.rmi.RemoteException
Returns the bean instance of this context Used in the generated classes to retrieve the instance
Returns:
the bean instance
Throws:
java.rmi.RemoteException - if no instance.

getEntityFactory

public JEntityFactory getEntityFactory()
JEntityFactory accessor
Returns:
the JEntityFactory

getEntitySwitch

public JEntitySwitch getEntitySwitch()
JEntitySwitch accessor
Returns:
the JEntitySwitch

setEntitySwitch

public void setEntitySwitch(JEntitySwitch bs)
set the EntitySwitch
Parameters:
bs - - the EntitySwitch

storeIfModified

public void storeIfModified()
Persistence: write data on storage

passivate

public void passivate()
passivate this instance

activate

public void activate(boolean doactivate)
Activate instance.
Parameters:
doactivate - True if ejbActivate() is called before ejbLoad()
Throws:
java.rmi.RemoteException - if a system problem occured.