Search in sources :

Example 36 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID 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)

Example 37 with ServerUUID

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

the class ServerQueries method fetchServerNames.

public static Query<Map<ServerUUID, String>> fetchServerNames() {
    String sql = Select.from(ServerTable.TABLE_NAME, ServerTable.SERVER_ID, ServerTable.SERVER_UUID, ServerTable.NAME).toString();
    return new QueryAllStatement<Map<ServerUUID, String>>(sql) {

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

Example 38 with ServerUUID

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

the class WorldTimesTable method addSessionWorldTimesToBatch.

public static void addSessionWorldTimesToBatch(PreparedStatement statement, FinishedSession session, String[] gms) throws SQLException {
    UUID uuid = session.getPlayerUUID();
    ServerUUID serverUUID = session.getServerUUID();
    Optional<WorldTimes> worldTimes = session.getExtraData().get(WorldTimes.class);
    if (!worldTimes.isPresent())
        return;
    for (Map.Entry<String, GMTimes> worldTimesEntry : worldTimes.get().getWorldTimes().entrySet()) {
        String worldName = worldTimesEntry.getKey();
        GMTimes gmTimes = worldTimesEntry.getValue();
        // Session ID select statement
        statement.setString(1, uuid.toString());
        statement.setString(2, serverUUID.toString());
        statement.setLong(3, session.getStart());
        statement.setLong(4, session.getEnd());
        // World ID select statement
        statement.setString(5, worldName);
        statement.setString(6, serverUUID.toString());
        statement.setString(7, uuid.toString());
        statement.setString(8, serverUUID.toString());
        statement.setLong(9, gmTimes.getTime(gms[0]));
        statement.setLong(10, gmTimes.getTime(gms[1]));
        statement.setLong(11, gmTimes.getTime(gms[2]));
        statement.setLong(12, gmTimes.getTime(gms[3]));
        statement.addBatch();
    }
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) Map(java.util.Map)

Example 39 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID 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 40 with ServerUUID

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

the class BukkitImporter method processUserData.

private void processUserData() {
    List<UserImportData> userImportData = getUserImportData();
    if (userImportData == null || userImportData.isEmpty()) {
        return;
    }
    BukkitUserImportRefiner userImportRefiner = new BukkitUserImportRefiner(userImportData);
    userImportData = userImportRefiner.refineData();
    Database db = dbSystem.getDatabase();
    Set<UUID> existingUUIDs = db.query(UserIdentifierQueries.fetchAllPlayerUUIDs());
    Set<UUID> existingUserInfoTableUUIDs = db.query(UserIdentifierQueries.fetchPlayerUUIDsOfServer(serverUUID.get()));
    Map<UUID, BaseUser> users = new HashMap<>();
    List<UserInfo> userInfo = new ArrayList<>();
    Map<UUID, List<Nickname>> nickNames = new HashMap<>();
    List<FinishedSession> sessions = new ArrayList<>();
    Map<UUID, List<GeoInfo>> geoInfo = new HashMap<>();
    userImportData.parallelStream().forEach(data -> {
        UUID uuid = data.getUuid();
        if (!existingUUIDs.contains(uuid)) {
            users.put(uuid, toBaseUser(data));
        }
        if (!existingUserInfoTableUUIDs.contains(uuid)) {
            userInfo.add(toUserInfo(data));
        }
        nickNames.put(uuid, data.getNicknames());
        geoInfo.put(uuid, convertGeoInfo(data));
        sessions.add(toSession(data));
    });
    db.executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllCommonUserInformation(users.values()));
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
            Map<ServerUUID, List<UserInfo>> userInformation = Collections.singletonMap(serverUUID.get(), userInfo);
            execute(LargeStoreQueries.storePerServerUserInformation(userInformation));
            execute(LargeStoreQueries.storeAllNicknameData(Collections.singletonMap(serverUUID.get(), nickNames)));
            execute(LargeStoreQueries.storeAllGeoInformation(geoInfo));
        }
    });
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) BukkitUserImportRefiner(com.djrapitops.plan.gathering.importing.data.BukkitUserImportRefiner) UserImportData(com.djrapitops.plan.gathering.importing.data.UserImportData)

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