Search in sources :

Example 81 with ServerUUID

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;
        }
    };
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 82 with ServerUUID

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();
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 83 with ServerUUID

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();
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 84 with ServerUUID

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();
                    }
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 85 with ServerUUID

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();
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Aggregations

ServerUUID (com.djrapitops.plan.identification.ServerUUID)105 UUID (java.util.UUID)26 ResultSet (java.sql.ResultSet)23 PreparedStatement (java.sql.PreparedStatement)21 Database (com.djrapitops.plan.storage.database.Database)17 Test (org.junit.jupiter.api.Test)17 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)14 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)12 Nickname (com.djrapitops.plan.delivery.domain.Nickname)11 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)11 Server (com.djrapitops.plan.identification.Server)11 HashMap (java.util.HashMap)11 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)9 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)9 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)9 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)9 Lists (com.djrapitops.plan.utilities.java.Lists)9 CallEvents (com.djrapitops.plan.extension.CallEvents)8 List (java.util.List)8 Map (java.util.Map)8