public MappingDefaultsImpl(StandardServiceRegistry serviceRegistry) {
      final ConfigurationService configService =
          serviceRegistry.getService(ConfigurationService.class);

      this.implicitSchemaName =
          configService.getSetting(
              AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING, null);

      this.implicitCatalogName =
          configService.getSetting(
              AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING, null);

      this.implicitlyQuoteIdentifiers =
          configService.getSetting(
              AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, StandardConverters.BOOLEAN, false);

      this.implicitCacheAccessType =
          configService.getSetting(
              AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY,
              new ConfigurationService.Converter<AccessType>() {
                @Override
                public AccessType convert(Object value) {
                  return AccessType.fromExternalName(value.toString());
                }
              });
    }
  public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) {
    try {
      final ConfigurationService cfgService =
          serviceRegistry.getService(ConfigurationService.class);

      String factoryType =
          cfgService.getSetting(AvailableSettings.CACHE_REGION_FACTORY, StandardConverters.STRING);
      Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryType);
      InfinispanRegionFactory regionFactory;
      if (clazz == InfinispanRegionFactory.class) {
        regionFactory = new SingleNodeTestCase.TestInfinispanRegionFactory();
      } else {
        regionFactory = (InfinispanRegionFactory) clazz.newInstance();
      }

      final SessionFactoryOptionsImpl sessionFactoryOptions =
          new SessionFactoryOptionsImpl(
              new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl(
                  (StandardServiceRegistry) serviceRegistry));
      final Properties properties = toProperties(cfgService.getSettings());

      regionFactory.start(sessionFactoryOptions, properties);

      return regionFactory;
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
 private static Properties extractProperties(final ConfigurationService configurationService) {
   Properties props = new Properties();
   Set<Map.Entry> entrySet = configurationService.getSettings().entrySet();
   for (Map.Entry entry : entrySet) {
     final Object key = entry.getKey();
     if (key instanceof String) {
       props.put(key, entry.getValue());
     }
   }
   return props;
 }
    private ArrayList<MetadataSourceType> resolveInitialSourceProcessOrdering(
        ConfigurationService configService) {
      final ArrayList<MetadataSourceType> initialSelections = new ArrayList<MetadataSourceType>();

      final String sourceProcessOrderingSetting =
          configService.getSetting(
              AvailableSettings.ARTIFACT_PROCESSING_ORDER, StandardConverters.STRING);
      if (sourceProcessOrderingSetting != null) {
        final String[] orderChoices =
            StringHelper.split(",; ", sourceProcessOrderingSetting, false);
        initialSelections.addAll(
            CollectionHelper.<MetadataSourceType>arrayList(orderChoices.length));
        for (String orderChoice : orderChoices) {
          initialSelections.add(MetadataSourceType.parsePrecedence(orderChoice));
        }
      }
      if (initialSelections.isEmpty()) {
        initialSelections.add(MetadataSourceType.HBM);
        initialSelections.add(MetadataSourceType.CLASS);
      }

      return initialSelections;
    }
Beispiel #5
0
  @Override
  public IdentifierGenerator createIdentifierGenerator(
      IdentifierGeneratorFactory identifierGeneratorFactory,
      Dialect dialect,
      String defaultCatalog,
      String defaultSchema,
      RootClass rootClass)
      throws MappingException {

    if (identifierGenerator != null) {
      return identifierGenerator;
    }

    Properties params = new Properties();

    // if the hibernate-mapping did not specify a schema/catalog, use the defaults
    // specified by properties - but note that if the schema/catalog were specified
    // in hibernate-mapping, or as params, they will already be initialized and
    // will override the values set here (they are in identifierGeneratorProperties)
    if (defaultSchema != null) {
      params.setProperty(PersistentIdentifierGenerator.SCHEMA, defaultSchema);
    }
    if (defaultCatalog != null) {
      params.setProperty(PersistentIdentifierGenerator.CATALOG, defaultCatalog);
    }

    // pass the entity-name, if not a collection-id
    if (rootClass != null) {
      params.setProperty(IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName());
      params.setProperty(IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName());
    }

    // init the table here instead of earlier, so that we can get a quoted table name
    // TODO: would it be better to simply pass the qualified table name, instead of
    //      splitting it up into schema/catalog/table names
    String tableName = getTable().getQuotedName(dialect);
    params.setProperty(PersistentIdentifierGenerator.TABLE, tableName);

    // pass the column name (a generated id almost always has a single column)
    String columnName = ((Column) getColumnIterator().next()).getQuotedName(dialect);
    params.setProperty(PersistentIdentifierGenerator.PK, columnName);

    if (rootClass != null) {
      StringBuilder tables = new StringBuilder();
      Iterator iter = rootClass.getIdentityTables().iterator();
      while (iter.hasNext()) {
        Table table = (Table) iter.next();
        tables.append(table.getQuotedName(dialect));
        if (iter.hasNext()) {
          tables.append(", ");
        }
      }
      params.setProperty(PersistentIdentifierGenerator.TABLES, tables.toString());
    } else {
      params.setProperty(PersistentIdentifierGenerator.TABLES, tableName);
    }

    if (identifierGeneratorProperties != null) {
      params.putAll(identifierGeneratorProperties);
    }

    // TODO : we should pass along all settings once "config lifecycle" is hashed out...
    final ConfigurationService cs =
        metadata
            .getMetadataBuildingOptions()
            .getServiceRegistry()
            .getService(ConfigurationService.class);

    params.put(
        AvailableSettings.PREFER_POOLED_VALUES_LO,
        cs.getSetting(
            AvailableSettings.PREFER_POOLED_VALUES_LO, StandardConverters.BOOLEAN, false));
    if (cs.getSettings().get(AvailableSettings.PREFERRED_POOLED_OPTIMIZER) != null) {
      params.put(
          AvailableSettings.PREFERRED_POOLED_OPTIMIZER,
          cs.getSettings().get(AvailableSettings.PREFERRED_POOLED_OPTIMIZER));
    }

    identifierGeneratorFactory.setDialect(dialect);
    identifierGenerator =
        identifierGeneratorFactory.createIdentifierGenerator(
            identifierGeneratorStrategy, getType(), params);

    return identifierGenerator;
  }
    public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
      this.serviceRegistry = serviceRegistry;

      final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
      final ConfigurationService configService =
          serviceRegistry.getService(ConfigurationService.class);

      this.mappingDefaults = new MappingDefaultsImpl(serviceRegistry);

      //			jandexView = (IndexView) configService.getSettings().get( AvailableSettings.JANDEX_INDEX
      // );

      scanOptions =
          new StandardScanOptions(
              (String) configService.getSettings().get(AvailableSettings.SCANNER_DISCOVERY), false);
      // ScanEnvironment must be set explicitly
      scannerSetting = configService.getSettings().get(AvailableSettings.SCANNER);
      if (scannerSetting == null) {
        scannerSetting = configService.getSettings().get(AvailableSettings.SCANNER_DEPRECATED);
        if (scannerSetting != null) {
          DEPRECATION_LOGGER.logDeprecatedScannerSetting();
        }
      }
      archiveDescriptorFactory =
          strategySelector.resolveStrategy(
              ArchiveDescriptorFactory.class,
              configService.getSettings().get(AvailableSettings.SCANNER_ARCHIVE_INTERPRETER));

      multiTenancyStrategy =
          MultiTenancyStrategy.determineMultiTenancyStrategy(configService.getSettings());

      implicitDiscriminatorsForJoinedInheritanceSupported =
          configService.getSetting(
              AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
              StandardConverters.BOOLEAN,
              false);

      explicitDiscriminatorsForJoinedInheritanceSupported =
          !configService.getSetting(
              AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
              StandardConverters.BOOLEAN,
              false);

      implicitlyForceDiscriminatorInSelect =
          configService.getSetting(
              AvailableSettings.FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT,
              StandardConverters.BOOLEAN,
              false);

      sharedCacheMode =
          configService.getSetting(
              "javax.persistence.sharedCache.mode",
              new ConfigurationService.Converter<SharedCacheMode>() {
                @Override
                public SharedCacheMode convert(Object value) {
                  if (value == null) {
                    return null;
                  }

                  if (SharedCacheMode.class.isInstance(value)) {
                    return (SharedCacheMode) value;
                  }

                  return SharedCacheMode.valueOf(value.toString());
                }
              },
              SharedCacheMode.UNSPECIFIED);

      defaultCacheAccessType =
          configService.getSetting(
              AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY,
              new ConfigurationService.Converter<AccessType>() {
                @Override
                public AccessType convert(Object value) {
                  if (value == null) {
                    return null;
                  }

                  if (CacheConcurrencyStrategy.class.isInstance(value)) {
                    return ((CacheConcurrencyStrategy) value).toAccessType();
                  }

                  if (AccessType.class.isInstance(value)) {
                    return (AccessType) value;
                  }

                  return AccessType.fromExternalName(value.toString());
                }
              },
              // by default, see if the defined RegionFactory (if one) defines a default
              serviceRegistry.getService(RegionFactory.class) == null
                  ? null
                  : serviceRegistry.getService(RegionFactory.class).getDefaultAccessType());

      specjProprietarySyntaxEnabled =
          configService.getSetting(
              "hibernate.enable_specj_proprietary_syntax", StandardConverters.BOOLEAN, false);

      implicitNamingStrategy =
          strategySelector.resolveDefaultableStrategy(
              ImplicitNamingStrategy.class,
              configService.getSettings().get(AvailableSettings.IMPLICIT_NAMING_STRATEGY),
              ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

      physicalNamingStrategy =
          strategySelector.resolveDefaultableStrategy(
              PhysicalNamingStrategy.class,
              configService.getSettings().get(AvailableSettings.PHYSICAL_NAMING_STRATEGY),
              PhysicalNamingStrategyStandardImpl.INSTANCE);

      sourceProcessOrdering = resolveInitialSourceProcessOrdering(configService);

      final boolean useNewIdentifierGenerators =
          configService.getSetting(
              AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, StandardConverters.BOOLEAN, false);
      if (useNewIdentifierGenerators) {
        idGenerationTypeInterpreter.disableLegacyFallback();
      } else {
        idGenerationTypeInterpreter.enableLegacyFallback();
      }

      reflectionManager = generateDefaultReflectionManager();
    }
 @Override
 public String getProperty(String propertyName) {
   return configurationService.getSetting(
       propertyName, org.hibernate.engine.config.spi.StandardConverters.STRING);
 }