use of com.fredboat.backend.quarterdeck.db.DatabaseManager 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;
}
Aggregations