Search in sources :

Example 21 with LocalSessionFactoryBean

use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project midpoint by Evolveum.

the class TestSqlRepositoryBeanConfig method sessionFactory.

/*
     * This is working alternative to @Autowired private LocalSessionFactoryBean sessionFactory
     * with @PostConstruct init method that adds the properties. That solution didn't work, because
     * the properties are probably used to initialize the session before added.
     * This nicely reuses existing production config method and adds the properties before they
     * are read and reflected in the final setup.
     * (There is actually just one test that using the inspector - ObjectDeltaUpdaterTest.)
     */
@Bean
@Primary
public LocalSessionFactoryBean sessionFactory(DataSource dataSource, SqlRepositoryConfiguration configuration, MidPointImplicitNamingStrategy midPointImplicitNamingStrategy, MidPointPhysicalNamingStrategy midPointPhysicalNamingStrategy, EntityStateInterceptor entityStateInterceptor) {
    LocalSessionFactoryBean sessionFactory = new SqlRepositoryBeanConfig().sessionFactory(dataSource, configuration, midPointImplicitNamingStrategy, midPointPhysicalNamingStrategy, entityStateInterceptor);
    // These are only test-related changes regarding the session factory.
    Properties hibernateProperties = sessionFactory.getHibernateProperties();
    hibernateProperties.setProperty("hibernate.show_sql", "false");
    hibernateProperties.setProperty("hibernate.session_factory.statement_inspector", "com.evolveum.midpoint.repo.sql.testing.TestStatementInspector");
    return sessionFactory;
}
Also used : SqlRepositoryBeanConfig(com.evolveum.midpoint.repo.sql.SqlRepositoryBeanConfig) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) Properties(java.util.Properties) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean)

Aggregations

Bean (org.springframework.context.annotation.Bean)17 LocalSessionFactoryBean (org.springframework.orm.hibernate4.LocalSessionFactoryBean)12 LocalSessionFactoryBean (org.springframework.orm.hibernate5.LocalSessionFactoryBean)7 Properties (java.util.Properties)6 IOException (java.io.IOException)2 Resource (org.springframework.core.io.Resource)2 LocalSessionFactoryBean (org.springframework.orm.hibernate3.LocalSessionFactoryBean)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 SqlRepositoryBeanConfig (com.evolveum.midpoint.repo.sql.SqlRepositoryBeanConfig)1 DataSourcePropertiesBean (com.remswork.project.alice.bean.DataSourcePropertiesBean)1 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)1 FactoryBean (org.springframework.beans.factory.FactoryBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 DependsOn (org.springframework.context.annotation.DependsOn)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)1 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)1