9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-30 20:29:28 +00:00

Add mariadb protocol option type (#145)

Co-authored-by: William <will27528@gmail.com>
This commit is contained in:
Joo200
2023-07-01 14:54:30 +02:00
committed by GitHub
parent f7419f7277
commit 97ad608d56
4 changed files with 45 additions and 2 deletions

View File

@@ -191,4 +191,30 @@ public abstract class Database {
*/
public abstract void close();
/**
* Identifies types of databases
*/
public enum Type {
MYSQL("MySQL", "mysql"),
MARIADB("MariaDB", "mariadb");
private final String displayName;
private final String protocol;
Type(@NotNull String displayName, @NotNull String protocol) {
this.displayName = displayName;
this.protocol = protocol;
}
@NotNull
public String getDisplayName() {
return displayName;
}
@NotNull
public String getProtocol() {
return protocol;
}
}
}

View File

@@ -40,6 +40,11 @@ import java.util.logging.Level;
public class MySqlDatabase extends Database {
/**
* MySQL protocol
*/
private final Database.Type type;
/**
* MySQL server hostname
*/
@@ -74,6 +79,7 @@ public class MySqlDatabase extends Database {
public MySqlDatabase(@NotNull HuskSync plugin) {
super(plugin);
final Settings settings = plugin.getSettings();
this.type = settings.getSqlType();
this.mySqlHost = settings.getMySqlHost();
this.mySqlPort = settings.getMySqlPort();
this.mySqlDatabaseName = settings.getMySqlDatabase();
@@ -101,7 +107,7 @@ public class MySqlDatabase extends Database {
public boolean initialize() {
try {
// Create jdbc driver connection url
final String jdbcUrl = "jdbc:mysql://" + mySqlHost + ":" + mySqlPort + "/" + mySqlDatabaseName + mySqlConnectionParameters;
final String jdbcUrl = "jdbc:" + type.getProtocol() + "://" + mySqlHost + ":" + mySqlPort + "/" + mySqlDatabaseName + mySqlConnectionParameters;
connectionPool = new HikariDataSource();
connectionPool.setJdbcUrl(jdbcUrl);