Removed WorldTable.Col

This commit is contained in:
Rsl1122 2019-01-24 15:24:24 +02:00
parent 18e39d1394
commit dec81cc12f
3 changed files with 28 additions and 53 deletions

View File

@ -19,7 +19,6 @@ package com.djrapitops.plan.db.patches;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.sql.tables.WorldTable; import com.djrapitops.plan.db.sql.tables.WorldTable;
import com.djrapitops.plan.db.sql.tables.WorldTable.Col;
public class WorldsOptimizationPatch extends Patch { public class WorldsOptimizationPatch extends Patch {
@ -34,8 +33,8 @@ public class WorldsOptimizationPatch extends Patch {
@Override @Override
public boolean hasBeenApplied() { public boolean hasBeenApplied() {
return hasColumn(tableName, Col.ID.get()) return hasColumn(tableName, WorldTable.ID)
&& hasColumn(tableName, Col.SERVER_UUID.get()) && hasColumn(tableName, WorldTable.SERVER_UUID)
&& !hasColumn(tableName, "server_id") && !hasColumn(tableName, "server_id")
&& !hasTable(tempTableName); // If this table exists the patch has failed to finish. && !hasTable(tempTableName); // If this table exists the patch has failed to finish.
} }
@ -50,13 +49,13 @@ public class WorldsOptimizationPatch extends Patch {
db.getWorldTable().createTable(); db.getWorldTable().createTable();
execute("INSERT INTO " + tableName + " (" + execute("INSERT INTO " + tableName + " (" +
Col.ID + ", " + WorldTable.ID + ", " +
Col.SERVER_UUID + ", " + WorldTable.SERVER_UUID + ", " +
Col.NAME + WorldTable.NAME +
") SELECT " + ") SELECT " +
Col.ID + ", " + WorldTable.ID + ", " +
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " + "(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
Col.NAME + WorldTable.NAME +
" FROM " + tempTableName " FROM " + tempTableName
); );

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.db.access.QueryStatement;
import com.djrapitops.plan.db.patches.Version10Patch; import com.djrapitops.plan.db.patches.Version10Patch;
import com.djrapitops.plan.db.patches.WorldsOptimizationPatch; import com.djrapitops.plan.db.patches.WorldsOptimizationPatch;
import com.djrapitops.plan.db.patches.WorldsServerIDPatch; import com.djrapitops.plan.db.patches.WorldsServerIDPatch;
import com.djrapitops.plan.db.sql.parsing.Column;
import com.djrapitops.plan.db.sql.parsing.CreateTableParser; import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
import com.djrapitops.plan.db.sql.parsing.Sql; import com.djrapitops.plan.db.sql.parsing.Sql;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
@ -44,7 +43,7 @@ import java.util.*;
* {@link WorldsServerIDPatch} * {@link WorldsServerIDPatch}
* {@link WorldsOptimizationPatch} * {@link WorldsOptimizationPatch}
* *
* @author Rsl1122 / Database version 7 * @author Rsl1122
*/ */
public class WorldTable extends Table { public class WorldTable extends Table {
@ -60,9 +59,9 @@ public class WorldTable extends Table {
public WorldTable(SQLDB db) { public WorldTable(SQLDB db) {
super(TABLE_NAME, db); super(TABLE_NAME, db);
serverTable = db.getServerTable(); serverTable = db.getServerTable();
statementSelectID = "(SELECT " + Col.ID + " FROM " + tableName + statementSelectID = "(SELECT " + ID + " FROM " + tableName +
" WHERE (" + Col.NAME + "=?)" + " WHERE (" + NAME + "=?)" +
" AND (" + Col.SERVER_UUID + "=?)" + " AND (" + SERVER_UUID + "=?)" +
" LIMIT 1)"; " LIMIT 1)";
} }
@ -85,7 +84,7 @@ public class WorldTable extends Table {
public List<String> getWorlds(UUID serverUUID) { public List<String> getWorlds(UUID serverUUID) {
String sql = "SELECT * FROM " + tableName + String sql = "SELECT * FROM " + tableName +
" WHERE " + Col.SERVER_UUID + "=?"; " WHERE " + SERVER_UUID + "=?";
return query(new QueryStatement<List<String>>(sql) { return query(new QueryStatement<List<String>>(sql) {
@ -98,7 +97,7 @@ public class WorldTable extends Table {
public List<String> processResults(ResultSet set) throws SQLException { public List<String> processResults(ResultSet set) throws SQLException {
List<String> worldNames = new ArrayList<>(); List<String> worldNames = new ArrayList<>();
while (set.next()) { while (set.next()) {
String worldName = set.getString(Col.NAME.get()); String worldName = set.getString(NAME);
worldNames.add(worldName); worldNames.add(worldName);
} }
return worldNames; return worldNames;
@ -108,8 +107,8 @@ public class WorldTable extends Table {
public void saveWorlds(Map<UUID, Collection<String>> worldMap) { public void saveWorlds(Map<UUID, Collection<String>> worldMap) {
String sql = "INSERT INTO " + tableName + " (" String sql = "INSERT INTO " + tableName + " ("
+ Col.NAME + ", " + NAME + ", "
+ Col.SERVER_UUID + SERVER_UUID
+ ") VALUES (?, ?)"; + ") VALUES (?, ?)";
executeBatch(new ExecStatement(sql) { executeBatch(new ExecStatement(sql) {
@ -149,8 +148,8 @@ public class WorldTable extends Table {
} }
String sql = "INSERT INTO " + tableName + " (" String sql = "INSERT INTO " + tableName + " ("
+ Col.NAME + ", " + NAME + ", "
+ Col.SERVER_UUID + SERVER_UUID
+ ") VALUES (?, ?)"; + ") VALUES (?, ?)";
executeBatch(new ExecStatement(sql) { executeBatch(new ExecStatement(sql) {
@ -166,8 +165,8 @@ public class WorldTable extends Table {
} }
public Set<String> getWorldNames(UUID serverUUID) { public Set<String> getWorldNames(UUID serverUUID) {
String sql = "SELECT DISTINCT " + Col.NAME + " FROM " + tableName + String sql = "SELECT DISTINCT " + NAME + " FROM " + tableName +
" WHERE " + Col.SERVER_UUID + "=?"; " WHERE " + SERVER_UUID + "=?";
return query(new QueryStatement<Set<String>>(sql, 100) { return query(new QueryStatement<Set<String>>(sql, 100) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
@ -178,36 +177,13 @@ public class WorldTable extends Table {
public Set<String> processResults(ResultSet set) throws SQLException { public Set<String> processResults(ResultSet set) throws SQLException {
Set<String> worldNames = new HashSet<>(); Set<String> worldNames = new HashSet<>();
while (set.next()) { while (set.next()) {
worldNames.add(set.getString(Col.NAME.get())); worldNames.add(set.getString(NAME));
} }
return worldNames; return worldNames;
} }
}); });
} }
@Deprecated
public enum Col implements Column {
@Deprecated ID("id"),
@Deprecated SERVER_UUID("server_uuid"),
@Deprecated NAME("world_name");
private final String column;
Col(String column) {
this.column = column;
}
@Override
public String get() {
return toString();
}
@Override
public String toString() {
return column;
}
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -114,8 +114,8 @@ public class WorldTimesTable extends Table {
} }
public void addWorldTimesToSessions(UUID uuid, Map<Integer, Session> sessions) { public void addWorldTimesToSessions(UUID uuid, Map<Integer, Session> sessions) {
String worldIDColumn = worldTable + "." + WorldTable.Col.ID; String worldIDColumn = worldTable + "." + WorldTable.ID;
String worldNameColumn = worldTable + "." + WorldTable.Col.NAME + " as world_name"; String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";
String sql = "SELECT " + String sql = "SELECT " +
Col.SESSION_ID + ", " + Col.SESSION_ID + ", " +
Col.SURVIVAL + ", " + Col.SURVIVAL + ", " +
@ -195,8 +195,8 @@ public class WorldTimesTable extends Table {
} }
public WorldTimes getWorldTimesOfServer(UUID serverUUID) { public WorldTimes getWorldTimesOfServer(UUID serverUUID) {
String worldIDColumn = worldTable + "." + WorldTable.Col.ID; String worldIDColumn = worldTable + "." + WorldTable.ID;
String worldNameColumn = worldTable + "." + WorldTable.Col.NAME + " as world"; String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world";
String sql = "SELECT " + String sql = "SELECT " +
"SUM(" + Col.SURVIVAL + ") as survival, " + "SUM(" + Col.SURVIVAL + ") as survival, " +
"SUM(" + Col.CREATIVE + ") as creative, " + "SUM(" + Col.CREATIVE + ") as creative, " +
@ -237,8 +237,8 @@ public class WorldTimesTable extends Table {
} }
public WorldTimes getWorldTimesOfUser(UUID uuid) { public WorldTimes getWorldTimesOfUser(UUID uuid) {
String worldIDColumn = worldTable + "." + WorldTable.Col.ID; String worldIDColumn = worldTable + "." + WorldTable.ID;
String worldNameColumn = worldTable + "." + WorldTable.Col.NAME + " as world"; String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world";
String sql = "SELECT " + String sql = "SELECT " +
"SUM(" + Col.SURVIVAL + ") as survival, " + "SUM(" + Col.SURVIVAL + ") as survival, " +
"SUM(" + Col.CREATIVE + ") as creative, " + "SUM(" + Col.CREATIVE + ") as creative, " +
@ -279,8 +279,8 @@ public class WorldTimesTable extends Table {
} }
public Map<Integer, WorldTimes> getAllWorldTimesBySessionID() { public Map<Integer, WorldTimes> getAllWorldTimesBySessionID() {
String worldIDColumn = worldTable + "." + WorldTable.Col.ID; String worldIDColumn = worldTable + "." + WorldTable.ID;
String worldNameColumn = worldTable + "." + WorldTable.Col.NAME + " as world"; String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world";
String sql = "SELECT " + String sql = "SELECT " +
Col.SESSION_ID + ", " + Col.SESSION_ID + ", " +
Col.SURVIVAL + ", " + Col.SURVIVAL + ", " +