/**
   * 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;
  }
 /**
  * Create EE container entity manager factory
  *
  * @return EntityManagerFactory
  */
 private EntityManagerFactory createContainerEntityManagerFactory() {
   persistenceProviderAdaptor.beforeCreateContainerEntityManagerFactory(pu);
   try {
     return persistenceProvider.createContainerEntityManagerFactory(pu, properties.getValue());
   } finally {
     try {
       persistenceProviderAdaptor.afterCreateContainerEntityManagerFactory(pu);
     } finally {
       pu.setAnnotationIndex(
           null); // close reference to Annotation Index (only needed during call to
                  // createContainerEntityManagerFactory)
       // This is needed if the datasource is restarted
       // pu.setTempClassLoaderFactory(null);    // close reference to temp classloader factory
       // (only needed during call to createEntityManagerFactory)
     }
   }
 }
Example #3
0
  @Override
  public void initialize(ExtensionContext context) {
    SubsystemRegistration registration =
        context.registerSubsystem(
            SUBSYSTEM_NAME, MANAGEMENT_API_MAJOR_VERSION, MANAGEMENT_API_MINOR_VERSION);
    final ManagementResourceRegistration nodeRegistration =
        registration.registerSubsystemModel(DESCRIPTION);
    PersistenceUnitRegistryImpl persistenceUnitRegistry = new PersistenceUnitRegistryImpl();
    JPASubSystemAdd subsystemAdd = new JPASubSystemAdd(persistenceUnitRegistry);
    nodeRegistration.registerOperationHandler(
        JPASubSystemAdd.OPERATION_NAME, subsystemAdd, subsystemAdd, false);
    nodeRegistration.registerOperationHandler(
        JPASubSystemRemove.OPERATION_NAME,
        JPASubSystemRemove.INSTANCE,
        JPASubSystemRemove.INSTANCE,
        false);
    nodeRegistration.registerOperationHandler(
        DESCRIBE,
        JPADescribeHandler.INSTANCE,
        JPADescribeHandler.INSTANCE,
        false,
        OperationEntry.EntryType.PRIVATE);
    nodeRegistration.registerReadWriteAttribute(
        CommonAttributes.DEFAULT_DATASOURCE,
        null,
        JPADefaultDatasourceWriteHandler.INSTANCE,
        Storage.CONFIGURATION);
    registration.registerXMLElementWriter(parser);

    try {
      PersistenceProviderLoader.loadDefaultProvider();
    } catch (ModuleLoadException e) {
      JPA_LOGGER.errorPreloadingDefaultProvider(e);
    }

    try {
      // load the default persistence provider adaptor
      PersistenceProviderAdaptor provider =
          PersistenceProviderAdaptorLoader.loadPersistenceAdapterModule(
              Configuration.ADAPTER_MODULE_DEFAULT);
      final ManagementAdaptor managementAdaptor = provider.getManagementAdaptor();
      if (managementAdaptor != null && context.isRuntimeOnlyRegistrationValid()) {
        DescriptionProvider JPA_SUBSYSTEM =
            new DescriptionProvider() {
              @Override
              public ModelNode getModelDescription(Locale locale) {
                ModelNode subsystem = new ModelNode();
                subsystem
                    .get(org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION)
                    .set("Runtime information about JPA use in the deployment.");
                subsystem.get(ATTRIBUTES).setEmptyObject();
                subsystem.get("operations"); // placeholder

                subsystem
                    .get(
                        CHILDREN,
                        managementAdaptor.getIdentificationLabel(),
                        org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION)
                    .set(
                        "Runtime information about "
                            + managementAdaptor.getIdentificationLabel()
                            + " use in the deployment.");

                subsystem
                    .get(CHILDREN, managementAdaptor.getIdentificationLabel(), MIN_OCCURS)
                    .set(0);
                return subsystem;
              }
            };

        final ManagementResourceRegistration jpaSubsystemDeployments =
            registration.registerDeploymentModel(JPA_SUBSYSTEM);

        managementAdaptor.register(jpaSubsystemDeployments, persistenceUnitRegistry);
      }
    } catch (ModuleLoadException e) {
      JPA_LOGGER.errorPreloadingDefaultProviderAdaptor(e);
    }
  }