Commit cb6cef58 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

possibilty for configuring other dialects added to config file

parent 3b603722
......@@ -21,6 +21,15 @@ public class ConfigurationHolder {
@Value("${database.password}")
private String dbPassword;
@Value("${database.driver:org.postgresql.Driver}")
private String dbDriver;
@Value("${database.dialect:org.hibernate.dialect.PostgreSQL95Dialect}")
private String dbDialect;
@Value("${database.connectionQuery:select 1}")
private String dbConnectionQuery;
public String getDbUri() {
return dbUri;
}
......@@ -44,4 +53,28 @@ public class ConfigurationHolder {
public void setDbPassword(String dbPassword) {
this.dbPassword = dbPassword;
}
public String getDbDriver() {
return dbDriver;
}
public void setDbDriver(String dbDriver) {
this.dbDriver = dbDriver;
}
public String getDbDialect() {
return dbDialect;
}
public void setDbDialect(String dbDialect) {
this.dbDialect = dbDialect;
}
public String getDbConnectionQuery() {
return dbConnectionQuery;
}
public void setDbConnectionQuery(String dbConnectionQuery) {
this.dbConnectionQuery = dbConnectionQuery;
}
}
......@@ -29,21 +29,21 @@ public class SpringPersistConfig {
@Bean(destroyMethod = "close")
public HikariDataSource dataSource(ConfigurationHolder config) {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setDriverClassName(config.getDbDriver());
dataSource.setJdbcUrl(config.getDbUri());
dataSource.setUsername(config.getDbUsername());
dataSource.setPassword(config.getDbPassword());
dataSource.setIdleTimeout(30000);
dataSource.setMaximumPoolSize(40);
dataSource.setMinimumIdle(10);
dataSource.setConnectionTestQuery("select 1");
dataSource.setConnectionTestQuery(config.getDbConnectionQuery());
return dataSource;
}
@Bean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) {
public LocalSessionFactoryBean sessionFactory(DataSource dataSource, ConfigurationHolder config) {
Properties props = new Properties();
props.setProperty(Environment.DIALECT, "org.hibernate.dialect.PostgreSQL95Dialect");
props.setProperty(Environment.DIALECT, config.getDbDialect());
props.setProperty(Environment.SHOW_SQL, "false");
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
factoryBean.setDataSource(dataSource);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment