org.objectweb.jonas_ejb.container
Class JEntitySwitch

java.lang.Object
  |
  +--org.objectweb.jonas_ejb.container.JEntitySwitch

public class JEntitySwitch
extends java.lang.Object

JEntitySwitch is used internally to synchronize accesses to the entity context and thus to the entity bean instance. All parts common to EJBObject and EJBLocalObject should be here. Different policies can be applied to manage context/instance pairs: - only 1 pair (container manages the transaction isolation) - 1 pair for each transaction (transaction isolation managed by DataBase) - 2 pairs (1 for transactional accesses, 1 for non transaction accesses) In the current version, we implement only the first. Others will be implemented later.

Author:
Philippe Durieux, Philippe Coq

Field Summary
protected  JEntityFactory bf
           
protected  javax.transaction.Transaction currtx
           
protected  JEntityContext Icontext
           
protected  java.lang.String ident
           
protected  int IHcount
           
protected  JEntityLocal local
           
protected  java.lang.Object pk
           
protected  boolean reentrant
           
protected  JEntityRemote remote
           
protected  boolean shared
           
 
Constructor Summary
JEntitySwitch()
          empty constructor.
 
Method Summary
 void bindICtx(javax.transaction.Transaction tx, JEntityContext bctx)
          bind a JEntityContext for a create method.
 void discardICtx(javax.transaction.Transaction tx)
          Discard a context/instance at end of request.
 JEntityContext getICtx(javax.transaction.Transaction tx)
          Get a context/instance associated with this transaction Called at each request on the bean (including remove)
 JEntityContext getICtx(javax.transaction.Transaction tx, JEntityContext newctx)
          bind a JEntityContext for a remove method. called in case of remove(pk) or remove(handle)
 JEntityLocal getLocal()
           
 java.lang.Object getPrimaryKey()
           
 JEntityRemote getRemote()
           
 int getState()
           
 void init(JEntityFactory bf, java.lang.Object pk)
          constructor.
 JEntityContext mapICtx(javax.transaction.Transaction tx, JEntityContext bctx, boolean forced, boolean holdit)
          Map a context and its instance.
 boolean passivateIH(boolean passivation)
          try to passivate IH (called from swapper)
 void releaseICtx(javax.transaction.Transaction tx)
          Release a context/instance at end of request.
 void tryBindICtx(javax.transaction.Transaction tx, JEntityContext bctx)
          Try to bind a JEntityContext if none already bound.
 void txCompleted(javax.transaction.Transaction tx, boolean committed)
          This transaction is now over.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bf

protected JEntityFactory bf

pk

protected java.lang.Object pk

local

protected JEntityLocal local

remote

protected JEntityRemote remote

shared

protected boolean shared

reentrant

protected boolean reentrant

IHcount

protected int IHcount

Icontext

protected JEntityContext Icontext

ident

protected java.lang.String ident

currtx

protected javax.transaction.Transaction currtx
Constructor Detail

JEntitySwitch

public JEntitySwitch()
empty constructor. Object is initialized via init() because it is implemented differently according to jorm mappers.
Method Detail

init

public void init(JEntityFactory bf,
                 java.lang.Object pk)
constructor. A new object is build when a new PK is known in the container, either when a new bean is created, or when a find occurs. For create(), PK is not known yet when this object is build.
Parameters:
bf - The Entity Factory
pk - The Primary Key

getLocal

public JEntityLocal getLocal()
Returns:
the underlaying EJBLocalObject

getRemote

public JEntityRemote getRemote()
Returns:
the underlaying EJBObject

getPrimaryKey

public java.lang.Object getPrimaryKey()
Returns:
the Primary Key Object for this instance.

bindICtx

public void bindICtx(javax.transaction.Transaction tx,
                     JEntityContext bctx)
bind a JEntityContext for a create method. No need to synchronize since object was unknown before. Do not activate the bean instance since ejbCreate has been done.
Parameters:
tx - - the Transaction object
bctx - - the JEntityContext to bind

tryBindICtx

public void tryBindICtx(javax.transaction.Transaction tx,
                        JEntityContext bctx)
Try to bind a JEntityContext if none already bound. Called by finder methods
Parameters:
tx - - the Transaction object
bctx - The Entity Context

getICtx

public JEntityContext getICtx(javax.transaction.Transaction tx,
                              JEntityContext newctx)
bind a JEntityContext for a remove method. called in case of remove(pk) or remove(handle)
Parameters:
tx - - the Transaction object
newctx - - the JEntityContext to bind
Returns:
the BeanContext

getICtx

public JEntityContext getICtx(javax.transaction.Transaction tx)
Get a context/instance associated with this transaction Called at each request on the bean (including remove)
Parameters:
tx - - the Transaction object
Returns:
the BeanContext

mapICtx

public JEntityContext mapICtx(javax.transaction.Transaction tx,
                              JEntityContext bctx,
                              boolean forced,
                              boolean holdit)
Map a context and its instance. This version manages only 1 context (Icontext).
Parameters:
tx - - the Transaction object
bctx - - the JEntityContext to bind if not null
forced - - force to take this context. (case of create)
holdit - - increment count to hold it, a release will be called later.
Returns:
JEntityContext actually mapped

releaseICtx

public void releaseICtx(javax.transaction.Transaction tx)
Release a context/instance at end of request.
Parameters:
tx - - transaction associated to this context

discardICtx

public void discardICtx(javax.transaction.Transaction tx)
Discard a context/instance at end of request. A problem occured on this insance and it must be discarded.
Parameters:
tx - - transaction associated to this context

txCompleted

public void txCompleted(javax.transaction.Transaction tx,
                        boolean committed)
This transaction is now over. We can dispose of the instance for another transaction or discard it.
Parameters:
tx - the transaction object
committed - true if transaction was committed.

passivateIH

public boolean passivateIH(boolean passivation)
try to passivate IH (called from swapper)
Parameters:
passivation - false if only store bean state.
Returns:
true if OK, false if busy.

getState

public int getState()
Returns:
ejb instance's state state values are 0=in-tx, 1=out-tx, 2=idle, 3=passive, 4=removed. we don't synchronize this method to avoid jadmin blocks