Search in sources :

Example 6 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 selectSmallestRegisterDates = SELECT + UserInfoTable.USER_ID + ',' + "MIN(" + UserInfoTable.REGISTERED + ") as min_registered" + FROM + UserInfoTable.TABLE_NAME + GROUP_BY + UserInfoTable.USER_ID;
    String sql = SELECT + UsersTable.USER_UUID + ",u1." + UsersTable.REGISTERED + ",min_registered" + FROM + '(' + selectSmallestRegisterDates + ") u2" + INNER_JOIN + UsersTable.TABLE_NAME + " u1 on u1." + UsersTable.ID + "=u2." + UserInfoTable.USER_ID + 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(UsersTable.USER_UUID));
                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 7 with QueryAllStatement

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

the class UserIdentifierQueries method fetchAllPlayerUUIDs.

/**
 * Query database for all player UUIDs stored in the Plan database.
 *
 * @return Set of UUIDs.
 */
public static Query<Set<UUID>> fetchAllPlayerUUIDs() {
    String sql = Select.from(UsersTable.TABLE_NAME, UsersTable.USER_UUID).toString();
    return new QueryAllStatement<Set<UUID>>(sql, 20000) {

        @Override
        public Set<UUID> processResults(ResultSet set) throws SQLException {
            Set<UUID> playerUUIDs = new HashSet<>();
            while (set.next()) {
                UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
                playerUUIDs.add(playerUUID);
            }
            return playerUUIDs;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) ResultSet(java.sql.ResultSet) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 8 with QueryAllStatement

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

the class UserInfoQueries method fetchAllUserInformation.

/**
 * Query database for user information.
 * <p>
 * The user information does not contain player names.
 *
 * @return Map: Server UUID - List of user information
 */
public static Query<Map<ServerUUID, List<UserInfo>>> fetchAllUserInformation() {
    String sql = SELECT + "ux." + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.OP + ',' + "u." + UsersTable.USER_UUID + ',' + "s." + ServerTable.SERVER_UUID + " as server_uuid," + UserInfoTable.JOIN_ADDRESS + FROM + UserInfoTable.TABLE_NAME + " ux" + INNER_JOIN + UsersTable.TABLE_NAME + " u on u." + UsersTable.ID + '=' + "ux." + UserInfoTable.USER_ID + INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.ID + '=' + "ux." + UserInfoTable.SERVER_ID;
    return new QueryAllStatement<Map<ServerUUID, List<UserInfo>>>(sql, 50000) {

        @Override
        public Map<ServerUUID, List<UserInfo>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<UserInfo>> serverMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString("server_uuid"));
                UUID uuid = UUID.fromString(set.getString(UsersTable.USER_UUID));
                List<UserInfo> userInfos = serverMap.computeIfAbsent(serverUUID, Lists::create);
                long registered = set.getLong(UserInfoTable.REGISTERED);
                boolean banned = set.getBoolean(UserInfoTable.BANNED);
                boolean op = set.getBoolean(UserInfoTable.OP);
                String joinAddress = set.getString(UserInfoTable.JOIN_ADDRESS);
                userInfos.add(new UserInfo(uuid, serverUUID, registered, op, joinAddress, banned));
            }
            return serverMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) Lists(com.djrapitops.plan.utilities.java.Lists) ResultSet(java.sql.ResultSet) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 9 with QueryAllStatement

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

the class ExtensionInformationQueries method allExtensions.

public static Query<Map<ServerUUID, List<ExtensionInformation>>> allExtensions() {
    String sql = SELECT + ExtensionPluginTable.TABLE_NAME + '.' + ExtensionPluginTable.ID + " as id," + ExtensionPluginTable.TABLE_NAME + '.' + ExtensionPluginTable.PLUGIN_NAME + " as plugin_name," + ExtensionPluginTable.SERVER_UUID + ',' + ExtensionIconTable.TABLE_NAME + '.' + ExtensionIconTable.ICON_NAME + " as icon_name," + ExtensionIconTable.COLOR + ',' + ExtensionIconTable.FAMILY + FROM + ExtensionPluginTable.TABLE_NAME + INNER_JOIN + ExtensionIconTable.TABLE_NAME + " on " + ExtensionPluginTable.ICON_ID + "=" + ExtensionIconTable.TABLE_NAME + '.' + ExtensionIconTable.ID;
    return new QueryAllStatement<Map<ServerUUID, List<ExtensionInformation>>>(sql, 100) {

        @Override
        public Map<ServerUUID, List<ExtensionInformation>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<ExtensionInformation>> byServerUUID = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(ExtensionPluginTable.SERVER_UUID));
                List<ExtensionInformation> information = byServerUUID.computeIfAbsent(serverUUID, Lists::create);
                information.add(extractExtensionInformationFromQuery(set));
            }
            return byServerUUID;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) Lists(com.djrapitops.plan.utilities.java.Lists) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionInformation(com.djrapitops.plan.extension.implementation.results.ExtensionInformation)

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