mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Removed WorldTimesTable.Col
This commit is contained in:
parent
dec81cc12f
commit
e75fb76906
@ -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.WorldTimesTable;
|
import com.djrapitops.plan.db.sql.tables.WorldTimesTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.WorldTimesTable.Col;
|
|
||||||
|
|
||||||
public class WorldTimesOptimizationPatch extends Patch {
|
public class WorldTimesOptimizationPatch extends Patch {
|
||||||
|
|
||||||
@ -34,9 +33,9 @@ public class WorldTimesOptimizationPatch extends Patch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasBeenApplied() {
|
public boolean hasBeenApplied() {
|
||||||
return hasColumn(tableName, Col.ID.get())
|
return hasColumn(tableName, WorldTimesTable.ID)
|
||||||
&& hasColumn(tableName, Col.UUID.get())
|
&& hasColumn(tableName, WorldTimesTable.USER_UUID)
|
||||||
&& hasColumn(tableName, Col.SERVER_UUID.get())
|
&& hasColumn(tableName, WorldTimesTable.SERVER_UUID)
|
||||||
&& !hasColumn(tableName, "user_id")
|
&& !hasColumn(tableName, "user_id")
|
||||||
&& !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.
|
||||||
@ -49,23 +48,23 @@ public class WorldTimesOptimizationPatch extends Patch {
|
|||||||
db.getWorldTimesTable().createTable();
|
db.getWorldTimesTable().createTable();
|
||||||
|
|
||||||
execute("INSERT INTO " + tableName + " (" +
|
execute("INSERT INTO " + tableName + " (" +
|
||||||
Col.UUID + ", " +
|
WorldTimesTable.USER_UUID + ", " +
|
||||||
Col.SERVER_UUID + ", " +
|
WorldTimesTable.SERVER_UUID + ", " +
|
||||||
Col.ADVENTURE + ", " +
|
WorldTimesTable.ADVENTURE + ", " +
|
||||||
Col.CREATIVE + ", " +
|
WorldTimesTable.CREATIVE + ", " +
|
||||||
Col.SURVIVAL + ", " +
|
WorldTimesTable.SURVIVAL + ", " +
|
||||||
Col.SPECTATOR + ", " +
|
WorldTimesTable.SPECTATOR + ", " +
|
||||||
Col.SESSION_ID + ", " +
|
WorldTimesTable.SESSION_ID + ", " +
|
||||||
Col.WORLD_ID +
|
WorldTimesTable.WORLD_ID +
|
||||||
") SELECT " +
|
") SELECT " +
|
||||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||||
"(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.ADVENTURE + ", " +
|
WorldTimesTable.ADVENTURE + ", " +
|
||||||
Col.CREATIVE + ", " +
|
WorldTimesTable.CREATIVE + ", " +
|
||||||
Col.SURVIVAL + ", " +
|
WorldTimesTable.SURVIVAL + ", " +
|
||||||
Col.SPECTATOR + ", " +
|
WorldTimesTable.SPECTATOR + ", " +
|
||||||
Col.SESSION_ID + ", " +
|
WorldTimesTable.SESSION_ID + ", " +
|
||||||
Col.WORLD_ID +
|
WorldTimesTable.WORLD_ID +
|
||||||
" FROM " + tempTableName
|
" FROM " + tempTableName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class WorldTimesSeverIDPatch extends Patch {
|
|||||||
|
|
||||||
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " +
|
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " +
|
||||||
"server_id=?" +
|
"server_id=?" +
|
||||||
" WHERE " + WorldTimesTable.Col.SESSION_ID + "=?";
|
" WHERE " + WorldTimesTable.SESSION_ID + "=?";
|
||||||
|
|
||||||
executeBatch(new ExecStatement(sql) {
|
executeBatch(new ExecStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,7 +30,6 @@ import com.djrapitops.plan.db.patches.Version10Patch;
|
|||||||
import com.djrapitops.plan.db.patches.WorldTimesOptimizationPatch;
|
import com.djrapitops.plan.db.patches.WorldTimesOptimizationPatch;
|
||||||
import com.djrapitops.plan.db.patches.WorldTimesSeverIDPatch;
|
import com.djrapitops.plan.db.patches.WorldTimesSeverIDPatch;
|
||||||
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;
|
||||||
@ -46,8 +45,6 @@ import java.util.stream.Collectors;
|
|||||||
* <p>
|
* <p>
|
||||||
* Table Name: plan_world_times
|
* Table Name: plan_world_times
|
||||||
* <p>
|
* <p>
|
||||||
* For contained columns {@link Col}
|
|
||||||
* <p>
|
|
||||||
* Patches related to this table:
|
* Patches related to this table:
|
||||||
* {@link Version10Patch}
|
* {@link Version10Patch}
|
||||||
* {@link WorldTimesSeverIDPatch}
|
* {@link WorldTimesSeverIDPatch}
|
||||||
@ -79,14 +76,14 @@ public class WorldTimesTable extends Table {
|
|||||||
worldTable = db.getWorldTable();
|
worldTable = db.getWorldTable();
|
||||||
sessionsTable = db.getSessionsTable();
|
sessionsTable = db.getSessionsTable();
|
||||||
insertStatement = "INSERT INTO " + tableName + " (" +
|
insertStatement = "INSERT INTO " + tableName + " (" +
|
||||||
Col.UUID + ", " +
|
USER_UUID + ", " +
|
||||||
Col.WORLD_ID + ", " +
|
WORLD_ID + ", " +
|
||||||
Col.SERVER_UUID + ", " +
|
SERVER_UUID + ", " +
|
||||||
Col.SESSION_ID + ", " +
|
SESSION_ID + ", " +
|
||||||
Col.SURVIVAL + ", " +
|
SURVIVAL + ", " +
|
||||||
Col.CREATIVE + ", " +
|
CREATIVE + ", " +
|
||||||
Col.ADVENTURE + ", " +
|
ADVENTURE + ", " +
|
||||||
Col.SPECTATOR +
|
SPECTATOR +
|
||||||
") VALUES (?, " +
|
") VALUES (?, " +
|
||||||
worldTable.statementSelectID + ", " +
|
worldTable.statementSelectID + ", " +
|
||||||
"?, ?, ?, ?, ?, ?)";
|
"?, ?, ?, ?, ?, ?)";
|
||||||
@ -117,15 +114,15 @@ public class WorldTimesTable extends Table {
|
|||||||
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
||||||
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";
|
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
Col.SESSION_ID + ", " +
|
SESSION_ID + ", " +
|
||||||
Col.SURVIVAL + ", " +
|
SURVIVAL + ", " +
|
||||||
Col.CREATIVE + ", " +
|
CREATIVE + ", " +
|
||||||
Col.ADVENTURE + ", " +
|
ADVENTURE + ", " +
|
||||||
Col.SPECTATOR + ", " +
|
SPECTATOR + ", " +
|
||||||
worldNameColumn +
|
worldNameColumn +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + Col.WORLD_ID +
|
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + WORLD_ID +
|
||||||
" WHERE " + Col.UUID + "=?";
|
" WHERE " + USER_UUID + "=?";
|
||||||
|
|
||||||
query(new QueryStatement<Object>(sql, 2000) {
|
query(new QueryStatement<Object>(sql, 2000) {
|
||||||
@Override
|
@Override
|
||||||
@ -138,7 +135,7 @@ public class WorldTimesTable extends Table {
|
|||||||
String[] gms = GMTimes.getGMKeyArray();
|
String[] gms = GMTimes.getGMKeyArray();
|
||||||
|
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int sessionID = set.getInt(Col.SESSION_ID.get());
|
int sessionID = set.getInt(SESSION_ID);
|
||||||
Session session = sessions.get(sessionID);
|
Session session = sessions.get(sessionID);
|
||||||
|
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
@ -148,10 +145,10 @@ public class WorldTimesTable extends Table {
|
|||||||
String worldName = set.getString("world_name");
|
String worldName = set.getString("world_name");
|
||||||
|
|
||||||
Map<String, Long> gmMap = new HashMap<>();
|
Map<String, Long> gmMap = new HashMap<>();
|
||||||
gmMap.put(gms[0], set.getLong(Col.SURVIVAL.get()));
|
gmMap.put(gms[0], set.getLong(SURVIVAL));
|
||||||
gmMap.put(gms[1], set.getLong(Col.CREATIVE.get()));
|
gmMap.put(gms[1], set.getLong(CREATIVE));
|
||||||
gmMap.put(gms[2], set.getLong(Col.ADVENTURE.get()));
|
gmMap.put(gms[2], set.getLong(ADVENTURE));
|
||||||
gmMap.put(gms[3], set.getLong(Col.SPECTATOR.get()));
|
gmMap.put(gms[3], set.getLong(SPECTATOR));
|
||||||
GMTimes gmTimes = new GMTimes(gmMap);
|
GMTimes gmTimes = new GMTimes(gmMap);
|
||||||
|
|
||||||
session.getUnsafe(SessionKeys.WORLD_TIMES).setGMTimesForWorld(worldName, gmTimes);
|
session.getUnsafe(SessionKeys.WORLD_TIMES).setGMTimesForWorld(worldName, gmTimes);
|
||||||
@ -196,17 +193,17 @@ public class WorldTimesTable extends Table {
|
|||||||
|
|
||||||
public WorldTimes getWorldTimesOfServer(UUID serverUUID) {
|
public WorldTimes getWorldTimesOfServer(UUID serverUUID) {
|
||||||
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
||||||
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world";
|
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
"SUM(" + Col.SURVIVAL + ") as survival, " +
|
"SUM(" + SURVIVAL + ") as survival, " +
|
||||||
"SUM(" + Col.CREATIVE + ") as creative, " +
|
"SUM(" + CREATIVE + ") as creative, " +
|
||||||
"SUM(" + Col.ADVENTURE + ") as adventure, " +
|
"SUM(" + ADVENTURE + ") as adventure, " +
|
||||||
"SUM(" + Col.SPECTATOR + ") as spectator, " +
|
"SUM(" + SPECTATOR + ") as spectator, " +
|
||||||
worldNameColumn +
|
worldNameColumn +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + Col.WORLD_ID +
|
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + WORLD_ID +
|
||||||
" WHERE " + tableName + "." + Col.SERVER_UUID + "=?" +
|
" WHERE " + tableName + "." + SERVER_UUID + "=?" +
|
||||||
" GROUP BY world";
|
" GROUP BY " + WORLD_ID;
|
||||||
|
|
||||||
return query(new QueryStatement<WorldTimes>(sql, 1000) {
|
return query(new QueryStatement<WorldTimes>(sql, 1000) {
|
||||||
@Override
|
@Override
|
||||||
@ -220,7 +217,7 @@ public class WorldTimesTable extends Table {
|
|||||||
|
|
||||||
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
String worldName = set.getString("world");
|
String worldName = set.getString("world_name");
|
||||||
|
|
||||||
Map<String, Long> gmMap = new HashMap<>();
|
Map<String, Long> gmMap = new HashMap<>();
|
||||||
gmMap.put(gms[0], set.getLong("survival"));
|
gmMap.put(gms[0], set.getLong("survival"));
|
||||||
@ -238,17 +235,17 @@ public class WorldTimesTable extends Table {
|
|||||||
|
|
||||||
public WorldTimes getWorldTimesOfUser(UUID uuid) {
|
public WorldTimes getWorldTimesOfUser(UUID uuid) {
|
||||||
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
||||||
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world";
|
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
"SUM(" + Col.SURVIVAL + ") as survival, " +
|
"SUM(" + SURVIVAL + ") as survival, " +
|
||||||
"SUM(" + Col.CREATIVE + ") as creative, " +
|
"SUM(" + CREATIVE + ") as creative, " +
|
||||||
"SUM(" + Col.ADVENTURE + ") as adventure, " +
|
"SUM(" + ADVENTURE + ") as adventure, " +
|
||||||
"SUM(" + Col.SPECTATOR + ") as spectator, " +
|
"SUM(" + SPECTATOR + ") as spectator, " +
|
||||||
worldNameColumn +
|
worldNameColumn +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + Col.WORLD_ID +
|
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + WORLD_ID +
|
||||||
" WHERE " + Col.UUID + "=?" +
|
" WHERE " + USER_UUID + "=?" +
|
||||||
" GROUP BY world";
|
" GROUP BY " + WORLD_ID;
|
||||||
|
|
||||||
return query(new QueryStatement<WorldTimes>(sql) {
|
return query(new QueryStatement<WorldTimes>(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -262,7 +259,7 @@ public class WorldTimesTable extends Table {
|
|||||||
|
|
||||||
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
String worldName = set.getString("world");
|
String worldName = set.getString("world_name");
|
||||||
|
|
||||||
Map<String, Long> gmMap = new HashMap<>();
|
Map<String, Long> gmMap = new HashMap<>();
|
||||||
gmMap.put(gms[0], set.getLong("survival"));
|
gmMap.put(gms[0], set.getLong("survival"));
|
||||||
@ -280,16 +277,16 @@ public class WorldTimesTable extends Table {
|
|||||||
|
|
||||||
public Map<Integer, WorldTimes> getAllWorldTimesBySessionID() {
|
public Map<Integer, WorldTimes> getAllWorldTimesBySessionID() {
|
||||||
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
String worldIDColumn = worldTable + "." + WorldTable.ID;
|
||||||
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world";
|
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
Col.SESSION_ID + ", " +
|
SESSION_ID + ", " +
|
||||||
Col.SURVIVAL + ", " +
|
SURVIVAL + ", " +
|
||||||
Col.CREATIVE + ", " +
|
CREATIVE + ", " +
|
||||||
Col.ADVENTURE + ", " +
|
ADVENTURE + ", " +
|
||||||
Col.SPECTATOR + ", " +
|
SPECTATOR + ", " +
|
||||||
worldNameColumn +
|
worldNameColumn +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + Col.WORLD_ID;
|
" INNER JOIN " + worldTable + " on " + worldIDColumn + "=" + WORLD_ID;
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<Integer, WorldTimes>>(sql, 50000) {
|
return query(new QueryAllStatement<Map<Integer, WorldTimes>>(sql, 50000) {
|
||||||
@Override
|
@Override
|
||||||
@ -298,15 +295,15 @@ public class WorldTimesTable extends Table {
|
|||||||
|
|
||||||
Map<Integer, WorldTimes> worldTimes = new HashMap<>();
|
Map<Integer, WorldTimes> worldTimes = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int sessionID = set.getInt(Col.SESSION_ID.get());
|
int sessionID = set.getInt(SESSION_ID);
|
||||||
|
|
||||||
String worldName = set.getString("world");
|
String worldName = set.getString("world_name");
|
||||||
|
|
||||||
Map<String, Long> gmMap = new HashMap<>();
|
Map<String, Long> gmMap = new HashMap<>();
|
||||||
gmMap.put(gms[0], set.getLong(Col.SURVIVAL.get()));
|
gmMap.put(gms[0], set.getLong(SURVIVAL));
|
||||||
gmMap.put(gms[1], set.getLong(Col.CREATIVE.get()));
|
gmMap.put(gms[1], set.getLong(CREATIVE));
|
||||||
gmMap.put(gms[2], set.getLong(Col.ADVENTURE.get()));
|
gmMap.put(gms[2], set.getLong(ADVENTURE));
|
||||||
gmMap.put(gms[3], set.getLong(Col.SPECTATOR.get()));
|
gmMap.put(gms[3], set.getLong(SPECTATOR));
|
||||||
GMTimes gmTimes = new GMTimes(gmMap);
|
GMTimes gmTimes = new GMTimes(gmMap);
|
||||||
|
|
||||||
WorldTimes worldTOfSession = worldTimes.getOrDefault(sessionID, new WorldTimes(new HashMap<>()));
|
WorldTimes worldTOfSession = worldTimes.getOrDefault(sessionID, new WorldTimes(new HashMap<>()));
|
||||||
@ -402,32 +399,4 @@ public class WorldTimesTable extends Table {
|
|||||||
return Objects.hash(super.hashCode(), worldTable, sessionsTable, insertStatement);
|
return Objects.hash(super.hashCode(), worldTable, sessionsTable, insertStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public enum Col implements Column {
|
|
||||||
@Deprecated ID("id"),
|
|
||||||
@Deprecated UUID("uuid"),
|
|
||||||
@Deprecated SERVER_UUID("server_uuid"),
|
|
||||||
@Deprecated SESSION_ID("session_id"),
|
|
||||||
@Deprecated WORLD_ID("world_id"),
|
|
||||||
@Deprecated SURVIVAL("survival_time"),
|
|
||||||
@Deprecated CREATIVE("creative_time"),
|
|
||||||
@Deprecated ADVENTURE("adventure_time"),
|
|
||||||
@Deprecated SPECTATOR("spectator_time");
|
|
||||||
|
|
||||||
private final String column;
|
|
||||||
|
|
||||||
Col(String column) {
|
|
||||||
this.column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get() {
|
|
||||||
return toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user