Skip to content
Snippets Groups Projects
Commit 0c501752 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

work in progress

parent 0eb6d557
No related branches found
No related tags found
No related merge requests found
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
# See http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html # See http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
spring: spring:
datasource: datasource:
url: {{ default .Env.DB_URL "jdbc:postgresql://172.22.0.1:5432/postgres" }} url: {{ default .Env.DB_URL "jdbc:postgresql://172.22.0.1:5433/postgres" }}
username: {{ default .Env.DB_USER "postgres" }} username: {{ default .Env.DB_USER "postgres" }}
password: {{ .Env.DB_PASSWORD }} password: {{ .Env.DB_PASSWORD }}
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
variablesDatasource: metaDatasource:
url: {{ default .Env.VARIABLES_DB_URL "jdbc:postgresql://172.22.0.1:5433/postgres" }} url: {{ default .Env.META_DB_URL "jdbc:postgresql://172.22.0.1:5432/postgres" }}
username: {{ default .Env.VARIABLES_DB_USER "postgres" }} username: {{ default .Env.META_DB_USER "postgres" }}
password: {{ .Env.VARIABLES_DB_PASSWORD }} password: {{ .Env.META_DB_PASSWORD }}
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
jpa: jpa:
hibernate: hibernate:
......
...@@ -2,11 +2,16 @@ package eu.hbp.mip.configuration; ...@@ -2,11 +2,16 @@ package eu.hbp.mip.configuration;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityScan; import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary;
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.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.JpaVendorAdapter;
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;
...@@ -22,27 +27,41 @@ import javax.sql.DataSource; ...@@ -22,27 +27,41 @@ import javax.sql.DataSource;
@EntityScan(basePackages = "eu.hbp.mip.model") @EntityScan(basePackages = "eu.hbp.mip.model")
public class PersistenceConfiguration { public class PersistenceConfiguration {
@Autowired @Bean(name = "datasource")
DataSource dataSource; @Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Autowired @Bean(name = "metaDatasource")
DataSource variablesDatasource; // TODO: Fix this problem @ConfigurationProperties(prefix="spring.variablesDatasource")
public DataSource metaDataSource() {
return DataSourceBuilder.create().build();
}
@Bean @Bean
@Autowired
@Qualifier("metaJDBC")
public JdbcTemplate metaJDBC() {
return new JdbcTemplate(metaDataSource());
}
@Bean(name = "metaEntityManagerFactory")
@DependsOn("flyway") @DependsOn("flyway")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { public LocalContainerEntityManagerFactoryBean metaEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource); em.setDataSource(dataSource());
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter); em.setJpaVendorAdapter(vendorAdapter);
return em; return em;
} }
@Bean(initMethod = "migrate") @Bean(name = "metaMigrations", initMethod = "migrate")
public Flyway flyway() { public Flyway metaMigrations() {
Flyway flyway = new Flyway(); Flyway flyway = new Flyway();
flyway.setBaselineOnMigrate(true); flyway.setBaselineOnMigrate(true);
flyway.setDataSource(dataSource); flyway.setDataSource(metaDataSource());
return flyway; return flyway;
} }
......
...@@ -13,14 +13,13 @@ import io.swagger.annotations.ApiResponse; ...@@ -13,14 +13,13 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.sql.DataSource;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController @RestController
...@@ -37,8 +36,8 @@ public class StatsApi { ...@@ -37,8 +36,8 @@ public class StatsApi {
ArticleRepository articleRepository; ArticleRepository articleRepository;
@Autowired @Autowired
DataSource variablesDatasource; @Qualifier("metaJDBC")
private JdbcTemplate metaJDBC;
@ApiOperation(value = "Get general statistics", response = GeneralStats.class) @ApiOperation(value = "Get general statistics", response = GeneralStats.class)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") }) @ApiResponses(value = {@ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") })
...@@ -57,9 +56,8 @@ public class StatsApi { ...@@ -57,9 +56,8 @@ public class StatsApi {
private Long countVariables() private Long countVariables()
{ {
JdbcTemplate db = new JdbcTemplate(variablesDatasource); LOGGER.warn("TEST DB : " + metaJDBC.queryForObject("select count(*) from information_schema.tables", Long.class)); // This is a test
LOGGER.warn("TEST DB : " + db.queryForObject("select count(*) from information_schema.tables", Long.class)); // This is a test Long count = metaJDBC.queryForObject("select count(*) from adni_merge", Long.class); // TODO: compute from adni_merge DB
Long count = db.queryForObject("select count(*) from adni_merge", Long.class); // TODO: compute from adni_merge DB
return count; return count;
} }
......
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