Search in sources :

Example 11 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata 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 12 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class PersistenceUnitSearch method findWithinApplication.

private static PersistenceUnitMetadata findWithinApplication(DeploymentUnit unit, String persistenceUnitName) {
    if (traceEnabled) {
        ROOT_LOGGER.tracef("pu findWithinApplication for %s", persistenceUnitName);
    }
    PersistenceUnitMetadata name = findWithinDeployment(unit, persistenceUnitName);
    if (name != null) {
        if (traceEnabled) {
            ROOT_LOGGER.tracef("pu findWithinApplication matched for %s", persistenceUnitName);
        }
        return name;
    }
    List<ResourceRoot> resourceRoots = unit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (!SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            name = findWithinLibraryJar(unit, resourceRoot, persistenceUnitName);
            if (name != null) {
                return name;
            }
        }
    }
    return null;
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 13 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata 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 14 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class PersistenceUnitParseProcessor method normalize.

/**
     * Eliminate duplicate PU definitions from clustering the deployment (first definition will win)
     * <p/>
     * JPA 8.2  A persistence unit must have a name. Only one persistence unit of any given name must be defined
     * within a single EJB-JAR file, within a single WAR file, within a single application client jar, or within
     * an EAR. See Section 8.2.2, “Persistence Unit Scope”.
     *
     * @param listPUHolders
     * @return
     */
private PersistenceUnitMetadataHolder normalize(List<PersistenceUnitMetadataHolder> listPUHolders) {
    // eliminate duplicates (keeping the first instance of each PU by name)
    Map<String, PersistenceUnitMetadata> flattened = new HashMap<String, PersistenceUnitMetadata>();
    for (PersistenceUnitMetadataHolder puHolder : listPUHolders) {
        for (PersistenceUnitMetadata pu : puHolder.getPersistenceUnits()) {
            if (!flattened.containsKey(pu.getPersistenceUnitName())) {
                flattened.put(pu.getPersistenceUnitName(), pu);
            } else {
                PersistenceUnitMetadata first = flattened.get(pu.getPersistenceUnitName());
                PersistenceUnitMetadata duplicate = pu;
                ROOT_LOGGER.duplicatePersistenceUnitDefinition(duplicate.getPersistenceUnitName(), first.getScopedPersistenceUnitName(), duplicate.getScopedPersistenceUnitName());
            }
        }
    }
    PersistenceUnitMetadataHolder holder = new PersistenceUnitMetadataHolder(new ArrayList<PersistenceUnitMetadata>(flattened.values()));
    return holder;
}
Also used : PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) HashMap(java.util.HashMap) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 15 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class JpaDependenciesProvider method getDependencies.

@Override
public Set<ServiceName> getDependencies(DeploymentUnit deploymentUnit) {
    Set<ServiceName> dependencies = new HashSet<>();
    for (ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) {
        final PersistenceUnitMetadataHolder persistenceUnits = root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
        if (persistenceUnits != null && persistenceUnits.getPersistenceUnits() != null) {
            for (final PersistenceUnitMetadata pu : persistenceUnits.getPersistenceUnits()) {
                final Properties properties = pu.getProperties();
                final String jpaContainerManaged = properties.getProperty(Configuration.JPA_CONTAINER_MANAGED);
                final boolean deployPU = (jpaContainerManaged == null || Boolean.parseBoolean(jpaContainerManaged));
                if (deployPU) {
                    final ServiceName serviceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
                    dependencies.add(serviceName);
                }
            }
        }
    }
    return dependencies;
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ServiceName(org.jboss.msc.service.ServiceName) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Properties(java.util.Properties) HashSet(java.util.HashSet)

Aggregations

PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)25 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)10 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ServiceName (org.jboss.msc.service.ServiceName)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3 Index (org.jboss.jandex.Index)3 URL (java.net.URL)2 Properties (java.util.Properties)2 PersistenceProvider (javax.persistence.spi.PersistenceProvider)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 JPADeploymentSettings (org.jboss.as.jpa.config.JPADeploymentSettings)2 PersistenceProviderDeploymentHolder (org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder)2 PersistenceUnitsInApplication (org.jboss.as.jpa.config.PersistenceUnitsInApplication)2 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)2 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 AnnotationValue (org.jboss.jandex.AnnotationValue)2