Commit 4b08b71f authored by Matija Obreza's avatar Matija Obreza
Browse files

Run controlled database migration only when not generating schema automatically

Connect set to readonly(false) by default by JDBC pool
parent c59d4dde
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
<aspectj.version>1.7.2</aspectj.version> <aspectj.version>1.7.2</aspectj.version>
<mysql.version>5.1.31</mysql.version> <mysql.version>5.1.38</mysql.version>
<hazelcast.version>3.8.1</hazelcast.version> <hazelcast.version>3.8.1</hazelcast.version>
<oval.version>1.81</oval.version> <oval.version>1.81</oval.version>
......
...@@ -30,7 +30,6 @@ import org.springframework.context.annotation.DependsOn; ...@@ -30,7 +30,6 @@ import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
...@@ -88,6 +87,7 @@ public class SpringDataBaseConfig { ...@@ -88,6 +87,7 @@ public class SpringDataBaseConfig {
@Bean @Bean
public DataSource dataSource() { public DataSource dataSource() {
final DataSource dataSource = new DataSource(); final DataSource dataSource = new DataSource();
dataSource.setDefaultReadOnly(false);
dataSource.setUrl(dbUrl); dataSource.setUrl(dbUrl);
dataSource.setDriverClassName(dbDriverClassName); dataSource.setDriverClassName(dbDriverClassName);
dataSource.setUsername(dbUsername); dataSource.setUsername(dbUsername);
...@@ -103,26 +103,19 @@ public class SpringDataBaseConfig { ...@@ -103,26 +103,19 @@ public class SpringDataBaseConfig {
return dataSource; return dataSource;
} }
@Bean @Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) { public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource); return new JdbcTemplate(dataSource);
} }
private javax.sql.DataSource liquibaseDataSource() {
DriverManagerDataSource dataSource=new DriverManagerDataSource();
dataSource.setDriverClassName(dbDriverClassName);
dataSource.setUrl(dbUrl);
dataSource.setUsername(dbUsername);
dataSource.setPassword(dbPassword);
return dataSource;
}
@Bean(name = "databaseMigration") @Bean(name = "databaseMigration")
public SpringLiquibase databaseMigration() { public SpringLiquibase databaseMigration() {
SpringLiquibase liquibase = new SpringLiquibase(); SpringLiquibase liquibase = new SpringLiquibase();
// Run controlled database migration only when not generating schema automatically
liquibase.setShouldRun(!dbGenerateDdl);
liquibase.setChangeLog("classpath:liquibase/liquibase-changeLog.yml"); liquibase.setChangeLog("classpath:liquibase/liquibase-changeLog.yml");
liquibase.setDataSource(liquibaseDataSource()); liquibase.setDataSource(dataSource());
return liquibase; return liquibase;
} }
......
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