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);
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations