Skip to content

Commit 6991a2b

Browse files
Fix dbPrefix issue when using convert command
1 parent dd7817b commit 6991a2b

File tree

5 files changed

+56
-47
lines changed

5 files changed

+56
-47
lines changed

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
214214
private DatabaseManager databaseManager;
215215
/**
216216
* Default database prefix, can overwrite by config
217+
* <p>
218+
* Deprecated: use manager#getDatabase#getTableprefix instead
217219
*/
218220
@Getter
221+
@Deprecated
219222
private String dbPrefix = "";
220223
/**
221224
* Whether we should use display items or not
@@ -1190,10 +1193,12 @@ private boolean setupDatabase() {
11901193
AbstractDatabaseCore dbCore;
11911194
if (Objects.requireNonNull(dbCfg).getBoolean("mysql")) {
11921195
// MySQL database - Required database be created first.
1193-
dbPrefix = dbCfg.getString("prefix");
1194-
if (dbPrefix == null || "none".equals(dbPrefix)) {
1195-
dbPrefix = "";
1196+
String prefix = dbCfg.getString("prefix");
1197+
if (prefix == null || "none".equals(prefix)) {
1198+
prefix = "";
11961199
}
1200+
//just keep backward compatible
1201+
dbPrefix = prefix;
11971202
String user = dbCfg.getString("user");
11981203
String pass = dbCfg.getString("password");
11991204
String host = dbCfg.getString("host");
@@ -1207,7 +1212,7 @@ private boolean setupDatabase() {
12071212
optionsMap.put(strings[0], strings[1]);
12081213
}
12091214
}
1210-
dbCore = new MySQLCore(this, Objects.requireNonNull(host, "MySQL host can't be null"), Objects.requireNonNull(user, "MySQL username can't be null"), Objects.requireNonNull(pass, "MySQL password can't be null"), Objects.requireNonNull(database, "MySQL database name can't be null"), Objects.requireNonNull(port, "MySQL port can't be null"), useSSL, optionsMap);
1215+
dbCore = new MySQLCore(this, Objects.requireNonNull(host, "MySQL host can't be null"), Objects.requireNonNull(user, "MySQL username can't be null"), Objects.requireNonNull(pass, "MySQL password can't be null"), Objects.requireNonNull(database, "MySQL database name can't be null"), Objects.requireNonNull(port, "MySQL port can't be null"), prefix, useSSL, optionsMap);
12111216
} else {
12121217
// SQLite database - Doing this handles file creation
12131218
dbCore = new SQLiteCore(this, new File(this.getDataFolder(), "shops.db"));

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Convert.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void onCommand(@NotNull ConsoleCommandSender sender, @NotNull String comm
8686
String port = dbCfg.getString("port");
8787
String databaseStr = dbCfg.getString("database");
8888
boolean useSSL = dbCfg.getBoolean("usessl");
89+
String prefix = dbCfg.getString("prefix", "");
8990
Map<String, String> optionsMap = new HashMap<>();
9091
for (String options : dbCfg.getStringList("mysql-connect-options")) {
9192
String[] strings = options.split("=", 2);
@@ -96,7 +97,7 @@ public void onCommand(@NotNull ConsoleCommandSender sender, @NotNull String comm
9697
running = true;
9798
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
9899
try {
99-
AbstractDatabaseCore dbCore = new MySQLCore(plugin, Objects.requireNonNull(host, "MySQL host can't be null"), Objects.requireNonNull(user, "MySQL username can't be null"), Objects.requireNonNull(pass, "MySQL password can't be null"), Objects.requireNonNull(databaseStr, "MySQL database name can't be null"), Objects.requireNonNull(port, "MySQL port can't be null"), useSSL, optionsMap);
100+
AbstractDatabaseCore dbCore = new MySQLCore(plugin, Objects.requireNonNull(host, "MySQL host can't be null"), Objects.requireNonNull(user, "MySQL username can't be null"), Objects.requireNonNull(pass, "MySQL password can't be null"), Objects.requireNonNull(databaseStr, "MySQL database name can't be null"), Objects.requireNonNull(port, "MySQL port can't be null"), prefix, useSSL, optionsMap);
100101
DatabaseManager databaseManager = new DatabaseManager(QuickShop.getInstance(), dbCore);
101102
sender.sendMessage(ChatColor.GREEN + "Converting...");
102103
transferShops(new SimpleDatabaseHelper(plugin, databaseManager), sender);

src/main/java/org/maxgamer/quickshop/database/AbstractDatabaseCore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void signalForNewConnection() {
5757

5858
}
5959

60+
public String getTablePrefix() {
61+
return "";
62+
}
63+
6064
/**
6165
* Close all not in-use connections created by DatabaseCore.
6266
*/

src/main/java/org/maxgamer/quickshop/database/MySQLCore.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ public class MySQLCore extends AbstractDatabaseCore {
4646
@NotNull
4747
private final QuickShop plugin;
4848

49+
50+
private final String tablePrefix;
51+
4952
public MySQLCore(
5053
@NotNull QuickShop plugin,
5154
@NotNull String host,
5255
@NotNull String user,
5356
@NotNull String pass,
5457
@NotNull String database,
5558
@NotNull String port,
59+
@NotNull String tablePrefix,
5660
boolean useSSL, Map<String, String> options) {
5761
this.plugin = plugin;
62+
this.tablePrefix = tablePrefix;
5863
info = new Properties();
5964
info.setProperty("autoReconnect", "true");
6065
info.setProperty("user", user);
@@ -76,6 +81,10 @@ public MySQLCore(
7681
}
7782
}
7883

84+
@Override
85+
public String getTablePrefix() {
86+
return tablePrefix;
87+
}
7988

8089
@Override
8190
synchronized void close() {

0 commit comments

Comments
 (0)