From 8f6ad171fb82a68b3e11547037fb8bdcdf251501 Mon Sep 17 00:00:00 2001 From: MrNavaStar Date: Fri, 24 Nov 2023 17:08:25 -0700 Subject: [PATCH] fix mysql/mariadb --- .github/workflows/publish.yml | 2 ++ build.gradle | 22 +++++++++++-------- gradle.properties | 2 ++ .../sqlib/database/AuthenticatedDatabase.java | 7 +----- .../mrnavastar/sqlib/database/Database.java | 6 ++++- .../sqlib/database/MySQLDatabase.java | 7 +++++- .../sqlib/database/SQLiteDatabase.java | 10 ++++----- .../mrnavastar/sqlib/sql/SQLConnection.java | 4 ++-- 8 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d4b8993..aae45c6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,3 +43,5 @@ jobs: java: 17 game-versions: | >=1.16.5 + dependencies: | + fabric-api diff --git a/build.gradle b/build.gradle index ef1607d..e1439a5 100644 --- a/build.gradle +++ b/build.gradle @@ -18,10 +18,10 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // SQL Drivers - shadow implementation("org.xerial:sqlite-jdbc:${project.sqlite_version}") - shadow implementation("mysql:mysql-connector-java:${project.mysql_version}") - //Config - shadow implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:${project.jackson_version}") + implementation("org.xerial:sqlite-jdbc:${project.sqlite_version}") + implementation("org.mariadb.jdbc:mariadb-java-client:${project.mariadb_version}") + // Config + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:${project.jackson_version}") // Extra compileOnly "org.projectlombok:lombok:1.18.28" @@ -31,13 +31,17 @@ dependencies { shadowJar { archiveBaseName.set('sqlib') - configurations = [project.configurations.shadow] - minimize { - exclude(dependency("org.xerial:sqlite-jdbc:.*")) - exclude(dependency("mysql:mysql-connector-java:.*")) + dependencies { + mergeServiceFiles() + include(dependency("org.xerial:sqlite-jdbc:.*")) + include(dependency("org.mariadb.jdbc:mariadb-java-client:.*")) + // Jackson Pain + include(dependency("com.fasterxml.jackson.core:jackson-annotations:.*")) + include(dependency("com.fasterxml.jackson.core:jackson-core:.*")) + include(dependency("com.fasterxml.jackson.core:jackson-databind:.*")) + include(dependency("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:.*")) } - minimize() } jar.finalizedBy('shadowJar') diff --git a/gradle.properties b/gradle.properties index 07c03fe..ed99682 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,5 +13,7 @@ archives_base_name=sqlib sqlite_version=3.44.0.0 # https://mvnrepository.com/artifact/mysql/mysql-connector-java mysql_version=8.0.33 +# https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client +mariadb_version=3.3.0 # https://github.com/FasterXML/jackson-dataformats-text jackson_version=2.15.3 diff --git a/src/main/java/me/mrnavastar/sqlib/database/AuthenticatedDatabase.java b/src/main/java/me/mrnavastar/sqlib/database/AuthenticatedDatabase.java index fcd4f2d..c9b646f 100644 --- a/src/main/java/me/mrnavastar/sqlib/database/AuthenticatedDatabase.java +++ b/src/main/java/me/mrnavastar/sqlib/database/AuthenticatedDatabase.java @@ -28,9 +28,4 @@ public Properties getConnectionProperties() { properties.put("password", password); return properties; } - - @Override - public void beginTransaction() { - sqlConnection.beginTransaction(false); - } -} +} \ No newline at end of file diff --git a/src/main/java/me/mrnavastar/sqlib/database/Database.java b/src/main/java/me/mrnavastar/sqlib/database/Database.java index 8ad10ac..0a9612f 100644 --- a/src/main/java/me/mrnavastar/sqlib/database/Database.java +++ b/src/main/java/me/mrnavastar/sqlib/database/Database.java @@ -44,7 +44,11 @@ public void close() { sqlConnection = null; } - public abstract void beginTransaction(); + public abstract String getTransactionString(); + + public void beginTransaction() { + sqlConnection.beginTransaction(getTransactionString()); + }; public void endTransaction() { sqlConnection.endTransaction(); diff --git a/src/main/java/me/mrnavastar/sqlib/database/MySQLDatabase.java b/src/main/java/me/mrnavastar/sqlib/database/MySQLDatabase.java index 8fb5159..fc00d50 100644 --- a/src/main/java/me/mrnavastar/sqlib/database/MySQLDatabase.java +++ b/src/main/java/me/mrnavastar/sqlib/database/MySQLDatabase.java @@ -8,7 +8,7 @@ public MySQLDatabase(String name, String address, String port, String username, @Override public String getConnectionUrl() { - return "jdbc:mysql://" + address + ":" + port + "/" + name; + return "jdbc:mariadb://" + address + ":" + port + "/" + name; } @Override @@ -16,4 +16,9 @@ public String getTableCreationQuery(String tableName, String columns, boolean au if (autoIncrementId) return "CREATE TABLE IF NOT EXISTS %s (ID int, %s, PRIMARY KEY (ID) AUTO_INCREMENT);".formatted(tableName, columns); return "CREATE TABLE IF NOT EXISTS %s (ID TEXT, %s, PRIMARY KEY (ID(256)));".formatted(tableName, columns); } + + @Override + public String getTransactionString() { + return "BEGIN;"; + } } \ No newline at end of file diff --git a/src/main/java/me/mrnavastar/sqlib/database/SQLiteDatabase.java b/src/main/java/me/mrnavastar/sqlib/database/SQLiteDatabase.java index ac8f914..d1d3981 100644 --- a/src/main/java/me/mrnavastar/sqlib/database/SQLiteDatabase.java +++ b/src/main/java/me/mrnavastar/sqlib/database/SQLiteDatabase.java @@ -39,13 +39,13 @@ public String getTableCreationQuery(String tableName, String columns, boolean au return "CREATE TABLE IF NOT EXISTS %s (%s, ID MEDIUMTEXT PRIMARY KEY);".formatted(tableName, columns); } + @Override + public String getTransactionString() { + return "BEGIN EXCLUSIVE;"; + } + public void setMode(@NonNull Mode mode) { this.mode = mode; executeCommand("PRAGMA journal_mode = %s;".formatted(mode), true); } - - @Override - public void beginTransaction() { - sqlConnection.beginTransaction(true); - } } \ No newline at end of file diff --git a/src/main/java/me/mrnavastar/sqlib/sql/SQLConnection.java b/src/main/java/me/mrnavastar/sqlib/sql/SQLConnection.java index 93734fd..3225d69 100644 --- a/src/main/java/me/mrnavastar/sqlib/sql/SQLConnection.java +++ b/src/main/java/me/mrnavastar/sqlib/sql/SQLConnection.java @@ -49,8 +49,8 @@ public PreparedStatement executeCommand(String sql, boolean autoClose, Object... } } - public void beginTransaction(boolean exclusive) { - executeCommand((exclusive) ? "BEGIN;" : "BEGIN EXCLUSIVE;", true); + public void beginTransaction(String transactionString) { + executeCommand(transactionString, true); } public void endTransaction() {