unitMetaData = EntityManagerFactoryImpl.unitMetaDataCache.get(unitName);
if (unitMetaData == null)
{
// Find all "META-INF/persistence.xml" files in the current thread loader CLASSPATH and parse them
// Create a temporary PMFContext so we have a parser
OMFContext pmfCtxt = new OMFContext(new PersistenceConfiguration(){});
pmfCtxt.setApi("JPA");
MetaDataManager metadataMgr = pmfCtxt.getMetaDataManager();
PersistenceFileMetaData[] files = metadataMgr.parsePersistenceFiles();
if (files == null)
{
// No "persistence.xml" files found
NucleusLogger.JPA.warn(LOCALISER.msg("EMF.NoPersistenceXML"));
//throw new NoPersistenceXmlException(LOCALISER.msg("EMF.NoPersistenceXML"));
}
else
{
for (int i=0;i<files.length;i++)
{
PersistenceUnitMetaData[] unitmds = files[i].getPersistenceUnits();
for (int j=0;j<unitmds.length;j++)
{
// Cache the "persistence-unit" for future reference
EntityManagerFactoryImpl.unitMetaDataCache.put(unitmds[j].getName(), unitmds[j]);
if (unitmds[j].getName().equals(unitName))
{
unitMetaData = unitmds[j];
unitMetaData.clearJarFiles(); // Jar files not applicable to J2SE [JPA 6.3]
}
}
}
}
if (unitMetaData == null)
{
// No "persistence-unit" of the same name as requested so nothing to manage the persistence of
NucleusLogger.JPA.warn(LOCALISER.msg("EMF.PersistenceUnitNotFound", unitName));
}
else
{
EntityManagerFactoryImpl.unitMetaDataCache.put(unitMetaData.getName(), unitMetaData);
}
}
// Check the provider is ok for our use
boolean validProvider = false;
if (unitMetaData != null)
{
if (unitMetaData.getProvider() == null ||
unitMetaData.getProvider().equals(PersistenceProviderImpl.class.getName()))
{
validProvider = true;
}
}
if (overridingProps != null &&
PersistenceProviderImpl.class.getName().equals(overridingProps.get("javax.persistence.provider")))
{
validProvider = true;
}
if (!validProvider)
{
// Not a valid provider
throw new NotProviderException(LOCALISER.msg("EMF.NotProviderForPersistenceUnit",
unitName));
}
// Initialise the PMF (even if unitMetaData is null)
pmf = initialisePMF(unitMetaData, overridingProps);
// Initialise the L2 cache (if used)
JDODataStoreCache cache = (JDODataStoreCache)pmf.getDataStoreCache();
OMFContext omfCtx = ((JDOPersistenceManagerFactory)pmf).getOMFContext();
if (cache != null)
{
datastoreCache = new JPADataStoreCache(omfCtx, cache.getLevel2Cache());
}
// Turn off loading of metadata from here if required
boolean allowMetadataLoad =
omfCtx.getPersistenceConfiguration().getBooleanProperty("datanucleus.metadata.allowLoadAtRuntime");
if (!allowMetadataLoad)
{
omfCtx.getMetaDataManager().setAllowMetaDataLoad(false);
}
}