/**
   * Loads/caches the persistence provider adapter
   *
   * @param adapterModule may specify the adapter module name (can be null to use noop provider)
   * @return the persistence provider adaptor for the provider class
   * @throws ModuleLoadException
   */
  public static PersistenceProviderAdaptor loadPersistenceAdapterModule(String adapterModule)
      throws ModuleLoadException {
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();

    if (adapterModule == null) {
      return noopAdaptor;
    }

    PersistenceProviderAdaptor persistenceProviderAdaptor = null;

    Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(adapterModule));
    final ServiceLoader<PersistenceProviderAdaptor> serviceLoader =
        module.loadService(PersistenceProviderAdaptor.class);
    if (serviceLoader != null) {
      for (PersistenceProviderAdaptor adaptor : serviceLoader) {
        if (persistenceProviderAdaptor != null) {
          throw MESSAGES.multipleAdapters(adapterModule);
        }
        persistenceProviderAdaptor = adaptor;
        JPA_LOGGER.debugf("loaded persistence provider adapter %s", adapterModule);
      }
      if (persistenceProviderAdaptor != null) {
        persistenceProviderAdaptor.injectJtaManager(JtaManagerImpl.getInstance());
      }
    }
    return persistenceProviderAdaptor;
  }
  /**
   * 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(
      PersistenceProvider persistenceProvider) {
    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 MESSAGES.classloaderHasMultipleAdapters(
              persistenceProvider.getClass().getClassLoader().toString());
        }
        persistenceProviderAdaptor = adaptor;
        JPA_LOGGER.debugf(
            "loaded persistence provider adapter %s from classloader %s",
            persistenceProviderAdaptor.getClass().getName(),
            persistenceProvider.getClass().getClassLoader().toString());
      }
      if (persistenceProviderAdaptor != null) {
        persistenceProviderAdaptor.injectJtaManager(JtaManagerImpl.getInstance());
      }
    }

    return persistenceProviderAdaptor == null ? noopAdaptor : persistenceProviderAdaptor;
  }