use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class WorldTimesQueries method fetchPlayerWorldTimesOnServers.
/**
* Find total world times of the player on servers.
*
* @param playerUUID UUID of the player.
* @return Map: Server UUID - WorldTimes total for the server
*/
public static Query<Map<ServerUUID, WorldTimes>> fetchPlayerWorldTimesOnServers(UUID playerUUID) {
String sql = SELECT_WORLD_TIMES_STATEMENT_START + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID + ',' + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.USER_UUID + "=?" + GROUP_BY + WORLD_COLUMN + ',' + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID;
return new QueryStatement<Map<ServerUUID, WorldTimes>>(sql, 1000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
}
@Override
public Map<ServerUUID, WorldTimes> processResults(ResultSet set) throws SQLException {
String[] gms = GMTimes.getGMKeyArray();
Map<ServerUUID, WorldTimes> worldTimesMap = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(WorldTimesTable.SERVER_UUID));
WorldTimes worldTimes = worldTimesMap.getOrDefault(serverUUID, new WorldTimes());
String worldName = set.getString(WORLD_COLUMN);
GMTimes gmTimes = extractGMTimes(set, gms);
worldTimes.setGMTimesForWorld(worldName, gmTimes);
worldTimesMap.put(serverUUID, worldTimes);
}
return worldTimesMap;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeStoreQueries method storeAllWorldNames.
/**
* Execute a big batch of world name insert statements.
*
* @param ofServers Map: Server UUID - Collection of world names
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable storeAllWorldNames(Map<ServerUUID, Collection<String>> ofServers) {
if (ofServers == null || ofServers.isEmpty())
return Executable.empty();
return new ExecBatchStatement(WorldTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<ServerUUID, Collection<String>> entry : ofServers.entrySet()) {
ServerUUID serverUUID = entry.getKey();
for (String world : entry.getValue()) {
statement.setString(1, StringUtils.truncate(world, 100));
statement.setString(2, serverUUID.toString());
statement.addBatch();
}
}
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeStoreQueries method storeAllPlanServerInformation.
/**
* Execute a big batch of server information insert statements.
*
* @param servers Collection of Plan Servers.
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable storeAllPlanServerInformation(Collection<Server> servers) {
if (servers == null || servers.isEmpty())
return Executable.empty();
return new ExecBatchStatement(ServerTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Server server : servers) {
ServerUUID serverUUID = server.getUuid();
if (serverUUID == null) {
continue;
}
statement.setString(1, serverUUID.toString());
statement.setString(2, server.getName());
statement.setString(3, server.getWebAddress());
statement.setBoolean(4, true);
statement.setBoolean(5, server.isProxy());
statement.addBatch();
}
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeStoreQueries method storeAllNicknameData.
/**
* Execute a big batch of nickname insert statements.
*
* @param ofServersAndUsers Multimap: Server UUID - (Player UUID - List of nicknames)
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable storeAllNicknameData(Map<ServerUUID, Map<UUID, List<Nickname>>> ofServersAndUsers) {
if (ofServersAndUsers == null || ofServersAndUsers.isEmpty())
return Executable.empty();
return new ExecBatchStatement(NicknamesTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Every Server
for (Map.Entry<ServerUUID, Map<UUID, List<Nickname>>> serverEntry : ofServersAndUsers.entrySet()) {
ServerUUID serverUUID = serverEntry.getKey();
// Every User
for (Map.Entry<UUID, List<Nickname>> entry : serverEntry.getValue().entrySet()) {
UUID uuid = entry.getKey();
// Every Nickname
List<Nickname> nicknames = entry.getValue();
for (Nickname nickname : nicknames) {
statement.setString(1, uuid.toString());
statement.setString(2, serverUUID.toString());
statement.setString(3, nickname.getName());
statement.setLong(4, nickname.getDate());
statement.addBatch();
}
}
}
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeStoreQueries method storeAllTPSData.
/**
* Execute a big batch of TPS insert statements.
*
* @param ofServers Map: Server UUID - List of TPS data
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable storeAllTPSData(Map<ServerUUID, List<TPS>> ofServers) {
if (ofServers == null || ofServers.isEmpty())
return Executable.empty();
return new ExecBatchStatement(TPSTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Every Server
for (Map.Entry<ServerUUID, List<TPS>> entry : ofServers.entrySet()) {
ServerUUID serverUUID = entry.getKey();
// Every TPS Data point
List<TPS> tpsList = entry.getValue();
for (TPS tps : tpsList) {
statement.setString(1, serverUUID.toString());
statement.setLong(2, tps.getDate());
statement.setDouble(3, tps.getTicksPerSecond());
statement.setInt(4, tps.getPlayers());
statement.setDouble(5, tps.getCPUUsage());
statement.setLong(6, tps.getUsedMemory());
statement.setDouble(7, tps.getEntityCount());
statement.setDouble(8, tps.getChunksLoaded());
statement.setLong(9, tps.getFreeDiskSpace());
statement.addBatch();
}
}
}
};
}
Aggregations