org.openejb.alt.containers.castor_cmp11
Class CastorCMP11_EntityContainer

java.lang.Object
  |
  +--org.openejb.alt.containers.castor_cmp11.CastorCMP11_EntityContainer
All Implemented Interfaces:
org.exolab.castor.persist.spi.CallbackInterceptor, Container, org.exolab.castor.persist.spi.InstanceFactory, RpcContainer, TransactionContainer

public class CastorCMP11_EntityContainer
extends java.lang.Object
implements RpcContainer, TransactionContainer, org.exolab.castor.persist.spi.CallbackInterceptor, org.exolab.castor.persist.spi.InstanceFactory

Container-Managed Persistence EntityBean container

Version:
$Revision: 1.6 $ $Date: 2002/05/07 17:28:37 $

Inner Class Summary
 class CastorCMP11_EntityContainer.Key
           
 class CastorCMP11_EntityContainer.SynchronizationWrapper
           
 
Field Summary
(package private)  java.lang.Object containerID
           
(package private)  java.util.HashMap deploymentRegistry
           
protected static java.lang.reflect.Method EJB_REMOVE_METHOD
           
protected  java.lang.String Global_TX_Database
          The name of the database.xml file that is used for global or container managed transactions.
protected  java.io.PrintWriter globalTransactionLogWriter
           
protected  org.exolab.castor.jdo.JDO jdo_ForGlobalTransaction
          This is a handle into a specific Castor JDO instance for a specific database mapping that has been configured to work with the transaciton manager.
protected  org.exolab.castor.jdo.JDO jdo_ForLocalTransaction
          This is a handle into a specific Castor JDO instance for a specific database mapping that has been configured to manage its own transactions.
protected  java.lang.String Local_TX_Database
          The name of the database.xml file that is used for local or unspecified transaction contexts.
protected  java.io.PrintWriter localTransactionLogWriter
           
 org.apache.log4j.Category logger
           
protected  java.util.HashMap methodReadyPoolMap
           
protected static java.lang.Object[] noArgs
           
protected  java.util.Hashtable pooledInstancesMap
           
protected  int poolsize
           
protected  java.util.Hashtable readyInstancesMap
           
protected  java.util.HashMap resetMap
           
protected static java.lang.reflect.Method SET_ENTITY_CONTEXT_METHOD
           
(package private)  java.util.Hashtable syncWrappers
           
protected  java.util.Hashtable txReadyPoolMap
           
protected static java.lang.reflect.Method UNSET_ENTITY_CONTEXT_METHOD
           
 
Fields inherited from interface org.openejb.Container
ENTITY, MESSAGE_DRIVEN, STATEFUL, STATELESS
 
Constructor Summary
CastorCMP11_EntityContainer()
           
 
Method Summary
(package private) static void ()
           
protected  java.lang.Object businessMethod(java.lang.reflect.Method callMethod, java.lang.reflect.Method runMethod, java.lang.Object[] args, ThreadContext callContext)
          Processes a business method invokation
 void created(java.lang.Object object)
          Called to indicate that an object has been created.
protected  ProxyInfo createEJBObject(java.lang.reflect.Method callMethod, java.lang.Object[] args, ThreadContext callContext)
          This method is responsible for delegating the ejbCreate() and ejbPostCreate() methods on the an entity bean.
 void creating(java.lang.Object object, org.exolab.castor.jdo.Database db)
          Called to indicate that an object is to be created in persistent storage.
 void deploy(java.lang.Object deploymentID, DeploymentInfo info)
          Adds a bean to this container.
 DeploymentInfo[] deployments()
          Gets the DeploymentInfo objects for all the beans deployed in this container.
 void discardInstance(javax.ejb.EnterpriseBean bean, ThreadContext threadContext)
          Discards this instance so that it may be garbage collected
protected  javax.ejb.EntityBean fetchAndLoadBean(ThreadContext callContext, org.exolab.castor.jdo.Database db)
          This method is responsible for loading the bean from the database based on the primary key identity contained in the callContext parameter.
 javax.ejb.EntityBean fetchFreeInstance(ThreadContext callContext)
          Obtains a bean instance from the method ready pool.
protected  java.lang.Object findEJBObject(java.lang.reflect.Method callMethod, java.lang.Object[] args, ThreadContext callContext)
          This method is used to execute the find methods which are considered global in scope.
 java.lang.Object getContainerID()
          Gets the id of this container.
 int getContainerType()
          Gets the type of container (STATELESS, STATEFUL, ENTITY, or MESSAGE_DRIVEN
protected  org.exolab.castor.jdo.Database getDatabase(ThreadContext callContext)
          If their is no transaction the CastorTransactionScopeManager.begin() method would have set the unspecified value of the ThreadContext to a non-transaction managed database object.
 DeploymentInfo getDeploymentInfo(java.lang.Object deploymentID)
          Gets the DeploymentInfo object for the bean with the specified deployment id.
 void init(java.lang.Object id, java.util.HashMap registry, java.util.Properties properties)
          Construct this container with the specified container id, deployments, container manager and properties.
 java.lang.Object invoke(java.lang.Object deployID, java.lang.reflect.Method callMethod, java.lang.Object[] args, java.lang.Object primKey, java.lang.Object securityIdentity)
          Invokes a method on an instance of the specified bean deployment.
 java.lang.Class loaded(java.lang.Object object, short accessMode)
          Called to indicate that the object has been loaded from persistent storage.
 java.lang.Object newInstance(java.lang.String className, java.lang.ClassLoader loader)
          Called to indicate that an object needs to be instatiated.
 void releasing(java.lang.Object object, boolean committed)
          Called to indicate that an object has been made transient.
 void removed(java.lang.Object object)
          Called to indicate that an object has been deleted.
protected  void removeEJBObject(java.lang.reflect.Method callMethod, java.lang.Object[] args, ThreadContext callContext)
          Removes the EJBObject
 void removing(java.lang.Object object)
          Called to indicate that an object is to be deleted.
protected  void resetBeanFields(java.lang.Object bean, DeploymentInfo info)
          Section 9.2.4 EJB 1.1: "The Container must ensure that the values of the container-managed fields are set to the Java language defaults (e.g.
 void storing(java.lang.Object object, boolean modified)
          Called to indicate that an object is to be stored in persistent storage.
 void updated(java.lang.Object object)
          Called to indicate that an object has been updated at the end of a "long" transaction.
 void using(java.lang.Object object, org.exolab.castor.jdo.Database db)
          Called to indicate that an object has been made persistent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txReadyPoolMap

protected java.util.Hashtable txReadyPoolMap

pooledInstancesMap

protected java.util.Hashtable pooledInstancesMap

readyInstancesMap

protected java.util.Hashtable readyInstancesMap

methodReadyPoolMap

protected java.util.HashMap methodReadyPoolMap

poolsize

protected int poolsize

SET_ENTITY_CONTEXT_METHOD

protected static java.lang.reflect.Method SET_ENTITY_CONTEXT_METHOD

UNSET_ENTITY_CONTEXT_METHOD

protected static java.lang.reflect.Method UNSET_ENTITY_CONTEXT_METHOD

EJB_REMOVE_METHOD

protected static java.lang.reflect.Method EJB_REMOVE_METHOD

logger

public org.apache.log4j.Category logger

deploymentRegistry

java.util.HashMap deploymentRegistry

containerID

java.lang.Object containerID

Global_TX_Database

protected java.lang.String Global_TX_Database
The name of the database.xml file that is used for global or container managed transactions. This will be used when the TransactionManager is managing the transaction, such as when the tx attribute is Supports (client has tx), RequiresNew, Required or Manditory. specifies the configuration for obtaining a database connections and the mapping.xml schema which describes how beans map to the database.

Local_TX_Database

protected java.lang.String Local_TX_Database
The name of the database.xml file that is used for local or unspecified transaction contexts. This will be used when the TransactionManager is not managing the transaction, such as when the tx attribute is Supports (no client tx), NotSupported, or Never. specifies the configuration for obtaining a database connections and the mapping.xml schema which describes how beans map to the database.

jdo_ForGlobalTransaction

protected org.exolab.castor.jdo.JDO jdo_ForGlobalTransaction
This is a handle into a specific Castor JDO instance for a specific database mapping that has been configured to work with the transaciton manager.

jdo_ForLocalTransaction

protected org.exolab.castor.jdo.JDO jdo_ForLocalTransaction
This is a handle into a specific Castor JDO instance for a specific database mapping that has been configured to manage its own transactions.

syncWrappers

java.util.Hashtable syncWrappers

globalTransactionLogWriter

protected java.io.PrintWriter globalTransactionLogWriter

localTransactionLogWriter

protected java.io.PrintWriter localTransactionLogWriter

resetMap

protected java.util.HashMap resetMap

noArgs

protected static final java.lang.Object[] noArgs
Constructor Detail

CastorCMP11_EntityContainer

public CastorCMP11_EntityContainer()
Method Detail

static void ()

init

public void init(java.lang.Object id,
                 java.util.HashMap registry,
                 java.util.Properties properties)
          throws OpenEJBException
Construct this container with the specified container id, deployments, container manager and properties. The properties can include the class name of the preferred InstanceManager, org.openejb.core.entity.EntityInstanceManager is the default. The properties should also include the properties for the instance manager.
Specified by:
init in interface Container
Parameters:
id - the unique id to identify this container in the ContainerSystem
registry - a hashMap of bean delpoyments that this container will be responsible for
properties - the properties this container needs to initialize and run
Throws:
OpenEJBException - if there is a problem constructing the container
OpenEJBException -  
See Also:
Container

deployments

public DeploymentInfo[] deployments()
Gets the DeploymentInfo objects for all the beans deployed in this container.
Specified by:
deployments in interface Container
Returns:
an array of DeploymentInfo objects
See Also:
DeploymentInfo, ContainerSystem.deployments()

getDeploymentInfo

public DeploymentInfo getDeploymentInfo(java.lang.Object deploymentID)
Gets the DeploymentInfo object for the bean with the specified deployment id.
Specified by:
getDeploymentInfo in interface Container
Parameters:
deploymentID -  
Returns:
the DeploymentInfo object associated with the bean.
See Also:
DeploymentInfo, ContainerSystem.getDeploymentInfo, DeploymentInfo.getDeploymentID()

getContainerType

public int getContainerType()
Gets the type of container (STATELESS, STATEFUL, ENTITY, or MESSAGE_DRIVEN
Specified by:
getContainerType in interface Container
Returns:
id type bean container

getContainerID

public java.lang.Object getContainerID()
Gets the id of this container.
Specified by:
getContainerID in interface Container
Returns:
the id of this container.
See Also:
DeploymentInfo.getContainerID()

deploy

public void deploy(java.lang.Object deploymentID,
                   DeploymentInfo info)
            throws OpenEJBException
Adds a bean to this container.
Specified by:
deploy in interface Container
Parameters:
deploymentId - the deployment id of the bean to deploy.
info - the DeploymentInfo object associated with the bean.
Throws:
OpenEJBException - Occurs when the container is not able to deploy the bean for some reason.

invoke

public java.lang.Object invoke(java.lang.Object deployID,
                               java.lang.reflect.Method callMethod,
                               java.lang.Object[] args,
                               java.lang.Object primKey,
                               java.lang.Object securityIdentity)
                        throws OpenEJBException
Invokes a method on an instance of the specified bean deployment.
Specified by:
invoke in interface RpcContainer
Parameters:
deployID - the dployment id of the bean deployment
callMethod - the method to be called on the bean instance
args - the arguments to use when invoking the specified method
primKey - the primary key class of the bean or null if the bean does not need a primary key
prncpl -  
Returns:
the result of invoking the specified method on the bean instance
Throws:
OpenEJBException -  
See Also:
Container.invoke, StatefulContainer.invoke

discardInstance

public void discardInstance(javax.ejb.EnterpriseBean bean,
                            ThreadContext threadContext)
Discards this instance so that it may be garbage collected
Specified by:
discardInstance in interface TransactionContainer
Parameters:
bean -  
threadContext -  

fetchFreeInstance

public javax.ejb.EntityBean fetchFreeInstance(ThreadContext callContext)
                                       throws java.lang.IllegalAccessException,
                                              java.lang.reflect.InvocationTargetException,
                                              java.lang.InstantiationException
Obtains a bean instance from the method ready pool. If the pool is empty a new instance is instantiated, and the setEntityContext method is called. The bean instance is transitioned into the tx method ready pool before its returned to the caller. this ensures it can returned to the method ready pool when its released from the transaction.
Parameters:
callContext -  
Returns:
 
Throws:
java.lang.IllegalAccessException -  
java.lang.reflect.InvocationTargetException -  
java.lang.InstantiationException -  

businessMethod

protected java.lang.Object businessMethod(java.lang.reflect.Method callMethod,
                                          java.lang.reflect.Method runMethod,
                                          java.lang.Object[] args,
                                          ThreadContext callContext)
                                   throws OpenEJBException
Processes a business method invokation
Parameters:
callMethod -  
runMethod -  
args -  
callContext -  
Returns:
 
Throws:
OpenEJBException -  

createEJBObject

protected ProxyInfo createEJBObject(java.lang.reflect.Method callMethod,
                                    java.lang.Object[] args,
                                    ThreadContext callContext)
                             throws OpenEJBException
This method is responsible for delegating the ejbCreate() and ejbPostCreate() methods on the an entity bean. Transaction attributes are applied to determine the correct transaction context. Allowed operations are imposed according to the EJB 1.1 specification.
Parameters:
callMethod -  
args -  
callContext -  
Returns:
 
Throws:
OpenEJBException -  

findEJBObject

protected java.lang.Object findEJBObject(java.lang.reflect.Method callMethod,
                                         java.lang.Object[] args,
                                         ThreadContext callContext)
                                  throws OpenEJBException
This method is used to execute the find methods which are considered global in scope. Global methods use bean instances from the MethodReady pool and are not specific to on bean identity. The return value will be either a single ProxyInfo object or collection of ProxyInfo objects representing one or more remote references.
Parameters:
callMethod -  
args -  
callContext -  
Returns:
 
Throws:
OpenEJBException -  

removeEJBObject

protected void removeEJBObject(java.lang.reflect.Method callMethod,
                               java.lang.Object[] args,
                               ThreadContext callContext)
                        throws OpenEJBException
Removes the EJBObject
Parameters:
callMethod -  
args -  
callContext -  
Throws:
OpenEJBException -  

fetchAndLoadBean

protected javax.ejb.EntityBean fetchAndLoadBean(ThreadContext callContext,
                                                org.exolab.castor.jdo.Database db)
                                         throws org.exolab.castor.jdo.PersistenceException,
                                                org.exolab.castor.jdo.ObjectNotFoundException,
                                                org.exolab.castor.jdo.TransactionNotInProgressException,
                                                org.exolab.castor.jdo.LockNotGrantedException,
                                                java.lang.InstantiationException,
                                                java.lang.reflect.InvocationTargetException,
                                                java.lang.IllegalAccessException
This method is responsible for loading the bean from the database based on the primary key identity contained in the callContext parameter. If the primary key is complex (a custom class with one or more fields) the key is converted into a Castor JDO Complex identity object which is used by the Database.load() method. If the primary key is a single field key (usally a primitive wrapper (Integer, Boolean, etc.) or String) then the primary key is used by the Database.load() method directly.
Parameters:
callContext -  
db -  
Returns:
 
Throws:
org.exolab.castor.jdo.PersistenceException -  
org.exolab.castor.jdo.ObjectNotFoundException -  
org.exolab.castor.jdo.TransactionNotInProgressException -  
org.exolab.castor.jdo.LockNotGrantedException -  
java.lang.InstantiationException -  
java.lang.reflect.InvocationTargetException -  
java.lang.IllegalAccessException -  

getDatabase

protected org.exolab.castor.jdo.Database getDatabase(ThreadContext callContext)
                                              throws org.exolab.castor.jdo.DatabaseNotFoundException,
                                                     org.exolab.castor.jdo.PersistenceException,
                                                     javax.transaction.SystemException
If their is no transaction the CastorTransactionScopeManager.begin() method would have set the unspecified value of the ThreadContext to a non-transaction managed database object. Otherwise if their is a transction contrext, the unspecified value will be null. This allows us to know when an operation (createEJBObject, removeEJBObject, busienssMethod) requires transaction-managed Database object or a non-transaction managed database object.
Parameters:
callContext -  
Returns:
 
Throws:
org.exolab.castor.jdo.DatabaseNotFoundException -  
org.exolab.castor.jdo.PersistenceException -  
javax.transaction.SystemException -  

resetBeanFields

protected void resetBeanFields(java.lang.Object bean,
                               DeploymentInfo info)
Section 9.2.4 EJB 1.1: "The Container must ensure that the values of the container-managed fields are set to the Java language defaults (e.g. 0 for integer, null for pointers) prior to invoking an ejbCreate(...) method on an instance."

newInstance

public java.lang.Object newInstance(java.lang.String className,
                                    java.lang.ClassLoader loader)
Called to indicate that an object needs to be instatiated.

The parameters are ignored. Data is obtained from the deployment info which has been obtained, in turn, from the current call context.

Specified by:
newInstance in interface org.exolab.castor.persist.spi.InstanceFactory
Parameters:
The - name of the class of the object to be created
The - class loader to use when creating the object
Returns:
an instance of the object needs to be instatiated

loaded

public java.lang.Class loaded(java.lang.Object object,
                              short accessMode)
Called to indicate that the object has been loaded from persistent storage.
Specified by:
loaded in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object
Returns:
null or the extending Class. In the latter case Castor will reload the object of the given class with the same identity.
Throws:
java.lang.Exception - An exception occured, the object cannot be loaded

storing

public void storing(java.lang.Object object,
                    boolean modified)
Called to indicate that an object is to be stored in persistent storage.
Specified by:
storing in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object
modified - Is the object modified?
Throws:
java.lang.Exception - An exception occured, the object cannot be stored

creating

public void creating(java.lang.Object object,
                     org.exolab.castor.jdo.Database db)
Called to indicate that an object is to be created in persistent storage.
Specified by:
creating in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object
db - The database in which this object will be created

created

public void created(java.lang.Object object)
Called to indicate that an object has been created.
Specified by:
created in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object

removing

public void removing(java.lang.Object object)
Called to indicate that an object is to be deleted.

This method is made at commit time on objects deleted during the transaction before setting their fields to null.

Specified by:
removing in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object

removed

public void removed(java.lang.Object object)
Called to indicate that an object has been deleted.

This method is called during db.remove().

Specified by:
removed in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object

releasing

public void releasing(java.lang.Object object,
                      boolean committed)
Called to indicate that an object has been made transient.

This method is made at commit or rollback time on all objects that were presistent during the life time of the transaction.

Specified by:
releasing in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object
committed - True if the object has been commited, false if rollback or otherwise cancelled

using

public void using(java.lang.Object object,
                  org.exolab.castor.jdo.Database db)
Called to indicate that an object has been made persistent.
Specified by:
using in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object
db - The database to which this object belongs

updated

public void updated(java.lang.Object object)
Called to indicate that an object has been updated at the end of a "long" transaction.
Specified by:
updated in interface org.exolab.castor.persist.spi.CallbackInterceptor
Parameters:
object - The object