org.objectweb.jonas_ejb.container
Class JEntityContext

java.lang.Object
  extended by org.objectweb.jonas_ejb.container.JContext
      extended by 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

Field Summary
 
Fields inherited from class org.objectweb.jonas_ejb.container.JContext
bf, myinstance, 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)
          This method is typically called after the transaction is committed.
 void beforeCompletion()
          This method is typically called at beforeCompletion
 void detachTx()
          Detach this Context from tx
 javax.ejb.EJBLocalObject get2EJBLocalObject()
          Obtain a reference to the EJB local object that is currently associated with the instance.
 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
 javax.transaction.Transaction getMyTx()
           
 java.lang.Object getPrimaryKey()
          Obtains the primary key of the EJB object that is currently associated with this instance.
 javax.ejb.TimerService getTimerService()
          Get access to the EJB Timer Service.
 boolean initEntityContext(JEntitySwitch bs)
          Reinit Context for reuse
 boolean isDirty()
           
 boolean isInitialized()
           
 boolean isMarkedRemoved()
          Check if context has been marked removed
 boolean isNewInstance()
          Check if context is a newly created instance
 boolean passivate()
          passivate this instance
 void razEntityContext()
          Raz Context before freeing it.
 void reuseEntityContext(boolean newtrans)
          reuse EntityContext for another transaction.
 void setDirty(boolean d)
          Set the dirty flag: true = instance modified.
 void setEntitySwitch(JEntitySwitch bs)
          set the EntitySwitch
 void setNewInstance()
          Set new instance flag
 void setRemoved()
          Mark this context as removed.
 boolean setRunningTx(javax.transaction.Transaction tx)
          Associate transaction to ths Context
 void storeIfModified()
          Persistence: write data on storage
 
Methods inherited from class org.objectweb.jonas_ejb.container.JContext
getCallerIdentity, getCallerPrincipal, getEJBHome, getEJBLocalHome, getEnvironment, getRollbackOnly, getState, getUserTransaction, getWorkManager, isCallerInRole, isCallerInRole, setRollbackOnly, setState
 
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

getMyTx

public javax.transaction.Transaction getMyTx()
Returns:
the transaction associated to this context.

getTimerService

public javax.ejb.TimerService getTimerService()
                                       throws java.lang.IllegalStateException
Get access to the EJB Timer Service.

Specified by:
getTimerService in interface javax.ejb.EJBContext
Specified by:
getTimerService in class JContext
Returns:
the EJB Timer Service
Throws:
java.lang.IllegalStateException - Thrown if the instance is not allowed to use this method

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

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.

get2EJBLocalObject

public javax.ejb.EJBLocalObject get2EJBLocalObject()
                                            throws java.lang.IllegalStateException
Obtain a reference to the EJB local object that is currently associated with the instance. (internal use of getEJBLocalObject with no check).

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 method is typically called at beforeCompletion

Specified by:
beforeCompletion in interface javax.transaction.Synchronization

afterCompletion

public void afterCompletion(int status)
This method is typically called after the transaction is committed.

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.


detachTx

public void detachTx()
Detach this Context from tx


initEntityContext

public boolean initEntityContext(JEntitySwitch bs)
Reinit Context for reuse

Parameters:
bs - - The Bean Switch this Context belongs to.

setRunningTx

public boolean setRunningTx(javax.transaction.Transaction tx)
Associate transaction to ths Context

Parameters:
tx -
Returns:
true if correctly associated, false if was already done.

reuseEntityContext

public void reuseEntityContext(boolean newtrans)
reuse EntityContext for another transaction. optimization: don't pass it by the pool.

Parameters:
newtrans - true if new transaction

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.

Throws:
java.rmi.RemoteException - ejbRemove failed
javax.ejb.RemoveException - ejbRemove failed

isMarkedRemoved

public boolean isMarkedRemoved()
Check if context has been marked removed

Returns:
true when instance is marked removed.

isNewInstance

public boolean isNewInstance()
Check if context is a newly created instance

Returns:
true when instance has been created in the current transaction.

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

isInitialized

public boolean isInitialized()
Returns:
True if Entity Switch has been already associated

setEntitySwitch

public void setEntitySwitch(JEntitySwitch bs)
set the EntitySwitch

Parameters:
bs - - the EntitySwitch

isDirty

public boolean isDirty()
Returns:
true if instance has been modified

setDirty

public void setDirty(boolean d)
Set the dirty flag: true = instance modified.


storeIfModified

public void storeIfModified()
Persistence: write data on storage


passivate

public boolean passivate()
passivate this instance

Returns:
true if passivated.

activate

public void activate(boolean doactivate)
Activate instance.

Parameters:
doactivate - True if ejbActivate() is called before ejbLoad()