com.sun.jdo.spi.persistence.support.ejb.cmp
Class CMPBeanHelper

java.lang.Object
  extended by com.sun.jdo.spi.persistence.support.ejb.cmp.CMPBeanHelper

public class CMPBeanHelper
extends Object

Provides static helper methods for CMP bean implementation to simplify the generated code.


Constructor Summary
CMPBeanHelper()
           
 
Method Summary
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.
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.
static void assertPersistenceManagerIsNull(PersistenceManager pm, Object bean, StringBuffer buf)
          Called from a CMP bean to verify that the PersistenceManager is null.
static void assertPersistenceManagerNotNull(PersistenceManager pm, Object bean)
          Called from a CMP bean to verify that the PersistenceManager is not null.
static void assertPersistent(PersistenceCapable pc, String beanName)
          Called from a CMP bean to verify that the PersistenceCapable instance is already persistent.
static void handleCloneException(Object primaryKey, String beanName, Exception ex)
          Throws EJBException on failed clone of persistence state in read-only beans.
static void handleJDODuplicateObjectIdAsDuplicateKeyException(String beanName, String paramList, JDOException ex)
          Called from a CMP bean to process JDODuplicateObjectIdException.
static void handleJDODuplicateObjectIdAsEJBException(String beanName, String paramList, JDOException ex)
          Called from a CMP bean to process JDODuplicateObjectIdException.
static void handleJDOObjectNotFoundException(Object primaryKey, String beanName, JDOException ex)
          Called from a CMP bean to process JDOObjectNotFoundException.
static void handleUpdateNotAllowedException(String beanName)
          Throws EJBException on attempted updates to the calling bean.
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.
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.
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.
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.
static void logJDOExceptionWithLifecycleLogger(String key, String beanName, JDOException ex)
          Called from a CMP bean to log JDOException message with the LifecycleLogger.
static void logJDOExceptionWithLifecycleLogger(String key, String beanName, String paramList, JDOException ex)
          Called from a CMP bean to log JDOException message with the LifecycleLogger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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,
                                                  StringBuffer 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 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:
DuplicateKeyException.
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.
Throws:
EJBException.

handleJDOObjectNotFoundException

public static void handleJDOObjectNotFoundException(Object primaryKey,
                                                    String beanName,
                                                    JDOException ex)
                                             throws 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:
ObjectNotFoundException.
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.
Throws:
EJBException.

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.
Throws:
EJBException.


Copyright © 2012. All Rights Reserved.