mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 19:51:25 +01:00
Removed KillsTable.Col
This commit is contained in:
parent
2b5e3c61f3
commit
857892b0e3
@ -19,7 +19,6 @@ package com.djrapitops.plan.db.patches;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.sql.tables.KillsTable;
|
||||
import com.djrapitops.plan.db.sql.tables.KillsTable.Col;
|
||||
|
||||
public class KillsOptimizationPatch extends Patch {
|
||||
|
||||
@ -34,9 +33,9 @@ public class KillsOptimizationPatch extends Patch {
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(tableName, Col.VICTIM_UUID.get())
|
||||
&& hasColumn(tableName, Col.KILLER_UUID.get())
|
||||
&& hasColumn(tableName, Col.SERVER_UUID.get())
|
||||
return hasColumn(tableName, KillsTable.VICTIM_UUID)
|
||||
&& hasColumn(tableName, KillsTable.KILLER_UUID)
|
||||
&& hasColumn(tableName, KillsTable.SERVER_UUID)
|
||||
&& !hasColumn(tableName, "killer_id")
|
||||
&& !hasColumn(tableName, "victim_id")
|
||||
&& !hasColumn(tableName, "server_id")
|
||||
@ -50,19 +49,19 @@ public class KillsOptimizationPatch extends Patch {
|
||||
db.getKillsTable().createTable();
|
||||
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
Col.VICTIM_UUID + ", " +
|
||||
Col.KILLER_UUID + ", " +
|
||||
Col.SERVER_UUID + ", " +
|
||||
Col.DATE + ", " +
|
||||
Col.WEAPON + ", " +
|
||||
Col.SESSION_ID +
|
||||
KillsTable.VICTIM_UUID + ", " +
|
||||
KillsTable.KILLER_UUID + ", " +
|
||||
KillsTable.SERVER_UUID + ", " +
|
||||
KillsTable.DATE + ", " +
|
||||
KillsTable.WEAPON + ", " +
|
||||
KillsTable.SESSION_ID +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".victim_id LIMIT 1), " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".killer_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
Col.DATE + ", " +
|
||||
Col.WEAPON + ", " +
|
||||
Col.SESSION_ID +
|
||||
KillsTable.DATE + ", " +
|
||||
KillsTable.WEAPON + ", " +
|
||||
KillsTable.SESSION_ID +
|
||||
" FROM " + tempTableName
|
||||
);
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class KillsServerIDPatch extends Patch {
|
||||
String columnName = "server_id";
|
||||
|
||||
// KillsOptimizationPatch makes this patch incompatible with newer patch versions.
|
||||
return hasColumn(tableName, KillsTable.Col.SERVER_UUID.get())
|
||||
return hasColumn(tableName, KillsTable.SERVER_UUID)
|
||||
|| (hasColumn(tableName, columnName) && allValuesHaveServerID(tableName, columnName));
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ public class KillsServerIDPatch extends Patch {
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
if (hasColumn(KillsTable.TABLE_NAME, KillsTable.Col.SERVER_UUID.get())) {
|
||||
if (hasColumn(KillsTable.TABLE_NAME, KillsTable.SERVER_UUID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class KillsServerIDPatch extends Patch {
|
||||
|
||||
Map<Integer, Integer> sessionIDServerIDRelation = db.getSessionsTable().getIDServerIDRelation();
|
||||
|
||||
String sql = "UPDATE " + KillsTable.TABLE_NAME + " SET server_id=? WHERE " + KillsTable.Col.SESSION_ID + "=?";
|
||||
String sql = "UPDATE " + KillsTable.TABLE_NAME + " SET server_id=? WHERE " + KillsTable.SESSION_ID + "=?";
|
||||
|
||||
executeBatch(new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -28,7 +28,6 @@ import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.patches.KillsOptimizationPatch;
|
||||
import com.djrapitops.plan.db.patches.KillsServerIDPatch;
|
||||
import com.djrapitops.plan.db.patches.Version10Patch;
|
||||
import com.djrapitops.plan.db.sql.parsing.Column;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
import com.djrapitops.plan.db.sql.queries.LargeFetchQueries;
|
||||
@ -72,12 +71,12 @@ public class KillsTable extends UserUUIDTable {
|
||||
usersTable = db.getUsersTable();
|
||||
sessionsTable = db.getSessionsTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ Col.KILLER_UUID + ", "
|
||||
+ Col.VICTIM_UUID + ", "
|
||||
+ Col.SERVER_UUID + ", "
|
||||
+ Col.SESSION_ID + ", "
|
||||
+ Col.DATE + ", "
|
||||
+ Col.WEAPON
|
||||
+ KILLER_UUID + ", "
|
||||
+ VICTIM_UUID + ", "
|
||||
+ SERVER_UUID + ", "
|
||||
+ SESSION_ID + ", "
|
||||
+ DATE + ", "
|
||||
+ WEAPON
|
||||
+ ") VALUES (?, ?, ?, ?, ?, ?)";
|
||||
}
|
||||
|
||||
@ -105,8 +104,8 @@ public class KillsTable extends UserUUIDTable {
|
||||
@Override
|
||||
public void removeUser(UUID uuid) {
|
||||
String sql = "DELETE FROM " + tableName +
|
||||
" WHERE " + Col.KILLER_UUID + "=?" +
|
||||
" OR " + Col.VICTIM_UUID + "=?";
|
||||
" WHERE " + KILLER_UUID + "=?" +
|
||||
" OR " + VICTIM_UUID + "=?";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
@ -118,17 +117,17 @@ public class KillsTable extends UserUUIDTable {
|
||||
}
|
||||
|
||||
public void addKillsToSessions(UUID uuid, Map<Integer, Session> sessions) {
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID;
|
||||
String usersNameColumn = usersTable + "." + UsersTable.Col.USER_NAME + " as victim_name";
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.USER_UUID;
|
||||
String usersNameColumn = usersTable + "." + UsersTable.USER_NAME + " as victim_name";
|
||||
String sql = "SELECT " +
|
||||
Col.SESSION_ID + ", " +
|
||||
Col.DATE + ", " +
|
||||
Col.WEAPON + ", " +
|
||||
Col.VICTIM_UUID + ", " +
|
||||
SESSION_ID + ", " +
|
||||
DATE + ", " +
|
||||
WEAPON + ", " +
|
||||
VICTIM_UUID + ", " +
|
||||
usersNameColumn +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + Col.VICTIM_UUID +
|
||||
" WHERE " + Col.KILLER_UUID + "=?";
|
||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + VICTIM_UUID +
|
||||
" WHERE " + KILLER_UUID + "=?";
|
||||
|
||||
query(new QueryStatement<Object>(sql, 50000) {
|
||||
@Override
|
||||
@ -139,15 +138,15 @@ public class KillsTable extends UserUUIDTable {
|
||||
@Override
|
||||
public Object processResults(ResultSet set) throws SQLException {
|
||||
while (set.next()) {
|
||||
int sessionID = set.getInt(Col.SESSION_ID.get());
|
||||
int sessionID = set.getInt(SESSION_ID);
|
||||
Session session = sessions.get(sessionID);
|
||||
if (session == null) {
|
||||
continue;
|
||||
}
|
||||
UUID victim = UUID.fromString(set.getString(Col.VICTIM_UUID.get()));
|
||||
UUID victim = UUID.fromString(set.getString(VICTIM_UUID));
|
||||
String victimName = set.getString("victim_name");
|
||||
long date = set.getLong(Col.DATE.get());
|
||||
String weapon = set.getString(Col.WEAPON.get());
|
||||
long date = set.getLong(DATE);
|
||||
String weapon = set.getString(WEAPON);
|
||||
session.getPlayerKills().add(new PlayerKill(victim, weapon, date, victimName));
|
||||
}
|
||||
return null;
|
||||
@ -156,17 +155,17 @@ public class KillsTable extends UserUUIDTable {
|
||||
}
|
||||
|
||||
public void addDeathsToSessions(UUID uuid, Map<Integer, Session> sessions) {
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID;
|
||||
String usersNameColumn = usersTable + "." + UsersTable.Col.USER_NAME + " as killer_name";
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.USER_UUID;
|
||||
String usersNameColumn = usersTable + "." + UsersTable.USER_NAME + " as killer_name";
|
||||
String sql = "SELECT " +
|
||||
Col.SESSION_ID + ", " +
|
||||
Col.DATE + ", " +
|
||||
Col.WEAPON + ", " +
|
||||
Col.KILLER_UUID + ", " +
|
||||
SESSION_ID + ", " +
|
||||
DATE + ", " +
|
||||
WEAPON + ", " +
|
||||
KILLER_UUID + ", " +
|
||||
usersNameColumn +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + Col.KILLER_UUID +
|
||||
" WHERE " + Col.VICTIM_UUID + "=?";
|
||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + KILLER_UUID +
|
||||
" WHERE " + VICTIM_UUID + "=?";
|
||||
|
||||
query(new QueryStatement<Object>(sql, 50000) {
|
||||
@Override
|
||||
@ -177,15 +176,15 @@ public class KillsTable extends UserUUIDTable {
|
||||
@Override
|
||||
public Object processResults(ResultSet set) throws SQLException {
|
||||
while (set.next()) {
|
||||
int sessionID = set.getInt(Col.SESSION_ID.get());
|
||||
int sessionID = set.getInt(SESSION_ID);
|
||||
Session session = sessions.get(sessionID);
|
||||
if (session == null) {
|
||||
continue;
|
||||
}
|
||||
UUID killer = UUID.fromString(set.getString(Col.KILLER_UUID.get()));
|
||||
UUID killer = UUID.fromString(set.getString(KILLER_UUID));
|
||||
String name = set.getString("killer_name");
|
||||
long date = set.getLong(Col.DATE.get());
|
||||
String weapon = set.getString(Col.WEAPON.get());
|
||||
long date = set.getLong(DATE);
|
||||
String weapon = set.getString(WEAPON);
|
||||
session.getUnsafe(SessionKeys.PLAYER_DEATHS).add(new PlayerDeath(killer, name, weapon, date));
|
||||
}
|
||||
return null;
|
||||
@ -271,38 +270,4 @@ public class KillsTable extends UserUUIDTable {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public enum Col implements Column {
|
||||
@Deprecated
|
||||
ID("id"),
|
||||
@Deprecated
|
||||
KILLER_UUID("killer_uuid"),
|
||||
@Deprecated
|
||||
VICTIM_UUID("victim_uuid"),
|
||||
@Deprecated
|
||||
SERVER_UUID("server_uuid"),
|
||||
@Deprecated
|
||||
SESSION_ID("session_id"),
|
||||
@Deprecated
|
||||
WEAPON("weapon"),
|
||||
@Deprecated
|
||||
DATE("date");
|
||||
|
||||
private final String column;
|
||||
|
||||
Col(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package com.djrapitops.plan.db.tasks;
|
||||
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.sql.parsing.Column;
|
||||
import com.djrapitops.plan.db.sql.queries.schema.MySQLSchemaQueries;
|
||||
import com.djrapitops.plan.db.sql.tables.*;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
@ -35,44 +34,44 @@ public class CreateIndexTask extends AbsRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
createIndex(UsersTable.TABLE_NAME, "plan_users_uuid_index",
|
||||
UsersTable.Col.UUID
|
||||
UsersTable.USER_UUID
|
||||
);
|
||||
createIndex(UserInfoTable.TABLE_NAME, "plan_user_info_uuid_index",
|
||||
UserInfoTable.Col.UUID,
|
||||
UserInfoTable.Col.SERVER_UUID
|
||||
UserInfoTable.USER_UUID,
|
||||
UserInfoTable.SERVER_UUID
|
||||
);
|
||||
createIndex(SessionsTable.TABLE_NAME, "plan_sessions_uuid_index",
|
||||
SessionsTable.Col.UUID,
|
||||
SessionsTable.Col.SERVER_UUID
|
||||
SessionsTable.USER_UUID,
|
||||
SessionsTable.SERVER_UUID
|
||||
);
|
||||
createIndex(SessionsTable.TABLE_NAME, "plan_sessions_date_index",
|
||||
SessionsTable.Col.SESSION_START
|
||||
SessionsTable.SESSION_START
|
||||
);
|
||||
createIndex(WorldTimesTable.TABLE_NAME, "plan_world_times_uuid_index",
|
||||
WorldTimesTable.Col.UUID,
|
||||
WorldTimesTable.Col.SERVER_UUID
|
||||
WorldTimesTable.USER_UUID,
|
||||
WorldTimesTable.SERVER_UUID
|
||||
);
|
||||
createIndex(KillsTable.TABLE_NAME, "plan_kills_uuid_index",
|
||||
KillsTable.Col.KILLER_UUID,
|
||||
KillsTable.Col.VICTIM_UUID,
|
||||
KillsTable.Col.SERVER_UUID
|
||||
KillsTable.KILLER_UUID,
|
||||
KillsTable.VICTIM_UUID,
|
||||
KillsTable.SERVER_UUID
|
||||
);
|
||||
createIndex(KillsTable.TABLE_NAME, "plan_kills_date_index",
|
||||
KillsTable.Col.DATE
|
||||
KillsTable.DATE
|
||||
);
|
||||
createIndex(PingTable.TABLE_NAME, "plan_ping_uuid_index",
|
||||
PingTable.Col.UUID,
|
||||
PingTable.Col.SERVER_UUID
|
||||
PingTable.USER_UUID,
|
||||
PingTable.SERVER_UUID
|
||||
);
|
||||
createIndex(PingTable.TABLE_NAME, "plan_ping_date_index",
|
||||
PingTable.Col.DATE
|
||||
PingTable.DATE
|
||||
);
|
||||
createIndex(TPSTable.TABLE_NAME, "plan_tps_date_index",
|
||||
TPSTable.Col.DATE
|
||||
TPSTable.DATE
|
||||
);
|
||||
}
|
||||
|
||||
private void createIndex(String tableName, String indexName, Column... indexedColumns) {
|
||||
private void createIndex(String tableName, String indexName, String... indexedColumns) {
|
||||
if (indexedColumns.length == 0) {
|
||||
throw new IllegalArgumentException("Can not create index without columns");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user