FileDocCategorySizeDatePackage
CMPHelper.javaAPI DocGlassfish v2 API14926Fri May 04 22:35:02 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.ejb

CMPHelper

public class CMPHelper extends Object
Provides helper methods for CMP support implementation with the application server specific information. Calls corresponding methods on the registered class which implements ContainerHelper interface.

Fields Summary
private static final ResourceBundle
messages
I18N message handler
private static com.sun.jdo.spi.persistence.utility.logging.Logger
logger
The logger
private static ContainerHelper
containerHelper
Reference to a class that implements ContainerHelper interface for this particular application server. In a non-managed environment the will throw JDOFatalInternalException for any method invocation.
private static long
counter
This counter is used to populate primary key columns for CMP beans with an unknown Primary Key Class. It is a single counter per vm and is initialized at the start up time.
Constructors Summary
Methods Summary
public static voidassertValidLocalObject(java.lang.Object o, java.lang.Object container)
Called in a CMP environment to verify that the specified object is of a valid local interface type. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
o the instance to validate.
param
container a Container instance for the request.

        getContainerHelper().assertValidLocalObject(o, container);
    
public static voidassertValidRemoteObject(java.lang.Object o, java.lang.Object container)
Called in a CMP environment to verify that the specified object is of a valid remote interface type. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
o the instance to validate.
param
container a Container instance for the request.

        getContainerHelper().assertValidRemoteObject(o, container);
    
public static voidbeginInternalTransaction(com.sun.jdo.api.persistence.support.PersistenceManager pm)
Called in a unspecified transaction context of a managed environment. According to p.364 of EJB 2.0 spec, CMP may need to manage its own transaction when its transaction attribute is NotSupported, Never, Supports.

param
pm PersistenceManager

        getContainerHelper().beginInternalTransaction(pm);
    
public static voidcommitInternalTransaction(com.sun.jdo.api.persistence.support.PersistenceManager pm)
Called in a unspecified transaction context of a managed environment. According to p.364 of EJB 2.0 spec, CMP may need to manage its own transaction when its transaction attribute is NotSupported, Never, Supports.

param
pm PersistenceManager

        getContainerHelper().commitInternalTransaction(pm);
    
public static voidflush(com.sun.jdo.api.persistence.support.PersistenceManager pm)
Flush transactional changes to the database.

param
pm PersistenceManager

        Transaction tx = pm.currentTransaction();
        // flush updates to the database if transaction is active.
        if (tx != null && tx.isActive()) {
            PersistenceManagerWrapper pmw = (PersistenceManagerWrapper)pm;
            PersistenceManagerImpl pmi = 
                    (PersistenceManagerImpl)pmw.getPersistenceManager();
            pmi.internalFlush();
        }
    
public static java.lang.ObjectgetContainer(java.lang.Object info)
Called in a CMP supported environment to get a Container instance that will be passed unchanged to the required methods. In a non-managed environment throws JDOFatalInternalException. The info argument can be an array of Objects if necessary.

see
getEJBObject(Object, Object)
see
getEJBLocalObject(Object, Object)
see
getEJBLocalObject(Object, Object, EJBContext)
see
removeByEJBLocalObject(EJBLocalObject, Object)
see
removeByPK(Object, Object)
param
info Object with the request information that is application server specific.
return
a Container instance as an Object.
throws
JDOFatalInternalException if ContainerHelper instance is not registered.

        return getContainerHelper().getContainer(info); 
    
private static ContainerHelpergetContainerHelper()
Returns a ContainerHelper instance that can be used to invoke the corresponding method.

return
a ContainerHelper instance registered with this class.
throws
JDOFatalInternalException if the instance is null.

        if (containerHelper == null) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(
                    messages, "ejb.cmphelper.nonmanaged")); //NOI18N
        }

        return containerHelper;
    
public static javax.ejb.EJBLocalObjectgetEJBLocalObject(java.lang.Object pk, java.lang.Object container)
Called in a managed environment to get an EJBLocalObject reference for this primary key instance and Container object. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
pk the primary key instance.
param
container a Container instance for the request.
return
a corresponding EJBLocalObject (as an Object) to be used by the client.

        return getContainerHelper().getEJBLocalObject(pk, container); 
    
public static javax.ejb.EJBLocalObjectgetEJBLocalObject(java.lang.Object pk, java.lang.Object container, javax.ejb.EJBContext context)
Called in a managed environment to get an EJBLocalObject reference for this primary key instance, Container object, and EJBContext of the calling bean. Allows the container to check if this method is called during ejbRemove that is part of a cascade-delete remove. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
pk the primary key instance.
param
container a Container instance for the request.
param
context an EJBContext of the calling bean.
return
a corresponding EJBLocalObject (as an Object) to be used by the client.

        return getContainerHelper().getEJBLocalObject(pk, container, context); 
    
public static javax.ejb.EJBObjectgetEJBObject(java.lang.Object pk, java.lang.Object container)
Called in a CMP supported environment to get an EJBObject reference for this primary key instance and Container object. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
pk the primary key instance.
param
container a Container instance for the request.
return
a corresponding EJBObject (as an Object) to be used by the client.

        return getContainerHelper().getEJBObject(pk, container);
    
public static synchronized longgetNextId()
Increments the counter and returns the value. Used to populate primary key columns for EJB with an unknown Primary Key Class.

return
the next value for the counter.

        counter++;
        return counter;
    
public static intgetNumericConverterPolicy(java.lang.Object container)
Called in CMP environment to get NumericConverter policy referenced by this Container instance.

see
getContainer(Object)
param
container a Container instance for the request
return
a valid NumericConverter policy type

        return getContainerHelper().getNumericConverterPolicy(container);
    
public static com.sun.jdo.api.persistence.support.PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.Object container)
Called in a CMP environment to lookup PersistenceManagerFactory referenced by this Container instance as the CMP resource. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
container a Container instance for the request.

        return getContainerHelper().getPersistenceManagerFactory(container);
    
public static voidpreSelect(java.lang.Object container)
Called in a CMP supported environment. Notifies the container that ejbSelect had been called. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
container a Container instance for the request.

        getContainerHelper().preSelect(container);
    
public static voidregisterContainerHelper(ContainerHelper h)
Register class that implements ContainerHelper interface Should be called by a static method at class initialization time.

param
h application server specific implemetation of the ContainerHelper interface.


                      	 	       			    
          
        containerHelper = h;
    
public static voidremoveByEJBLocalObject(javax.ejb.EJBLocalObject ejb, java.lang.Object container)
Called in a managed environment to remove a bean for a given EJBLocalObject, and Container instance. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
ejb the EJBLocalObject for the bean to be removed.
param
container a Container instance for the request.

        getContainerHelper().removeByEJBLocalObject(ejb, container);  
    
public static voidremoveByPK(java.lang.Object pk, java.lang.Object container)
Called in a managed environment to remove a bean for a given primary key and Container instance. The Container instance is acquired via #getContainer(Object).

see
getContainer(Object)
param
pk the primary key for the bean to be removed.
param
container a Container instance for the request.

        getContainerHelper().removeByPK(pk, container);  
    
public static voidresumeCurrentTransaction(javax.transaction.Transaction tx)
Called from read-only beans to resume current transaction. This will guarantee that the transaction continues to run after read-only bean accessed its PersistenceManager.

param
tx - The javax.transaction.Transaction object that represents the transaction to be resumed.


        getContainerHelper().resumeCurrentTransaction(tx);
    
public static voidrollbackInternalTransaction(com.sun.jdo.api.persistence.support.PersistenceManager pm)
Called in a unspecified transaction context of a managed environment. According to p.364 of EJB 2.0 spec, CMP may need to manage its own transaction when its transaction attribute is NotSupported, Never, Supports.

param
pm PersistenceManager

        getContainerHelper().rollbackInternalTransaction(pm);
    
public static voidsetCascadeDeleteAfterSuperEJBRemove(javax.ejb.EntityContext context)
Called in a managed environment to mark EntityContext of the bean as already removed during cascade-delete operation. Called by the generated ejbRemove method before calling ejbRemove of the related beans (via removeByEJBLocalObject) that are to be cascade-deleted. The Container instance is acquired via #getContainer(Object).

param
context the EntityContext of the bean beeing removed.

        getContainerHelper().setCascadeDeleteAfterSuperEJBRemove(context);  
    
public static javax.transaction.TransactionsuspendCurrentTransaction()
Called from read-only beans to suspend current transaction. This will guarantee that PersistenceManager is not bound to any transaction.

return
javax.transaction.Transaction object representing the suspended transaction. Returns null if the calling thread is not associated with a transaction.

        return getContainerHelper().suspendCurrentTransaction();