Search in sources :

Example 1 with PersistenceUnitMetadataHolder

use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.

the class PersistenceUnitSearch method getPersistenceUnit.

private static PersistenceUnitMetadata getPersistenceUnit(DeploymentUnit current, final String absolutePath, String puName) {
    final String path;
    if (absolutePath.startsWith("../")) {
        path = absolutePath.substring(3);
    } else {
        path = absolutePath;
    }
    final VirtualFile parent = current.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getParent();
    final VirtualFile resolvedPath = parent.getChild(path);
    List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(DeploymentUtils.getTopDeploymentUnit(current));
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (resourceRoot.getRoot().equals(resolvedPath)) {
            PersistenceUnitMetadataHolder holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
            if (holder != null) {
                for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
                    if (traceEnabled) {
                        ROOT_LOGGER.tracef("getPersistenceUnit check '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
                    }
                    if (pu.getPersistenceUnitName().equals(puName)) {
                        if (traceEnabled) {
                            ROOT_LOGGER.tracef("getPersistenceUnit matched '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
                        }
                        return pu;
                    }
                }
            }
        }
    }
    throw JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(absolutePath, puName, current);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 2 with PersistenceUnitMetadataHolder

use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.

the class PersistenceUnitSearch method findWithinLibraryJar.

private static PersistenceUnitMetadata findWithinLibraryJar(DeploymentUnit unit, ResourceRoot moduleResourceRoot, String persistenceUnitName) {
    final ResourceRoot deploymentRoot = moduleResourceRoot;
    PersistenceUnitMetadataHolder holder = deploymentRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
    if (holder == null || holder.getPersistenceUnits() == null) {
        if (traceEnabled) {
            ROOT_LOGGER.tracef("findWithinLibraryJar checking for '%s' found no persistence units", persistenceUnitName);
        }
        return null;
    }
    ambiguousPUError(unit, persistenceUnitName, holder);
    persistenceUnitName = defaultPersistenceUnitName(persistenceUnitName, holder);
    for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
        if (traceEnabled) {
            ROOT_LOGGER.tracef("findWithinLibraryJar check '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
        }
        if (persistenceUnitName == null || persistenceUnitName.length() == 0 || persistenceUnit.getPersistenceUnitName().equals(persistenceUnitName)) {
            if (traceEnabled) {
                ROOT_LOGGER.tracef("findWithinLibraryJar matched '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
            }
            return persistenceUnit;
        }
    }
    return null;
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 3 with PersistenceUnitMetadataHolder

use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.

the class PersistenceUnitSearch method findWithinDeployment.

/*
     * When finding the default persistence unit, the first persistence unit encountered is returned.
     */
private static PersistenceUnitMetadata findWithinDeployment(DeploymentUnit unit, String persistenceUnitName) {
    if (traceEnabled) {
        ROOT_LOGGER.tracef("pu findWithinDeployment searching for %s", persistenceUnitName);
    }
    for (ResourceRoot root : DeploymentUtils.allResourceRoots(unit)) {
        PersistenceUnitMetadataHolder holder = root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
        if (holder == null || holder.getPersistenceUnits() == null) {
            if (traceEnabled) {
                ROOT_LOGGER.tracef("pu findWithinDeployment skipping empty pu holder for %s", persistenceUnitName);
            }
            continue;
        }
        ambiguousPUError(unit, persistenceUnitName, holder);
        persistenceUnitName = defaultPersistenceUnitName(persistenceUnitName, holder);
        for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
            if (traceEnabled) {
                ROOT_LOGGER.tracef("findWithinDeployment check '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
            }
            if (persistenceUnitName == null || persistenceUnitName.length() == 0 || persistenceUnit.getPersistenceUnitName().equals(persistenceUnitName)) {
                if (traceEnabled) {
                    ROOT_LOGGER.tracef("findWithinDeployment matched '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
                }
                return persistenceUnit;
            }
        }
    }
    return null;
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 4 with PersistenceUnitMetadataHolder

use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.

the class PersistenceUnitXmlParserTestCase method testVersion.

/**
     * See http://issues.jboss.org/browse/STXM-8
     */
@Test
public void testVersion() throws Exception {
    final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + "  <persistence-unit name=\"mypc\">" + "    <description>Persistence Unit." + "    </description>" + "    <jta-data-source>java:/H2DS</jta-data-source>" + "    <class>org.jboss.as.test.integration.jpa.epcpropagation.MyEntity</class>" + "    <properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + "  </persistence-unit>" + "</persistence>";
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(persistence_xml));
    PersistenceUnitMetadataHolder metadataHolder = PersistenceUnitXmlParser.parse(reader, PropertyReplacers.noop());
    PersistenceUnitMetadata metadata = metadataHolder.getPersistenceUnits().get(0);
    String version = metadata.getPersistenceXMLSchemaVersion();
    assertEquals("1.0", version);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) StringReader(java.io.StringReader) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Test(org.junit.Test)

Example 5 with PersistenceUnitMetadataHolder

use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.

the class PersistenceUnitParseProcessor method handleJarDeployment.

private void handleJarDeployment(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!isEarDeployment(deploymentUnit) && !isWarDeployment(deploymentUnit) && (!appClientContainerMode || DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit))) {
        // handle META-INF/persistence.xml
        // 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);
        // save the persistent unit definitions
        // deploymentUnit.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
        deploymentRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
        markDU(holder, deploymentUnit);
        ROOT_LOGGER.tracef("parsed persistence unit definitions for jar %s", deploymentRoot.getRootName());
        incrementPersistenceUnitCount(deploymentUnit, holder.getPersistenceUnits().size());
        addApplicationDependenciesOnProvider(deploymentUnit, holder);
    }
}
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)

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