Search in sources :

Example 1 with PersistenceProviderAdaptor

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

the class PersistenceUnitServiceHandler method getPersistenceProviderAdaptor.

/**
 * Get the persistence provider adaptor.  Will load the adapter module if needed.
 *
 * @param pu
 * @param persistenceProviderDeploymentHolder
 *
 * @param provider
 * @param platform
 * @return
 * @throws DeploymentUnitProcessingException
 */
private static PersistenceProviderAdaptor getPersistenceProviderAdaptor(final PersistenceUnitMetadata pu, final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder, final DeploymentUnit deploymentUnit, final PersistenceProvider provider, final Platform platform) throws DeploymentUnitProcessingException {
    String adapterClass = pu.getProperties().getProperty(Configuration.ADAPTER_CLASS);
    /**
     * use adapter packaged in application deployment.
     */
    if (persistenceProviderDeploymentHolder != null && adapterClass != null) {
        List<PersistenceProviderAdaptor> persistenceProviderAdaptors = persistenceProviderDeploymentHolder.getAdapters();
        for (PersistenceProviderAdaptor persistenceProviderAdaptor : persistenceProviderAdaptors) {
            if (adapterClass.equals(persistenceProviderAdaptor.getClass().getName())) {
                return persistenceProviderAdaptor;
            }
        }
    }
    String adaptorModule = pu.getProperties().getProperty(Configuration.ADAPTER_MODULE);
    PersistenceProviderAdaptor adaptor;
    adaptor = getPerDeploymentSharedPersistenceProviderAdaptor(deploymentUnit, adaptorModule, provider);
    if (adaptor == null) {
        try {
            // are handled externally via properties or code in the persistence provider).
            if (adaptorModule != null) {
                // legacy way of loading adapter module
                adaptor = PersistenceProviderAdaptorLoader.loadPersistenceAdapterModule(adaptorModule, platform, createManager(deploymentUnit));
            } else {
                adaptor = PersistenceProviderAdaptorLoader.loadPersistenceAdapter(provider, platform, createManager(deploymentUnit));
            }
        } catch (ModuleLoadException e) {
            throw JpaLogger.ROOT_LOGGER.persistenceProviderAdaptorModuleLoadError(e, adaptorModule);
        }
        adaptor = savePerDeploymentSharedPersistenceProviderAdaptor(deploymentUnit, adaptorModule, adaptor, provider);
    }
    if (adaptor == null) {
        throw JpaLogger.ROOT_LOGGER.failedToGetAdapter(pu.getPersistenceProviderClassName());
    }
    return adaptor;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 2 with PersistenceProviderAdaptor

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

the class PersistenceProviderAdaptorLoader method loadPersistenceAdapter.

/**
 * Loads the persistence provider adapter
 *
 * @param persistenceProvider classloader will be used to load the persistence provider adapter
 * @return the persistence provider adaptor for the provider class
 */
public static PersistenceProviderAdaptor loadPersistenceAdapter(final PersistenceProvider persistenceProvider, final Platform platform, final JtaManagerImpl jtaManager) {
    PersistenceProviderAdaptor persistenceProviderAdaptor = null;
    final ServiceLoader<PersistenceProviderAdaptor> serviceLoader = ServiceLoader.load(PersistenceProviderAdaptor.class, persistenceProvider.getClass().getClassLoader());
    if (serviceLoader != null) {
        for (PersistenceProviderAdaptor adaptor : serviceLoader) {
            if (persistenceProviderAdaptor != null) {
                throw JpaLogger.ROOT_LOGGER.classloaderHasMultipleAdapters(persistenceProvider.getClass().getClassLoader().toString());
            }
            persistenceProviderAdaptor = adaptor;
            ROOT_LOGGER.debugf("loaded persistence provider adapter %s from classloader %s", persistenceProviderAdaptor.getClass().getName(), persistenceProvider.getClass().getClassLoader().toString());
        }
        if (persistenceProviderAdaptor != null) {
            persistenceProviderAdaptor.injectJtaManager(jtaManager);
            persistenceProviderAdaptor.injectPlatform(platform);
        }
    }
    return persistenceProviderAdaptor == null ? noopAdaptor : persistenceProviderAdaptor;
}
Also used : PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 3 with PersistenceProviderAdaptor

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

the class PersistenceUnitServiceHandler method savePerDeploymentSharedPersistenceProviderAdaptor.

/**
 * Will save the PersistenceProviderAdaptor at the top level application deployment unit level for sharing with other persistence units
 *
 * @param deploymentUnit
 * @param adaptorModule
 * @param adaptor
 * @param provider
 * @return the application level shared PersistenceProviderAdaptor (which may of been set by a different thread)
 */
private static PersistenceProviderAdaptor savePerDeploymentSharedPersistenceProviderAdaptor(DeploymentUnit deploymentUnit, String adaptorModule, PersistenceProviderAdaptor adaptor, PersistenceProvider provider) {
    if (deploymentUnit.getParent() != null) {
        deploymentUnit = deploymentUnit.getParent();
    }
    synchronized (deploymentUnit) {
        Map<String, PersistenceProviderAdaptor> map = deploymentUnit.getAttachment(providerAdaptorMapKey);
        String key;
        if (adaptorModule != null) {
            // handle legacy adapter module
            key = adaptorModule;
        } else {
            key = provider.getClass().getName();
        }
        PersistenceProviderAdaptor current = map.get(key);
        // saved if not already set by another thread
        if (current == null) {
            map.put(key, adaptor);
            current = adaptor;
        }
        return current;
    }
}
Also used : PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 4 with PersistenceProviderAdaptor

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

the class PersistenceUnitServiceHandler method addPuService.

/**
 * Add one PU service per top level deployment that represents
 *
 * @param phaseContext
 * @param puList
 * @param startEarly
 * @param platform
 * @throws DeploymentUnitProcessingException
 */
private static void addPuService(final DeploymentPhaseContext phaseContext, final ArrayList<PersistenceUnitMetadataHolder> puList, final boolean startEarly, final Platform platform) throws DeploymentUnitProcessingException {
    if (!puList.isEmpty()) {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        final ModuleClassLoader classLoader = module.getClassLoader();
        for (PersistenceUnitMetadataHolder holder : puList) {
            setAnnotationIndexes(holder, deploymentUnit);
            for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
                // only start the persistence unit if JPA_CONTAINER_MANAGED is true
                String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED);
                boolean deployPU = (jpaContainerManaged == null ? true : Boolean.parseBoolean(jpaContainerManaged));
                if (deployPU) {
                    final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(deploymentUnit);
                    final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, deploymentUnit);
                    final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, deploymentUnit, provider, platform);
                    final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu);
                    if (startEarly) {
                        if (twoPhaseBootStrapCapable) {
                            deployPersistenceUnitPhaseOne(deploymentUnit, eeModuleDescription, serviceTarget, classLoader, pu, adaptor);
                        } else if (false == Configuration.needClassFileTransformer(pu)) {
                            // will start later when startEarly == false
                            ROOT_LOGGER.tracef("persistence unit %s in deployment %s is configured to not need class transformer to be set, no class rewriting will be allowed", pu.getPersistenceUnitName(), deploymentUnit.getName());
                        } else {
                            // we need class file transformer to work, don't allow Jakarta Contexts and Dependency Injection bean manager to be access since that
                            // could cause application classes to be loaded (workaround by setting jboss.as.jpa.classtransformer to false).  WFLY-1463
                            final boolean allowCdiBeanManagerAccess = false;
                            deployPersistenceUnit(deploymentUnit, eeModuleDescription, serviceTarget, classLoader, pu, provider, adaptor, allowCdiBeanManagerAccess);
                        }
                    } else {
                        // !startEarly
                        if (twoPhaseBootStrapCapable) {
                            deployPersistenceUnitPhaseTwo(deploymentUnit, eeModuleDescription, serviceTarget, classLoader, pu, provider, adaptor);
                        } else if (false == Configuration.needClassFileTransformer(pu)) {
                            final boolean allowCdiBeanManagerAccess = true;
                            // PUs that have Configuration.JPA_CONTAINER_CLASS_TRANSFORMER = false will start during INSTALL phase
                            deployPersistenceUnit(deploymentUnit, eeModuleDescription, serviceTarget, classLoader, pu, provider, adaptor, allowCdiBeanManagerAccess);
                        }
                    }
                } else {
                    ROOT_LOGGER.tracef("persistence unit %s in deployment %s is not container managed (%s is set to false)", pu.getPersistenceUnitName(), deploymentUnit.getName(), Configuration.JPA_CONTAINER_MANAGED);
                }
            }
        }
    }
}
Also used : PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ServiceTarget(org.jboss.msc.service.ServiceTarget) PersistenceProvider(javax.persistence.spi.PersistenceProvider) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Module(org.jboss.modules.Module) 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 5 with PersistenceProviderAdaptor

use of org.jipijapa.plugin.spi.PersistenceProviderAdaptor 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) && !Configuration.allowApplicationDefinedDatasource(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)

Aggregations

PersistenceProviderAdaptor (org.jipijapa.plugin.spi.PersistenceProviderAdaptor)7 PersistenceProvider (javax.persistence.spi.PersistenceProvider)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Module (org.jboss.modules.Module)3 PersistenceProviderDeploymentHolder (org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder)2 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)2 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)2 PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)2 TwoPhaseBootstrapCapable (org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable)2 ArrayList (java.util.ArrayList)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 PersistenceUnitsInApplication (org.jboss.as.jpa.config.PersistenceUnitsInApplication)1 JtaManagerImpl (org.jboss.as.jpa.transaction.JtaManagerImpl)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 ServicesAttachment (org.jboss.as.server.deployment.ServicesAttachment)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 ModuleLoader (org.jboss.modules.ModuleLoader)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1