Search in sources :

Example 11 with ConfigurationService

use of org.hibernate.engine.config.spi.ConfigurationService in project hibernate-orm by hibernate.

the class Dialect method resolveLegacyLimitHandlerBehavior.

private void resolveLegacyLimitHandlerBehavior(ServiceRegistry serviceRegistry) {
    // HHH-11194
    // Temporary solution to set whether legacy limit handler behavior should be used.
    final ConfigurationService configurationService = serviceRegistry.getService(ConfigurationService.class);
    legacyLimitHandlerBehavior = configurationService.getSetting(AvailableSettings.USE_LEGACY_LIMIT_HANDLERS, StandardConverters.BOOLEAN, false);
}
Also used : ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService)

Example 12 with ConfigurationService

use of org.hibernate.engine.config.spi.ConfigurationService in project hibernate-orm by hibernate.

the class TypeSafeActivator method applyCallbackListeners.

@SuppressWarnings({ "UnusedDeclaration" })
public static void applyCallbackListeners(ValidatorFactory validatorFactory, ActivationContext activationContext) {
    final Set<ValidationMode> modes = activationContext.getValidationModes();
    if (!(modes.contains(ValidationMode.CALLBACK) || modes.contains(ValidationMode.AUTO))) {
        return;
    }
    final ConfigurationService cfgService = activationContext.getServiceRegistry().getService(ConfigurationService.class);
    final ClassLoaderService classLoaderService = activationContext.getServiceRegistry().getService(ClassLoaderService.class);
    // asks for it
    if (cfgService.getSettings().get(Environment.CHECK_NULLABILITY) == null) {
        activationContext.getSessionFactory().getSessionFactoryOptions().setCheckNullability(false);
    }
    final BeanValidationEventListener listener = new BeanValidationEventListener(validatorFactory, cfgService.getSettings(), classLoaderService);
    final EventListenerRegistry listenerRegistry = activationContext.getServiceRegistry().getService(EventListenerRegistry.class);
    listenerRegistry.addDuplicationStrategy(DuplicationStrategyImpl.INSTANCE);
    listenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
    listenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
    listenerRegistry.appendListeners(EventType.PRE_DELETE, listener);
    listener.initialize(cfgService.getSettings(), classLoaderService);
}
Also used : ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 13 with ConfigurationService

use of org.hibernate.engine.config.spi.ConfigurationService in project hibernate-orm by hibernate.

the class PersistentTableBulkIdStrategy method initialize.

@Override
protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) {
    final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry();
    final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
    final ConfigurationService configService = serviceRegistry.getService(ConfigurationService.class);
    final String catalogName = configService.getSetting(CATALOG, StandardConverters.STRING, configService.getSetting(AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING));
    final String schemaName = configService.getSetting(SCHEMA, StandardConverters.STRING, configService.getSetting(AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING));
    this.catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(catalogName);
    this.schema = jdbcEnvironment.getIdentifierHelper().toIdentifier(schemaName);
    this.dropIdTables = configService.getSetting(DROP_ID_TABLES, StandardConverters.BOOLEAN, false);
}
Also used : ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 14 with ConfigurationService

use of org.hibernate.engine.config.spi.ConfigurationService in project hibernate-orm by hibernate.

the class SimpleValue method createIdentifierGenerator.

@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();
    //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;
}
Also used : Iterator(java.util.Iterator) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Properties(java.util.Properties)

Example 15 with ConfigurationService

use of org.hibernate.engine.config.spi.ConfigurationService in project hibernate-orm by hibernate.

the class CfgXmlParsingTest method testCfgXmlWithSchemaLocation.

@Test
public void testCfgXmlWithSchemaLocation() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("org/hibernate/test/boot/cfgXml/hibernate.cfg.xml").build();
    try {
        final ConfigurationService cs = ssr.getService(ConfigurationService.class);
        // augmented form
        assertNotNull(cs.getSettings().get("hibernate.cache.provider_class"));
        // original form
        assertNotNull(cs.getSettings().get("cache.provider_class"));
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)15 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)4 Properties (java.util.Properties)3 HibernateException (org.hibernate.HibernateException)2 ReflectionManager (org.hibernate.annotations.common.reflection.ReflectionManager)2 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)2 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)2 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConnectionFinder (org.geolatte.geom.codec.db.oracle.ConnectionFinder)1 OracleJDBCTypeFactory (org.geolatte.geom.codec.db.oracle.OracleJDBCTypeFactory)1 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)1 SessionFactoryBuilderImpl (org.hibernate.boot.internal.SessionFactoryBuilderImpl)1 SessionFactoryOptionsImpl (org.hibernate.boot.internal.SessionFactoryOptionsImpl)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1