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 final String flavor;
private final String driverClass;
private HikariDataSource dataSource;
public MySqlDatabase(@NotNull HuskHomes 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 {
// Initialize the Hikari pooled connection
dataSource = new HikariDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setJdbcUrl(String.format("jdbc:%s://%s:%s/%s%s",
flavor,
plugin.getSettings().getMySqlHost(),