Removed CommandUseTable.Col

This commit is contained in:
Rsl1122 2019-01-24 14:44:32 +02:00
parent 766749fe41
commit c7d84c0c3b
2 changed files with 129 additions and 160 deletions

View File

@ -49,14 +49,14 @@ public class LargeFetchQueries {
* @return Multi map: Server UUID - (Command name - Usage count) * @return Multi map: Server UUID - (Command name - Usage count)
*/ */
public static Query<Map<UUID, Map<String, Integer>>> fetchAllCommandUsageData() { public static Query<Map<UUID, Map<String, Integer>>> fetchAllCommandUsageData() {
String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.Col.SERVER_ID; String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_ID;
String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.Col.SERVER_UUID + " as s_uuid"; String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_UUID + " as s_uuid";
String sql = "SELECT " + String sql = "SELECT " +
CommandUseTable.Col.COMMAND + ", " + CommandUseTable.COMMAND + ", " +
CommandUseTable.Col.TIMES_USED + ", " + CommandUseTable.TIMES_USED + ", " +
serverUUIDColumn + serverUUIDColumn +
" FROM " + CommandUseTable.TABLE_NAME + " FROM " + CommandUseTable.TABLE_NAME +
" INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + CommandUseTable.Col.SERVER_ID; " INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + CommandUseTable.SERVER_ID;
return new QueryAllStatement<Map<UUID, Map<String, Integer>>>(sql, 10000) { return new QueryAllStatement<Map<UUID, Map<String, Integer>>>(sql, 10000) {
@Override @Override
@ -67,8 +67,8 @@ public class LargeFetchQueries {
Map<String, Integer> serverMap = map.getOrDefault(serverUUID, new HashMap<>()); Map<String, Integer> serverMap = map.getOrDefault(serverUUID, new HashMap<>());
String command = set.getString(CommandUseTable.Col.COMMAND.get()); String command = set.getString(CommandUseTable.COMMAND);
int timesUsed = set.getInt(CommandUseTable.Col.TIMES_USED.get()); int timesUsed = set.getInt(CommandUseTable.TIMES_USED);
serverMap.put(command, timesUsed); serverMap.put(command, timesUsed);
map.put(serverUUID, serverMap); map.put(serverUUID, serverMap);
@ -85,11 +85,11 @@ public class LargeFetchQueries {
*/ */
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInfoData() { public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInfoData() {
String sql = "SELECT " + String sql = "SELECT " +
GeoInfoTable.Col.IP + ", " + GeoInfoTable.IP + ", " +
GeoInfoTable.Col.GEOLOCATION + ", " + GeoInfoTable.GEOLOCATION + ", " +
GeoInfoTable.Col.LAST_USED + ", " + GeoInfoTable.LAST_USED + ", " +
GeoInfoTable.Col.IP_HASH + ", " + GeoInfoTable.IP_HASH + ", " +
GeoInfoTable.Col.UUID + GeoInfoTable.USER_UUID +
" FROM " + GeoInfoTable.TABLE_NAME; " FROM " + GeoInfoTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, List<GeoInfo>>>(sql, 50000) { return new QueryAllStatement<Map<UUID, List<GeoInfo>>>(sql, 50000) {
@ -97,14 +97,14 @@ public class LargeFetchQueries {
public Map<UUID, List<GeoInfo>> processResults(ResultSet set) throws SQLException { public Map<UUID, List<GeoInfo>> processResults(ResultSet set) throws SQLException {
Map<UUID, List<GeoInfo>> geoLocations = new HashMap<>(); Map<UUID, List<GeoInfo>> geoLocations = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID uuid = UUID.fromString(set.getString(GeoInfoTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(GeoInfoTable.USER_UUID));
List<GeoInfo> userGeoInfo = geoLocations.getOrDefault(uuid, new ArrayList<>()); List<GeoInfo> userGeoInfo = geoLocations.getOrDefault(uuid, new ArrayList<>());
String ip = set.getString(GeoInfoTable.Col.IP.get()); String ip = set.getString(GeoInfoTable.IP);
String geolocation = set.getString(GeoInfoTable.Col.GEOLOCATION.get()); String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
String ipHash = set.getString(GeoInfoTable.Col.IP_HASH.get()); String ipHash = set.getString(GeoInfoTable.IP_HASH);
long lastUsed = set.getLong(GeoInfoTable.Col.LAST_USED.get()); long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash)); userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash));
geoLocations.put(uuid, userGeoInfo); geoLocations.put(uuid, userGeoInfo);
@ -120,30 +120,30 @@ public class LargeFetchQueries {
* @return Map: Session ID - List of PlayerKills * @return Map: Session ID - List of PlayerKills
*/ */
public static Query<Map<Integer, List<PlayerKill>>> fetchAllPlayerKillDataBySessionID() { public static Query<Map<Integer, List<PlayerKill>>> fetchAllPlayerKillDataBySessionID() {
String usersUUIDColumn = UsersTable.TABLE_NAME + "." + UsersTable.Col.UUID; String usersUUIDColumn = UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID;
String usersNameColumn = UsersTable.TABLE_NAME + "." + UsersTable.Col.USER_NAME + " as victim_name"; String usersNameColumn = UsersTable.TABLE_NAME + "." + UsersTable.USER_NAME + " as victim_name";
String sql = "SELECT " + String sql = "SELECT " +
KillsTable.Col.SESSION_ID + ", " + KillsTable.SESSION_ID + ", " +
KillsTable.Col.DATE + ", " + KillsTable.DATE + ", " +
KillsTable.Col.WEAPON + ", " + KillsTable.WEAPON + ", " +
KillsTable.Col.VICTIM_UUID + ", " + KillsTable.VICTIM_UUID + ", " +
usersNameColumn + usersNameColumn +
" FROM " + KillsTable.TABLE_NAME + " FROM " + KillsTable.TABLE_NAME +
" INNER JOIN " + UsersTable.TABLE_NAME + " on " + usersUUIDColumn + "=" + KillsTable.Col.VICTIM_UUID; " INNER JOIN " + UsersTable.TABLE_NAME + " on " + usersUUIDColumn + "=" + KillsTable.VICTIM_UUID;
return new QueryAllStatement<Map<Integer, List<PlayerKill>>>(sql, 50000) { return new QueryAllStatement<Map<Integer, List<PlayerKill>>>(sql, 50000) {
@Override @Override
public Map<Integer, List<PlayerKill>> processResults(ResultSet set) throws SQLException { public Map<Integer, List<PlayerKill>> processResults(ResultSet set) throws SQLException {
Map<Integer, List<PlayerKill>> allPlayerKills = new HashMap<>(); Map<Integer, List<PlayerKill>> allPlayerKills = new HashMap<>();
while (set.next()) { while (set.next()) {
int sessionID = set.getInt(KillsTable.Col.SESSION_ID.get()); int sessionID = set.getInt(KillsTable.SESSION_ID);
List<PlayerKill> playerKills = allPlayerKills.getOrDefault(sessionID, new ArrayList<>()); List<PlayerKill> playerKills = allPlayerKills.getOrDefault(sessionID, new ArrayList<>());
UUID victim = UUID.fromString(set.getString(KillsTable.Col.VICTIM_UUID.get())); UUID victim = UUID.fromString(set.getString(KillsTable.VICTIM_UUID));
String victimName = set.getString("victim_name"); String victimName = set.getString("victim_name");
long date = set.getLong(KillsTable.Col.DATE.get()); long date = set.getLong(KillsTable.DATE);
String weapon = set.getString(KillsTable.Col.WEAPON.get()); String weapon = set.getString(KillsTable.WEAPON);
playerKills.add(new PlayerKill(victim, weapon, date, victimName)); playerKills.add(new PlayerKill(victim, weapon, date, victimName));
allPlayerKills.put(sessionID, playerKills); allPlayerKills.put(sessionID, playerKills);
@ -160,10 +160,10 @@ public class LargeFetchQueries {
*/ */
public static Query<Map<UUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() { public static Query<Map<UUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
String sql = "SELECT " + String sql = "SELECT " +
NicknamesTable.Col.NICKNAME + ", " + NicknamesTable.NICKNAME + ", " +
NicknamesTable.Col.LAST_USED + ", " + NicknamesTable.LAST_USED + ", " +
NicknamesTable.Col.UUID + ", " + NicknamesTable.USER_UUID + ", " +
NicknamesTable.Col.SERVER_UUID + NicknamesTable.SERVER_UUID +
" FROM " + NicknamesTable.TABLE_NAME; " FROM " + NicknamesTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, Map<UUID, List<Nickname>>>>(sql, 5000) { return new QueryAllStatement<Map<UUID, Map<UUID, List<Nickname>>>>(sql, 5000) {
@ -171,15 +171,15 @@ public class LargeFetchQueries {
public Map<UUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException { public Map<UUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException {
Map<UUID, Map<UUID, List<Nickname>>> map = new HashMap<>(); Map<UUID, Map<UUID, List<Nickname>>> map = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID serverUUID = UUID.fromString(set.getString(NicknamesTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
UUID uuid = UUID.fromString(set.getString(NicknamesTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
Map<UUID, List<Nickname>> serverMap = map.getOrDefault(serverUUID, new HashMap<>()); Map<UUID, List<Nickname>> serverMap = map.getOrDefault(serverUUID, new HashMap<>());
List<Nickname> nicknames = serverMap.getOrDefault(uuid, new ArrayList<>()); List<Nickname> nicknames = serverMap.getOrDefault(uuid, new ArrayList<>());
nicknames.add(new Nickname( nicknames.add(new Nickname(
set.getString(NicknamesTable.Col.NICKNAME.get()), set.getString(NicknamesTable.NICKNAME),
set.getLong(NicknamesTable.Col.LAST_USED.get()), set.getLong(NicknamesTable.LAST_USED),
serverUUID serverUUID
)); ));
@ -198,21 +198,21 @@ public class LargeFetchQueries {
*/ */
public static Query<Map<UUID, List<Nickname>>> fetchAllNicknameDataByPlayerUUIDs() { public static Query<Map<UUID, List<Nickname>>> fetchAllNicknameDataByPlayerUUIDs() {
String sql = "SELECT " + String sql = "SELECT " +
NicknamesTable.Col.NICKNAME + ", " + NicknamesTable.NICKNAME + ", " +
NicknamesTable.Col.LAST_USED + ", " + NicknamesTable.LAST_USED + ", " +
NicknamesTable.Col.UUID + ", " + NicknamesTable.USER_UUID + ", " +
NicknamesTable.Col.SERVER_UUID + NicknamesTable.SERVER_UUID +
" FROM " + NicknamesTable.TABLE_NAME; " FROM " + NicknamesTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, List<Nickname>>>(sql, 5000) { return new QueryAllStatement<Map<UUID, List<Nickname>>>(sql, 5000) {
@Override @Override
public Map<UUID, List<Nickname>> processResults(ResultSet set) throws SQLException { public Map<UUID, List<Nickname>> processResults(ResultSet set) throws SQLException {
Map<UUID, List<Nickname>> map = new HashMap<>(); Map<UUID, List<Nickname>> map = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID uuid = UUID.fromString(set.getString(NicknamesTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
UUID serverUUID = UUID.fromString(set.getString(NicknamesTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
List<Nickname> nicknames = map.computeIfAbsent(uuid, x -> new ArrayList<>()); List<Nickname> nicknames = map.computeIfAbsent(uuid, x -> new ArrayList<>());
nicknames.add(new Nickname( nicknames.add(new Nickname(
set.getString(NicknamesTable.Col.NICKNAME.get()), set.getLong(NicknamesTable.Col.LAST_USED.get()), serverUUID set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID
)); ));
} }
return map; return map;
@ -227,12 +227,12 @@ public class LargeFetchQueries {
*/ */
public static Query<Map<UUID, List<Ping>>> fetchAllPingData() { public static Query<Map<UUID, List<Ping>>> fetchAllPingData() {
String sql = "SELECT " + String sql = "SELECT " +
PingTable.Col.DATE + ", " + PingTable.DATE + ", " +
PingTable.Col.MAX_PING + ", " + PingTable.MAX_PING + ", " +
PingTable.Col.MIN_PING + ", " + PingTable.MIN_PING + ", " +
PingTable.Col.AVG_PING + ", " + PingTable.AVG_PING + ", " +
PingTable.Col.UUID + ", " + PingTable.USER_UUID + ", " +
PingTable.Col.SERVER_UUID + PingTable.SERVER_UUID +
" FROM " + PingTable.TABLE_NAME; " FROM " + PingTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, List<Ping>>>(sql, 100000) { return new QueryAllStatement<Map<UUID, List<Ping>>>(sql, 100000) {
@Override @Override
@ -240,12 +240,12 @@ public class LargeFetchQueries {
Map<UUID, List<Ping>> userPings = new HashMap<>(); Map<UUID, List<Ping>> userPings = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID uuid = UUID.fromString(set.getString(PingTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(PingTable.USER_UUID));
UUID serverUUID = UUID.fromString(set.getString(PingTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(PingTable.SERVER_UUID));
long date = set.getLong(PingTable.Col.DATE.get()); long date = set.getLong(PingTable.DATE);
double avgPing = set.getDouble(PingTable.Col.AVG_PING.get()); double avgPing = set.getDouble(PingTable.AVG_PING);
int minPing = set.getInt(PingTable.Col.MIN_PING.get()); int minPing = set.getInt(PingTable.MIN_PING);
int maxPing = set.getInt(PingTable.Col.MAX_PING.get()); int maxPing = set.getInt(PingTable.MAX_PING);
List<Ping> pings = userPings.getOrDefault(uuid, new ArrayList<>()); List<Ping> pings = userPings.getOrDefault(uuid, new ArrayList<>());
pings.add(new Ping(date, serverUUID, pings.add(new Ping(date, serverUUID,
@ -266,16 +266,16 @@ public class LargeFetchQueries {
* @return Set of Plan WebUsers. * @return Set of Plan WebUsers.
*/ */
public static Query<List<WebUser>> fetchAllPlanWebUsers() { public static Query<List<WebUser>> fetchAllPlanWebUsers() {
String sql = "SELECT * FROM " + SecurityTable.TABLE_NAME + " ORDER BY " + SecurityTable.Col.PERMISSION_LEVEL + " ASC"; String sql = "SELECT * FROM " + SecurityTable.TABLE_NAME + " ORDER BY " + SecurityTable.PERMISSION_LEVEL + " ASC";
return new QueryAllStatement<List<WebUser>>(sql, 5000) { return new QueryAllStatement<List<WebUser>>(sql, 5000) {
@Override @Override
public List<WebUser> processResults(ResultSet set) throws SQLException { public List<WebUser> processResults(ResultSet set) throws SQLException {
List<WebUser> list = new ArrayList<>(); List<WebUser> list = new ArrayList<>();
while (set.next()) { while (set.next()) {
String user = set.getString(SecurityTable.Col.USERNAME.get()); String user = set.getString(SecurityTable.USERNAME);
String saltedPassHash = set.getString(SecurityTable.Col.SALT_PASSWORD_HASH.get()); String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
int permissionLevel = set.getInt(SecurityTable.Col.PERMISSION_LEVEL.get()); int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
WebUser info = new WebUser(user, saltedPassHash, permissionLevel); WebUser info = new WebUser(user, saltedPassHash, permissionLevel);
list.add(info); list.add(info);
} }
@ -290,7 +290,7 @@ public class LargeFetchQueries {
* @return Map: Server UUID - Plan Server Information * @return Map: Server UUID - Plan Server Information
*/ */
public static Query<Map<UUID, Server>> fetchPlanServerInformation() { public static Query<Map<UUID, Server>> fetchPlanServerInformation() {
String sql = "SELECT * FROM " + ServerTable.TABLE_NAME + " WHERE " + ServerTable.Col.INSTALLED + "=?"; String sql = "SELECT * FROM " + ServerTable.TABLE_NAME + " WHERE " + ServerTable.INSTALLED + "=?";
return new QueryStatement<Map<UUID, Server>>(sql, 100) { return new QueryStatement<Map<UUID, Server>>(sql, 100) {
@Override @Override
@ -302,13 +302,13 @@ public class LargeFetchQueries {
public Map<UUID, Server> processResults(ResultSet set) throws SQLException { public Map<UUID, Server> processResults(ResultSet set) throws SQLException {
Map<UUID, Server> servers = new HashMap<>(); Map<UUID, Server> servers = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID serverUUID = UUID.fromString(set.getString(ServerTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(ServerTable.SERVER_UUID));
servers.put(serverUUID, new Server( servers.put(serverUUID, new Server(
set.getInt(ServerTable.Col.SERVER_ID.get()), set.getInt(ServerTable.SERVER_ID),
serverUUID, serverUUID,
set.getString(ServerTable.Col.NAME.get()), set.getString(ServerTable.NAME),
set.getString(ServerTable.Col.WEBSERVER_ADDRESS.get()), set.getString(ServerTable.WEB_ADDRESS),
set.getInt(ServerTable.Col.MAX_PLAYERS.get()))); set.getInt(ServerTable.MAX_PLAYERS)));
} }
return servers; return servers;
} }
@ -322,14 +322,14 @@ public class LargeFetchQueries {
*/ */
public static Query<Map<UUID, Map<UUID, List<Session>>>> fetchAllSessionsWithoutKillOrWorldData() { public static Query<Map<UUID, Map<UUID, List<Session>>>> fetchAllSessionsWithoutKillOrWorldData() {
String sql = "SELECT " + String sql = "SELECT " +
SessionsTable.Col.ID + ", " + SessionsTable.ID + ", " +
SessionsTable.Col.UUID + ", " + SessionsTable.USER_UUID + ", " +
SessionsTable.Col.SERVER_UUID + ", " + SessionsTable.SERVER_UUID + ", " +
SessionsTable.Col.SESSION_START + ", " + SessionsTable.SESSION_START + ", " +
SessionsTable.Col.SESSION_END + ", " + SessionsTable.SESSION_END + ", " +
SessionsTable.Col.DEATHS + ", " + SessionsTable.DEATHS + ", " +
SessionsTable.Col.MOB_KILLS + ", " + SessionsTable.MOB_KILLS + ", " +
SessionsTable.Col.AFK_TIME + SessionsTable.AFK_TIME +
" FROM " + SessionsTable.TABLE_NAME; " FROM " + SessionsTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, Map<UUID, List<Session>>>>(sql, 20000) { return new QueryAllStatement<Map<UUID, Map<UUID, List<Session>>>>(sql, 20000) {
@ -337,20 +337,20 @@ public class LargeFetchQueries {
public Map<UUID, Map<UUID, List<Session>>> processResults(ResultSet set) throws SQLException { public Map<UUID, Map<UUID, List<Session>>> processResults(ResultSet set) throws SQLException {
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>(); Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID serverUUID = UUID.fromString(set.getString(SessionsTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(SessionsTable.SERVER_UUID));
UUID uuid = UUID.fromString(set.getString(SessionsTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(SessionsTable.USER_UUID));
Map<UUID, List<Session>> sessionsByUser = map.getOrDefault(serverUUID, new HashMap<>()); Map<UUID, List<Session>> sessionsByUser = map.getOrDefault(serverUUID, new HashMap<>());
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>()); List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
long start = set.getLong(SessionsTable.Col.SESSION_START.get()); long start = set.getLong(SessionsTable.SESSION_START);
long end = set.getLong(SessionsTable.Col.SESSION_END.get()); long end = set.getLong(SessionsTable.SESSION_END);
int deaths = set.getInt(SessionsTable.Col.DEATHS.get()); int deaths = set.getInt(SessionsTable.DEATHS);
int mobKills = set.getInt(SessionsTable.Col.MOB_KILLS.get()); int mobKills = set.getInt(SessionsTable.MOB_KILLS);
int id = set.getInt(SessionsTable.Col.ID.get()); int id = set.getInt(SessionsTable.ID);
long timeAFK = set.getLong(SessionsTable.Col.AFK_TIME.get()); long timeAFK = set.getLong(SessionsTable.AFK_TIME);
sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK)); sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
@ -382,20 +382,20 @@ public class LargeFetchQueries {
* @return Map: Server UUID - List of TPS data * @return Map: Server UUID - List of TPS data
*/ */
public static Query<Map<UUID, List<TPS>>> fetchAllTPSData() { public static Query<Map<UUID, List<TPS>>> fetchAllTPSData() {
String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.Col.SERVER_ID; String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_ID;
String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.Col.SERVER_UUID + " as s_uuid"; String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.SERVER_UUID + " as s_uuid";
String sql = "SELECT " + String sql = "SELECT " +
TPSTable.Col.DATE + ", " + TPSTable.DATE + ", " +
TPSTable.Col.TPS + ", " + TPSTable.TPS + ", " +
TPSTable.Col.PLAYERS_ONLINE + ", " + TPSTable.PLAYERS_ONLINE + ", " +
TPSTable.Col.CPU_USAGE + ", " + TPSTable.CPU_USAGE + ", " +
TPSTable.Col.RAM_USAGE + ", " + TPSTable.RAM_USAGE + ", " +
TPSTable.Col.ENTITIES + ", " + TPSTable.ENTITIES + ", " +
TPSTable.Col.CHUNKS + ", " + TPSTable.CHUNKS + ", " +
TPSTable.Col.FREE_DISK + ", " + TPSTable.FREE_DISK + ", " +
serverUUIDColumn + serverUUIDColumn +
" FROM " + TPSTable.TABLE_NAME + " FROM " + TPSTable.TABLE_NAME +
" INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.Col.SERVER_ID; " INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
return new QueryAllStatement<Map<UUID, List<TPS>>>(sql, 50000) { return new QueryAllStatement<Map<UUID, List<TPS>>>(sql, 50000) {
@Override @Override
@ -407,14 +407,14 @@ public class LargeFetchQueries {
List<TPS> tpsList = serverMap.getOrDefault(serverUUID, new ArrayList<>()); List<TPS> tpsList = serverMap.getOrDefault(serverUUID, new ArrayList<>());
TPS tps = TPSBuilder.get() TPS tps = TPSBuilder.get()
.date(set.getLong(TPSTable.Col.DATE.get())) .date(set.getLong(TPSTable.DATE))
.tps(set.getDouble(TPSTable.Col.TPS.get())) .tps(set.getDouble(TPSTable.TPS))
.playersOnline(set.getInt(TPSTable.Col.PLAYERS_ONLINE.get())) .playersOnline(set.getInt(TPSTable.PLAYERS_ONLINE))
.usedCPU(set.getDouble(TPSTable.Col.CPU_USAGE.get())) .usedCPU(set.getDouble(TPSTable.CPU_USAGE))
.usedMemory(set.getLong(TPSTable.Col.RAM_USAGE.get())) .usedMemory(set.getLong(TPSTable.RAM_USAGE))
.entities(set.getInt(TPSTable.Col.ENTITIES.get())) .entities(set.getInt(TPSTable.ENTITIES))
.chunksLoaded(set.getInt(TPSTable.Col.CHUNKS.get())) .chunksLoaded(set.getInt(TPSTable.CHUNKS))
.freeDiskSpace(set.getLong(TPSTable.Col.FREE_DISK.get())) .freeDiskSpace(set.getLong(TPSTable.FREE_DISK))
.toTPS(); .toTPS();
tpsList.add(tps); tpsList.add(tps);
@ -434,11 +434,11 @@ public class LargeFetchQueries {
*/ */
public static Query<Map<UUID, List<UserInfo>>> fetchPerServerUserInformation() { public static Query<Map<UUID, List<UserInfo>>> fetchPerServerUserInformation() {
String sql = "SELECT " + String sql = "SELECT " +
UserInfoTable.Col.REGISTERED + ", " + UserInfoTable.REGISTERED + ", " +
UserInfoTable.Col.BANNED + ", " + UserInfoTable.BANNED + ", " +
UserInfoTable.Col.OP + ", " + UserInfoTable.OP + ", " +
UserInfoTable.Col.UUID + ", " + UserInfoTable.USER_UUID + ", " +
UserInfoTable.Col.SERVER_UUID + UserInfoTable.SERVER_UUID +
" FROM " + UserInfoTable.TABLE_NAME; " FROM " + UserInfoTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, List<UserInfo>>>(sql, 50000) { return new QueryAllStatement<Map<UUID, List<UserInfo>>>(sql, 50000) {
@ -446,14 +446,14 @@ public class LargeFetchQueries {
public Map<UUID, List<UserInfo>> processResults(ResultSet set) throws SQLException { public Map<UUID, List<UserInfo>> processResults(ResultSet set) throws SQLException {
Map<UUID, List<UserInfo>> serverMap = new HashMap<>(); Map<UUID, List<UserInfo>> serverMap = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID serverUUID = UUID.fromString(set.getString(UserInfoTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
UUID uuid = UUID.fromString(set.getString(UserInfoTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(UserInfoTable.USER_UUID));
List<UserInfo> userInfos = serverMap.getOrDefault(serverUUID, new ArrayList<>()); List<UserInfo> userInfos = serverMap.getOrDefault(serverUUID, new ArrayList<>());
long registered = set.getLong(UserInfoTable.Col.REGISTERED.get()); long registered = set.getLong(UserInfoTable.REGISTERED);
boolean banned = set.getBoolean(UserInfoTable.Col.BANNED.get()); boolean banned = set.getBoolean(UserInfoTable.BANNED);
boolean op = set.getBoolean(UserInfoTable.Col.OP.get()); boolean op = set.getBoolean(UserInfoTable.OP);
userInfos.add(new UserInfo(uuid, "", registered, op, banned)); userInfos.add(new UserInfo(uuid, "", registered, op, banned));
@ -479,9 +479,9 @@ public class LargeFetchQueries {
public Map<UUID, UserInfo> processResults(ResultSet set) throws SQLException { public Map<UUID, UserInfo> processResults(ResultSet set) throws SQLException {
Map<UUID, UserInfo> users = new HashMap<>(); Map<UUID, UserInfo> users = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID uuid = UUID.fromString(set.getString(UsersTable.Col.UUID.get())); UUID uuid = UUID.fromString(set.getString(UsersTable.USER_UUID));
String name = set.getString(UsersTable.Col.USER_NAME.get()); String name = set.getString(UsersTable.USER_NAME);
long registered = set.getLong(UsersTable.Col.REGISTERED.get()); long registered = set.getLong(UsersTable.REGISTERED);
users.put(uuid, new UserInfo(uuid, name, registered, false, false)); users.put(uuid, new UserInfo(uuid, name, registered, false, false));
} }
@ -503,9 +503,9 @@ public class LargeFetchQueries {
public Map<UUID, Collection<String>> processResults(ResultSet set) throws SQLException { public Map<UUID, Collection<String>> processResults(ResultSet set) throws SQLException {
Map<UUID, Collection<String>> worldMap = new HashMap<>(); Map<UUID, Collection<String>> worldMap = new HashMap<>();
while (set.next()) { while (set.next()) {
UUID serverUUID = UUID.fromString(set.getString(WorldTable.Col.SERVER_UUID.get())); UUID serverUUID = UUID.fromString(set.getString(WorldTable.SERVER_UUID));
Collection<String> worlds = worldMap.getOrDefault(serverUUID, new HashSet<>()); Collection<String> worlds = worldMap.getOrDefault(serverUUID, new HashSet<>());
worlds.add(set.getString(WorldTable.Col.NAME.get())); worlds.add(set.getString(WorldTable.NAME));
worldMap.put(serverUUID, worlds); worldMap.put(serverUUID, worlds);
} }
return worldMap; return worldMap;

View File

@ -21,7 +21,6 @@ import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.access.ExecStatement;
import com.djrapitops.plan.db.access.QueryStatement; import com.djrapitops.plan.db.access.QueryStatement;
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;
@ -38,8 +37,6 @@ import java.util.UUID;
* Table that is in charge of storing command data. * Table that is in charge of storing command data.
* <p> * <p>
* Table Name: plan_commandusages * Table Name: plan_commandusages
* <p>
* For contained columns {@link Col}
* *
* @author Rsl1122 * @author Rsl1122
*/ */
@ -56,9 +53,9 @@ public class CommandUseTable extends Table {
super(TABLE_NAME, db); super(TABLE_NAME, db);
serverTable = db.getServerTable(); serverTable = db.getServerTable();
insertStatement = "INSERT INTO " + tableName + " (" insertStatement = "INSERT INTO " + tableName + " ("
+ Col.COMMAND + ", " + COMMAND + ", "
+ Col.TIMES_USED + ", " + TIMES_USED + ", "
+ Col.SERVER_ID + SERVER_ID
+ ") VALUES (?, ?, " + serverTable.statementSelectServerID + ")"; + ") VALUES (?, ?, " + serverTable.statementSelectServerID + ")";
} }
@ -88,8 +85,8 @@ public class CommandUseTable extends Table {
*/ */
public Map<String, Integer> getCommandUse(UUID serverUUID) { public Map<String, Integer> getCommandUse(UUID serverUUID) {
String sql = Select.from(tableName, String sql = Select.from(tableName,
Col.COMMAND, Col.TIMES_USED) COMMAND, TIMES_USED)
.where(Col.SERVER_ID + "=" + serverTable.statementSelectServerID) .where(SERVER_ID + "=" + serverTable.statementSelectServerID)
.toString(); .toString();
return query(new QueryStatement<Map<String, Integer>>(sql, 5000) { return query(new QueryStatement<Map<String, Integer>>(sql, 5000) {
@ -102,8 +99,8 @@ public class CommandUseTable extends Table {
public Map<String, Integer> processResults(ResultSet set) throws SQLException { public Map<String, Integer> processResults(ResultSet set) throws SQLException {
Map<String, Integer> commandUse = new HashMap<>(); Map<String, Integer> commandUse = new HashMap<>();
while (set.next()) { while (set.next()) {
String cmd = set.getString(Col.COMMAND.get()).toLowerCase(); String cmd = set.getString(COMMAND).toLowerCase();
int amountUsed = set.getInt(Col.TIMES_USED.get()); int amountUsed = set.getInt(TIMES_USED);
commandUse.put(cmd, amountUsed); commandUse.put(cmd, amountUsed);
} }
return commandUse; return commandUse;
@ -126,9 +123,9 @@ public class CommandUseTable extends Table {
} }
String sql = "UPDATE " + tableName + " SET " String sql = "UPDATE " + tableName + " SET "
+ Col.TIMES_USED + "=" + Col.TIMES_USED + "+ 1" + + TIMES_USED + "=" + TIMES_USED + "+ 1" +
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID + " WHERE " + SERVER_ID + "=" + serverTable.statementSelectServerID +
" AND " + Col.COMMAND + "=?"; " AND " + COMMAND + "=?";
boolean updated = execute(new ExecStatement(sql) { boolean updated = execute(new ExecStatement(sql) {
@Override @Override
@ -143,7 +140,7 @@ public class CommandUseTable extends Table {
} }
public Optional<String> getCommandByID(int id) { public Optional<String> getCommandByID(int id) {
String sql = Select.from(tableName, Col.COMMAND).where(Col.COMMAND_ID + "=?").toString(); String sql = Select.from(tableName, COMMAND).where(COMMAND_ID + "=?").toString();
return query(new QueryStatement<Optional<String>>(sql) { return query(new QueryStatement<Optional<String>>(sql) {
@Override @Override
@ -154,7 +151,7 @@ public class CommandUseTable extends Table {
@Override @Override
public Optional<String> processResults(ResultSet set) throws SQLException { public Optional<String> processResults(ResultSet set) throws SQLException {
if (set.next()) { if (set.next()) {
return Optional.of(set.getString(Col.COMMAND.get())); return Optional.of(set.getString(COMMAND));
} }
return Optional.empty(); return Optional.empty();
} }
@ -173,7 +170,7 @@ public class CommandUseTable extends Table {
} }
public Optional<Integer> getCommandID(String command) { public Optional<Integer> getCommandID(String command) {
String sql = Select.from(tableName, Col.COMMAND_ID).where(Col.COMMAND + "=?").toString(); String sql = Select.from(tableName, COMMAND_ID).where(COMMAND + "=?").toString();
return query(new QueryStatement<Optional<Integer>>(sql) { return query(new QueryStatement<Optional<Integer>>(sql) {
@Override @Override
@ -184,41 +181,13 @@ public class CommandUseTable extends Table {
@Override @Override
public Optional<Integer> processResults(ResultSet set) throws SQLException { public Optional<Integer> processResults(ResultSet set) throws SQLException {
if (set.next()) { if (set.next()) {
return Optional.of(set.getInt(Col.COMMAND_ID.get())); return Optional.of(set.getInt(COMMAND_ID));
} }
return Optional.empty(); return Optional.empty();
} }
}); });
} }
@Deprecated
public enum Col implements Column {
@Deprecated
COMMAND_ID("id"),
@Deprecated
SERVER_ID("server_id"),
@Deprecated
COMMAND("command"),
@Deprecated
TIMES_USED("times_used");
private final String column;
Col(String column) {
this.column = column;
}
@Override
public String get() {
return toString();
}
@Override
public String toString() {
return column;
}
}
public void insertCommandUsage(Map<UUID, Map<String, Integer>> allCommandUsages) { public void insertCommandUsage(Map<UUID, Map<String, Integer>> allCommandUsages) {
if (allCommandUsages.isEmpty()) { if (allCommandUsages.isEmpty()) {
return; return;