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