From eef444d0bd34756466708083d0fe8b55ed80d6a5 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Sun, 5 Aug 2018 21:59:03 +0200 Subject: [PATCH] Bugfixes and code cleanup Fix batch execution for uuid converter Fix last update for SQLite --- .../Minepacks/Bukkit/Database/Files.java | 7 ++----- .../Minepacks/Bukkit/Database/MySQL.java | 4 ++-- .../Minepacks/Bukkit/Database/MySQLShared.java | 7 +++---- .../Minepacks/Bukkit/Database/SQL.java | 13 ++++++++----- .../Minepacks/Bukkit/Database/SQLite.java | 9 +++------ .../Minepacks/Bukkit/Database/SQLiteShared.java | 4 ++-- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Files.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Files.java index e9691e0..ff6b576 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Files.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Files.java @@ -112,12 +112,9 @@ private void checkFiles() } } } - else // Use name-based saving + else if(len > 16) // Use name-based saving, we only have to rename it if it's name is more than 16 chars (minecraft max player name length) { - if(len > 16) // We only have to rename it if it's name is more than 16 chars (minecraft max player name length) - { - file.renameTo(new File(saveFolder, UUIDConverter.getNameFromUUID(file.getName().substring(0, len)) + EXT)); - } + file.renameTo(new File(saveFolder, UUIDConverter.getNameFromUUID(file.getName().substring(0, len)) + EXT)); } } } diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java index eb97beb..ef4dd00 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java @@ -28,9 +28,9 @@ public class MySQL extends SQL { //TODO add cooldown sync table - public MySQL(Minepacks mp) + public MySQL(Minepacks plugin) { - super(mp); // Load Settings + super(plugin); // Load Settings } @Override diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java index 348a07e..99996d8 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java @@ -31,9 +31,9 @@ public class MySQLShared extends MySQL { private DatabaseConnectionPool pool; - protected MySQLShared(Minepacks minepacks, DatabaseConnectionPool pool) + protected MySQLShared(Minepacks plugin, DatabaseConnectionPool pool) { - super(minepacks); + super(plugin); this.pool = pool; } @@ -44,8 +44,7 @@ protected HikariConfig getPoolConfig() } @Override - @NotNull - public Connection getConnection() throws SQLException + public @NotNull Connection getConnection() throws SQLException { return pool.getConnection(); } diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java index f830ea9..7b3e407 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java @@ -35,7 +35,10 @@ import org.jetbrains.annotations.Nullable; import java.sql.*; -import java.util.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; public abstract class SQL extends Database { @@ -47,9 +50,9 @@ public abstract class SQL extends Database @Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys protected boolean updatePlayer, syncCooldown; - public SQL(Minepacks mp) + public SQL(Minepacks plugin) { - super(mp); + super(plugin); HikariConfig poolConfig = getPoolConfig(); if(poolConfig != null) @@ -178,8 +181,8 @@ public UpdateData(String uuid, int id) ps.setString(1, updateData.uuid); ps.setInt(2, updateData.id); ps.addBatch(); - ps.executeBatch(); } + ps.executeBatch(); } plugin.getLogger().info(String.format(UUIDS_UPDATED, toUpdate.size())); } @@ -190,7 +193,7 @@ public UpdateData(String uuid, int id) } } - protected Connection getConnection() throws SQLException + public Connection getConnection() throws SQLException { return dataSource.getConnection(); } diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java index 3a9b6cf..2dddf2d 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java @@ -33,9 +33,9 @@ public class SQLite extends SQL { //TODO add cooldown sync table - public SQLite(Minepacks mp) + public SQLite(Minepacks plugin) { - super(mp); + super(plugin); } @Override @@ -84,10 +84,7 @@ protected HikariConfig getPoolConfig() @Override protected void updateQuerysForDialect() { - if(maxAge > 0) - { - queryInsertBp = queryInsertBp.replaceAll("\\) VALUES \\(\\?,\\?,\\?", "{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')"); - } + queryInsertBp = queryInsertBp.replaceAll("\\) VALUES \\(\\?,\\?,\\?", ",{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')"); queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')"; queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW}", "DATE('now')"); if(useUUIDs) diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java index f5d48c2..ae27566 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java @@ -32,9 +32,9 @@ public class SQLiteShared extends SQLite { private DatabaseConnectionPool pool; - protected SQLiteShared(Minepacks minepacks, DatabaseConnectionPool pool) + protected SQLiteShared(Minepacks plugin, DatabaseConnectionPool pool) { - super(minepacks); + super(plugin); this.pool = pool; }