pmfProps.putAll(pumd.getProperties());
}
}
else
{
throw new JDOUserException(LOCALISER.msg("012004", persistenceUnitName));
}
if (nucleusContext.getApiName().equalsIgnoreCase("JPA"))
{
pumd.clearJarFiles(); // Don't use JARs when in J2SE for JPA
}
}
catch (NucleusException jpe)
{
throw new JDOUserException(LOCALISER.msg("012005", persistenceUnitName));
}
}
}
// Append on any user properties
if (props != null)
{
pmfProps.putAll(props);
if (!pmfProps.containsKey("datanucleus.TransactionType") &&
!pmfProps.containsKey("javax.jdo.option.TransactionType"))
{
// Default to RESOURCE_LOCAL txns
pmfProps.put("datanucleus.TransactionType", TransactionType.RESOURCE_LOCAL.toString());
}
else
{
// let TransactionType.JTA imply ResourceType.JTA
String transactionType = pmfProps.get("datanucleus.TransactionType") != null ?
(String)pmfProps.get("datanucleus.TransactionType") : (String)pmfProps.get("javax.jdo.option.TransactionType");
if (TransactionType.JTA.toString().equalsIgnoreCase(transactionType))
{
pmfProps.put(ConnectionFactory.DATANUCLEUS_CONNECTION_RESOURCE_TYPE,
ConnectionResourceType.JTA.toString());
pmfProps.put(ConnectionFactory.DATANUCLEUS_CONNECTION2_RESOURCE_TYPE,
ConnectionResourceType.JTA.toString());
}
}
}
else
{
pmfProps.put("datanucleus.TransactionType", TransactionType.RESOURCE_LOCAL.toString());
}
// Apply the properties to the PMF
try
{
String propsFileProp = "datanucleus.propertiesFile";
if (pmfProps.containsKey(propsFileProp))
{
// Apply properties file first
getConfiguration().setPropertiesUsingFile((String)pmfProps.get(propsFileProp));
pmfProps.remove(propsFileProp);
}
getConfiguration().setPersistenceProperties(pmfProps);
}
catch (IllegalArgumentException iae)
{
throw new JDOFatalUserException("Exception thrown setting persistence properties", iae);
}
catch (NucleusException jpe)
{
// Only throw JDOException and subclasses
throw NucleusJDOHelper.getJDOExceptionForNucleusException(jpe);
}
if (pumd != null)
{
// Initialise the MetaDataManager with all files/classes for this persistence-unit
// This is done now that all PMF properties are set (including the persistence-unit props)
try
{
nucleusContext.getMetaDataManager().loadPersistenceUnit(pumd, null);
}
catch (NucleusException jpe)
{
throw new JDOException(jpe.getMessage(),jpe);
}
}
if (props != null)
{
// Process any lifecycle listeners defined in persistent properties
Iterator<Map.Entry> propsIter = props.entrySet().iterator();
while (propsIter.hasNext())
{
Map.Entry entry = propsIter.next();
String key = (String)entry.getKey();
if (key.startsWith("javax.jdo.listener.InstanceLifecycleListener"))
{
String listenerClsName = key.substring(45);
String listenerClasses = (String)entry.getValue();
ClassLoaderResolver clr = nucleusContext.getClassLoaderResolver(null);
Class listenerCls = null;
try
{
listenerCls = clr.classForName(listenerClsName);
}
catch (ClassNotResolvedException cnre)
{
throw new JDOUserException(LOCALISER.msg("012022", listenerClsName));
}
InstanceLifecycleListener listener = null;
// Find method getInstance()
Method method = ClassUtils.getMethodForClass(listenerCls, "getInstance", null);
if (method != null)
{
// Create instance via getInstance()
try
{
listener = (InstanceLifecycleListener)method.invoke(null);
}
catch (Exception e)
{
throw new JDOUserException(LOCALISER.msg("012021", listenerClsName), e);
}
}
else
{
// Try default constructor
try
{
listener = (InstanceLifecycleListener)listenerCls.newInstance();
}
catch (Exception e)
{
throw new JDOUserException(LOCALISER.msg("012020", listenerClsName), e);
}
}
Class[] classes = null;
if (!StringUtils.isWhitespace(listenerClasses))