Search in sources :

Example 26 with PersistenceUnitMetadata

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

the class PersistenceUnitSearch method resolvePersistenceUnitSupplier.

public static PersistenceUnitMetadata resolvePersistenceUnitSupplier(DeploymentUnit deploymentUnit, String persistenceUnitName) {
    if (traceEnabled) {
        ROOT_LOGGER.tracef("pu search for name '%s' inside of %s", persistenceUnitName, deploymentUnit.getName());
    }
    int scopeSeparatorCharacter = (persistenceUnitName == null ? -1 : persistenceUnitName.indexOf('#'));
    if (scopeSeparatorCharacter != -1) {
        final String path = persistenceUnitName.substring(0, scopeSeparatorCharacter);
        final String name = persistenceUnitName.substring(scopeSeparatorCharacter + 1);
        PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, path, name);
        if (traceEnabled) {
            ROOT_LOGGER.tracef("pu search found %s", pu.getScopedPersistenceUnitName());
        }
        return pu;
    } else {
        PersistenceUnitMetadata name = findPersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
        if (traceEnabled && name != null) {
            ROOT_LOGGER.tracef("pu search found %s", name.getScopedPersistenceUnitName());
        }
        return name;
    }
}
Also used : PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 27 with PersistenceUnitMetadata

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

the class PersistenceUnitSearch method ambiguousPUError.

private static void ambiguousPUError(DeploymentUnit unit, String persistenceUnitName, PersistenceUnitMetadataHolder holder) {
    if (holder.getPersistenceUnits().size() > 1 && (persistenceUnitName == null || persistenceUnitName.length() == 0)) {
        int numberOfDefaultPersistenceUnits = 0;
        // get number of persistence units that are marked as default
        for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
            String defaultPU = persistenceUnit.getProperties().getProperty(Configuration.JPA_DEFAULT_PERSISTENCE_UNIT);
            if (Boolean.TRUE.toString().equals(defaultPU)) {
                numberOfDefaultPersistenceUnits++;
            }
        }
        ROOT_LOGGER.tracef("checking for ambiguous persistence unit injection error, " + "number of persistence units marked default (%s) = %d", Configuration.JPA_DEFAULT_PERSISTENCE_UNIT, numberOfDefaultPersistenceUnits);
        // don't throw an error if there is exactly one default persistence unit
        if (numberOfDefaultPersistenceUnits != 1) {
            // AS7-2275 no unitName and there is more than one persistence unit;
            throw JpaLogger.ROOT_LOGGER.noPUnitNameSpecifiedAndMultiplePersistenceUnits(holder.getPersistenceUnits().size(), unit);
        }
    }
}
Also used : PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Aggregations

PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)27 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)11 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ServiceName (org.jboss.msc.service.ServiceName)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 PersistenceUnitsInApplication (org.jboss.as.jpa.config.PersistenceUnitsInApplication)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3 Index (org.jboss.jandex.Index)3 StringReader (java.io.StringReader)2 URL (java.net.URL)2 Properties (java.util.Properties)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 JPADeploymentSettings (org.jboss.as.jpa.config.JPADeploymentSettings)2 PersistenceProviderDeploymentHolder (org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder)2