@SuppressWarnings("deprecation")
 @Override
 public void addProviderProperties(Map properties, PersistenceUnitMetadata pu) {
   putPropertyIfAbsent(pu, properties, Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
   putPropertyIfAbsent(
       pu,
       properties,
       org.hibernate.ejb.AvailableSettings.SCANNER,
       HibernateAnnotationScanner.class.getName());
   properties.put(AvailableSettings.APP_CLASSLOADER, pu.getClassLoader());
   putPropertyIfAbsent(pu, properties, AvailableSettings.JTA_PLATFORM, appServerJtaPlatform);
   properties.remove(
       AvailableSettings
           .TRANSACTION_MANAGER_STRATEGY); // remove legacy way of specifying TX manager (conflicts
   // with JTA_PLATFORM)
   putPropertyIfAbsent(
       pu,
       properties,
       org.hibernate.ejb.AvailableSettings.ENTITY_MANAGER_FACTORY_NAME,
       pu.getScopedPersistenceUnitName());
   putPropertyIfAbsent(
       pu, properties, AvailableSettings.SESSION_FACTORY_NAME, pu.getScopedPersistenceUnitName());
   if (!pu.getProperties().containsKey(AvailableSettings.SESSION_FACTORY_NAME)) {
     putPropertyIfAbsent(
         pu, properties, AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, Boolean.FALSE);
   }
 }
  /**
   * determine if management console can display the second level cache entries
   *
   * @param pu
   * @return false if a custom AvailableSettings.CACHE_REGION_PREFIX property is specified. true if
   *     the scoped persistence unit name is used to prefix cache entries.
   */
  @Override
  public boolean doesScopedPersistenceUnitNameIdentifyCacheRegionName(PersistenceUnitMetadata pu) {
    String cacheRegionPrefix =
        pu.getProperties().getProperty(AvailableSettings.CACHE_REGION_PREFIX);

    return cacheRegionPrefix == null || cacheRegionPrefix.equals(pu.getScopedPersistenceUnitName());
  }
 @Override
 public void stop(StopContext context) {
   JPA_LOGGER.stoppingService("Persistence Unit", pu.getScopedPersistenceUnitName());
   if (entityManagerFactory != null) {
     entityManagerFactory.close();
     entityManagerFactory = null;
   }
 }
 @Override
 public void start(StartContext context) throws StartException {
   try {
     JPA_LOGGER.startingService("Persistence Unit", pu.getScopedPersistenceUnitName());
     pu.setJtaDataSource(jtaDataSource.getOptionalValue());
     pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
     this.entityManagerFactory = createContainerEntityManagerFactory();
   } finally {
     pu.setTempClassLoaderFactory(
         null); // release the temp classloader factory (only needed when creating the EMF)
   }
 }
 @Override
 public void stop(StopContext context) {
   JPA_LOGGER.stoppingService("Persistence Unit", pu.getScopedPersistenceUnitName());
   if (entityManagerFactory != null) {
     WritableServiceBasedNamingStore.pushOwner(
         context.getController().getServiceContainer().subTarget());
     try {
       entityManagerFactory.close();
     } finally {
       entityManagerFactory = null;
       pu.setTempClassLoaderFactory(null);
       WritableServiceBasedNamingStore.popOwner();
     }
   }
 }
Пример #6
0
 private InjectionSource getPersistenceUnitBindingSource(
     final DeploymentUnit deploymentUnit, final String unitName)
     throws DeploymentUnitProcessingException {
   final String searchName;
   if (isEmpty(unitName)) {
     searchName = null;
   } else {
     searchName = unitName;
   }
   final PersistenceUnitMetadata pu =
       PersistenceUnitSearch.resolvePersistenceUnitSupplier(deploymentUnit, searchName);
   String scopedPuName = pu.getScopedPersistenceUnitName();
   ServiceName puServiceName = getPuServiceName(scopedPuName);
   return new PersistenceUnitInjectionSource(
       puServiceName, deploymentUnit, EntityManagerFactory.class.getName(), pu);
 }
 @Override
 public void start(StartContext context) throws StartException {
   try {
     JPA_LOGGER.startingService("Persistence Unit", pu.getScopedPersistenceUnitName());
     pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader));
     pu.setJtaDataSource(jtaDataSource.getOptionalValue());
     pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
     WritableServiceBasedNamingStore.pushOwner(
         context.getController().getServiceContainer().subTarget());
     this.entityManagerFactory = createContainerEntityManagerFactory();
   } finally {
     pu.setTempClassLoaderFactory(
         null); // release the temp classloader factory (only needed when creating the EMF)
     WritableServiceBasedNamingStore.popOwner();
   }
 }
Пример #8
0
 private InjectionSource getPersistenceContextBindingSource(
     final DeploymentUnit deploymentUnit,
     final String unitName,
     PersistenceContextType type,
     Map properties)
     throws DeploymentUnitProcessingException {
   PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, unitName);
   String scopedPuName = pu.getScopedPersistenceUnitName();
   ServiceName puServiceName = getPuServiceName(scopedPuName);
   return new PersistenceContextInjectionSource(
       type,
       properties,
       puServiceName,
       deploymentUnit,
       scopedPuName,
       EntityManager.class.getName(),
       pu);
 }
  private InjectionSource getBindingSource(
      final DeploymentUnit deploymentUnit,
      final AnnotationInstance annotation,
      String injectionTypeName,
      final EEModuleClassDescription classDescription)
      throws DeploymentUnitProcessingException {
    PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, annotation, classDescription);
    if (pu == null) {
      return null;
    }
    String scopedPuName = pu.getScopedPersistenceUnitName();
    ServiceName puServiceName = getPuServiceName(scopedPuName);
    if (isPersistenceContext(annotation)) {
      if (pu.getTransactionType() == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
        classDescription.setInvalid(MESSAGES.cannotInjectResourceLocalEntityManager());
        return null;
      }
      AnnotationValue pcType = annotation.value("type");
      PersistenceContextType type =
          (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString()))
              ? PersistenceContextType.TRANSACTION
              : PersistenceContextType.EXTENDED;

      Map properties;
      AnnotationValue value = annotation.value("properties");
      AnnotationInstance[] props = value != null ? value.asNestedArray() : null;
      if (props != null) {
        properties = new HashMap();
        for (int source = 0; source < props.length; source++) {
          properties.put(props[source].value("name"), props[source].value("value"));
        }
      } else {
        properties = null;
      }

      return new PersistenceContextInjectionSource(
          type, properties, puServiceName, deploymentUnit, scopedPuName, injectionTypeName, pu);
    } else {
      return new PersistenceUnitInjectionSource(
          puServiceName, deploymentUnit, injectionTypeName, pu);
    }
  }
 /**
  * Returns the Persistence Unit service name used for creation or lookup. The service name
  * contains the unique fully scoped persistence unit name
  *
  * @param pu persistence unit definition
  * @return
  */
 public static ServiceName getPUServiceName(PersistenceUnitMetadata pu) {
   return JPAServiceNames.getPUServiceName(pu.getScopedPersistenceUnitName());
 }
 @Override
 public String getScopedPersistenceUnitName() {
   return pu.getScopedPersistenceUnitName();
 }