9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2026-01-03 22:16:17 +00:00

Compare commits

..

4 Commits
2.2.6 ... 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
William
b73de81519 Add missing Maria schema 2023-07-28 19:41:42 +01:00
4 changed files with 46 additions and 8 deletions

View File

@@ -130,10 +130,12 @@ public class BukkitHuskSync extends JavaPlugin implements HuskSync {
// Prepare database connection
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();
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 {
throw new HuskSyncInitializationException("Failed to establish a connection to the database. " +
"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 net.william278.husksync.HuskSync;
import net.william278.husksync.config.Settings;
import net.william278.husksync.data.DataAdaptionException;
import net.william278.husksync.data.DataSaveCause;
import net.william278.husksync.data.UserData;
@@ -41,12 +40,16 @@ import java.util.logging.Level;
public class MySqlDatabase extends Database {
private static final String DATA_POOL_NAME = "HuskSyncHikariPool";
private final String protocol;
private final String flavor;
private final String driverClass;
private HikariDataSource dataSource;
public MySqlDatabase(@NotNull HuskSync 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 {
// Initialize the Hikari pooled connection
dataSource = new HikariDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setJdbcUrl(String.format("jdbc:%s://%s:%s/%s%s",
protocol,
flavor,
plugin.getSettings().getMySqlHost(),
plugin.getSettings().getMySqlPort(),
plugin.getSettings().getMySqlDatabase(),
@@ -105,7 +109,7 @@ public class MySqlDatabase extends Database {
// Prepare database schema; make tables if they don't exist
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()) {
for (String tableCreationStatement : databaseSchema) {
statement.execute(tableCreationStatement);

View File

@@ -0,0 +1,32 @@
-- Set the storage engine
SET DEFAULT_STORAGE_ENGINE = INNODB;
-- Enable foreign key constraints
SET FOREIGN_KEY_CHECKS = 1;
-- Create the users table if it does not exist
CREATE TABLE IF NOT EXISTS `%users_table%`
(
`uuid` char(36) NOT NULL UNIQUE,
`username` varchar(16) NOT NULL,
PRIMARY KEY (`uuid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
CREATE INDEX IF NOT EXISTS `%users_table%_username` ON `%users_table%` (`username`);
-- Create the user data table if it does not exist
CREATE TABLE IF NOT EXISTS `%user_data_table%`
(
`version_uuid` char(36) NOT NULL UNIQUE,
`player_uuid` char(36) NOT NULL,
`timestamp` datetime NOT NULL,
`save_cause` varchar(32) NOT NULL,
`pinned` boolean NOT NULL DEFAULT FALSE,
`data` longblob NOT NULL,
PRIMARY KEY (`version_uuid`, `player_uuid`),
FOREIGN KEY (`player_uuid`) REFERENCES `%users_table%` (`uuid`) ON DELETE CASCADE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci;

View File

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