Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Jan 16, 2025
2 parents 7119934 + a11f712 commit ead31c5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;

public interface IDataSourceAdapter<T> {
int DATABASE_VERSION = 1;

void prepare(T config);

void initStorage(DataType type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import static com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlConstants.FIELD_UNIVERSAL_TRAITS;
import static com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlConstants.FIELD_UNIVERSAL_UUID;

import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.IDataSourceAdapter;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlCommonAdapter;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlUtils;
import com.xzavier0722.mc.plugin.slimefun4.storage.common.*;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -389,10 +391,16 @@ private void createUniversalDataTable() {

private void createTableInformationTable() {
executeSql("CREATE TABLE IF NOT EXISTS "
+ tableInformationTable
+ "("
+ FIELD_TABLE_VERSION
+ " INT UNIQUE NOT NULL DEFAULT '0'"
+ ");");
+ tableInformationTable
+ "("
+ FIELD_TABLE_VERSION
+ " INT UNIQUE NOT NULL DEFAULT '0'"
+ ");");

if (Slimefun.isNewlyInstalled()) {
executeSql("INSERT INTO " + tableInformationTable + " (" + FIELD_TABLE_VERSION + ") SELECT '"
+ IDataSourceAdapter.DATABASE_VERSION + "' WHERE NOT EXISTS (SELECT 1 FROM " + tableInformationTable
+ ")");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import static com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlConstants.FIELD_UNIVERSAL_TRAITS;
import static com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlConstants.FIELD_UNIVERSAL_UUID;

import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.IDataSourceAdapter;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlCommonAdapter;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlUtils;
import com.xzavier0722.mc.plugin.slimefun4.storage.common.*;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -403,10 +405,16 @@ private void createUniversalDataTable() {

private void createTableInformationTable() {
executeSql("CREATE TABLE IF NOT EXISTS "
+ tableInformationTable
+ "("
+ FIELD_TABLE_VERSION
+ " INT UNIQUE NOT NULL DEFAULT '0'"
+ ");");
+ tableInformationTable
+ "("
+ FIELD_TABLE_VERSION
+ " INT UNIQUE NOT NULL DEFAULT '0'"
+ ");");

if (Slimefun.isNewlyInstalled()) {
executeSql("INSERT INTO " + tableInformationTable + " (" + FIELD_TABLE_VERSION + ") SELECT '"
+ IDataSourceAdapter.DATABASE_VERSION + "' WHERE NOT EXISTS (SELECT 1 FROM " + tableInformationTable
+ ")");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import static com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlConstants.FIELD_UNIVERSAL_TRAITS;
import static com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlConstants.FIELD_UNIVERSAL_UUID;

import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.IDataSourceAdapter;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlCommonAdapter;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlUtils;
import com.xzavier0722.mc.plugin.slimefun4.storage.common.*;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

import java.sql.SQLException;
import java.util.List;
Expand Down Expand Up @@ -382,11 +384,17 @@ private void createUniversalDataTable() {
private void createTableInformationTable() {
var table = SqlUtils.mapTable(DataScope.TABLE_INFORMATION);
executeSql("CREATE TABLE IF NOT EXISTS "
+ table
+ "("
+ FIELD_TABLE_VERSION
+ " INT UNIQUE NOT NULL DEFAULT '0'"
+ ");");
+ table
+ "("
+ FIELD_TABLE_VERSION
+ " INT UNIQUE NOT NULL DEFAULT '0'"
+ ");");

if (Slimefun.isNewlyInstalled()) {
executeSql("INSERT INTO " + tableInformationTable + " (" + FIELD_TABLE_VERSION + ") SELECT '"
+ IDataSourceAdapter.DATABASE_VERSION + "' WHERE NOT EXISTS (SELECT 1 FROM " + tableInformationTable
+ ")");
}
}

public synchronized void executeSql(String sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.ISqlCommonConfig;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlCommonConfig;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlcommon.SqlUtils;
import com.xzavier0722.mc.plugin.slimefun4.storage.adapter.sqlite.SqliteConfig;
import com.xzavier0722.mc.plugin.slimefun4.storage.common.DataScope;
import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -21,7 +22,11 @@ public void patch(Statement stmt, ISqlCommonConfig config) throws SQLException {
var table = SqlUtils.mapTable(
DataScope.TABLE_INFORMATION, config instanceof SqlCommonConfig scc ? scc.tablePrefix() : "");

stmt.execute("UPDATE " + table + " SET " + FIELD_TABLE_VERSION + " = '1' LIMIT 1;");
if (config instanceof SqliteConfig) {
stmt.execute("UPDATE " + table + " SET " + FIELD_TABLE_VERSION + " = '1' ");
} else {
stmt.execute("insert into " + table + " values (" + FIELD_TABLE_VERSION + " = '1');");
}

if (config instanceof MysqlConfig mysqlConf) {
var uniInvTable = SqlUtils.mapTable(DataScope.UNIVERSAL_INVENTORY, mysqlConf.tablePrefix());
Expand Down

0 comments on commit ead31c5

Please sign in to comment.