Search in sources :

Example 1 with WebNonTxEmCloserAction

use of org.jboss.as.jpa.interceptor.WebNonTxEmCloserAction in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method handleWarDeployment.

private static void handleWarDeployment(DeploymentPhaseContext phaseContext, boolean startEarly, Platform platform) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (isWarDeployment(deploymentUnit) && JPADeploymentMarker.isJPADeployment(deploymentUnit)) {
        final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        PersistenceUnitMetadataHolder holder;
        ArrayList<PersistenceUnitMetadataHolder> puList = new ArrayList<PersistenceUnitMetadataHolder>(1);
        String deploymentRootName = null;
        // handle persistence.xml definition in the root of the war
        if (deploymentRoot != null && (holder = deploymentRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS)) != null && holder.getPersistenceUnits().size() > 0) {
            // assemble and install the PU service
            puList.add(holder);
            deploymentRootName = deploymentRoot.getRootName();
        }
        // look for persistence.xml in war files in the META-INF/persistence.xml directory
        List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
        for (ResourceRoot resourceRoot : resourceRoots) {
            if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
                if ((holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS)) != null && holder.getPersistenceUnits().size() > 0) {
                    // assemble and install the PU service
                    puList.add(holder);
                }
            }
        }
        if (startEarly) {
            // only add the WebNonTxEmCloserAction valve on the earlier invocation (AS7-6690).
            deploymentUnit.addToAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS, new WebNonTxEmCloserAction());
        }
        ROOT_LOGGER.tracef("install persistence unit definitions for war %s", deploymentRootName);
        addPuService(phaseContext, puList, startEarly, platform);
    }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) WebNonTxEmCloserAction(org.jboss.as.jpa.interceptor.WebNonTxEmCloserAction) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ArrayList (java.util.ArrayList)1 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)1 WebNonTxEmCloserAction (org.jboss.as.jpa.interceptor.WebNonTxEmCloserAction)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1