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