checkForDataSourceOverride(pud);
calculateDefaultDataSource(pud);
PersistenceUnitInfo pInfo = new PersistenceUnitInfoImpl(pud, providerContainerContractInfo);
String applicationLocation = providerContainerContractInfo.getApplicationLocation();
final boolean fineMsgLoggable = logger.isLoggable(Level.FINE);
if(fineMsgLoggable) {
logger.fine("Loading persistence unit for application: \"" + applicationLocation + "\"pu Root is: " +
pud.getPuRoot());
logger.fine("PersistenceInfo for this pud is :\n" + pInfo); // NOI18N
}
PersistenceProvider provider;
try {
// See we use application CL as opposed to system CL to loadPU
// provider. This allows user to get hold of provider specific
// implementation classes in their code. But this also means
// provider must not use appserver implementation classes directly
// because once we implement isolation in our class loader hierarchy
// the only classes available to application class loader would be
// our appserver interface classes. By Sahoo
provider =
PersistenceProvider.class.cast(
providerContainerContractInfo.getClassLoader()
.loadClass(pInfo.getPersistenceProviderClassName())
.newInstance());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
// XXX - use DeploymentContext directly instead of creating helper instance first
if (providerContainerContractInfo.isJava2DBRequired()) {
processor = new JPAJava2DBProcessor(new Java2DBProcessorHelper(providerContainerContractInfo.getDeploymentContext()));
java2db = processor.isJava2DbPU(pud);
}
Map<String, Object> overRides = new HashMap<String, Object>( (java2db)? integrationPropertiesWithJava2DB : integrationPropertiesWithoutJava2DB );
// Check if the persistence unit requires Bean Validation
ValidationMode validationMode = getValidationMode(pud);
if(validationMode == ValidationMode.AUTO || validationMode == ValidationMode.CALLBACK ) {
overRides.put(VALIDATOR_FACTORY, providerContainerContractInfo.getValidatorFactory());
}
if(!providerContainerContractInfo.isWeavingEnabled()) {
overRides.put(ECLIPSELINK_WEAVING_PROPERTY, System.getProperty(ECLIPSELINK_WEAVING_PROPERTY,"false")); // NOI18N
}
EntityManagerFactory emf = provider.createContainerEntityManagerFactory(pInfo, overRides);
EntityManager em = null;
try {
// Create EM to trigger any validations that are lazily performed by the provider
// EM creation also triggers DDL generation by provider.
em = emf.createEntityManager();
} catch (PersistenceException e) {
// Exception indicates something went wrong while performing validation. Clean up and rethrow to fail deployment
emf.close();
throw e;
} finally {
if (em != null) {
em.close();
}
}
if (fineMsgLoggable) {
logger.logp(Level.FINE, "PersistenceUnitLoader", "loadPU", // NOI18N
"emf = {0}", emf); // NOI18N
}
PersistenceUnitsDescriptor parent = pud.getParent();
RootDeploymentDescriptor containingBundle = parent.getParent();
providerContainerContractInfo.registerEMF(pInfo.getPersistenceUnitName(), pud.getPuRoot(), containingBundle, emf);
if(fineMsgLoggable) {
logger.fine("Finished loading persistence unit for application: " + // NOI18N
applicationLocation);
}