Search in sources :

Example 21 with PersistenceUnitMetadata

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

the class PersistenceUnitParseProcessor method postParseSteps.

/**
     * Some of this might need to move to the install phase
     *
     * @param persistence_xml
     * @param puHolder
     */
private void postParseSteps(final VirtualFile persistence_xml, final PersistenceUnitMetadataHolder puHolder, final DeploymentUnit deploymentUnit) {
    for (PersistenceUnitMetadata pu : puHolder.getPersistenceUnits()) {
        // set URLs
        List<URL> jarfilesUrls = new ArrayList<URL>();
        if (pu.getJarFiles() != null) {
            for (String jar : pu.getJarFiles()) {
                jarfilesUrls.add(getRelativeURL(persistence_xml, jar));
            }
        }
        pu.setJarFileUrls(jarfilesUrls);
        URL url = getPersistenceUnitURL(persistence_xml);
        pu.setPersistenceUnitRootUrl(url);
        String scopedPersistenceUnitName;
        /**
             * WFLY-5478 allow custom scoped persistence unit name hint in persistence unit definition.
             * Specified scoped persistence unit name needs to be unique across application server deployments.
             * Application is responsible for picking a unique name.
             * Currently, a non-unique name will result in a DuplicateServiceException deployment failure:
             *   org.jboss.msc.service.DuplicateServiceException: Service jboss.persistenceunit.my2lccustom#test_pu.__FIRST_PHASE__ is already registered
             */
        scopedPersistenceUnitName = Configuration.getScopedPersistenceUnitName(pu);
        if (scopedPersistenceUnitName == null) {
            scopedPersistenceUnitName = createBeanName(deploymentUnit, pu.getPersistenceUnitName());
        } else {
            ROOT_LOGGER.tracef("persistence unit '%s' specified a custom scoped persistence unit name hint " + "(jboss.as.jpa.scopedname=%s).  The specified name *must* be unique across all application server deployments.", pu.getPersistenceUnitName(), scopedPersistenceUnitName);
            if (scopedPersistenceUnitName.indexOf('/') != -1) {
                throw JpaLogger.ROOT_LOGGER.invalidScopedName(scopedPersistenceUnitName, '/');
            }
        }
        pu.setScopedPersistenceUnitName(scopedPersistenceUnitName);
    }
}
Also used : ArrayList(java.util.ArrayList) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) URL(java.net.URL)

Example 22 with PersistenceUnitMetadata

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

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

the class JPADependencyProcessor method loadPersistenceUnits.

private int loadPersistenceUnits(final ModuleSpecification moduleSpecification, final ModuleLoader moduleLoader, final DeploymentUnit deploymentUnit, final Set<String> moduleDependencies, final PersistenceUnitMetadataHolder holder) throws DeploymentUnitProcessingException {
    int defaultProviderCount = 0;
    if (holder != null) {
        for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
            String providerModule = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
            String adapterModule = pu.getProperties().getProperty(Configuration.ADAPTER_MODULE);
            String adapterClass = pu.getProperties().getProperty(Configuration.ADAPTER_CLASS);
            if (adapterModule != null) {
                ROOT_LOGGER.debugf("%s is configured to use adapter module '%s'", pu.getPersistenceUnitName(), adapterModule);
                moduleDependencies.add(adapterModule);
            }
            deploymentUnit.putAttachment(JpaAttachments.ADAPTOR_CLASS_NAME, adapterClass);
            String provider = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
            if (provider != null) {
                if (provider.equals(Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED)) {
                    ROOT_LOGGER.debugf("%s is configured to use application supplied persistence provider", pu.getPersistenceUnitName());
                } else {
                    moduleDependencies.add(provider);
                    ROOT_LOGGER.debugf("%s is configured to use provider module '%s'", pu.getPersistenceUnitName(), provider);
                }
            } else if (Configuration.PROVIDER_CLASS_DEFAULT.equals(pu.getPersistenceProviderClassName())) {
                // track number of references to default provider module
                defaultProviderCount++;
            } else {
                // inject other provider modules into application
                // in case its not obvious, everything but hibernate3 can end up here.  For Hibernate3, the Configuration.PROVIDER_MODULE
                // should of been specified.
                //
                // since we don't know (until after PersistenceProviderProcessor runs in a later phase) if the provider
                // is packaged with the app or will be accessed as a module, make the module dependency optional (in case it
                // doesn't exist).
                String providerModuleName = Configuration.getProviderModuleNameFromProviderClassName(pu.getPersistenceProviderClassName());
                if (providerModuleName != null) {
                    addOptionalDependency(moduleSpecification, moduleLoader, deploymentUnit, ModuleIdentifier.fromString(providerModuleName));
                    ROOT_LOGGER.debugf("%s is configured to use persistence provider '%s', adding an optional dependency on module '%s'", pu.getPersistenceUnitName(), pu.getPersistenceProviderClassName(), providerModuleName);
                }
            }
        }
    }
    return defaultProviderCount;
}
Also used : PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 24 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) {
            if (name != null) {
                ROOT_LOGGER.tracef("pu search found %s", name.getScopedPersistenceUnitName());
            }
        }
        return name;
    }
}
Also used : PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 25 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)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