jpa/subsystem/src/main/java/org/jboss/as/jpa/processor/PersistenceUnitServiceHandler.java
private static PersistenceProvider lookupProvider(
            PersistenceUnitMetadata pu,
            PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder,
            DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {

        /**
         * check if the deployment is already associated with the specified persistence provider
         */
        Map<String, PersistenceProvider> providerMap = persistenceProviderDeploymentHolder != null ?
                persistenceProviderDeploymentHolder.getProviders() : null;
        if (providerMap != null) {
            synchronized (providerMap) {
                if(providerMap.containsKey(pu.getPersistenceProviderClassName())){
                    ROOT_LOGGER.tracef("deployment %s is using %s", deploymentUnit.getName(), pu.getPersistenceProviderClassName());
                    return providerMap.get(pu.getPersistenceProviderClassName());
                }
            }
        }

        String configuredPersistenceProviderModule = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
        String persistenceProviderClassName = pu.getPersistenceProviderClassName();

        if (persistenceProviderClassName == null) {
            persistenceProviderClassName = Configuration.PROVIDER_CLASS_DEFAULT;
        }

        /**
         * locate persistence provider in specified static module
         */
        if (configuredPersistenceProviderModule != null) {
            List<PersistenceProvider> providers;
            if (Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED.equals(configuredPersistenceProviderModule)) {
                try {
                    // load the persistence provider from the application deployment
                    final ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
                    PersistenceProvider provider = PersistenceProviderLoader.loadProviderFromDeployment(classLoader, persistenceProviderClassName);
                    providers = new ArrayList<>();
                    providers.add(provider);
                    PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                    return provider;

                } catch (ClassNotFoundException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
                } catch (InstantiationException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
                } catch (IllegalAccessException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
                }
            } else {
                try {
                    providers = PersistenceProviderLoader.loadProviderModuleByName(configuredPersistenceProviderModule);
                    PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                    PersistenceProvider provider = getProviderByName(pu, providers);
                    if (provider != null) {
                        return provider;
                    }
                } catch (ModuleLoadException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, configuredPersistenceProviderModule, persistenceProviderClassName);
                }
            }
        }

        // try to determine the static module name based on the persistence provider class name
        String providerNameDerivedFromClassName = Configuration.getProviderModuleNameFromProviderClassName(persistenceProviderClassName);

        // see if the providerNameDerivedFromClassName has been loaded yet
        PersistenceProvider provider = getProviderByName(pu);

        // if we haven't loaded the provider yet, try loading now
        if (provider == null && providerNameDerivedFromClassName != null) {
            try {
                List<PersistenceProvider> providers = PersistenceProviderLoader.loadProviderModuleByName(providerNameDerivedFromClassName);
                PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                provider = getProviderByName(pu, providers);
            } catch (ModuleLoadException e) {
                throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, providerNameDerivedFromClassName, persistenceProviderClassName);
            }
        }

        if (provider == null)
            throw JpaLogger.ROOT_LOGGER.persistenceProviderNotFound(persistenceProviderClassName);

        return provider;
    }
private static PersistenceProvider lookupProvider(
            PersistenceUnitMetadata pu,
            PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder,
            DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {

        /**
         * check if the deployment is already associated with the specified persistence provider
         */
        Map<String, PersistenceProvider> providerMap = persistenceProviderDeploymentHolder != null ?
                persistenceProviderDeploymentHolder.getProviders() : null;
        if (providerMap != null) {
            synchronized (providerMap) {
                if(providerMap.containsKey(pu.getPersistenceProviderClassName())){
                    ROOT_LOGGER.tracef("deployment %s is using %s", deploymentUnit.getName(), pu.getPersistenceProviderClassName());
                    return providerMap.get(pu.getPersistenceProviderClassName());
                }
            }
        }

        String configuredPersistenceProviderModule = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
        String persistenceProviderClassName = pu.getPersistenceProviderClassName();

        if (persistenceProviderClassName == null) {
            persistenceProviderClassName = Configuration.PROVIDER_CLASS_DEFAULT;
        }

        /**
         * locate persistence provider in specified static module
         */
        if (configuredPersistenceProviderModule != null) {
            List<PersistenceProvider> providers;
            if (Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED.equals(configuredPersistenceProviderModule)) {
                try {
                    // load the persistence provider from the application deployment
                    final ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
                    PersistenceProvider provider = PersistenceProviderLoader.loadProviderFromDeployment(classLoader, persistenceProviderClassName);
                    providers = new ArrayList<>();
                    providers.add(provider);
                    PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                    return provider;

                } catch (ClassNotFoundException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
                } catch (InstantiationException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
                } catch (IllegalAccessException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
                }
            } else {
                try {
                    providers = PersistenceProviderLoader.loadProviderModuleByName(configuredPersistenceProviderModule);
                    PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                    PersistenceProvider provider = getProviderByName(pu, providers);
                    if (provider != null) {
                        return provider;
                    }
                } catch (ModuleLoadException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, configuredPersistenceProviderModule, persistenceProviderClassName);
                }
            }
        }

        // try to determine the static module name based on the persistence provider class name
        String providerNameDerivedFromClassName = Configuration.getProviderModuleNameFromProviderClassName(persistenceProviderClassName);

        // see if the providerNameDerivedFromClassName has been loaded yet
        PersistenceProvider provider = getProviderByName(pu);

        // if we haven't loaded the provider yet, try loading now
        if (provider == null && providerNameDerivedFromClassName != null) {
            try {
                List<PersistenceProvider> providers = PersistenceProviderLoader.loadProviderModuleByName(providerNameDerivedFromClassName);
                PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                provider = getProviderByName(pu, providers);
            } catch (ModuleLoadException e) {
                throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, providerNameDerivedFromClassName, persistenceProviderClassName);
            }
        }

        if (provider == null)
            throw JpaLogger.ROOT_LOGGER.persistenceProviderNotFound(persistenceProviderClassName);

        return provider;
    }
private static PersistenceProvider lookupProvider ( PersistenceUnitMetadata pu , PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder , DeploymentUnit deploymentUnit ) throws DeploymentUnitProcessingException { /**
         * check if the deployment is already associated with the specified persistence provider
         */ Map < String , PersistenceProvider > providerMap = persistenceProviderDeploymentHolder != null ? persistenceProviderDeploymentHolder . getProviders ( ) : null ; if ( providerMap != null ) { synchronized ( providerMap ) { if ( providerMap . containsKey ( pu . getPersistenceProviderClassName ( ) ) ) { ROOT_LOGGER . tracef ( "deployment %s is using %s" , deploymentUnit . getName ( ) , pu . getPersistenceProviderClassName ( ) ) ; return providerMap . get ( pu . getPersistenceProviderClassName ( ) ) ; } } } String configuredPersistenceProviderModule = pu . getProperties ( ) . getProperty ( Configuration . PROVIDER_MODULE ) ; String persistenceProviderClassName = pu . getPersistenceProviderClassName ( ) ; if ( persistenceProviderClassName == null ) { persistenceProviderClassName = Configuration . PROVIDER_CLASS_DEFAULT ; } /**
         * locate persistence provider in specified static module
         */ if ( configuredPersistenceProviderModule != null ) { List < PersistenceProvider > providers ; if ( Configuration . PROVIDER_MODULE_APPLICATION_SUPPLIED . equals ( configuredPersistenceProviderModule ) ) { try { // load the persistence provider from the application deployment final ModuleClassLoader classLoader = deploymentUnit . getAttachment ( Attachments . MODULE ) . getClassLoader ( ) ; PersistenceProvider provider = PersistenceProviderLoader . loadProviderFromDeployment ( classLoader , persistenceProviderClassName ) ; providers = new ArrayList <> ( ) ; providers . add ( provider ) ; PersistenceProviderDeploymentHolder . savePersistenceProviderInDeploymentUnit ( deploymentUnit , providers , null ) ; return provider ; } catch ( ClassNotFoundException e ) { throw JpaLogger . ROOT_LOGGER . cannotDeployApp ( e , persistenceProviderClassName ) ; } catch ( InstantiationException e ) { throw JpaLogger . ROOT_LOGGER . cannotDeployApp ( e , persistenceProviderClassName ) ; } catch ( IllegalAccessException e ) { throw JpaLogger . ROOT_LOGGER . cannotDeployApp ( e , persistenceProviderClassName ) ; } } else { try { providers = PersistenceProviderLoader . loadProviderModuleByName ( configuredPersistenceProviderModule ) ; PersistenceProviderDeploymentHolder . savePersistenceProviderInDeploymentUnit ( deploymentUnit , providers , null ) ; PersistenceProvider provider = getProviderByName ( pu , providers ) ; if ( provider != null ) { return provider ; } } catch ( ModuleLoadException e ) { throw JpaLogger . ROOT_LOGGER . cannotLoadPersistenceProviderModule ( e , configuredPersistenceProviderModule , persistenceProviderClassName ) ; } } } // try to determine the static module name based on the persistence provider class name String providerNameDerivedFromClassName = Configuration . getProviderModuleNameFromProviderClassName ( persistenceProviderClassName ) ; // see if the providerNameDerivedFromClassName has been loaded yet PersistenceProvider provider = getProviderByName ( pu ) ; // if we haven't loaded the provider yet, try loading now if ( provider == null && providerNameDerivedFromClassName != null ) { try { List < PersistenceProvider > providers = PersistenceProviderLoader . loadProviderModuleByName ( providerNameDerivedFromClassName ) ; PersistenceProviderDeploymentHolder . savePersistenceProviderInDeploymentUnit ( deploymentUnit , providers , null ) ; provider = getProviderByName ( pu , providers ) ; } catch ( ModuleLoadException e ) { throw JpaLogger . ROOT_LOGGER . cannotLoadPersistenceProviderModule ( e , providerNameDerivedFromClassName , persistenceProviderClassName ) ; } } if ( provider == null ) throw JpaLogger . ROOT_LOGGER . persistenceProviderNotFound ( persistenceProviderClassName ) ; return provider ; }
Look up the persistence provider


@param pu
@param deploymentUnit
@return
Look up the persistence provider