Search in sources :

Example 11 with QueryStatement

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

the class WorldTimesQueries method fetchGMTimes.

public static Query<GMTimes> fetchGMTimes(long after, long before, ServerUUID serverUUID) {
    String sql = SELECT + "SUM(" + WorldTimesTable.SURVIVAL + ") as SURVIVAL," + "SUM(" + WorldTimesTable.CREATIVE + ") as CREATIVE," + "SUM(" + WorldTimesTable.ADVENTURE + ") as ADVENTURE," + "SUM(" + WorldTimesTable.SPECTATOR + ") as SPECTATOR" + FROM + WorldTimesTable.TABLE_NAME + " w1" + INNER_JOIN + SessionsTable.TABLE_NAME + " s1 on s1." + SessionsTable.ID + '=' + WorldTimesTable.SESSION_ID + WHERE + "w1." + WorldTimesTable.SERVER_UUID + "=?" + AND + SessionsTable.SESSION_START + ">=?" + AND + SessionsTable.SESSION_END + "<=?";
    return new QueryStatement<GMTimes>(sql) {

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

        @Override
        public GMTimes processResults(ResultSet set) throws SQLException {
            return set.next() ? extractGMTimes(set, GMTimes.getGMKeyArray()) : new GMTimes();
        }
    };
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 12 with QueryStatement

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

the class TPSQueries method fetchTPSDataOfAllServersBut.

public static Query<Map<ServerUUID, List<TPS>>> fetchTPSDataOfAllServersBut(long after, long before, ServerUUID leaveOut) {
    String sql = SELECT + '*' + FROM + TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID + '=' + SERVER_ID + WHERE + ServerTable.SERVER_UUID + "!=?" + AND + ServerTable.INSTALLED + "=?" + AND + DATE + "<?" + AND + DATE + ">?";
    return new QueryStatement<Map<ServerUUID, List<TPS>>>(sql, 1000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            if (leaveOut != null) {
                statement.setString(1, leaveOut.toString());
            } else {
                statement.setNull(1, Types.VARCHAR);
            }
            statement.setBoolean(2, true);
            statement.setLong(3, before);
            statement.setLong(4, after);
        }

        @Override
        public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<TPS>> byServer = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
                List<TPS> ofServer = byServer.computeIfAbsent(serverUUID, Lists::create);
                ofServer.add(extractTPS(set));
            }
            return byServer;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Lists(com.djrapitops.plan.utilities.java.Lists) TPS(com.djrapitops.plan.gathering.domain.TPS) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 13 with QueryStatement

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

the class UserInfoQueries method fetchUserInformationOfServer.

/**
 * Query database for all User information of a specific server.
 *
 * @param serverUUID UUID of the Plan server.
 * @return Map: Player UUID - user information
 */
public static Query<Map<UUID, UserInfo>> fetchUserInformationOfServer(ServerUUID serverUUID) {
    String sql = SELECT + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.JOIN_ADDRESS + ',' + UserInfoTable.OP + ',' + UserInfoTable.USER_UUID + ',' + UserInfoTable.SERVER_UUID + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.SERVER_UUID + "=?";
    return new QueryStatement<Map<UUID, UserInfo>>(sql, 1000) {

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

        @Override
        public Map<UUID, UserInfo> processResults(ResultSet set) throws SQLException {
            Map<UUID, UserInfo> userInformation = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
                UUID uuid = UUID.fromString(set.getString(UserInfoTable.USER_UUID));
                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);
                userInformation.put(uuid, new UserInfo(uuid, serverUUID, registered, op, joinAddress, banned));
            }
            return userInformation;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 14 with QueryStatement

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

the class UserInfoQueries method fetchUserInformationOfUser.

/**
 * Query database for User information of a specific player.
 *
 * @param playerUUID UUID of the player.
 * @return List of UserInfo objects, one for each server where the player has played.
 */
public static Query<Set<UserInfo>> fetchUserInformationOfUser(UUID playerUUID) {
    String sql = SELECT + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.OP + ',' + UserInfoTable.SERVER_UUID + ',' + UserInfoTable.JOIN_ADDRESS + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
    return new QueryStatement<Set<UserInfo>>(sql) {

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

        @Override
        public Set<UserInfo> processResults(ResultSet set) throws SQLException {
            Set<UserInfo> userInformation = new HashSet<>();
            while (set.next()) {
                long registered = set.getLong(UserInfoTable.REGISTERED);
                boolean op = set.getBoolean(UserInfoTable.OP);
                boolean banned = set.getBoolean(UserInfoTable.BANNED);
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
                String joinAddress = set.getString(UserInfoTable.JOIN_ADDRESS);
                userInformation.add(new UserInfo(playerUUID, serverUUID, registered, op, joinAddress, banned));
            }
            return userInformation;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 15 with QueryStatement

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

the class UserInfoQueries method uuidsOfRegisteredBetween.

public static Query<Set<UUID>> uuidsOfRegisteredBetween(long after, long before, List<ServerUUID> serverUUIDs) {
    String sql = SELECT + DISTINCT + UserInfoTable.USER_UUID + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.REGISTERED + ">=?" + AND + UserInfoTable.REGISTERED + "<=?" + AND + UserInfoTable.SERVER_UUID + " IN ('" + new TextStringBuilder().appendWithSeparators(serverUUIDs, "','") + "')";
    return new QueryStatement<Set<UUID>>(sql) {

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

        @Override
        public Set<UUID> processResults(ResultSet set) throws SQLException {
            Set<UUID> uuids = new HashSet<>();
            while (set.next()) {
                uuids.add(UUID.fromString(set.getString(UsersTable.USER_UUID)));
            }
            return uuids;
        }
    };
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

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