Class 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.
    • Constructor Detail

      • CMPHelper

        public CMPHelper()
    • Method Detail

      • registerContainerHelper

        public static void registerContainerHelper​(ContainerHelper h)
        Register class that implements ContainerHelper interface Should be called by a static method at class initialization time.
        Parameters:
        h - application server specific implemetation of the ContainerHelper interface.
      • getNextId

        public static long getNextId()
        Increments the counter and returns the value. Used to populate primary key columns for EJB with an unknown Primary Key Class.
        Returns:
        the next value for the counter.
      • getEJBObject

        public static jakarta.ejb.EJBObject getEJBObject​(Object pk,
                                                         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).
        Parameters:
        pk - the primary key instance.
        container - a Container instance for the request.
        Returns:
        a corresponding EJBObject (as an Object) to be used by the client.
        See Also:
        getContainer(java.lang.Object)
      • getEJBLocalObject

        public static jakarta.ejb.EJBLocalObject getEJBLocalObject​(Object pk,
                                                                   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).
        Parameters:
        pk - the primary key instance.
        container - a Container instance for the request.
        Returns:
        a corresponding EJBLocalObject (as an Object) to be used by the client.
        See Also:
        getContainer(java.lang.Object)
      • getEJBLocalObject

        public static jakarta.ejb.EJBLocalObject getEJBLocalObject​(Object pk,
                                                                   Object container,
                                                                   jakarta.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).
        Parameters:
        pk - the primary key instance.
        container - a Container instance for the request.
        context - an EJBContext of the calling bean.
        Returns:
        a corresponding EJBLocalObject (as an Object) to be used by the client.
        See Also:
        getContainer(java.lang.Object)
      • removeByEJBLocalObject

        public static void removeByEJBLocalObject​(jakarta.ejb.EJBLocalObject ejb,
                                                  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).
        Parameters:
        ejb - the EJBLocalObject for the bean to be removed.
        container - a Container instance for the request.
        See Also:
        getContainer(java.lang.Object)
      • removeByPK

        public static void removeByPK​(Object pk,
                                      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).
        Parameters:
        pk - the primary key for the bean to be removed.
        container - a Container instance for the request.
        See Also:
        getContainer(java.lang.Object)
      • setCascadeDeleteAfterSuperEJBRemove

        public static void setCascadeDeleteAfterSuperEJBRemove​(jakarta.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).
        Parameters:
        context - the EntityContext of the bean beeing removed.
      • getPersistenceManagerFactory

        public static PersistenceManagerFactory getPersistenceManagerFactory​(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).
        Parameters:
        container - a Container instance for the request.
        See Also:
        getContainer(java.lang.Object)
      • assertValidLocalObject

        public static void assertValidLocalObject​(Object o,
                                                  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).
        Parameters:
        o - the instance to validate.
        container - a Container instance for the request.
        See Also:
        getContainer(java.lang.Object)
      • assertValidRemoteObject

        public static void assertValidRemoteObject​(Object o,
                                                   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).
        Parameters:
        o - the instance to validate.
        container - a Container instance for the request.
        See Also:
        getContainer(java.lang.Object)
      • preSelect

        public static void preSelect​(Object container)
        Called in a CMP supported environment. Notifies the container that ejbSelect had been called. The Container instance is acquired via #getContainer(Object).
        Parameters:
        container - a Container instance for the request.
        See Also:
        getContainer(java.lang.Object)
      • getNumericConverterPolicy

        public static int getNumericConverterPolicy​(Object container)
        Called in CMP environment to get NumericConverter policy referenced by this Container instance.
        Parameters:
        container - a Container instance for the request
        Returns:
        a valid NumericConverter policy type
        See Also:
        getContainer(java.lang.Object)
      • beginInternalTransaction

        public static void beginInternalTransaction​(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.
        Parameters:
        pm - PersistenceManager
      • commitInternalTransaction

        public static void commitInternalTransaction​(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.
        Parameters:
        pm - PersistenceManager
      • rollbackInternalTransaction

        public static void rollbackInternalTransaction​(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.
        Parameters:
        pm - PersistenceManager
      • suspendCurrentTransaction

        public static jakarta.transaction.Transaction suspendCurrentTransaction()
        Called from read-only beans to suspend current transaction. This will guarantee that PersistenceManager is not bound to any transaction.
        Returns:
        jakarta.transaction.Transaction object representing the suspended transaction. Returns null if the calling thread is not associated with a transaction.
      • resumeCurrentTransaction

        public static void resumeCurrentTransaction​(jakarta.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.
        Parameters:
        tx - - The jakarta.transaction.Transaction object that represents the transaction to be resumed.
      • flush

        public static void flush​(PersistenceManager pm)
        Flush transactional changes to the database.
        Parameters:
        pm - PersistenceManager
      • isContainerReady

        public static boolean isContainerReady()
        Returns:
        true if the container had been registered correctly.