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