Skip to content
Permalink
Browse files
FINCN-180 cleanup code that creates seshat db. make travis build 'dev…
…elop' branch
  • Loading branch information
Juhan Aasaru authored and Juhan Aasaru committed Oct 18, 2019
1 parent 14f1da9 commit a34de39ce093b70624027041469dd24d1c6d84ab
Showing 3 changed files with 11 additions and 12 deletions.
@@ -85,7 +85,6 @@ public void initialize() {
this.initializeCassandra();
this.initializeDatabase(PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT);
this.createTableTenants();
//this.initializeDatabase("playground");
} catch (final Exception ex) {
throw new IllegalStateException("Could not initialize service!", ex);
}
@@ -198,9 +197,9 @@ private void initializeCassandra() throws Exception {
}
}

private void initializeDatabase(String postgresDbName) throws Exception {
private void initializeDatabase(String metaDatabaseName) throws Exception {

this.logger.info("Creating meta database {} ", postgresDbName);
this.logger.info("Creating meta database {} ", metaDatabaseName);
try (
final Connection connection = DataSourceUtils.createProvisionerConnection(this.environment, "postgres");
final Statement testStatement = connection.createStatement();
@@ -209,12 +208,12 @@ private void initializeDatabase(String postgresDbName) throws Exception {
final ResultSet validityQuery = testStatement.executeQuery("SELECT 1");
if (validityQuery.next()){
this.logger.info("Connection to database postgres established");
final ResultSet findDB = statement.executeQuery("SELECT datname FROM pg_database WHERE datname = '" + postgresDbName + "'");
final ResultSet findDB = statement.executeQuery("SELECT datname FROM pg_database WHERE datname = '" + metaDatabaseName + "'");
if (!findDB.next()) {
this.logger.info("Database {} does not exists, creating the database {} now.", postgresDbName);
statement.execute("CREATE DATABASE " + postgresDbName);
this.logger.info("Database {} does not exists, creating the database {} now.", metaDatabaseName);
statement.execute("CREATE DATABASE " + metaDatabaseName);
} else {
this.logger.info("Database {} already exists.", postgresDbName);
this.logger.info("Database {} already exists.", metaDatabaseName);
}
} else {
this.logger.warn("Could not connect to database postgres");
@@ -252,4 +251,4 @@ private void createTableTenants() throws SQLException {
throw new IllegalStateException("Could not create table tenants");
}
}
}
}
@@ -64,9 +64,9 @@ public static Connection create(final DatabaseConnectionInfo databaseConnectionI
public static Connection createProvisionerConnection(final Environment environment, String databaseName) {
final DatabaseConnectionInfo databaseConnectionInfo = new DatabaseConnectionInfo();
databaseConnectionInfo.setDriverClass(environment.getProperty("postgresql.driverClass"));
databaseName = databaseName.equals(PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT) ? PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT :
(databaseName.equals("playground") ? "playground" : "postgres");
databaseConnectionInfo.setDatabaseName(databaseName);
if (databaseName != null) {
databaseConnectionInfo.setDatabaseName(databaseName);
}
databaseConnectionInfo.setHost(environment.getProperty("postgresql.host"));
databaseConnectionInfo.setPort(environment.getProperty("postgresql.port"));
databaseConnectionInfo.setUser(environment.getProperty("postgresql.user"));
@@ -88,7 +88,7 @@ artifactory {
}
}
}
artifactoryPublish.dependsOn('clean','publishToMavenLocal')
artifactoryPublish.dependsOn('publishToMavenLocal')

license {
header rootProject.file('../HEADER')

0 comments on commit a34de39

Please sign in to comment.