9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2026-01-01 05:06:42 +00:00

Compare commits

..

3 Commits
2.2.7 ... 2.2.8

Author SHA1 Message Date
William
bd83c8935d Tweak database connection confirmation messages 2023-07-28 21:38:10 +01:00
William
62095364ce 2.2.8: Explicitly specify MariaDB Driver class name 2023-07-28 21:25:23 +01:00
William
304df9984c [ci skip] Bump to 2.2.7 2023-07-28 19:44:09 +01:00
3 changed files with 14 additions and 8 deletions

View File

@@ -130,10 +130,12 @@ public class BukkitHuskSync extends JavaPlugin implements HuskSync {
// Prepare database connection // Prepare database connection
this.database = new MySqlDatabase(this); this.database = new MySqlDatabase(this);
log(Level.INFO, "Attempting to establish connection to the " + settings.getDatabaseType().getDisplayName() + " database..."); log(Level.INFO, String.format("Attempting to establish connection to the %s database...",
settings.getDatabaseType().getDisplayName()));
this.database.initialize(); this.database.initialize();
if (initialized.get()) { if (initialized.get()) {
log(Level.INFO, "Successfully established a connection to the database"); log(Level.INFO, String.format("Successfully established a connection to the %s database",
settings.getDatabaseType().getDisplayName()));
} else { } else {
throw new HuskSyncInitializationException("Failed to establish a connection to the database. " + throw new HuskSyncInitializationException("Failed to establish a connection to the database. " +
"Please check the supplied database credentials in the config file"); "Please check the supplied database credentials in the config file");

View File

@@ -21,7 +21,6 @@ package net.william278.husksync.database;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import net.william278.husksync.HuskSync; import net.william278.husksync.HuskSync;
import net.william278.husksync.config.Settings;
import net.william278.husksync.data.DataAdaptionException; import net.william278.husksync.data.DataAdaptionException;
import net.william278.husksync.data.DataSaveCause; import net.william278.husksync.data.DataSaveCause;
import net.william278.husksync.data.UserData; import net.william278.husksync.data.UserData;
@@ -41,12 +40,16 @@ import java.util.logging.Level;
public class MySqlDatabase extends Database { public class MySqlDatabase extends Database {
private static final String DATA_POOL_NAME = "HuskSyncHikariPool"; private static final String DATA_POOL_NAME = "HuskSyncHikariPool";
private final String protocol; private final String flavor;
private final String driverClass;
private HikariDataSource dataSource; private HikariDataSource dataSource;
public MySqlDatabase(@NotNull HuskSync plugin) { public MySqlDatabase(@NotNull HuskSync plugin) {
super(plugin); super(plugin);
this.protocol = plugin.getSettings().getDatabaseType().getProtocol(); 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";
} }
/** /**
@@ -63,8 +66,9 @@ 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",
protocol, flavor,
plugin.getSettings().getMySqlHost(), plugin.getSettings().getMySqlHost(),
plugin.getSettings().getMySqlPort(), plugin.getSettings().getMySqlPort(),
plugin.getSettings().getMySqlDatabase(), plugin.getSettings().getMySqlDatabase(),
@@ -105,7 +109,7 @@ public class MySqlDatabase extends Database {
// Prepare database schema; make tables if they don't exist // Prepare database schema; make tables if they don't exist
try (Connection connection = dataSource.getConnection()) { try (Connection connection = dataSource.getConnection()) {
final String[] databaseSchema = getSchemaStatements(String.format("database/%s_schema.sql", protocol)); final String[] databaseSchema = getSchemaStatements(String.format("database/%s_schema.sql", flavor));
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
for (String tableCreationStatement : databaseSchema) { for (String tableCreationStatement : databaseSchema) {
statement.execute(tableCreationStatement); statement.execute(tableCreationStatement);

View File

@@ -3,7 +3,7 @@ org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.daemon=true org.gradle.daemon=true
javaVersion=16 javaVersion=16
plugin_version=2.2.6 plugin_version=2.2.8
plugin_archive=husksync plugin_archive=husksync
plugin_description=A modern, cross-server player data synchronization system plugin_description=A modern, cross-server player data synchronization system