Skip to content

Commit

Permalink
Restore support for fully qualified storage drivers
Browse files Browse the repository at this point in the history
Related #1100
  • Loading branch information
games647 committed Oct 12, 2023
1 parent 7096066 commit e15ea9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -221,7 +220,7 @@ public String getMessage(String key) {
}

public boolean setupDatabase() {
String type = config.getString("driver").toLowerCase(Locale.ENGLISH);
String type = config.getString("driver");

HikariConfig databaseConfig = new HikariConfig();
String database = config.getString("database");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.zaxxer.hikari.HikariConfig;

import java.util.Locale;

public class MySQLStorage extends SQLStorage {

private static final String JDBC_PROTOCOL = "jdbc:";
Expand Down Expand Up @@ -68,12 +70,12 @@ private static HikariConfig setParams(HikariConfig config,
}

private static String buildJDBCUrl(String driver, String host, int port, String database) {
String protocol = "mysql";
if (driver.contains("mariadb")) {
protocol = "mariadb";
MySQLVariant variant = MySQLVariant.fromDriver(driver);
if (variant == null) {
throw new IllegalArgumentException("Unknown storage driver");
}

return protocol + "://" + host + ':' + port + '/' + database;
return variant.getJdbcPrefix() + "://" + host + ':' + port + '/' + database;
}

private static void addPerformanceProperties(HikariConfig config) {
Expand Down Expand Up @@ -106,4 +108,32 @@ private static void addPerformanceProperties(HikariConfig config) {
// In our case it can be useful to see the time in error messages
// config.addDataSourceProperty("maintainTimeStats", false);
}

enum MySQLVariant {

MYSQL("mysql"),

MARIADB("mariadb");

private final String jdbcPrefix;

public static MySQLVariant fromDriver(String driver) {
String normalizedDriver = driver.toLowerCase(Locale.ENGLISH);
if (normalizedDriver.contains("mysql")) {
return MYSQL;
} else if (normalizedDriver.contains("mariadb")) {
return MARIADB;
}

return null;
}

MySQLVariant(String jdbcPrefix) {
this.jdbcPrefix = jdbcPrefix;
}

public String getJdbcPrefix() {
return jdbcPrefix;
}
}
}

0 comments on commit e15ea9c

Please sign in to comment.