Search in sources :

Example 6 with JpaVendorAdapter

use of org.springframework.orm.jpa.JpaVendorAdapter in project Backend by FredBoat.

the class DatabaseConfiguration method databaseManager.

@Bean
public DatabaseManager databaseManager(HibernateStatisticsCollector hibernateStats, PrometheusMetricsTrackerFactory hikariStats) {
    DatabaseManager databaseManager = new DatabaseManager(hibernateStats, hikariStats, this.dbConf.getHikariPoolSize(), "Quarterdeck", true, this.dbConf.getMainJdbcUrl(), this.dbConf.getCacheJdbcUrl(), (puName, dataSource, properties, entityPackages) -> {
        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setDataSource(dataSource);
        emfb.setPackagesToScan(entityPackages.toArray(new String[entityPackages.size()]));
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        emfb.setJpaVendorAdapter(vendorAdapter);
        emfb.setJpaProperties(properties);
        // initiate creation of the native emf
        emfb.afterPropertiesSet();
        return emfb.getNativeEntityManagerFactory();
    });
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        if (databaseManager.isCacheConnBuilt()) {
            DatabaseConnection cacheDbConn = databaseManager.getCacheDbConn();
            if (cacheDbConn != null) {
                cacheDbConn.shutdown();
            }
        }
        if (databaseManager.isMainConnBuilt()) {
            databaseManager.getMainDbConn().shutdown();
        }
    }, "databasemanager-shutdown-hook"));
    return databaseManager;
}
Also used : DatabaseManager(com.fredboat.backend.quarterdeck.db.DatabaseManager) JpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) DatabaseConnection(space.npstr.sqlsauce.DatabaseConnection) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 7 with JpaVendorAdapter

use of org.springframework.orm.jpa.JpaVendorAdapter in project osms by malikov-yurii.

the class SpringDB method entityManagerFactory.

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan("com.malikov.**.domain");
    em.setJpaPropertyMap(ImmutableMap.of("hibernate.formal_sql", "false", "hibernate.use_sql_comments", "false"));
    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());
    return em;
}
Also used : JpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

JpaVendorAdapter (org.springframework.orm.jpa.JpaVendorAdapter)7 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)7 Bean (org.springframework.context.annotation.Bean)6 HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)6 DatabaseManager (com.fredboat.backend.quarterdeck.db.DatabaseManager)1 DataSourceBean (de.alpharogroup.springconfig.DataSourceBean)1 JdbcUrlBean (de.alpharogroup.springconfig.JdbcUrlBean)1 LocalSessionFactoryBean (org.springframework.orm.hibernate4.LocalSessionFactoryBean)1 JpaDialect (org.springframework.orm.jpa.JpaDialect)1 DatabaseConnection (space.npstr.sqlsauce.DatabaseConnection)1