use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method handleEarDeployment.
private void handleEarDeployment(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (isEarDeployment(deploymentUnit)) {
int puCount = 0;
// ordered list of PUs
List<PersistenceUnitMetadataHolder> listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
// handle META-INF/persistence.xml
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
VirtualFile persistence_xml = deploymentRoot.getRoot().getChild(META_INF_PERSISTENCE_XML);
parse(persistence_xml, listPUHolders, deploymentUnit);
PersistenceUnitMetadataHolder holder = normalize(listPUHolders);
deploymentRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
addApplicationDependenciesOnProvider(deploymentUnit, holder);
markDU(holder, deploymentUnit);
puCount = holder.getPersistenceUnits().size();
// Parsing persistence.xml in EJB jar/war files is handled as subdeployments.
// We need to handle jars in the EAR/lib folder here
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
// to deploy(DeploymentPhaseContext)).
if (!SubDeploymentMarker.isSubDeployment(resourceRoot) && resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_FILE_EXTENSION) && resourceRoot.getRoot().getParent().getName().equals(LIB_FOLDER)) {
listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
persistence_xml = resourceRoot.getRoot().getChild(META_INF_PERSISTENCE_XML);
parse(persistence_xml, listPUHolders, deploymentUnit);
holder = normalize(listPUHolders);
resourceRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
addApplicationDependenciesOnProvider(deploymentUnit, holder);
markDU(holder, deploymentUnit);
puCount += holder.getPersistenceUnits().size();
}
}
ROOT_LOGGER.tracef("parsed persistence unit definitions for ear %s", deploymentRoot.getRootName());
incrementPersistenceUnitCount(deploymentUnit, puCount);
}
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method nextPhaseDependsOnPersistenceUnit.
/**
* The sub-deployment phases run in parallel, ensure that no deployment/sub-deployment moves past
* Phase.FIRST_MODULE_USE, until the applications persistence unit services are started.
*
* Note that some application persistence units will not be created until the Phase.INSTALL, in which case
* NEXT_PHASE_DEPS is not needed.
*/
private static void nextPhaseDependsOnPersistenceUnit(final DeploymentPhaseContext phaseContext, final Platform platform) throws DeploymentUnitProcessingException {
final DeploymentUnit topDeploymentUnit = DeploymentUtils.getTopDeploymentUnit(phaseContext.getDeploymentUnit());
final PersistenceUnitsInApplication persistenceUnitsInApplication = topDeploymentUnit.getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
for (final PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
for (final PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED);
boolean deployPU = (jpaContainerManaged == null ? true : Boolean.parseBoolean(jpaContainerManaged));
if (deployPU) {
final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(phaseContext.getDeploymentUnit());
final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, phaseContext.getDeploymentUnit());
final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, phaseContext.getDeploymentUnit(), provider, platform);
final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu);
// only add the next phase dependency, if the persistence unit service is starting early.
if (Configuration.needClassFileTransformer(pu)) {
// wait until the persistence unit service is started before starting the next deployment phase
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, twoPhaseBootStrapCapable ? puServiceName.append(FIRST_PHASE) : puServiceName);
}
}
}
}
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class JPADependencyProcessor method addPersistenceProviderModuleDependencies.
private void addPersistenceProviderModuleDependencies(DeploymentPhaseContext phaseContext, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
int defaultProviderCount = 0;
Set<String> moduleDependencies = new HashSet<String>();
// get the number of persistence units that use the default persistence provider module.
// Dependencies for other persistence provider will be added to the passed
// 'moduleDependencies' collection. Each persistence provider module that is found, will be injected into the
// passed moduleSpecification (for the current deployment unit).
PersistenceUnitsInApplication persistenceUnitsInApplication = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
defaultProviderCount += loadPersistenceUnits(moduleSpecification, moduleLoader, deploymentUnit, moduleDependencies, holder);
}
// add dependencies for the default persistence provider module
if (defaultProviderCount > 0) {
moduleDependencies.add(Configuration.getDefaultProviderModuleName());
ROOT_LOGGER.debugf("added (default provider) %s dependency to %s (since %d PU(s) didn't specify %s", Configuration.getDefaultProviderModuleName(), deploymentUnit.getName(), defaultProviderCount, Configuration.PROVIDER_MODULE + ")");
}
// add persistence provider dependency
for (String dependency : moduleDependencies) {
addDependency(moduleSpecification, moduleLoader, deploymentUnit, ModuleIdentifier.fromString(dependency));
}
// add the PU service as a dependency to all EE components in this scope
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> components = eeModuleDescription.getComponentDescriptions();
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
addPUServiceDependencyToComponents(components, holder);
}
}
Aggregations