Skip to content

Commit

Permalink
Specify MySQL/MariaDB class by name
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Jul 22, 2023
1 parent fe241ee commit bffc6fd
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

/**
Expand All @@ -66,6 +70,7 @@ private Connection getConnection() throws SQLException {
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(),
Expand Down

0 comments on commit bffc6fd

Please sign in to comment.