mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-31 16:01:00 +01:00
Removed SessionsTable.Col
This commit is contained in:
parent
4a0a8b60b2
commit
a8825fbba3
@ -17,10 +17,10 @@
|
|||||||
package com.djrapitops.plan.db.patches;
|
package com.djrapitops.plan.db.patches;
|
||||||
|
|
||||||
import com.djrapitops.plan.db.SQLDB;
|
import com.djrapitops.plan.db.SQLDB;
|
||||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
import com.djrapitops.plan.db.access.CountQueryStatement;
|
||||||
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,13 +48,13 @@ public class BadAFKThresholdValuePatch extends Patch {
|
|||||||
// where |afk - session_length| < 5
|
// where |afk - session_length| < 5
|
||||||
String sql = "SELECT COUNT(1) as found FROM " + SessionsTable.TABLE_NAME +
|
String sql = "SELECT COUNT(1) as found FROM " + SessionsTable.TABLE_NAME +
|
||||||
" WHERE ABS(" +
|
" WHERE ABS(" +
|
||||||
SessionsTable.Col.AFK_TIME +
|
SessionsTable.AFK_TIME +
|
||||||
" - (" + SessionsTable.Col.SESSION_END + "-" + SessionsTable.Col.SESSION_START +
|
" - (" + SessionsTable.SESSION_END + "-" + SessionsTable.SESSION_START +
|
||||||
")) < 5 AND " + SessionsTable.Col.AFK_TIME + "!=0";
|
")) < 5 AND " + SessionsTable.AFK_TIME + "!=0";
|
||||||
return query(new QueryAllStatement<Boolean>(sql) {
|
return query(new CountQueryStatement(sql, "found") {
|
||||||
@Override
|
@Override
|
||||||
public Boolean processResults(ResultSet set) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
return set.next() && set.getInt("found") > 0;
|
/* Nothing to prepare */
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -62,10 +62,10 @@ public class BadAFKThresholdValuePatch extends Patch {
|
|||||||
@Override
|
@Override
|
||||||
protected void applyPatch() {
|
protected void applyPatch() {
|
||||||
// where |afk - session_length| < 5
|
// where |afk - session_length| < 5
|
||||||
String sql = "UPDATE " + SessionsTable.TABLE_NAME + " SET " + SessionsTable.Col.AFK_TIME + "=0 WHERE ABS(" +
|
String sql = "UPDATE " + SessionsTable.TABLE_NAME + " SET " + SessionsTable.AFK_TIME + "=0 WHERE ABS(" +
|
||||||
SessionsTable.Col.AFK_TIME +
|
SessionsTable.AFK_TIME +
|
||||||
" - (" + SessionsTable.Col.SESSION_END + "-" + SessionsTable.Col.SESSION_START +
|
" - (" + SessionsTable.SESSION_END + "-" + SessionsTable.SESSION_START +
|
||||||
")) < 5 AND " + SessionsTable.Col.AFK_TIME + "!=0";
|
")) < 5 AND " + SessionsTable.AFK_TIME + "!=0";
|
||||||
execute(sql);
|
execute(sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,13 +27,13 @@ public class SessionAFKTimePatch extends Patch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasBeenApplied() {
|
public boolean hasBeenApplied() {
|
||||||
return hasColumn(SessionsTable.TABLE_NAME, SessionsTable.Col.AFK_TIME.get());
|
return hasColumn(SessionsTable.TABLE_NAME, SessionsTable.AFK_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void applyPatch() {
|
protected void applyPatch() {
|
||||||
addColumn(SessionsTable.TABLE_NAME,
|
addColumn(SessionsTable.TABLE_NAME,
|
||||||
SessionsTable.Col.AFK_TIME + " bigint NOT NULL DEFAULT 0"
|
SessionsTable.AFK_TIME + " bigint NOT NULL DEFAULT 0"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.SessionsTable;
|
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.SessionsTable.Col;
|
|
||||||
|
|
||||||
public class SessionsOptimizationPatch extends Patch {
|
public class SessionsOptimizationPatch extends Patch {
|
||||||
|
|
||||||
@ -34,8 +33,8 @@ public class SessionsOptimizationPatch extends Patch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasBeenApplied() {
|
public boolean hasBeenApplied() {
|
||||||
return hasColumn(tableName, Col.UUID.get())
|
return hasColumn(tableName, SessionsTable.USER_UUID)
|
||||||
&& hasColumn(tableName, Col.SERVER_UUID.get())
|
&& hasColumn(tableName, SessionsTable.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.
|
||||||
@ -52,23 +51,23 @@ public class SessionsOptimizationPatch extends Patch {
|
|||||||
db.getSessionsTable().createTable();
|
db.getSessionsTable().createTable();
|
||||||
|
|
||||||
execute("INSERT INTO " + tableName + " (" +
|
execute("INSERT INTO " + tableName + " (" +
|
||||||
Col.UUID + ", " +
|
SessionsTable.USER_UUID + ", " +
|
||||||
Col.SERVER_UUID + ", " +
|
SessionsTable.SERVER_UUID + ", " +
|
||||||
Col.ID + ", " +
|
SessionsTable.ID + ", " +
|
||||||
Col.SESSION_START + ", " +
|
SessionsTable.SESSION_START + ", " +
|
||||||
Col.SESSION_END + ", " +
|
SessionsTable.SESSION_END + ", " +
|
||||||
Col.MOB_KILLS + ", " +
|
SessionsTable.MOB_KILLS + ", " +
|
||||||
Col.DEATHS + ", " +
|
SessionsTable.DEATHS + ", " +
|
||||||
Col.AFK_TIME +
|
SessionsTable.AFK_TIME +
|
||||||
") 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.ID + ", " +
|
SessionsTable.ID + ", " +
|
||||||
Col.SESSION_START + ", " +
|
SessionsTable.SESSION_START + ", " +
|
||||||
Col.SESSION_END + ", " +
|
SessionsTable.SESSION_END + ", " +
|
||||||
Col.MOB_KILLS + ", " +
|
SessionsTable.MOB_KILLS + ", " +
|
||||||
Col.DEATHS + ", " +
|
SessionsTable.DEATHS + ", " +
|
||||||
Col.AFK_TIME +
|
SessionsTable.AFK_TIME +
|
||||||
" FROM " + tempTableName
|
" FROM " + tempTableName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -89,15 +89,15 @@ public class WorldsServerIDPatch extends Patch {
|
|||||||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||||
SessionsTable sessionsTable = db.getSessionsTable();
|
SessionsTable sessionsTable = db.getSessionsTable();
|
||||||
|
|
||||||
String worldIDColumn = worldTimesTable + "." + WorldTimesTable.Col.WORLD_ID;
|
String worldIDColumn = worldTimesTable + "." + WorldTimesTable.WORLD_ID;
|
||||||
String worldSessionIDColumn = worldTimesTable + "." + WorldTimesTable.Col.SESSION_ID;
|
String worldSessionIDColumn = worldTimesTable + "." + WorldTimesTable.SESSION_ID;
|
||||||
String sessionIDColumn = sessionsTable + "." + SessionsTable.Col.ID;
|
String sessionIDColumn = sessionsTable + "." + SessionsTable.ID;
|
||||||
String sessionServerUUIDColumn = sessionsTable + "." + SessionsTable.Col.SERVER_UUID;
|
String sessionServerUUIDColumn = sessionsTable + "." + SessionsTable.SERVER_UUID;
|
||||||
|
|
||||||
String sql = "SELECT DISTINCT " +
|
String sql = "SELECT DISTINCT " +
|
||||||
WorldTable.Col.NAME + " FROM " +
|
WorldTable.NAME + " FROM " +
|
||||||
WorldTable.TABLE_NAME +
|
WorldTable.TABLE_NAME +
|
||||||
" INNER JOIN " + worldTimesTable + " on " + worldIDColumn + "=" + WorldTable.TABLE_NAME + "." + WorldTable.Col.ID +
|
" INNER JOIN " + worldTimesTable + " on " + worldIDColumn + "=" + WorldTable.TABLE_NAME + "." + WorldTable.ID +
|
||||||
" INNER JOIN " + sessionsTable + " on " + worldSessionIDColumn + "=" + sessionIDColumn +
|
" INNER JOIN " + sessionsTable + " on " + worldSessionIDColumn + "=" + sessionIDColumn +
|
||||||
" WHERE " + sessionServerUUIDColumn + "=?";
|
" WHERE " + sessionServerUUIDColumn + "=?";
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public class WorldsServerIDPatch extends Patch {
|
|||||||
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(WorldTable.Col.NAME.get()));
|
worldNames.add(set.getString(WorldTable.NAME));
|
||||||
}
|
}
|
||||||
return worldNames;
|
return worldNames;
|
||||||
}
|
}
|
||||||
@ -133,8 +133,8 @@ public class WorldsServerIDPatch extends Patch {
|
|||||||
|
|
||||||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||||
String sql = "UPDATE " + worldTimesTable + " SET " +
|
String sql = "UPDATE " + worldTimesTable + " SET " +
|
||||||
WorldTimesTable.Col.WORLD_ID + "=?" +
|
WorldTimesTable.WORLD_ID + "=?" +
|
||||||
" WHERE " + WorldTimesTable.Col.WORLD_ID + "=?" +
|
" WHERE " + WorldTimesTable.WORLD_ID + "=?" +
|
||||||
" AND " + "server_id=?";
|
" AND " + "server_id=?";
|
||||||
executeBatch(new ExecStatement(sql) {
|
executeBatch(new ExecStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -159,9 +159,9 @@ public class WorldsServerIDPatch extends Patch {
|
|||||||
public List<WorldObj> processResults(ResultSet set) throws SQLException {
|
public List<WorldObj> processResults(ResultSet set) throws SQLException {
|
||||||
List<WorldObj> objects = new ArrayList<>();
|
List<WorldObj> objects = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int worldID = set.getInt(WorldTable.Col.ID.get());
|
int worldID = set.getInt(WorldTable.ID);
|
||||||
int serverID = set.getInt("server_id");
|
int serverID = set.getInt("server_id");
|
||||||
String worldName = set.getString(WorldTable.Col.NAME.get());
|
String worldName = set.getString(WorldTable.NAME);
|
||||||
objects.add(new WorldObj(worldID, serverID, worldName));
|
objects.add(new WorldObj(worldID, serverID, worldName));
|
||||||
}
|
}
|
||||||
return objects;
|
return objects;
|
||||||
|
@ -27,7 +27,6 @@ import com.djrapitops.plan.db.access.QueryStatement;
|
|||||||
import com.djrapitops.plan.db.patches.SessionAFKTimePatch;
|
import com.djrapitops.plan.db.patches.SessionAFKTimePatch;
|
||||||
import com.djrapitops.plan.db.patches.SessionsOptimizationPatch;
|
import com.djrapitops.plan.db.patches.SessionsOptimizationPatch;
|
||||||
import com.djrapitops.plan.db.patches.Version10Patch;
|
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.CreateTableParser;
|
||||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||||
@ -69,13 +68,13 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
public SessionsTable(SQLDB db) {
|
public SessionsTable(SQLDB db) {
|
||||||
super(TABLE_NAME, db);
|
super(TABLE_NAME, db);
|
||||||
insertStatement = "INSERT INTO " + tableName + " ("
|
insertStatement = "INSERT INTO " + tableName + " ("
|
||||||
+ Col.UUID + ", "
|
+ USER_UUID + ", "
|
||||||
+ Col.SESSION_START + ", "
|
+ SESSION_START + ", "
|
||||||
+ Col.SESSION_END + ", "
|
+ SESSION_END + ", "
|
||||||
+ Col.DEATHS + ", "
|
+ DEATHS + ", "
|
||||||
+ Col.MOB_KILLS + ", "
|
+ MOB_KILLS + ", "
|
||||||
+ Col.AFK_TIME + ", "
|
+ AFK_TIME + ", "
|
||||||
+ Col.SERVER_UUID
|
+ SERVER_UUID
|
||||||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?)";
|
+ ") VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,10 +104,10 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
* @return ID of the inserted session or -1 if session has not been inserted.
|
* @return ID of the inserted session or -1 if session has not been inserted.
|
||||||
*/
|
*/
|
||||||
private int getSessionID(UUID uuid, Session session) {
|
private int getSessionID(UUID uuid, Session session) {
|
||||||
String sql = "SELECT " + Col.ID + " FROM " + tableName +
|
String sql = "SELECT " + ID + " FROM " + tableName +
|
||||||
" WHERE " + Col.UUID + "=?" +
|
" WHERE " + USER_UUID + "=?" +
|
||||||
" AND " + Col.SESSION_START + "=?" +
|
" AND " + SESSION_START + "=?" +
|
||||||
" AND " + Col.SESSION_END + "=?";
|
" AND " + SESSION_END + "=?";
|
||||||
|
|
||||||
return query(new QueryStatement<Integer>(sql) {
|
return query(new QueryStatement<Integer>(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -121,7 +120,7 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
@Override
|
@Override
|
||||||
public Integer processResults(ResultSet set) throws SQLException {
|
public Integer processResults(ResultSet set) throws SQLException {
|
||||||
if (set.next()) {
|
if (set.next()) {
|
||||||
return set.getInt(Col.ID.get());
|
return set.getInt(ID);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -181,7 +180,7 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
*/
|
*/
|
||||||
private Map<UUID, List<Session>> getSessionInformation(UUID uuid) {
|
private Map<UUID, List<Session>> getSessionInformation(UUID uuid) {
|
||||||
String sql = Select.from(tableName, "*")
|
String sql = Select.from(tableName, "*")
|
||||||
.where(Col.UUID + "=?")
|
.where(USER_UUID + "=?")
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
return query(new QueryStatement<Map<UUID, List<Session>>>(sql, 10000) {
|
return query(new QueryStatement<Map<UUID, List<Session>>>(sql, 10000) {
|
||||||
@ -194,15 +193,15 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
public Map<UUID, List<Session>> processResults(ResultSet set) throws SQLException {
|
public Map<UUID, List<Session>> processResults(ResultSet set) throws SQLException {
|
||||||
Map<UUID, List<Session>> sessionsByServer = new HashMap<>();
|
Map<UUID, List<Session>> sessionsByServer = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int id = set.getInt(Col.ID.get());
|
int id = set.getInt(ID);
|
||||||
long start = set.getLong(Col.SESSION_START.get());
|
long start = set.getLong(SESSION_START);
|
||||||
long end = set.getLong(Col.SESSION_END.get());
|
long end = set.getLong(SESSION_END);
|
||||||
UUID serverUUID = UUID.fromString(set.getString(Col.SERVER_UUID.get()));
|
UUID serverUUID = UUID.fromString(set.getString(SERVER_UUID));
|
||||||
|
|
||||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
long timeAFK = set.getLong(AFK_TIME);
|
||||||
|
|
||||||
int deaths = set.getInt(Col.DEATHS.get());
|
int deaths = set.getInt(DEATHS);
|
||||||
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
int mobKills = set.getInt(MOB_KILLS);
|
||||||
List<Session> sessions = sessionsByServer.getOrDefault(serverUUID, new ArrayList<>());
|
List<Session> sessions = sessionsByServer.getOrDefault(serverUUID, new ArrayList<>());
|
||||||
sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
|
sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
|
||||||
sessionsByServer.put(serverUUID, sessions);
|
sessionsByServer.put(serverUUID, sessions);
|
||||||
@ -222,11 +221,11 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
*/
|
*/
|
||||||
public long getPlaytime(UUID uuid, UUID serverUUID, long afterDate) {
|
public long getPlaytime(UUID uuid, UUID serverUUID, long afterDate) {
|
||||||
String sql = "SELECT" +
|
String sql = "SELECT" +
|
||||||
" (SUM(" + Col.SESSION_END + ") - SUM(" + Col.SESSION_START + ")) as playtime" +
|
" (SUM(" + SESSION_END + ") - SUM(" + SESSION_START + ")) as playtime" +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" WHERE " + Col.SESSION_START + ">?" +
|
" WHERE " + SESSION_START + ">?" +
|
||||||
" AND " + Col.UUID + "=?" +
|
" AND " + USER_UUID + "=?" +
|
||||||
" AND " + Col.SERVER_UUID + "=?";
|
" AND " + SERVER_UUID + "=?";
|
||||||
|
|
||||||
return query(new QueryStatement<Long>(sql) {
|
return query(new QueryStatement<Long>(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -299,10 +298,10 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
*/
|
*/
|
||||||
public long getPlaytimeOfServer(UUID serverUUID, long afterDate) {
|
public long getPlaytimeOfServer(UUID serverUUID, long afterDate) {
|
||||||
String sql = "SELECT" +
|
String sql = "SELECT" +
|
||||||
" (SUM(" + Col.SESSION_END + ") - SUM(" + Col.SESSION_START + ")) as playtime" +
|
" (SUM(" + SESSION_END + ") - SUM(" + SESSION_START + ")) as playtime" +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" WHERE " + Col.SESSION_START + ">?" +
|
" WHERE " + SESSION_START + ">?" +
|
||||||
" AND " + Col.SERVER_UUID + "=?";
|
" AND " + SERVER_UUID + "=?";
|
||||||
|
|
||||||
return query(new QueryStatement<Long>(sql) {
|
return query(new QueryStatement<Long>(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -343,9 +342,9 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
String sql = "SELECT" +
|
String sql = "SELECT" +
|
||||||
" COUNT(*) as logintimes" +
|
" COUNT(*) as logintimes" +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" WHERE (" + Col.SESSION_START + " >= ?)" +
|
" WHERE (" + SESSION_START + " >= ?)" +
|
||||||
" AND " + Col.UUID + "=?" +
|
" AND " + USER_UUID + "=?" +
|
||||||
" AND " + Col.SERVER_UUID + "=?";
|
" AND " + SERVER_UUID + "=?";
|
||||||
|
|
||||||
return query(new QueryStatement<Integer>(sql) {
|
return query(new QueryStatement<Integer>(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -388,15 +387,15 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
|
|
||||||
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) {
|
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) {
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
tableName + "." + Col.ID + ", " +
|
tableName + "." + ID + ", " +
|
||||||
Col.UUID + ", " +
|
USER_UUID + ", " +
|
||||||
Col.SESSION_START + ", " +
|
SESSION_START + ", " +
|
||||||
Col.SESSION_END + ", " +
|
SESSION_END + ", " +
|
||||||
Col.DEATHS + ", " +
|
DEATHS + ", " +
|
||||||
Col.MOB_KILLS + ", " +
|
MOB_KILLS + ", " +
|
||||||
Col.AFK_TIME +
|
AFK_TIME +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" WHERE " + Col.SERVER_UUID + "=?";
|
" WHERE " + SERVER_UUID + "=?";
|
||||||
|
|
||||||
return query(new QueryStatement<Map<UUID, List<Session>>>(sql, 5000) {
|
return query(new QueryStatement<Map<UUID, List<Session>>>(sql, 5000) {
|
||||||
@Override
|
@Override
|
||||||
@ -408,15 +407,15 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
public Map<UUID, List<Session>> processResults(ResultSet set) throws SQLException {
|
public Map<UUID, List<Session>> processResults(ResultSet set) throws SQLException {
|
||||||
Map<UUID, List<Session>> sessionsByUser = new HashMap<>();
|
Map<UUID, List<Session>> sessionsByUser = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int id = set.getInt(Col.ID.get());
|
int id = set.getInt(ID);
|
||||||
UUID uuid = UUID.fromString(set.getString(Col.UUID.get()));
|
UUID uuid = UUID.fromString(set.getString(USER_UUID));
|
||||||
long start = set.getLong(Col.SESSION_START.get());
|
long start = set.getLong(SESSION_START);
|
||||||
long end = set.getLong(Col.SESSION_END.get());
|
long end = set.getLong(SESSION_END);
|
||||||
|
|
||||||
int deaths = set.getInt(Col.DEATHS.get());
|
int deaths = set.getInt(DEATHS);
|
||||||
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
int mobKills = set.getInt(MOB_KILLS);
|
||||||
|
|
||||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
long timeAFK = set.getLong(AFK_TIME);
|
||||||
|
|
||||||
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
|
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
|
||||||
sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
|
sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
|
||||||
@ -433,10 +432,10 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
|
|
||||||
public Map<UUID, Long> getLastSeenForAllPlayers() {
|
public Map<UUID, Long> getLastSeenForAllPlayers() {
|
||||||
String sql = "SELECT" +
|
String sql = "SELECT" +
|
||||||
" MAX(" + Col.SESSION_END + ") as last_seen, " +
|
" MAX(" + SESSION_END + ") as last_seen, " +
|
||||||
Col.UUID +
|
USER_UUID +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" GROUP BY " + Col.UUID;
|
" GROUP BY " + USER_UUID;
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<UUID, Long>>(sql, 20000) {
|
return query(new QueryAllStatement<Map<UUID, Long>>(sql, 20000) {
|
||||||
@Override
|
@Override
|
||||||
@ -550,8 +549,8 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
|
|
||||||
public Map<Integer, Integer> getIDServerIDRelation() {
|
public Map<Integer, Integer> getIDServerIDRelation() {
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
Col.ID + ", " +
|
ID + ", " +
|
||||||
"(SELECT plan_servers.id FROM plan_servers WHERE plan_servers.uuid=" + Col.SERVER_UUID + ") as server_id" +
|
"(SELECT plan_servers.id FROM plan_servers WHERE plan_servers.uuid=" + SERVER_UUID + ") as server_id" +
|
||||||
" FROM " + tableName;
|
" FROM " + tableName;
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<Integer, Integer>>(sql, 10000) {
|
return query(new QueryAllStatement<Map<Integer, Integer>>(sql, 10000) {
|
||||||
@ -559,46 +558,10 @@ public class SessionsTable extends UserUUIDTable {
|
|||||||
public Map<Integer, Integer> processResults(ResultSet set) throws SQLException {
|
public Map<Integer, Integer> processResults(ResultSet set) throws SQLException {
|
||||||
Map<Integer, Integer> idServerIdMap = new HashMap<>();
|
Map<Integer, Integer> idServerIdMap = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
idServerIdMap.put(set.getInt(Col.ID.get()), set.getInt("server_id"));
|
idServerIdMap.put(set.getInt(ID), set.getInt("server_id"));
|
||||||
}
|
}
|
||||||
return idServerIdMap;
|
return idServerIdMap;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public enum Col implements Column {
|
|
||||||
@Deprecated
|
|
||||||
UUID(UserUUIDTable.Col.UUID.get()),
|
|
||||||
@Deprecated
|
|
||||||
ID("id"),
|
|
||||||
@Deprecated
|
|
||||||
SERVER_UUID("server_uuid"),
|
|
||||||
@Deprecated
|
|
||||||
SESSION_START("session_start"),
|
|
||||||
@Deprecated
|
|
||||||
SESSION_END("session_end"),
|
|
||||||
@Deprecated
|
|
||||||
MOB_KILLS("mob_kills"),
|
|
||||||
@Deprecated
|
|
||||||
DEATHS("deaths"),
|
|
||||||
@Deprecated
|
|
||||||
AFK_TIME("afk_time");
|
|
||||||
|
|
||||||
private final String column;
|
|
||||||
|
|
||||||
Col(String column) {
|
|
||||||
this.column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get() {
|
|
||||||
return toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.db.patches.WorldsServerIDPatch;
|
|||||||
import com.djrapitops.plan.db.sql.parsing.Column;
|
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.plan.db.sql.parsing.TableSqlParser;
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -111,21 +110,7 @@ public class WorldTimesTable extends UserUUIDTable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createTable() throws DBInitException {
|
public void createTable() throws DBInitException {
|
||||||
createTable(TableSqlParser.createTable(tableName)
|
createTable(createTableSQL(db.getType()));
|
||||||
.primaryKeyIDColumn(supportsMySQLQueries, Col.ID)
|
|
||||||
.column(Col.UUID, Sql.varchar(36)).notNull()
|
|
||||||
.column(Col.WORLD_ID, Sql.INT).notNull()
|
|
||||||
.column(Col.SERVER_UUID, Sql.varchar(36)).notNull()
|
|
||||||
.column(Col.SESSION_ID, Sql.INT).notNull()
|
|
||||||
.column(Col.SURVIVAL, Sql.LONG).notNull().defaultValue("0")
|
|
||||||
.column(Col.CREATIVE, Sql.LONG).notNull().defaultValue("0")
|
|
||||||
.column(Col.ADVENTURE, Sql.LONG).notNull().defaultValue("0")
|
|
||||||
.column(Col.SPECTATOR, Sql.LONG).notNull().defaultValue("0")
|
|
||||||
.primaryKey(supportsMySQLQueries, Col.ID)
|
|
||||||
.foreignKey(Col.WORLD_ID, worldTable.getTableName(), WorldTable.Col.ID)
|
|
||||||
.foreignKey(Col.SESSION_ID, sessionsTable.getTableName(), SessionsTable.Col.ID)
|
|
||||||
.toString()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWorldTimesToSessions(UUID uuid, Map<Integer, Session> sessions) {
|
public void addWorldTimesToSessions(UUID uuid, Map<Integer, Session> sessions) {
|
||||||
|
Loading…
Reference in New Issue
Block a user