use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PerServerContainerQuery method executeQuery.
@Override
public PerServerContainer executeQuery(SQLDB db) {
PerServerContainer perServerContainer = new PerServerContainer();
userInformation(db, perServerContainer);
lastSeen(db, perServerContainer);
playerKillCount(db, perServerContainer);
mobKillCount(db, perServerContainer);
totalDeathCount(db, perServerContainer);
worldTimes(db, perServerContainer);
Map<ServerUUID, List<FinishedSession>> sessions = db.query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
for (Map.Entry<ServerUUID, List<FinishedSession>> entry : sessions.entrySet()) {
ServerUUID serverUUID = entry.getKey();
List<FinishedSession> serverSessions = entry.getValue();
DataContainer serverContainer = perServerContainer.getOrDefault(serverUUID, new SupplierDataContainer());
serverContainer.putRawData(PerServerKeys.SESSIONS, serverSessions);
perServerContainer.put(serverUUID, serverContainer);
}
return perServerContainer;
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeFetchQueries method fetchAllWorldNames.
/**
* Query database for world names.
*
* @return Map: Server UUID - List of world names
*/
public static Query<Map<ServerUUID, Collection<String>>> fetchAllWorldNames() {
String sql = SELECT + '*' + FROM + WorldTable.TABLE_NAME;
return new QueryAllStatement<Map<ServerUUID, Collection<String>>>(sql, 1000) {
@Override
public Map<ServerUUID, Collection<String>> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Collection<String>> worldMap = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(WorldTable.SERVER_UUID));
Collection<String> worlds = worldMap.computeIfAbsent(serverUUID, Maps::createSet);
worlds.add(set.getString(WorldTable.NAME));
}
return worldMap;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeFetchQueries method fetchAllTPSData.
/**
* Query database for TPS data.
*
* @return Map: Server UUID - List of TPS data
*/
public static Query<Map<ServerUUID, List<TPS>>> fetchAllTPSData() {
String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID;
String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid";
String sql = SELECT + TPSTable.DATE + ',' + TPSTable.TPS + ',' + TPSTable.PLAYERS_ONLINE + ',' + TPSTable.CPU_USAGE + ',' + TPSTable.RAM_USAGE + ',' + TPSTable.ENTITIES + ',' + TPSTable.CHUNKS + ',' + TPSTable.FREE_DISK + ',' + serverUUIDColumn + FROM + TPSTable.TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
return new QueryAllStatement<Map<ServerUUID, List<TPS>>>(sql, 50000) {
@Override
public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, List<TPS>> serverMap = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString("s_uuid"));
List<TPS> tpsList = serverMap.computeIfAbsent(serverUUID, Lists::create);
TPS tps = TPSBuilder.get().date(set.getLong(TPSTable.DATE)).tps(set.getDouble(TPSTable.TPS)).playersOnline(set.getInt(TPSTable.PLAYERS_ONLINE)).usedCPU(set.getDouble(TPSTable.CPU_USAGE)).usedMemory(set.getLong(TPSTable.RAM_USAGE)).entities(set.getInt(TPSTable.ENTITIES)).chunksLoaded(set.getInt(TPSTable.CHUNKS)).freeDiskSpace(set.getLong(TPSTable.FREE_DISK)).toTPS();
tpsList.add(tps);
}
return serverMap;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class LargeStoreQueries method storePerServerUserInformation.
/**
* Execute a big batch of Per server UserInfo insert statements.
*
* @param ofServers Map: Server UUID - List of user information
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable storePerServerUserInformation(Map<ServerUUID, List<UserInfo>> ofServers) {
if (ofServers == null || ofServers.isEmpty())
return Executable.empty();
return new ExecBatchStatement(UserInfoTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Every Server
for (Map.Entry<ServerUUID, List<UserInfo>> entry : ofServers.entrySet()) {
ServerUUID serverUUID = entry.getKey();
// Every User
for (UserInfo user : entry.getValue()) {
statement.setString(1, user.getPlayerUuid().toString());
statement.setLong(2, user.getRegistered());
statement.setString(3, serverUUID.toString());
statement.setBoolean(4, user.isBanned());
statement.setString(5, user.getJoinAddress());
statement.setBoolean(6, user.isOperator());
statement.addBatch();
}
}
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class ServerSettingsManager method updateConfigInDB.
private void updateConfigInDB(File file) {
if (!file.exists()) {
return;
}
Database database = dbSystem.getDatabase();
Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
if (!serverUUID.isPresent()) {
return;
}
try (ConfigReader reader = new ConfigReader(file.toPath())) {
Config read = reader.read();
database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations