Search in sources :

Example 1 with QueryAllStatement

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

the class RegisterDateMinimizationPatch method fetchSmallestServerRegisterDates.

private Query<Map<UUID, Long>> fetchSmallestServerRegisterDates() {
    String sql = SELECT + "u1.uuid,u1." + UsersTable.REGISTERED + ",min_registered" + FROM + '(' + SELECT + UserInfoTable.USER_UUID + ',' + "MIN(" + UserInfoTable.REGISTERED + ") as min_registered" + FROM + UserInfoTable.TABLE_NAME + GROUP_BY + UserInfoTable.USER_UUID + ") u2" + INNER_JOIN + UsersTable.TABLE_NAME + " u1 on u1.uuid=u2.uuid" + WHERE + "u1." + UsersTable.REGISTERED + ">min_registered";
    return new QueryAllStatement<Map<UUID, Long>>(sql, 500) {

        @Override
        public Map<UUID, Long> processResults(ResultSet set) throws SQLException {
            Map<UUID, Long> dates = new HashMap<>();
            while (set.next()) {
                UUID playerUUID = UUID.fromString(set.getString(1));
                long newRegisterDate = set.getLong("min_registered");
                dates.put(playerUUID, newRegisterDate);
            }
            return dates;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) UUID(java.util.UUID)

Example 2 with QueryAllStatement

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

the class UserIdentifierQueries method fetchAllPlayerNames.

/**
 * Query database for a Map for all UUIDs and Player names.
 *
 * @return Map: Player UUID - Player name
 */
public static Query<Map<UUID, String>> fetchAllPlayerNames() {
    String sql = Select.from(UsersTable.TABLE_NAME, UsersTable.USER_UUID, UsersTable.USER_NAME).toString();
    return new QueryAllStatement<Map<UUID, String>>(sql, 20000) {

        @Override
        public Map<UUID, String> processResults(ResultSet set) throws SQLException {
            Map<UUID, String> names = new HashMap<>();
            while (set.next()) {
                UUID uuid = UUID.fromString(set.getString(UsersTable.USER_UUID));
                String name = set.getString(UsersTable.USER_NAME);
                names.put(uuid, name);
            }
            return names;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) ResultSet(java.sql.ResultSet) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 3 with QueryAllStatement

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

the class WebUserQueries method fetchAllUsers.

public static Query<List<User>> fetchAllUsers() {
    String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + LEFT_JOIN + UsersTable.TABLE_NAME + " on " + SecurityTable.LINKED_TO + "=" + UsersTable.USER_UUID;
    return new QueryAllStatement<List<User>>(sql) {

        @Override
        public List<User> processResults(ResultSet set) throws SQLException {
            List<User> users = new ArrayList<>();
            while (set.next()) {
                String username = set.getString(SecurityTable.USERNAME);
                String linkedTo = set.getString(UsersTable.USER_NAME);
                UUID linkedToUUID = linkedTo != null ? UUID.fromString(set.getString(SecurityTable.LINKED_TO)) : null;
                String passwordHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
                int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
                List<String> permissions = WebUser.getPermissionsForLevel(permissionLevel);
                users.add(new User(username, linkedTo != null ? linkedTo : "console", linkedToUUID, passwordHash, permissionLevel, permissions));
            }
            return users;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) User(com.djrapitops.plan.delivery.domain.auth.User) WebUser(com.djrapitops.plan.delivery.domain.WebUser) ResultSet(java.sql.ResultSet)

Example 4 with QueryAllStatement

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

the class PingQueries method fetchPingDataOfNetworkByGeolocation.

public static Query<Map<String, Ping>> fetchPingDataOfNetworkByGeolocation() {
    String selectPingOfServer = SELECT + PingTable.MAX_PING + ", " + PingTable.MIN_PING + ", " + PingTable.AVG_PING + ", " + PingTable.USER_UUID + ", " + PingTable.SERVER_UUID + FROM + PingTable.TABLE_NAME;
    String selectGeolocations = SELECT + GeoInfoTable.USER_UUID + ", " + GeoInfoTable.GEOLOCATION + ", " + GeoInfoTable.LAST_USED + FROM + GeoInfoTable.TABLE_NAME;
    String selectLatestGeolocationDate = SELECT + GeoInfoTable.USER_UUID + ", " + "MAX(" + GeoInfoTable.LAST_USED + ") as m" + FROM + GeoInfoTable.TABLE_NAME + GROUP_BY + GeoInfoTable.USER_UUID;
    String selectPingByGeolocation = SELECT + GeoInfoTable.GEOLOCATION + ", MIN(" + PingTable.MIN_PING + ") as minPing" + ", MAX(" + PingTable.MAX_PING + ") as maxPing" + ", AVG(" + PingTable.AVG_PING + ") as avgPing" + FROM + "(" + "(" + selectGeolocations + ") AS q1" + INNER_JOIN + "(" + selectLatestGeolocationDate + ") AS q2 ON q1.uuid = q2.uuid" + INNER_JOIN + '(' + selectPingOfServer + ") sp on sp." + PingTable.USER_UUID + "=q1.uuid)" + WHERE + GeoInfoTable.LAST_USED + "=m" + GROUP_BY + GeoInfoTable.GEOLOCATION;
    return new QueryAllStatement<Map<String, Ping>>(selectPingByGeolocation) {

        @Override
        public Map<String, Ping> processResults(ResultSet set) throws SQLException {
            // TreeMap to sort alphabetically
            Map<String, Ping> pingByGeolocation = new TreeMap<>();
            while (set.next()) {
                Ping ping = new Ping(0L, null, set.getInt("minPing"), set.getInt("maxPing"), (int) set.getDouble("avgPing"));
                pingByGeolocation.put(set.getString(GeoInfoTable.GEOLOCATION), ping);
            }
            return pingByGeolocation;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) Ping(com.djrapitops.plan.gathering.domain.Ping) ResultSet(java.sql.ResultSet)

Example 5 with QueryAllStatement

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

the class NicknameQueries method fetchAllNicknameData.

/**
 * Query database for all nickname data.
 *
 * @return Multimap: Server UUID - (Player UUID - List of nicknames)
 */
public static Query<Map<ServerUUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
    String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.USER_UUID + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME;
    return new QueryAllStatement<Map<ServerUUID, Map<UUID, List<Nickname>>>>(sql, 5000) {

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

Aggregations

QueryAllStatement (com.djrapitops.plan.storage.database.queries.QueryAllStatement)9 ResultSet (java.sql.ResultSet)9 ServerUUID (com.djrapitops.plan.identification.ServerUUID)6 Lists (com.djrapitops.plan.utilities.java.Lists)3 HashMap (java.util.HashMap)2 Nickname (com.djrapitops.plan.delivery.domain.Nickname)1 WebUser (com.djrapitops.plan.delivery.domain.WebUser)1 User (com.djrapitops.plan.delivery.domain.auth.User)1 ExtensionInformation (com.djrapitops.plan.extension.implementation.results.ExtensionInformation)1 Ping (com.djrapitops.plan.gathering.domain.Ping)1 UserInfo (com.djrapitops.plan.gathering.domain.UserInfo)1 Maps (com.djrapitops.plan.utilities.java.Maps)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1