CMPBeanHelperpublic class CMPBeanHelper extends Object Provides static helper methods for CMP bean implementation to simplify
the generated code. |
Fields Summary |
---|
private static final ResourceBundle | cmpMessagesI18N message handlers | private static com.sun.jdo.spi.persistence.utility.logging.Logger | cmpLifecycleLoggerThe lifecycle logger used to log messages from ejbCreate(), ejbRemove()
and other lifecycle methods. | private static com.sun.jdo.spi.persistence.utility.logging.Logger | cmpFinderLoggerThe finder logger used to log messages from ejbFindXXX and/or ejbSelectXXX
methods. | private static com.sun.jdo.spi.persistence.utility.logging.Logger | cmpInternalLoggerThe internal logger used to log messages from setters and getter and other
generated methods. |
Methods Summary |
---|
public static void | assertCollectionNotNull(java.util.Collection c, java.lang.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.
if (c == null) {
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.cmrsettercol_nullexception", beanName, findCallingMethodName()); // NOI18N
cmpInternalLogger.log(Logger.SEVERE, msg);
throw new IllegalArgumentException(msg);
}
| public static void | assertNotContainerTransaction(java.lang.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.
if (EJBHelper.getTransaction() != null) {
String msg = I18NHelper.getMessage(cmpMessages,
"JDO.containertransaction_exception", bean); // NOI18N
cmpInternalLogger.log(Logger.SEVERE, msg);
throw new IllegalStateException(msg);
}
| public static void | assertPersistenceManagerIsNull(com.sun.jdo.api.persistence.support.PersistenceManager pm, java.lang.Object bean)Called from a CMP bean to verify that the PersistenceManager
is null. Throws IllegalStateException if the argument is not null.
if (pm != null) {
String msg = I18NHelper.getMessage(cmpMessages,
"JDO.beaninuse_exception", bean); // NOI18N
cmpInternalLogger.log(Logger.SEVERE, msg);
throw new IllegalStateException(msg);
}
| public static void | assertPersistenceManagerNotNull(com.sun.jdo.api.persistence.support.PersistenceManager pm, java.lang.Object bean)Called from a CMP bean to verify that the PersistenceManager
is not null. Throws IllegalStateException if the argument is null.
if (pm == null) {
String msg = I18NHelper.getMessage(cmpMessages,
"JDO.beannotloaded_exception", bean); // NOI18N
cmpInternalLogger.log(Logger.SEVERE, msg);
throw new IllegalStateException(msg);
}
| public static void | assertPersistent(com.sun.jdo.api.persistence.support.PersistenceCapable pc, java.lang.String beanName)Called from a CMP bean to verify that the PersistenceCapable
instance is already persistent. Throws IllegalStateException
otherwise.
if (!JDOHelper.isPersistent(pc)) {
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.cmrgettersetter_exception", beanName, findCallingMethodName()); // NOI18N
cmpInternalLogger.log(Logger.SEVERE, msg);
throw new IllegalStateException(msg);
}
| private static java.lang.String | findCallingMethodName()Calculates the method name of the calling method.
StackTraceElement[] ste = (new Throwable()).getStackTrace();
return ste[2].getMethodName();
| public static void | handleCloneException(java.lang.Object primaryKey, java.lang.String beanName, java.lang.Exception ex)Throws EJBException on failed clone of persistence state
in read-only beans.
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.clone_exception", beanName, // NOI18N
primaryKey.toString());
cmpLifecycleLogger.log(Logger.SEVERE, msg, ex);
throw new EJBException(msg);
| public static void | handleJDODuplicateObjectIdAsDuplicateKeyException(java.lang.String beanName, java.lang.String paramList, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to process JDODuplicateObjectIdException.
Logs the message and throws DuplicateKeyException.
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.ejbcreate_exception_dup", beanName, // NOI18N
findCallingMethodName(), paramList);
cmpLifecycleLogger.log(Logger.FINER, msg, ex);
throw new DuplicateKeyException(msg);
| public static void | handleJDODuplicateObjectIdAsEJBException(java.lang.String beanName, java.lang.String paramList, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to process JDODuplicateObjectIdException.
Logs the message and throws EJBException.
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.ejbcreate_exception_dup", beanName, // NOI18N
findCallingMethodName(), paramList);
cmpLifecycleLogger.log(Logger.FINER, msg, ex);
throw new EJBException(msg);
| public static void | handleJDOObjectNotFoundException(java.lang.Object primaryKey, java.lang.String beanName, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to process JDOObjectNotFoundException.
Logs the message and throws ObjectNotFoundException
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.findbypk_exception_notfound", beanName, // NOI18N
primaryKey.toString());
cmpLifecycleLogger.log(Logger.FINER, msg, ex);
throw new ObjectNotFoundException(msg);
| public static void | handleUpdateNotAllowedException(java.lang.String beanName)Throws EJBException on attempted updates to the
calling bean.
String msg = I18NHelper.getMessage(cmpMessages,
"GEN.update_not_allowed", beanName, // NOI18N
findCallingMethodName());
cmpLifecycleLogger.log(Logger.SEVERE, msg);
throw new EJBException(msg);
| public static void | logFinderException(int level, java.lang.String beanName, java.lang.Exception ex)Called from a CMP bean to log JDOException message thrown
from a any finder or selector method, with the FinderLogger.
if (cmpFinderLogger.isLoggable(level)) {
cmpFinderLogger.log(level,
I18NHelper.getMessage(cmpMessages,
"GEN.generic_method_exception", // NOI18N
beanName, findCallingMethodName()), ex);
}
| public static java.lang.String | logJDOExceptionFromPKSetter(java.lang.String beanName, com.sun.jdo.api.persistence.support.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.
String msg = I18NHelper.getMessage(cmpMessages, "EXC_PKUpdate", // NOI18N
beanName, findCallingMethodName());
if (cmpInternalLogger.isLoggable(Logger.FINE)) {
cmpInternalLogger.log(Logger.FINE, msg, ex);
}
return msg;
| public static void | logJDOExceptionWithFinderLogger(java.lang.String beanName, java.lang.Object[] params, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to log JDOException message thrown
from a any finder or selector method, with the FinderLogger.
String msg = null;
if (params != null) {
msg = I18NHelper.getMessage(cmpMessages,
"GEN.ejbSSReturnBody_exception", beanName, // NOI18N
findCallingMethodName(),
java.util.Arrays.asList(params).toString());
} else {
msg = I18NHelper.getMessage(cmpMessages,
"GEN.ejbSSReturnBody_exception_woparams", beanName, // NOI18N
findCallingMethodName());
}
cmpFinderLogger.log(Logger.WARNING, msg, ex);
| public static void | logJDOExceptionWithInternalLogger(java.lang.String beanName, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to log JDOException message thrown
from a any getter or setter method, with the InternalLogger.
cmpInternalLogger.log(Logger.WARNING,
I18NHelper.getMessage(cmpMessages,
"GEN.generic_method_exception", // NOI18N
beanName, findCallingMethodName()), ex);
| public static void | logJDOExceptionWithLifecycleLogger(java.lang.String key, java.lang.String beanName, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to log JDOException message
with the LifecycleLogger.
cmpLifecycleLogger.log(Logger.WARNING,
I18NHelper.getMessage(cmpMessages, key,
beanName, findCallingMethodName()), ex);
| public static void | logJDOExceptionWithLifecycleLogger(java.lang.String key, java.lang.String beanName, java.lang.String paramList, com.sun.jdo.api.persistence.support.JDOException ex)Called from a CMP bean to log JDOException message
with the LifecycleLogger.
cmpLifecycleLogger.log(Logger.WARNING,
I18NHelper.getMessage(cmpMessages, key,
beanName, findCallingMethodName(), paramList),
ex);
|
|