Search in sources :

Example 86 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllWorldNames.

private static Executable storeAllWorldNames(Collection<FinishedSession> sessions, Set<World> existingWorlds) {
    Set<World> worlds = sessions.stream().flatMap(session -> {
        ServerUUID serverUUID = session.getServerUUID();
        return session.getExtraData(WorldTimes.class).map(WorldTimes::getWorldTimes).map(Map::keySet).orElseGet(Collections::emptySet).stream().map(worldName -> new World(worldName, serverUUID));
    }).filter(world -> !existingWorlds.contains(world)).collect(Collectors.toSet());
    if (worlds.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(WorldTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (World world : worlds) {
                statement.setString(1, world.getWorldName());
                statement.setString(2, world.getServerUUID().toString());
                statement.addBatch();
            }
        }
    };
}
Also used : WorldTimesQueries(com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) java.util(java.util) World(com.djrapitops.plan.delivery.domain.World) Executable(com.djrapitops.plan.storage.database.transactions.Executable) com.djrapitops.plan.gathering.domain(com.djrapitops.plan.gathering.domain) ServerUUID(com.djrapitops.plan.identification.ServerUUID) com.djrapitops.plan.storage.database.sql.tables(com.djrapitops.plan.storage.database.sql.tables) PreparedStatement(java.sql.PreparedStatement) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) SQLException(java.sql.SQLException) Server(com.djrapitops.plan.identification.Server) User(com.djrapitops.plan.delivery.domain.auth.User) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Types(java.sql.Types) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) World(com.djrapitops.plan.delivery.domain.World) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 87 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllPingData.

public static Executable storeAllPingData(Map<UUID, List<Ping>> ofUsers) {
    if (ofUsers == null || ofUsers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(PingTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (Map.Entry<UUID, List<Ping>> entry : ofUsers.entrySet()) {
                UUID uuid = entry.getKey();
                List<Ping> pings = entry.getValue();
                for (Ping ping : pings) {
                    ServerUUID serverUUID = ping.getServerUUID();
                    long date = ping.getDate();
                    int minPing = ping.getMin();
                    int maxPing = ping.getMax();
                    double avgPing = ping.getAverage();
                    statement.setString(1, uuid.toString());
                    statement.setString(2, serverUUID.toString());
                    statement.setLong(3, date);
                    statement.setInt(4, minPing);
                    statement.setInt(5, maxPing);
                    statement.setDouble(6, avgPing);
                    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)

Example 88 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class PluginBooleanGroupFilter method getMatchingUUIDs.

@Override
public Set<UUID> getMatchingUUIDs(InputFilterDto query) {
    Map<PluginBooleanOption, SelectedBoolean> selectedBooleanOptions = new HashMap<>();
    for (String selected : getSelected(query)) {
        String[] optionAndBoolean = StringUtils.split(selected, ":", 2);
        PluginBooleanOption pluginBooleanOption = PluginBooleanOption.parse(optionAndBoolean[0].trim());
        String selectedBoolean = optionAndBoolean[1].trim().toUpperCase();
        selectedBooleanOptions.computeIfPresent(pluginBooleanOption, (key, existing) -> SelectedBoolean.BOTH);
        selectedBooleanOptions.computeIfAbsent(pluginBooleanOption, key -> SelectedBoolean.valueOf(selectedBoolean));
    }
    Database db = dbSystem.getDatabase();
    Map<String, ServerUUID> namesToUUIDs = db.query(ServerQueries.fetchServerNamesToUUIDs());
    return db.query(playersInGroups(selectedBooleanOptions, namesToUUIDs));
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Database(com.djrapitops.plan.storage.database.Database)

Example 89 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class PingQueries method fetchPingDataOfServer.

public static Query<List<Ping>> fetchPingDataOfServer(long after, long before, ServerUUID serverUUID) {
    String sql = SELECT + PingTable.DATE + ", " + PingTable.MAX_PING + ", " + PingTable.MIN_PING + ", " + PingTable.AVG_PING + ", " + PingTable.SERVER_UUID + FROM + PingTable.TABLE_NAME + WHERE + PingTable.SERVER_UUID + "=?" + AND + PingTable.DATE + ">=?" + AND + PingTable.DATE + "<=?";
    return new QueryStatement<List<Ping>>(sql, 1000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, serverUUID.toString());
            statement.setLong(2, after);
            statement.setLong(3, before);
        }

        @Override
        public List<Ping> processResults(ResultSet set) throws SQLException {
            List<Ping> pings = new ArrayList<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(PingTable.SERVER_UUID));
                long date = set.getLong(PingTable.DATE);
                double avgPing = set.getDouble(PingTable.AVG_PING);
                int minPing = set.getInt(PingTable.MIN_PING);
                int maxPing = set.getInt(PingTable.MAX_PING);
                pings.add(new Ping(date, serverUUID, minPing, maxPing, avgPing));
            }
            return pings;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Ping(com.djrapitops.plan.gathering.domain.Ping) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 90 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class NicknameQueries method fetchNicknameDataOfServer.

/**
 * Query database for nickname information of a server.
 *
 * @param serverUUID UUID the the Plan server.
 * @return Map: Player UUID - List of Nicknames on the server.
 */
public static Query<Map<UUID, List<Nickname>>> fetchNicknameDataOfServer(ServerUUID serverUUID) {
    String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.USER_UUID + FROM + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.SERVER_UUID + "=?";
    return new QueryStatement<Map<UUID, List<Nickname>>>(sql, 5000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, serverUUID.toString());
        }

        @Override
        public Map<UUID, List<Nickname>> processResults(ResultSet set) throws SQLException {
            Map<UUID, List<Nickname>> serverMap = new HashMap<>();
            while (set.next()) {
                UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
                List<Nickname> nicknames = serverMap.computeIfAbsent(uuid, Lists::create);
                nicknames.add(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
            }
            return serverMap;
        }
    };
}
Also used : Lists(com.djrapitops.plan.utilities.java.Lists) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

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