}
}
// Initialise the context for JPA
NucleusContext nucleusCtx = new NucleusContext("JPA", startupProps);
PersistenceConfiguration propConfig = nucleusCtx.getPersistenceConfiguration();
// Apply remaining persistence properties
Map ctxProps = new HashMap();
ctxProps.putAll(props);
if (!props.containsKey("datanucleus.transactiontype") &&
!props.containsKey("javax.jdo.option.transactiontype"))
{
// Default to RESOURCE_LOCAL txns
ctxProps.put("datanucleus.transactiontype", TransactionType.RESOURCE_LOCAL.toString());
}
else
{
// let TransactionType.JTA imply ResourceType.JTA
String transactionType = props.get("datanucleus.transactiontype") != null ?
(String)props.get("datanucleus.transactiontype") : (String)props.get("javax.jdo.option.transactiontype");
if (TransactionType.JTA.toString().equalsIgnoreCase(transactionType))
{
ctxProps.put(ConnectionFactory.DATANUCLEUS_CONNECTION_RESOURCE_TYPE.toLowerCase(Locale.ENGLISH),
ConnectionResourceType.JTA.toString());
ctxProps.put(ConnectionFactory.DATANUCLEUS_CONNECTION2_RESOURCE_TYPE.toLowerCase(Locale.ENGLISH),
ConnectionResourceType.JTA.toString());
}
}
propConfig.setPersistenceProperties(ctxProps);
// Load up the MetaData implied by this "persistence-unit"
nucleusCtx.getMetaDataManager().loadPersistenceUnit(unitMetaData, null);
nucleusCtx.initialise();
// Load up any persistence-unit classes into the StoreManager
boolean loadClasses = propConfig.getBooleanProperty("datanucleus.persistenceunitloadclasses");
if (loadClasses)
{
// Load all classes into StoreManager so it knows about them
Collection<String> loadedClasses = nucleusCtx.getMetaDataManager().getClassesWithMetaData();
nucleusCtx.getStoreManager().addClasses(loadedClasses.toArray(new String[loadedClasses.size()]), nucleusCtx.getClassLoaderResolver(null));