org.openejb.alt.containers.castor_cmp11
Class CastorCMP11_EntityContainer

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

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 based on Castor

Version:
$Revision: 2167 $ $Date: 2005-09-19 15:15:13 -0700 (Mon, 19 Sep 2005) $
Author:
Richard Monson-Haefel, David Blevins

Nested Class Summary
static class CastorCMP11_EntityContainer.Key
           
 class CastorCMP11_EntityContainer.SynchronizationWrapper
           
 
Field Summary
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  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.
 Logger 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
           
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
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 loaded, org.exolab.castor.mapping.AccessMode mode)
           
 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.
protected  void postInit()
          I keep forgetting why I put this block outside the init method.
 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 Logger logger

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.


resetMap

protected java.util.HashMap resetMap

noArgs

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

CastorCMP11_EntityContainer

public CastorCMP11_EntityContainer()
Method Detail

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

postInit

protected void postInit()
I keep forgetting why I put this block outside the init method. Caused by: java.lang.NullPointerException at org.openejb.OpenEJB.getJNDIContext(OpenEJB.java:415) at org.openejb.core.ivm.naming.java.javaURLContextFactory.getContext(javaURLContextFactory.java:111) at org.openejb.core.ivm.naming.java.javaURLContextFactory.getObjectInstance(javaURLContextFactory.java:87) at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:579) That's the reason. A dependency problem. Castor JDO depends on looking up the datasource from JNDI, which has not been fully constructed till after the containers are constructed.


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, Container.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, Container.getDeploymentInfo(Object), 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:
Container.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
securityIdentity -
Returns:
the result of invoking the specified method on the bean instance
Throws:
OpenEJBException
See Also:
RpcContainer.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], java.lang.Object, java.lang.Object), 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:
EntityBean
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:
Object
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:
ProxyInfo
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:
Object
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:
EntityBean
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:
Database
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:
className - The name of the class of the object to be created
loader - 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.

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.

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?

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

loaded

public java.lang.Class loaded(java.lang.Object loaded,
                              org.exolab.castor.mapping.AccessMode mode)
                       throws java.lang.Exception
Specified by:
loaded in interface org.exolab.castor.persist.spi.CallbackInterceptor
Throws:
java.lang.Exception


Copyright © 1999-2011 OpenEJB. All Rights Reserved.