From e3333fabb8a561d11231d9fd3a396fdbb97ba13f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 16 Aug 2017 16:27:36 +0300 Subject: [PATCH] Removed Locations table --- .../plan/data/analysis/RawData.java | 3 +- .../djrapitops/plan/database/Database.java | 19 ---- .../plan/database/databases/SQLDB.java | 56 +++++++----- .../plan/database/tables/LocationsTable.java | 89 ------------------- 4 files changed, 34 insertions(+), 133 deletions(-) delete mode 100644 Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java index 4d0d7bf49..fd0b485d4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java @@ -72,8 +72,7 @@ public abstract class RawData { * @param value Any value the placeholder should be replaced with. */ public void addValue(String placeholder, Serializable value) { - placeholder = addPlaceholderSigns(placeholder); - replaceMap.put(placeholder, value.toString()); + replaceMap.put(addPlaceholderSigns(placeholder), value.toString()); } private String addPlaceholderSigns(String placeholder) { diff --git a/Plan/src/main/java/com/djrapitops/plan/database/Database.java b/Plan/src/main/java/com/djrapitops/plan/database/Database.java index d9303e43b..4c7ac5fea 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/Database.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/Database.java @@ -38,14 +38,6 @@ public abstract class Database { */ protected KillsTable killsTable; - /** - * Table representing plan_locations in the database. - * - * @deprecated Removed in 3.5.2 - */ - @Deprecated - protected LocationsTable locationsTable; - /** * Table representing plan_nicknames in the database. */ @@ -315,17 +307,6 @@ public abstract class Database { return killsTable; } - /** - * Used to get the locations table. - * - * @return Table representing plan_locations - * @deprecated Removed in 3.5.2 - */ - @Deprecated - public LocationsTable getLocationsTable() { - return locationsTable; - } - /** * Used to get the ips table. * diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index c71b9da96..a64ebd0fa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -48,7 +48,6 @@ public abstract class SQLDB extends Database { gmTimesTable = new GMTimesTable(this, usingMySQL); sessionsTable = new SessionsTable(this, usingMySQL); killsTable = new KillsTable(this, usingMySQL); - locationsTable = new LocationsTable(this, usingMySQL); ipsTable = new IPsTable(this, usingMySQL); nicknamesTable = new NicknamesTable(this, usingMySQL); commandUseTable = new CommandUseTable(this, usingMySQL); @@ -132,13 +131,8 @@ public abstract class SQLDB extends Database { return false; } - boolean newDatabase = true; - try { - getVersion(); - newDatabase = false; - } catch (Exception ignored) { + boolean newDatabase = isNewDatabase(); - } if (!versionTable.createTable()) { Log.error("Failed to create table: " + versionTable.getTableName()); return false; @@ -149,28 +143,46 @@ public abstract class SQLDB extends Database { setVersion(8); } - Benchmark.start("DCreate tables"); - - for (Table table : getAllTables()) { - if (!table.createTable()) { - Log.error("Failed to create table: " + table.getTableName()); - return false; - } - } - - if (!securityTable.createTable()) { - Log.error("Failed to create table: " + securityTable.getTableName()); + if (!createTables()) { return false; } - Benchmark.stop("Database", "Create tables"); if (!newDatabase && getVersion() < 8) { setVersion(8); } + connection.prepareStatement("DROP TABLE IF EXISTS plan_locations").execute(); } return true; } + /** + * Creates the tables that contain data. + * + * Updates table columns to latest schema. + * + * @return true if successful. + */ + private boolean createTables() { + Benchmark.start("Create tables"); + for (Table table : getAllTables()) { + if (!table.createTable()) { + Log.error("Failed to create table: " + table.getTableName()); + return false; + } + } + Benchmark.stop("Database", "Create tables"); + return true; + } + + private boolean isNewDatabase() { + try { + getVersion(); + return false; + } catch (Exception ignored) { + return true; + } + } + /** * */ @@ -214,7 +226,7 @@ public abstract class SQLDB extends Database { usersTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable, tpsTable, worldTable, - worldTimesTable}; + worldTimesTable, securityTable}; } /** @@ -222,7 +234,7 @@ public abstract class SQLDB extends Database { */ public Table[] getAllTablesInRemoveOrder() { return new Table[]{ - locationsTable, gmTimesTable, ipsTable, + gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, worldTimesTable, worldTable, usersTable, commandUseTable, tpsTable}; @@ -305,7 +317,6 @@ public abstract class SQLDB extends Database { } int userId = usersTable.getUserId(uuid); boolean success = userId != -1 - && locationsTable.removeUserLocations(userId) && ipsTable.removeUserIPs(userId) && nicknamesTable.removeUserNicknames(userId) && gmTimesTable.removeUserGMTimes(userId) @@ -567,7 +578,6 @@ public abstract class SQLDB extends Database { try { checkConnection(); tpsTable.clean(); - locationsTable.removeAllData(); Log.info("Clean complete."); } catch (SQLException e) { Log.toLog(this.getClass().getName(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java deleted file mode 100644 index d40f67454..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java +++ /dev/null @@ -1,89 +0,0 @@ -package main.java.com.djrapitops.plan.database.tables; - -import main.java.com.djrapitops.plan.Log; -import main.java.com.djrapitops.plan.database.databases.SQLDB; - -import java.sql.PreparedStatement; -import java.sql.SQLException; - -/** - * @author Rsl1122 - */ -@Deprecated -public class LocationsTable extends Table { - - private final String columnUserID; - private final String columnID; - private final String columnCoordinatesX; - private final String columnCoordinatesZ; - private final String columnWorld; - - /** - * @param db - * @param usingMySQL - * @deprecated Deprecated because it isn't used anymore - */ - @Deprecated - public LocationsTable(SQLDB db, boolean usingMySQL) { - super("plan_locations", db, usingMySQL); - columnID = "id"; - columnUserID = "user_id"; - columnCoordinatesX = "x"; - columnCoordinatesZ = "z"; - columnWorld = "world_name"; - } - - @Override - @Deprecated - public boolean removeAllData() { - try { - execute("DELETE FROM " + tableName); - } catch (Exception ignored) { - } - return true; - } - - /** - * @return - */ - @Override - @Deprecated - public boolean createTable() { - UsersTable usersTable = db.getUsersTable(); - try { - execute("CREATE TABLE IF NOT EXISTS " + tableName + " (" - + columnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", " - + columnUserID + " integer NOT NULL, " - + columnCoordinatesX + " integer NOT NULL, " - + columnCoordinatesZ + " integer NOT NULL, " - + columnWorld + " varchar(64) NOT NULL, " - + (usingMySQL ? "PRIMARY KEY (" + usersTable.getColumnID() + "), " : "") - + "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")" - + ")" - ); - return true; - } catch (SQLException ex) { - Log.toLog(this.getClass().getName(), ex); - return false; - } - } - - /** - * @param userId - * @return - */ - @Deprecated - public boolean removeUserLocations(int userId) { - PreparedStatement statement = null; - try { - statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUserID + "=?)"); - statement.setInt(1, userId); - statement.execute(); - return true; - } catch (SQLException ex) { - return true; - } finally { - close(statement); - } - } -}