Search in sources :

Example 16 with PersistenceUnitMetadataHolder

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);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 17 with PersistenceUnitMetadataHolder

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);
                }
            }
        }
    }
}
Also used : PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitsInApplication(org.jboss.as.jpa.config.PersistenceUnitsInApplication) ServiceName(org.jboss.msc.service.ServiceName) PersistenceProvider(javax.persistence.spi.PersistenceProvider) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) PersistenceProviderDeploymentHolder(org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) TwoPhaseBootstrapCapable(org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 18 with PersistenceUnitMetadataHolder

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);
    }
}
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

PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)18 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)10 PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)10 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)9 ArrayList (java.util.ArrayList)7 VirtualFile (org.jboss.vfs.VirtualFile)4 PersistenceUnitsInApplication (org.jboss.as.jpa.config.PersistenceUnitsInApplication)3 HashSet (java.util.HashSet)2 PersistenceProvider (javax.persistence.spi.PersistenceProvider)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 PersistenceProviderDeploymentHolder (org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder)2 ServiceName (org.jboss.msc.service.ServiceName)2 PersistenceProviderAdaptor (org.jipijapa.plugin.spi.PersistenceProviderAdaptor)2 TwoPhaseBootstrapCapable (org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1