Search in sources :

Example 6 with ConfigurationService

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

the class GlobalTemporaryTableBulkIdStrategy method initialize.

@Override
protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) {
    final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry();
    final ConfigurationService configService = serviceRegistry.getService(ConfigurationService.class);
    this.dropIdTables = configService.getSetting(DROP_ID_TABLES, StandardConverters.BOOLEAN, false);
}
Also used : ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 7 with ConfigurationService

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

the class SchemaManagementToolCoordinator method process.

public static void process(final Metadata metadata, final ServiceRegistry serviceRegistry, final Map configurationValues, DelayedDropRegistry delayedDropRegistry) {
    final ActionGrouping actions = ActionGrouping.interpret(configurationValues);
    if (actions.getDatabaseAction() == Action.NONE && actions.getScriptAction() == Action.NONE) {
        // no actions specified
        log.debug("No actions specified; doing nothing");
        return;
    }
    final SchemaManagementTool tool = serviceRegistry.getService(SchemaManagementTool.class);
    final ConfigurationService configService = serviceRegistry.getService(ConfigurationService.class);
    boolean haltOnError = configService.getSetting(AvailableSettings.HBM2DDL_HALT_ON_ERROR, Boolean.class, false);
    final ExecutionOptions executionOptions = buildExecutionOptions(configurationValues, haltOnError ? ExceptionHandlerHaltImpl.INSTANCE : ExceptionHandlerLoggedImpl.INSTANCE);
    performScriptAction(actions.getScriptAction(), metadata, tool, serviceRegistry, executionOptions);
    performDatabaseAction(actions.getDatabaseAction(), metadata, tool, serviceRegistry, executionOptions);
    if (actions.getDatabaseAction() == Action.CREATE_DROP) {
        //noinspection unchecked
        delayedDropRegistry.registerOnCloseAction(tool.getSchemaDropper(configurationValues).buildDelayedAction(metadata, executionOptions, buildDatabaseTargetDescriptor(configurationValues, DropSettingSelector.INSTANCE, serviceRegistry)));
    }
}
Also used : ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService)

Example 8 with ConfigurationService

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

the class JpaIntegrator method integrate.

/**
	 * Perform integration.
	 *
	 * @param metadata The "compiled" representation of the mapping information
	 * @param sessionFactory The session factory being created
	 * @param serviceRegistry The session factory's service registry
	 */
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    // first, register the JPA-specific persist cascade style
    try {
        oldPersistCascadeStyle = CascadeStyles.getCascadeStyle("persist");
    } catch (Exception e) {
    }
    CascadeStyles.registerCascadeStyle("persist", new PersistCascadeStyle());
    // then prepare listeners
    final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    eventListenerRegistry.addDuplicationStrategy(JPA_DUPLICATION_STRATEGY);
    // op listeners
    eventListenerRegistry.setListeners(EventType.AUTO_FLUSH, JpaAutoFlushEventListener.INSTANCE);
    eventListenerRegistry.setListeners(EventType.DELETE, new JpaDeleteEventListener());
    eventListenerRegistry.setListeners(EventType.FLUSH_ENTITY, new JpaFlushEntityEventListener());
    eventListenerRegistry.setListeners(EventType.FLUSH, JpaFlushEventListener.INSTANCE);
    eventListenerRegistry.setListeners(EventType.MERGE, new JpaMergeEventListener());
    eventListenerRegistry.setListeners(EventType.PERSIST, new JpaPersistEventListener());
    eventListenerRegistry.setListeners(EventType.PERSIST_ONFLUSH, new JpaPersistOnFlushEventListener());
    eventListenerRegistry.setListeners(EventType.SAVE, new JpaSaveEventListener());
    eventListenerRegistry.setListeners(EventType.SAVE_UPDATE, new JpaSaveOrUpdateEventListener());
    // post op listeners
    eventListenerRegistry.prependListeners(EventType.POST_DELETE, new JpaPostDeleteEventListener());
    eventListenerRegistry.prependListeners(EventType.POST_INSERT, new JpaPostInsertEventListener());
    eventListenerRegistry.prependListeners(EventType.POST_LOAD, new JpaPostLoadEventListener());
    eventListenerRegistry.prependListeners(EventType.POST_UPDATE, new JpaPostUpdateEventListener());
    final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
    for (Map.Entry entry : ((Map<?, ?>) cfgService.getSettings()).entrySet()) {
        if (!String.class.isInstance(entry.getKey())) {
            continue;
        }
        final String propertyName = (String) entry.getKey();
        if (!propertyName.startsWith(AvailableSettings.EVENT_LISTENER_PREFIX)) {
            continue;
        }
        final String eventTypeName = propertyName.substring(AvailableSettings.EVENT_LISTENER_PREFIX.length() + 1);
        final EventType eventType = EventType.resolveEventTypeByName(eventTypeName);
        final EventListenerGroup eventListenerGroup = eventListenerRegistry.getEventListenerGroup(eventType);
        for (String listenerImpl : ((String) entry.getValue()).split(" ,")) {
            eventListenerGroup.appendListener(instantiate(listenerImpl, serviceRegistry));
        }
    }
    // handle JPA "entity listener classes"...
    final ReflectionManager reflectionManager = ((MetadataImpl) metadata).getMetadataBuildingOptions().getReflectionManager();
    this.callbackRegistry = new CallbackRegistryImpl();
    this.jpaListenerFactory = ListenerFactoryBuilder.buildListenerFactory(sessionFactory.getSessionFactoryOptions());
    this.callbackBuilder = new CallbackBuilderLegacyImpl(jpaListenerFactory, reflectionManager);
    for (PersistentClass persistentClass : metadata.getEntityBindings()) {
        if (persistentClass.getClassName() == null) {
            // we can have non java class persisted by hibernate
            continue;
        }
        callbackBuilder.buildCallbacksForEntity(persistentClass.getClassName(), callbackRegistry);
    }
    for (EventType eventType : EventType.values()) {
        final EventListenerGroup eventListenerGroup = eventListenerRegistry.getEventListenerGroup(eventType);
        for (Object listener : eventListenerGroup.listeners()) {
            if (CallbackRegistryConsumer.class.isInstance(listener)) {
                ((CallbackRegistryConsumer) listener).injectCallbackRegistry(callbackRegistry);
            }
        }
    }
}
Also used : JpaPersistEventListener(org.hibernate.jpa.event.internal.core.JpaPersistEventListener) EventType(org.hibernate.event.spi.EventType) JpaPostInsertEventListener(org.hibernate.jpa.event.internal.core.JpaPostInsertEventListener) CallbackRegistryConsumer(org.hibernate.jpa.event.spi.jpa.CallbackRegistryConsumer) CallbackBuilderLegacyImpl(org.hibernate.jpa.event.internal.jpa.CallbackBuilderLegacyImpl) JpaPostDeleteEventListener(org.hibernate.jpa.event.internal.core.JpaPostDeleteEventListener) JpaPostLoadEventListener(org.hibernate.jpa.event.internal.core.JpaPostLoadEventListener) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) JpaSaveEventListener(org.hibernate.jpa.event.internal.core.JpaSaveEventListener) PersistentClass(org.hibernate.mapping.PersistentClass) EventListenerGroup(org.hibernate.event.service.spi.EventListenerGroup) ReflectionManager(org.hibernate.annotations.common.reflection.ReflectionManager) JpaDeleteEventListener(org.hibernate.jpa.event.internal.core.JpaDeleteEventListener) JpaSaveOrUpdateEventListener(org.hibernate.jpa.event.internal.core.JpaSaveOrUpdateEventListener) HibernateException(org.hibernate.HibernateException) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) JpaPersistOnFlushEventListener(org.hibernate.jpa.event.internal.core.JpaPersistOnFlushEventListener) CallbackRegistryImpl(org.hibernate.jpa.event.internal.jpa.CallbackRegistryImpl) JpaPostUpdateEventListener(org.hibernate.jpa.event.internal.core.JpaPostUpdateEventListener) JpaFlushEntityEventListener(org.hibernate.jpa.event.internal.core.JpaFlushEntityEventListener) JpaMergeEventListener(org.hibernate.jpa.event.internal.core.JpaMergeEventListener) Map(java.util.Map)

Example 9 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 10 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)

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