// if the persistence unit is contained in a deployment that is a CDI bean archive (has beans.xml).
if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
proxyBeanManager = new ProxyBeanManager();
}
final PhaseOnePersistenceUnitServiceImpl service = new PhaseOnePersistenceUnitServiceImpl(classLoader, pu, adaptor, deploymentUnit.getServiceName(), proxyBeanManager);
deploymentUnit.addToAttachmentList(REMOVAL_KEY, new PersistenceAdaptorRemoval(pu, adaptor));
// add persistence provider specific properties
adaptor.addProviderProperties(properties, pu);
final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu).append(FIRST_PHASE);
deploymentUnit.putAttachment(JpaAttachments.PERSISTENCE_UNIT_SERVICE_KEY, puServiceName);
deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, puServiceName);
deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);
ServiceBuilder<PhaseOnePersistenceUnitServiceImpl> builder = serviceTarget.addService(puServiceName, service);
boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu);
final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());
if (jtaDataSource != null && jtaDataSource.length() > 0) {
if (jtaDataSource.startsWith("java:")) {
if (jtaDataSource.equals(EE_DEFAULT_DATASOURCE)) { // explicit use of default datasource
useDefaultDataSource = true;
}
else {
builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
useDefaultDataSource = false;
}
} else {
builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(jtaDataSource), new CastingInjector<>(service.getJtaDataSourceInjector(), DataSource.class));
useDefaultDataSource = false;
}
}
if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
if (nonJtaDataSource.startsWith("java:")) {
builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
useDefaultDataSource = false;
} else {
builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(nonJtaDataSource), new CastingInjector<>(service.getNonJtaDataSourceInjector(), DataSource.class));
useDefaultDataSource = false;
}
}
// JPA 2.0 8.2.1.5, container provides default JTA datasource
if (useDefaultDataSource) {
// try the one defined in the jpa subsystem
String defaultJtaDataSource = null;
if (eeModuleDescription != null) {
defaultJtaDataSource = eeModuleDescription.getDefaultResourceJndiNames().getDataSource();
}
if (defaultJtaDataSource == null ||
defaultJtaDataSource.isEmpty()) {
// try the datasource defined in the JPA subsystem
defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
}
if (defaultJtaDataSource != null &&
!defaultJtaDataSource.isEmpty()) {
builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(defaultJtaDataSource), new CastingInjector<>(service.getJtaDataSourceInjector(), DataSource.class));
JPA_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
}
}
try {
// save a thread local reference to the builder for setting up the second level cache dependencies
CacheDeploymentListener.setInternalDeploymentServiceBuilder(builder);
adaptor.addProviderDependencies(pu);
}
finally {
CacheDeploymentListener.clearInternalDeploymentServiceBuilder();
}
builder.setInitialMode(ServiceController.Mode.ACTIVE)
.addInjection(service.getPropertiesInjector(), properties);
// get async executor from Services.addServerExecutorDependency
addServerExecutorDependency(builder, service.getExecutorInjector(), false);
builder.install();
JPA_LOGGER.tracef("added PersistenceUnitService (phase 1 of 2) for '%s'. PU is ready for injector action.", puServiceName);
} catch (ServiceRegistryException e) {