Search in sources :

Example 1 with SessionFactoryObserver

use of org.hibernate.SessionFactoryObserver in project hibernate-orm by hibernate.

the class EntityManagerFactoryBuilderImpl method populate.

protected void populate(SessionFactoryBuilder sfBuilder, StandardServiceRegistry ssr) {
    ((SessionFactoryBuilderImplementor) sfBuilder).markAsJpaBootstrap();
    final StrategySelector strategySelector = ssr.getService(StrategySelector.class);
    //		// Locate and apply the requested SessionFactory-level interceptor (if one)
    //		final Object sessionFactoryInterceptorSetting = configurationValues.remove( org.hibernate.cfg.AvailableSettings.INTERCEPTOR );
    //		if ( sessionFactoryInterceptorSetting != null ) {
    //			final Interceptor sessionFactoryInterceptor =
    //					strategySelector.resolveStrategy( Interceptor.class, sessionFactoryInterceptorSetting );
    //			sfBuilder.applyInterceptor( sessionFactoryInterceptor );
    //		}
    // will use user override value or default to false if not supplied to follow JPA spec.
    final boolean jtaTransactionAccessEnabled = readBooleanConfigurationValue(AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS);
    if (!jtaTransactionAccessEnabled) {
        ((SessionFactoryBuilderImplementor) sfBuilder).disableJtaTransactionAccess();
    }
    final boolean allowRefreshDetachedEntity = readBooleanConfigurationValue(org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY);
    if (!allowRefreshDetachedEntity) {
        ((SessionFactoryBuilderImplementor) sfBuilder).disableRefreshDetachedEntity();
    }
    // Locate and apply any requested SessionFactoryObserver
    final Object sessionFactoryObserverSetting = configurationValues.remove(AvailableSettings.SESSION_FACTORY_OBSERVER);
    if (sessionFactoryObserverSetting != null) {
        final SessionFactoryObserver suppliedSessionFactoryObserver = strategySelector.resolveStrategy(SessionFactoryObserver.class, sessionFactoryObserverSetting);
        sfBuilder.addSessionFactoryObservers(suppliedSessionFactoryObserver);
    }
    sfBuilder.addSessionFactoryObservers(ServiceRegistryCloser.INSTANCE);
    sfBuilder.applyEntityNotFoundDelegate(JpaEntityNotFoundDelegate.INSTANCE);
    if (this.validatorFactory != null) {
        sfBuilder.applyValidatorFactory(validatorFactory);
    }
    if (this.cdiBeanManager != null) {
        sfBuilder.applyBeanManager(cdiBeanManager);
    }
}
Also used : SessionFactoryBuilderImplementor(org.hibernate.boot.spi.SessionFactoryBuilderImplementor) SessionFactoryObserver(org.hibernate.SessionFactoryObserver) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector)

Aggregations

SessionFactoryObserver (org.hibernate.SessionFactoryObserver)1 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)1 SessionFactoryBuilderImplementor (org.hibernate.boot.spi.SessionFactoryBuilderImplementor)1