Skip to content

Commit

Permalink
#546 remove unused multi db code (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer authored and cbellone committed Nov 13, 2018
1 parent d499856 commit b8ed475
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 125 deletions.
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ ext {
// default settings
jettyPort = 8080
jettyHost = '0.0.0.0'
datasourceDialect = 'PGSQL'
datasourceDriver = 'org.postgresql.Driver'
datasourceUrl = 'jdbc:postgresql://localhost:5432/alfio'
datasourceUsername = 'postgres'
datasourcePassword = 'password'
Expand All @@ -89,8 +87,6 @@ ext {

switch (profile) {
case 'docker-test':
datasourceDialect = 'PGSQL'
datasourceDriver = 'org.postgresql.Driver'
datasourceUrl = 'jdbc:postgresql://0.0.0.0:5432/postgres'
datasourceUsername = 'postgres'
datasourcePassword = 'postgres'
Expand Down Expand Up @@ -267,12 +263,9 @@ bootRun {
def opts = []
opts += [
"-Dspring.profiles.active=${project.springProfilesActive},jdbc-session",
"-Ddatasource.dialect=${project.datasourceDialect}",
"-Ddatasource.driver=${project.datasourceDriver}",
"-Ddatasource.url=${project.datasourceUrl}",
"-Ddatasource.username=${project.datasourceUsername}",
"-Ddatasource.password=${project.datasourcePassword}",
"-Ddatasource.validationQuery=${project.datasourceValidationQuery}",
"-Dalfio.version=${project.version}",
"-Dalfio.build-ts=${ZonedDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)}"
]
Expand Down
30 changes: 2 additions & 28 deletions src/main/java/alfio/config/DataSourceConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ public PlatformProvider getCloudProvider(Environment environment) {
.filter(p -> p.isHosting(environment))
.findFirst()
.orElse(PlatformProvider.DEFAULT);
String dialect = current.getDialect(environment);
log.info("Detected cloud provider: {}, database: {}", current, dialect);
if(PlatformProvider.MYSQL.equals(dialect)) {
log.warn("********************** WARNING! WARNING! WARNING!****************************");
log.warn("** **");
log.warn("** MYSQL SUPPORT WILL BE DROPPED IN ALF.IO V2 (exp. Q4 2018) **");
log.warn("** Please consider switching to PostgreSql **");
log.warn("** **");
log.warn("*****************************************************************************");
}
return current;
}

Expand Down Expand Up @@ -261,24 +251,8 @@ public Trigger[] getTriggers() throws ParseException {
@Bean
@DependsOn("migrator")
@Profile("!"+ Initializer.PROFILE_DISABLE_JOBS)
public SchedulerFactoryBean schedulerFactory(Environment env, PlatformProvider platform, DataSource dataSource, PlatformTransactionManager platformTransactionManager, ApplicationContext applicationContext) throws ParseException {

String dialect = platform.getDialect(env);
String quartzDriverDelegateClass;
switch (dialect) {
case "PGSQL":
quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate";
break;
case "HSQLDB":
quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.HSQLDBDelegate";
break;
case "MYSQL":
quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.StdJDBCDelegate";
break;
default:
throw new IllegalArgumentException("Unsupported dialect: " + dialect);
}

public SchedulerFactoryBean schedulerFactory(DataSource dataSource, PlatformTransactionManager platformTransactionManager, ApplicationContext applicationContext) throws ParseException {
String quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate";
Properties properties = new Properties();
properties.setProperty("org.quartz.jobStore.isClustered", "true");
properties.setProperty("org.quartz.scheduler.instanceId", "AUTO");
Expand Down
92 changes: 5 additions & 87 deletions src/main/java/alfio/config/support/PlatformProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* Supported:
* - Openshift : pgsql only
* - ElephantDB: runs on Openshift and Cloud Foundry
* - Cloud Foundry: postgres, mysql (injected)
* - Cloud Foundry: postgres
* - Heroku
* - AWS: mysql and postgres
* - AWS
* - local use with system properties
*/
public enum PlatformProvider {
Expand Down Expand Up @@ -63,16 +63,6 @@ public String getPassword(Environment env) {
return isCloudFoundry(env) ? "" : resolveURI(env, "ELEPHANTSQL_URI").getUserInfo().split(":")[1];
}

@Override
public String getDialect(Environment env) {
return PGSQL;
}

@Override
public String getDriverClassName(Environment env) {
return POSTGRESQL_DRIVER;
}

@Override
public boolean isHosting(Environment env) {
return ofNullable(env.getProperty("ELEPHANTSQL_URI")).isPresent() || ofNullable(env.getProperty("VCAP_SERVICES")).filter(s -> s.contains("elephantsql")).isPresent();
Expand Down Expand Up @@ -109,16 +99,6 @@ public String getPassword(Environment env) {
return Objects.requireNonNull(System.getenv("OPENSHIFT_POSTGRESQL_DB_PASSWORD"), "OPENSHIFT_POSTGRESQL_DB_PASSWORD env variable is missing");
}

@Override
public String getDialect(Environment env) {
return PGSQL;
}

@Override
public String getDriverClassName(Environment env) {
return POSTGRESQL_DRIVER;
}

@Override
public boolean isHosting(Environment env) {
return ofNullable(env.getProperty("OPENSHIFT_APP_NAME")).isPresent();
Expand Down Expand Up @@ -146,16 +126,6 @@ public String getPassword(Environment env) {
return "";
}

@Override
public String getDialect(Environment env) {
return isMySql(env) ? MYSQL : PGSQL;
}

@Override
public String getDriverClassName(Environment env) {
return isMySql(env) ? MYSQL_DRIVER : POSTGRESQL_DRIVER;
}

@Override
public boolean isHosting(Environment env) {
//check if json object for services is returned
Expand All @@ -170,10 +140,6 @@ public boolean isHosting(Environment env) {
// "name": "alfio-db",
return env.getProperty("VCAP_SERVICES") != null;
}

private boolean isMySql(Environment env) {
return ofNullable(env.getProperty("VCAP_SERVICES")).map(props -> props.contains("mysql://")).orElse(false);
}
},

HEROKU {
Expand All @@ -195,16 +161,6 @@ public String getPassword(Environment env) {
return resolveURI(env).getUserInfo().split(":")[1];
}

@Override
public String getDialect(Environment env) {
return PGSQL;
}

@Override
public String getDriverClassName(Environment env) {
return POSTGRESQL_DRIVER;
}

@Override
public boolean isHosting(Environment env) {
return ofNullable(env.getProperty("DYNO")).isPresent();
Expand Down Expand Up @@ -237,17 +193,6 @@ public String getPassword(Environment env) {
return Objects.requireNonNull(System.getenv("POSTGRES_ENV_POSTGRES_PASSWORD"), "POSTGRES_ENV_POSTGRES_PASSWORD env variable is missing");
}

@Override
public String getDialect(Environment env) {
return PGSQL;
}


@Override
public String getDriverClassName(Environment env) {
return POSTGRESQL_DRIVER;
}

@Override
public boolean isHosting(Environment env) {
return ofNullable(System.getenv("POSTGRES_ENV_POSTGRES_DB")).isPresent();
Expand All @@ -258,7 +203,7 @@ public boolean isHosting(Environment env) {

@Override
public String getUrl(Environment env) {
String dbType = isMySql(env) ? "mysql" : "postgresql";
String dbType = "postgresql";
String host = env.getRequiredProperty("RDS_HOSTNAME");
String port = env.getRequiredProperty("RDS_PORT");
String db = env.getRequiredProperty("RDS_DB_NAME");
Expand All @@ -275,25 +220,11 @@ public String getPassword(Environment env) {
return env.getRequiredProperty("RDS_PASSWORD");
}

@Override
public String getDialect(Environment env) {
return isMySql(env) ? MYSQL : PGSQL;
}

@Override
public boolean isHosting(Environment env) {
return ofNullable(env.getProperty("RDS_HOSTNAME")).isPresent();
}

private boolean isMySql(Environment env) {
return ofNullable(env.getProperty("RDS_PORT")).filter("3306"::equals).isPresent();
}

@Override
public String getDriverClassName(Environment env) {
return isMySql(env) ? MYSQL_DRIVER : POSTGRESQL_DRIVER;
}

},

CLEVER_CLOUD {
Expand All @@ -313,16 +244,6 @@ public String getPassword(Environment env) {
return env.getRequiredProperty("POSTGRESQL_ADDON_PASSWORD");
}

@Override
public String getDriverClassName(Environment env) {
return POSTGRESQL_DRIVER;
}

@Override
public String getDialect(Environment env) {
return PGSQL;
}

@Override
public int getMaxActive(Environment env) {
//default limit to 5, to be on the safe side
Expand All @@ -338,9 +259,6 @@ public boolean isHosting(Environment env) {
private static final String POSTGRESQL_DRIVER = "org.postgresql.Driver";
public static final String PGSQL = "PGSQL";

private static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
public static final String MYSQL = "MYSQL";


public String getUrl(Environment env) {
return env.getRequiredProperty("datasource.url");
Expand All @@ -355,11 +273,11 @@ public String getPassword(Environment env) {
}

public String getDriverClassName(Environment env) {
return env.getRequiredProperty("datasource.driver");
return POSTGRESQL_DRIVER;
}

public String getDialect(Environment env) {
return env.getRequiredProperty("datasource.dialect");
return PGSQL;
}

public int getMaxActive(Environment env) {
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/alfio/test/util/IntegrationTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ public class IntegrationTestUtil {

public static Map<String, String> generateDBConfig(String url, String username, String password) {
Map<String, String> c = new HashMap<>();
c.put("datasource.dialect", "PGSQL");
c.put("datasource.driver", "org.postgresql.Driver");
c.put("datasource.url", url);
c.put("datasource.username", username);
c.put("datasource.password", password);
c.put("datasource.validationQuery", "SELECT 1");
return c;
}

Expand Down

0 comments on commit b8ed475

Please sign in to comment.