Search in sources :

Example 1 with ConfigurationService

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

the class CacheTestUtil method startRegionFactory.

public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) {
    try {
        final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
        final Properties properties = toProperties(cfgService.getSettings());
        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 TestInfinispanRegionFactory(properties);
        } else {
            if (InfinispanRegionFactory.class.isAssignableFrom(clazz)) {
                regionFactory = createRegionFactory(clazz, properties);
            } else {
                throw new IllegalArgumentException(clazz + " is not InfinispanRegionFactory");
            }
        }
        final SessionFactoryOptionsImpl sessionFactoryOptions = new SessionFactoryOptionsImpl(new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl((StandardServiceRegistry) serviceRegistry));
        regionFactory.start(sessionFactoryOptions, properties);
        return regionFactory;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) SessionFactoryOptionsImpl(org.hibernate.boot.internal.SessionFactoryOptionsImpl) Properties(java.util.Properties) TimeoutException(java.util.concurrent.TimeoutException) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) SessionFactoryBuilderImpl(org.hibernate.boot.internal.SessionFactoryBuilderImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 2 with ConfigurationService

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

the class EnversServiceImpl method doInitialize.

private void doInitialize(final MetadataImplementor metadata, final MappingCollector mappingCollector, ServiceRegistry serviceRegistry) {
    final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
    final Properties properties = new Properties();
    properties.putAll(cfgService.getSettings());
    this.globalConfiguration = new GlobalConfiguration(this, properties);
    final ReflectionManager reflectionManager = metadata.getMetadataBuildingOptions().getReflectionManager();
    final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration(globalConfiguration);
    final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(metadata, reflectionManager);
    EnversServiceImpl.this.auditEntitiesConfiguration = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName(), this);
    this.auditProcessManager = new AuditProcessManager(revInfoCfgResult.getRevisionInfoGenerator());
    this.revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
    this.revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
    this.modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
    this.auditStrategy = initializeAuditStrategy(auditEntitiesConfiguration.getAuditStrategyName(), revInfoCfgResult.getRevisionInfoClass(), revInfoCfgResult.getRevisionInfoTimestampData(), serviceRegistry);
    this.entitiesConfigurations = new EntitiesConfigurator().configure(metadata, serviceRegistry, reflectionManager, mappingCollector, globalConfiguration, auditEntitiesConfiguration, auditStrategy, revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
}
Also used : GlobalConfiguration(org.hibernate.envers.configuration.internal.GlobalConfiguration) AuditProcessManager(org.hibernate.envers.internal.synchronization.AuditProcessManager) EntitiesConfigurator(org.hibernate.envers.configuration.internal.EntitiesConfigurator) ReflectionManager(org.hibernate.annotations.common.reflection.ReflectionManager) RevisionInfoConfiguration(org.hibernate.envers.configuration.internal.RevisionInfoConfiguration) AuditEntitiesConfiguration(org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration) RevisionInfoConfigurationResult(org.hibernate.envers.configuration.internal.RevisionInfoConfigurationResult) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Properties(java.util.Properties)

Example 3 with ConfigurationService

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

the class BeanValidationIntegrator method integrate.

@Override
public void integrate(final Metadata metadata, final SessionFactoryImplementor sessionFactory, final SessionFactoryServiceRegistry serviceRegistry) {
    final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
    // IMPL NOTE : see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...
    final Set<ValidationMode> modes = ValidationMode.getModes(cfgService.getSettings().get(MODE_PROPERTY));
    if (modes.size() > 1) {
        LOG.multipleValidationModes(ValidationMode.loggable(modes));
    }
    if (modes.size() == 1 && modes.contains(ValidationMode.NONE)) {
        // we have nothing to do; just return
        return;
    }
    final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
    // see if the Bean Validation API is available on the classpath
    if (isBeanValidationApiAvailable(classLoaderService)) {
        // and if so, call out to the TypeSafeActivator
        try {
            final Class typeSafeActivatorClass = loadTypeSafeActivatorClass(classLoaderService);
            @SuppressWarnings("unchecked") final Method activateMethod = typeSafeActivatorClass.getMethod(ACTIVATE_METHOD_NAME, ActivationContext.class);
            final ActivationContext activationContext = new ActivationContext() {

                @Override
                public Set<ValidationMode> getValidationModes() {
                    return modes;
                }

                @Override
                public Metadata getMetadata() {
                    return metadata;
                }

                @Override
                public SessionFactoryImplementor getSessionFactory() {
                    return sessionFactory;
                }

                @Override
                public SessionFactoryServiceRegistry getServiceRegistry() {
                    return serviceRegistry;
                }
            };
            try {
                activateMethod.invoke(null, activationContext);
            } catch (InvocationTargetException e) {
                if (HibernateException.class.isInstance(e.getTargetException())) {
                    throw ((HibernateException) e.getTargetException());
                }
                throw new IntegrationException("Error activating Bean Validation integration", e.getTargetException());
            } catch (Exception e) {
                throw new IntegrationException("Error activating Bean Validation integration", e);
            }
        } catch (NoSuchMethodException e) {
            throw new HibernateException("Unable to locate TypeSafeActivator#activate method", e);
        }
    } else {
        // otherwise check the validation modes
        // todo : in many ways this duplicates thew checks done on the TypeSafeActivator when a ValidatorFactory could not be obtained
        validateMissingBeanValidationApi(modes);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 4 with ConfigurationService

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

the class TypeSafeActivator method applyRelationalConstraints.

@SuppressWarnings({ "unchecked", "UnusedParameters" })
private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) {
    final ConfigurationService cfgService = activationContext.getServiceRegistry().getService(ConfigurationService.class);
    if (!cfgService.getSetting(BeanValidationIntegrator.APPLY_CONSTRAINTS, StandardConverters.BOOLEAN, true)) {
        LOG.debug("Skipping application of relational constraints from legacy Hibernate Validator");
        return;
    }
    final Set<ValidationMode> modes = activationContext.getValidationModes();
    if (!(modes.contains(ValidationMode.DDL) || modes.contains(ValidationMode.AUTO))) {
        return;
    }
    applyRelationalConstraints(factory, activationContext.getMetadata().getEntityBindings(), cfgService.getSettings(), activationContext.getServiceRegistry().getService(JdbcServices.class).getDialect(), new ClassLoaderAccessImpl(null, activationContext.getServiceRegistry().getService(ClassLoaderService.class)));
}
Also used : ClassLoaderAccessImpl(org.hibernate.boot.internal.ClassLoaderAccessImpl) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService)

Example 5 with ConfigurationService

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

the class DefaultMergeEventListener method createEntityCopyObserver.

private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
    final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
    if (entityCopyObserverStrategy == null) {
        final ConfigurationService configurationService = serviceRegistry.getService(ConfigurationService.class);
        entityCopyObserverStrategy = configurationService.getSetting(AvailableSettings.MERGE_ENTITY_COPY_OBSERVER, new ConfigurationService.Converter<String>() {

            @Override
            public String convert(Object value) {
                return value.toString();
            }
        }, EntityCopyNotAllowedObserver.SHORT_NAME);
        LOG.debugf("EntityCopyObserver strategy: %s", entityCopyObserverStrategy);
    }
    final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
    return strategySelector.resolveStrategy(EntityCopyObserver.class, entityCopyObserverStrategy);
}
Also used : ServiceRegistry(org.hibernate.service.ServiceRegistry) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector)

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