Specify MySQL/MariaDB class by name

This commit is contained in:
William committed 2023-07-22 13:37:26 +01:00
1 parent fe241eec2b
commit bffc6fde76
1 file changed
+6 -1
@@ -45,11 +45,15 @@ public class MySqlDatabase extends Database {
private static final String DATA_POOL_NAME = "HuskHomesHikariPool"; private static final String DATA_POOL_NAME = "HuskHomesHikariPool";
private final String flavor; private final String flavor;
private final String driverClass;
private HikariDataSource dataSource; private HikariDataSource dataSource;
public MySqlDatabase(@NotNull HuskHomes plugin) { public MySqlDatabase(@NotNull HuskHomes plugin) {
super(plugin); super(plugin);
this.flavor = plugin.getSettings().getDatabaseType() == Type.MARIADB ? "mariadb" : "mysql"; this.flavor = plugin.getSettings().getDatabaseType() == Type.MARIADB
? "mariadb" : "mysql";
this.driverClass = plugin.getSettings().getDatabaseType() == Type.MARIADB
? "org.mariadb.jdbc.Driver" : "com.mysql.cj.jdbc.Driver";
} }
/** /**
@@ -66,6 +70,7 @@ public class MySqlDatabase extends Database {
public void initialize() throws IllegalStateException { public void initialize() throws IllegalStateException {
// Initialize the Hikari pooled connection // Initialize the Hikari pooled connection
dataSource = new HikariDataSource(); dataSource = new HikariDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setJdbcUrl(String.format("jdbc:%s://%s:%s/%s%s", dataSource.setJdbcUrl(String.format("jdbc:%s://%s:%s/%s%s",
flavor, flavor,
plugin.getSettings().getMySqlHost(), plugin.getSettings().getMySqlHost(),