Search in sources :

Example 1 with HibernateConfigurationValidator

use of com.peterphi.std.guice.hibernate.module.ext.HibernateConfigurationValidator in project stdlib by petergeneric.

the class HibernateModule method getHibernateConfiguration.

@Provides
@Singleton
public Configuration getHibernateConfiguration(GuiceConfig guiceConfig, @Named(GuiceProperties.HIBERNATE_PROPERTIES) String propertyFileName, HibernateObservingInterceptor interceptor) {
    final Properties properties = extractHibernateProperties(guiceConfig, propertyFileName);
    validateHibernateProperties(guiceConfig, properties);
    // Set up the hibernate Configuration
    Configuration config = new Configuration();
    // Set up the interceptor
    config.setInterceptor(interceptor.getInterceptor());
    config.addProperties(properties);
    configure(config);
    registerTypes(config);
    {
        ServiceLoader<HibernateConfigurationValidator> services = ServiceLoader.load(HibernateConfigurationValidator.class);
        final Iterator<HibernateConfigurationValidator> it = services.iterator();
        if (log.isTraceEnabled())
            log.trace("Evaluate HibernateConfigurationValidators. has at least one=" + it.hasNext());
        while (it.hasNext()) {
            final HibernateConfigurationValidator validator = it.next();
            if (log.isTraceEnabled())
                log.trace("Validating hibernate configuration with " + validator);
            // Have the validator check the hibernate/database configuration
            validator.validate(config, properties, guiceConfig);
        }
    }
    return config;
}
Also used : ServiceLoader(java.util.ServiceLoader) HibernateConfigurationValidator(com.peterphi.std.guice.hibernate.module.ext.HibernateConfigurationValidator) Configuration(org.hibernate.cfg.Configuration) Iterator(java.util.Iterator) Properties(java.util.Properties) GuiceProperties(com.peterphi.std.guice.apploader.GuiceProperties) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 GuiceProperties (com.peterphi.std.guice.apploader.GuiceProperties)1 HibernateConfigurationValidator (com.peterphi.std.guice.hibernate.module.ext.HibernateConfigurationValidator)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 ServiceLoader (java.util.ServiceLoader)1 Configuration (org.hibernate.cfg.Configuration)1