Search in sources :

Example 21 with QueryStatement

use of com.djrapitops.plan.storage.database.queries.QueryStatement 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)

Example 22 with QueryStatement

use of com.djrapitops.plan.storage.database.queries.QueryStatement in project Plan by plan-player-analytics.

the class NicknameQueries method fetchNicknameDataOfPlayer.

public static Query<List<Nickname>> fetchNicknameDataOfPlayer(UUID playerUUID) {
    String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.USER_UUID + "=?";
    return new QueryStatement<List<Nickname>>(sql, 5000) {

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

        @Override
        public List<Nickname> processResults(ResultSet set) throws SQLException {
            List<Nickname> nicknames = new ArrayList<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
                String nickname = set.getString(NicknamesTable.NICKNAME);
                nicknames.add(new Nickname(nickname, set.getLong(NicknamesTable.LAST_USED), serverUUID));
            }
            return nicknames;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 23 with QueryStatement

use of com.djrapitops.plan.storage.database.queries.QueryStatement in project Plan by plan-player-analytics.

the class ServerQueries method fetchPlanServerInformation.

/**
 * Query database for all Plan server information.
 *
 * @return Map: Server UUID - Plan Server Information
 */
public static Query<Map<ServerUUID, Server>> fetchPlanServerInformation() {
    String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + ServerTable.INSTALLED + "=?";
    return new QueryStatement<Map<ServerUUID, Server>>(sql, 100) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setBoolean(1, true);
        }

        @Override
        public Map<ServerUUID, Server> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Server> servers = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
                servers.put(serverUUID, new Server(set.getInt(ServerTable.SERVER_ID), serverUUID, set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY)));
            }
            return servers;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 24 with QueryStatement

use of com.djrapitops.plan.storage.database.queries.QueryStatement in project Plan by plan-player-analytics.

the class ServerQueries method findMatchingServers.

public static Query<List<Server>> findMatchingServers(String identifier) {
    if (identifier.isEmpty())
        return db -> Collections.emptyList();
    String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + "(LOWER(" + ServerTable.SERVER_UUID + ") LIKE LOWER(?)" + OR + "LOWER(" + ServerTable.NAME + ") LIKE LOWER(?)" + OR + ServerTable.SERVER_ID + "=?" + OR + ServerTable.SERVER_ID + "=?)" + AND + ServerTable.INSTALLED + "=?" + LIMIT + '1';
    return new QueryStatement<List<Server>>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, '%' + identifier + '%');
            statement.setString(2, '%' + identifier + '%');
            statement.setInt(3, NumberUtils.isParsable(identifier) ? Integer.parseInt(identifier) : -1);
            String id = identifier.startsWith("Server ") ? identifier.substring(7) : identifier;
            statement.setInt(4, NumberUtils.isParsable(id) ? Integer.parseInt(id) : -1);
            statement.setBoolean(5, true);
        }

        @Override
        public List<Server> processResults(ResultSet set) throws SQLException {
            List<Server> matches = new ArrayList<>();
            while (set.next()) {
                matches.add(new Server(set.getInt(ServerTable.SERVER_ID), ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)), set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY)));
            }
            return matches;
        }
    };
}
Also used : Server(com.djrapitops.plan.identification.Server) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 25 with QueryStatement

use of com.djrapitops.plan.storage.database.queries.QueryStatement in project Plan by plan-player-analytics.

the class ServerQueries method fetchProxyServerInformation.

public static Query<Optional<Server>> fetchProxyServerInformation() {
    String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + ServerTable.INSTALLED + "=?" + AND + ServerTable.PROXY + "=?" + LIMIT + '1';
    return new QueryStatement<Optional<Server>>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setBoolean(1, true);
            statement.setBoolean(2, true);
        }

        @Override
        public Optional<Server> processResults(ResultSet set) throws SQLException {
            if (set.next()) {
                return Optional.of(new Server(set.getInt(ServerTable.SERVER_ID), ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)), set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY)));
            }
            return Optional.empty();
        }
    };
}
Also used : Server(com.djrapitops.plan.identification.Server) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Aggregations

QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)35 PreparedStatement (java.sql.PreparedStatement)35 ResultSet (java.sql.ResultSet)35 ServerUUID (com.djrapitops.plan.identification.ServerUUID)13 ActivityIndex (com.djrapitops.plan.delivery.domain.mutators.ActivityIndex)6 WebUser (com.djrapitops.plan.delivery.domain.WebUser)5 User (com.djrapitops.plan.delivery.domain.auth.User)5 GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)4 Server (com.djrapitops.plan.identification.Server)4 Nickname (com.djrapitops.plan.delivery.domain.Nickname)3 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)3 TextStringBuilder (org.apache.commons.text.TextStringBuilder)3 Ping (com.djrapitops.plan.gathering.domain.Ping)2 TPS (com.djrapitops.plan.gathering.domain.TPS)2 UserInfo (com.djrapitops.plan.gathering.domain.UserInfo)2 Lists (com.djrapitops.plan.utilities.java.Lists)2 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)1 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)1 ArrayList (java.util.ArrayList)1