Class CMPBeanHelper


  • public class CMPBeanHelper
    extends Object
    Provides static helper methods for CMP bean implementation to simplify the generated code.
    • Constructor Detail

      • CMPBeanHelper

        public CMPBeanHelper()
    • Method Detail

      • logJDOExceptionWithLifecycleLogger

        public static void logJDOExceptionWithLifecycleLogger​(String key,
                                                              String beanName,
                                                              JDOException ex)
        Called from a CMP bean to log JDOException message with the LifecycleLogger.
        Parameters:
        key - the key for the corresponding Bundle.
        beanName - the name of the calling bean.
        ex - the JDOException.
      • logJDOExceptionWithLifecycleLogger

        public static void logJDOExceptionWithLifecycleLogger​(String key,
                                                              String beanName,
                                                              String paramList,
                                                              JDOException ex)
        Called from a CMP bean to log JDOException message with the LifecycleLogger.
        Parameters:
        key - the key for the corresponding Bundle.
        beanName - the name of the calling bean.
        paramList - the list of the concatenated parameters.
        ex - the JDOException.
      • logJDOExceptionWithInternalLogger

        public static void logJDOExceptionWithInternalLogger​(String beanName,
                                                             JDOException ex)
        Called from a CMP bean to log JDOException message thrown from a any getter or setter method, with the InternalLogger.
        Parameters:
        beanName - the name of the calling bean.
        ex - the JDOException.
      • logJDOExceptionWithFinderLogger

        public static void logJDOExceptionWithFinderLogger​(String beanName,
                                                           Object[] params,
                                                           JDOException ex)
        Called from a CMP bean to log JDOException message thrown from a any finder or selector method, with the FinderLogger.
        Parameters:
        beanName - the name of the calling bean.
        params - the Object[] of the parameter values for the finder or selector method.
        ex - the JDOException.
      • logFinderException

        public static void logFinderException​(int level,
                                              String beanName,
                                              Exception ex)
        Called from a CMP bean to log JDOException message thrown from a any finder or selector method, with the FinderLogger.
        Parameters:
        level - the logging level as int.
        beanName - the name of the calling bean.
        ex - the Exception.
      • logJDOExceptionFromPKSetter

        public static String logJDOExceptionFromPKSetter​(String beanName,
                                                         JDOException ex)
        Called from a CMP bean to log JDOException message thrown from a PK setter method, with the InternalLogger. Returns generated message to the caller to be used for a IllegalStateException.
        Parameters:
        beanName - the name of the calling bean.
        ex - the JDOException.
        Returns:
        logged message as String.
      • assertPersistent

        public static void assertPersistent​(PersistenceCapable pc,
                                            String beanName)
        Called from a CMP bean to verify that the PersistenceCapable instance is already persistent. Throws IllegalStateException otherwise.
        Parameters:
        pc - the PersistenceCapable instance to be checked.
        beanName - the name of the caller bean.
        Throws:
        IllegalStateException - if the instance is not persistent.
      • assertCollectionNotNull

        public static void assertCollectionNotNull​(Collection c,
                                                   String beanName)
        Called from a CMP bean to verify that the argument for a Collection set method is not null. Throws IllegalArgumentException if the argument is null.
        Parameters:
        c - the Collection to check.
        beanName - the name of the caller bean.
        Throws:
        IllegalArgumentException - if the argument is null.
      • assertPersistenceManagerNotNull

        public static void assertPersistenceManagerNotNull​(PersistenceManager pm,
                                                           Object bean)
        Called from a CMP bean to verify that the PersistenceManager is not null. Throws IllegalStateException if the argument is null.
        Parameters:
        pm - the PersistenceManager to check.
        bean - the calling bean instance.
        Throws:
        IllegalStateException - if the PersistenceManager is null.
      • assertPersistenceManagerIsNull

        public static void assertPersistenceManagerIsNull​(PersistenceManager pm,
                                                          Object bean,
                                                          StringBuilder buf)
        Called from a CMP bean to verify that the PersistenceManager is null. Throws IllegalStateException if the argument is not null.
        Parameters:
        pm - the PersistenceManager to check.
        bean - the calling bean instance.
        Throws:
        IllegalStateException - if the PersistenceManager is not null.
      • assertNotContainerTransaction

        public static void assertNotContainerTransaction​(Object bean)
        Called from a 1.1 CMP bean to verify that the bean method is not called in a container transaction. Throws IllegalStateException otherwise.
        Parameters:
        bean - the calling bean instance.
        Throws:
        IllegalStateException - if the bean method is called in a container transaction.
      • handleJDODuplicateObjectIdAsDuplicateKeyException

        public static void handleJDODuplicateObjectIdAsDuplicateKeyException​(String beanName,
                                                                             String paramList,
                                                                             JDOException ex)
                                                                      throws jakarta.ejb.DuplicateKeyException
        Called from a CMP bean to process JDODuplicateObjectIdException. Logs the message and throws DuplicateKeyException.
        Parameters:
        beanName - the name of the calling bean.
        paramList - the list of the concatenated parameters.
        ex - the JDOException.
        Throws:
        jakarta.ejb.DuplicateKeyException
      • handleJDODuplicateObjectIdAsEJBException

        public static void handleJDODuplicateObjectIdAsEJBException​(String beanName,
                                                                    String paramList,
                                                                    JDOException ex)
        Called from a CMP bean to process JDODuplicateObjectIdException. Logs the message and throws EJBException.
        Parameters:
        beanName - the name of the calling bean.
        paramList - the list of the concatenated parameters.
        ex - the JDOException.
      • handleJDOObjectNotFoundException

        public static void handleJDOObjectNotFoundException​(Object primaryKey,
                                                            String beanName,
                                                            JDOException ex)
                                                     throws jakarta.ejb.ObjectNotFoundException
        Called from a CMP bean to process JDOObjectNotFoundException. Logs the message and throws ObjectNotFoundException
        Parameters:
        primaryKey - the PrimaryKey instance.
        beanName - the name of the calling bean.
        ex - the JDOException.
        Throws:
        jakarta.ejb.ObjectNotFoundException
      • handleUpdateNotAllowedException

        public static void handleUpdateNotAllowedException​(String beanName)
        Throws EJBException on attempted updates to the calling bean.
        Parameters:
        beanName - the name of the calling bean.
      • handleCloneException

        public static void handleCloneException​(Object primaryKey,
                                                String beanName,
                                                Exception ex)
        Throws EJBException on failed clone of persistence state in read-only beans.
        Parameters:
        primaryKey - the PrimaryKey instance.
        beanName - the name of the calling bean.
        ex - the Exception.