org.objectweb.jonas_ejb.container
Class JEntityFactory

java.lang.Object
  |
  +--org.objectweb.jonas_ejb.container.JFactory
        |
        +--org.objectweb.jonas_ejb.container.JEntityFactory
All Implemented Interfaces:
BeanFactory
Direct Known Subclasses:
JormFactory

public class JEntityFactory
extends JFactory

This class is a factory for an Entity Bean. It is responsible for - managing Home and LocalHome. - managing a pool of instances/contexts - keeping the list of PKs and the associated JEntitySwitch's - keeping the JNDI context for this component (java:comp/env)

Author:
Philippe Coq, Philippe Durieux

Field Summary
protected  java.util.List bctxlist
           
protected  java.lang.Object datasource
           
protected  java.util.ArrayList entitySwitchUnused
          This field is a pool of JEntitySwitch instance unused.
protected  JEntityHome home
           
protected  int instanceCount
           
protected  JEntityLocalHome localhome
           
protected  int maxCacheSize
           
protected  int minPoolSize
           
protected  java.util.Hashtable pklist
           
protected  boolean reentrant
           
protected  boolean shared
           
 
Fields inherited from class org.objectweb.jonas_ejb.container.JFactory
beanclass, cont, dd, ejb10Env, ejbname, JNDICtx, naming, tm, txbeanmanaged
 
Constructor Summary
JEntityFactory()
          constructor must be without parameters (required by Jorm)
 
Method Summary
 void bindEJB(java.lang.Object pk, JEntitySwitch bs)
          Bind a PK with a JEntitySwitch
 int calculateAutomaticPk()
          Calculate a new uid for automatic pk creation Used by JEntityCmpJdbc.vm
 void checkTransaction(RequestCtx rctx)
          Check Transaction before calling a method on a bean.
protected  JEntityContext createNewInstance()
          Create a new instance of the bean and its EntityContext In case of CMP, the bean class is derived to manage entity persistence.
 JEntitySwitch existEJB(java.lang.Object pk)
          get EJB by its PK
 int getCacheSize()
           
 java.lang.Object getDataSource()
           
 JEntitySwitch getEJB(java.lang.Object pk)
          get EJB by its PK Creates if not exist yet.
 EntityCounters getEntityCounters()
          Take a dump of current entity counters and return them
 JHome getHome()
          returns the home if exist or null if not
 JEntityContext getJContext()
          Get a Context from the pool, or create a new one if no more available in the pool.
 JEntitySwitch getJEntitySwitch()
          This method allocates a new JEntitySwitch.
 JLocalHome getLocalHome()
          returns the local home if exist or null if not
 int getMaxCacheSize()
           
 int getMinPoolSize()
           
 int getPoolSize()
          Get the size of the instance pool for this bean
 void init(EntityDesc dd, JContainer cont)
          Init this object
 boolean isReentrant()
           
 boolean isShared()
           
 void reduceCache()
          Reduce number of instances in memory
 void releaseJContext(JContext ctx)
          Release a Context
 void removeEJB(java.lang.Object pk)
          remove an EJB by its PK
 void stop()
          stop this EJB.
 void sync()
          synchronize bean instances if needed
 
Methods inherited from class org.objectweb.jonas_ejb.container.JFactory
checkJonasVersion, checkTransactionContainer, getContainer, getCorbaInitialContext, getDeploymentDescriptor, getEjb10Environment, getEJBName, getEnv, getInitialContext, getTransactionManager, init, isClassAvailable, isTxBeanManaged, myClassLoader, postInvoke, postInvokeRemote, preInvoke, preInvokeRemote, resetComponentContext, setComponentContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

home

protected JEntityHome home

localhome

protected JEntityLocalHome localhome

reentrant

protected boolean reentrant

shared

protected boolean shared

bctxlist

protected java.util.List bctxlist

minPoolSize

protected int minPoolSize

instanceCount

protected int instanceCount

maxCacheSize

protected int maxCacheSize

pklist

protected java.util.Hashtable pklist

datasource

protected java.lang.Object datasource

entitySwitchUnused

protected java.util.ArrayList entitySwitchUnused
This field is a pool of JEntitySwitch instance unused.
Constructor Detail

JEntityFactory

public JEntityFactory()
constructor must be without parameters (required by Jorm)
Method Detail

init

public void init(EntityDesc dd,
                 JContainer cont)
Init this object
Parameters:
dd - the deployment descriptor
cont - the Container

getEJB

public JEntitySwitch getEJB(java.lang.Object pk)
get EJB by its PK Creates if not exist yet.
Parameters:
pk - The Primary Key Object
Returns:
The JEntitySwitch matching the PK.

existEJB

public JEntitySwitch existEJB(java.lang.Object pk)
get EJB by its PK
Parameters:
pk - The Primary Key Object
Returns:
The JEntitySwitch matching the PK, or null if none exist.

bindEJB

public void bindEJB(java.lang.Object pk,
                    JEntitySwitch bs)
Bind a PK with a JEntitySwitch
Parameters:
pk - The Primary Key Object
bs - The JEntitySwitch

getJEntitySwitch

public JEntitySwitch getJEntitySwitch()
This method allocates a new JEntitySwitch. But no association has been done between the primary key and the new JEntitySwitch. Therefore the initialisation is not done.
Returns:
The JEntitySwitch.

removeEJB

public void removeEJB(java.lang.Object pk)
remove an EJB by its PK
Parameters:
pk - The Primary Key Object

getPoolSize

public int getPoolSize()
Description copied from interface: BeanFactory
Get the size of the instance pool for this bean
Overrides:
getPoolSize in class JFactory
Returns:
the Instance pool size for this Ejb

stop

public void stop()
stop this EJB. Mainly unregister it in JNDI.

sync

public void sync()
synchronize bean instances if needed

reduceCache

public void reduceCache()
Reduce number of instances in memory

getHome

public JHome getHome()
Description copied from interface: BeanFactory
returns the home if exist or null if not
Returns:
the home if it exists

getLocalHome

public JLocalHome getLocalHome()
Description copied from interface: BeanFactory
returns the local home if exist or null if not
Returns:
the local home if it exists

getJContext

public JEntityContext getJContext()
Get a Context from the pool, or create a new one if no more available in the pool. This JContext must be initialized then by the caller.
Returns:
a JEntityContext, not initialized.

releaseJContext

public void releaseJContext(JContext ctx)
Release a Context
Parameters:
ctx - - The JContext to release.

getMinPoolSize

public int getMinPoolSize()
Returns:
min pool size for Jmx

getMaxCacheSize

public int getMaxCacheSize()
Returns:
max cache size for Jmx

getCacheSize

public int getCacheSize()
Returns:
current cache size for Jmx

isReentrant

public boolean isReentrant()
Returns:
true if reentrant

isShared

public boolean isShared()
Returns:
true if shared

getDataSource

public java.lang.Object getDataSource()
Returns:
the Datasource used for CMP

checkTransaction

public void checkTransaction(RequestCtx rctx)
                      throws javax.transaction.SystemException
Check Transaction before calling a method on a bean. For Entity beans, the only possible case is "Container Managed Tx"
Parameters:
rctx - The Request Context

getEntityCounters

public EntityCounters getEntityCounters()
Take a dump of current entity counters and return them
Returns:
EntityCounters

calculateAutomaticPk

public int calculateAutomaticPk()
Calculate a new uid for automatic pk creation Used by JEntityCmpJdbc.vm
Returns:
int (unique pk)

createNewInstance

protected JEntityContext createNewInstance()
                                    throws java.lang.Exception
Create a new instance of the bean and its EntityContext In case of CMP, the bean class is derived to manage entity persistence.
Returns:
JEntityContext