Search in sources :

Example 6 with PersistenceUnitsInApplication

use of org.jboss.as.jpa.config.PersistenceUnitsInApplication 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);
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) PersistenceUnitsInApplication(org.jboss.as.jpa.config.PersistenceUnitsInApplication) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Aggregations

PersistenceUnitsInApplication (org.jboss.as.jpa.config.PersistenceUnitsInApplication)6 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)2 HashSet (java.util.HashSet)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 PersistenceProviderDeploymentHolder (org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder)1 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)1 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)1 ServiceName (org.jboss.msc.service.ServiceName)1 PersistenceProviderAdaptor (org.jipijapa.plugin.spi.PersistenceProviderAdaptor)1 TwoPhaseBootstrapCapable (org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable)1