Search in sources :

Example 16 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname 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 17 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname 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 18 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.

the class NicknameQueriesTest method allNicknamesAreSaved.

@Test
default void allNicknamesAreSaved() {
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    List<Nickname> saved = RandomData.randomNicknames(serverUUID());
    for (Nickname nickname : saved) {
        db().executeTransaction(new NicknameStoreTransaction(playerUUID, nickname, (uuid, name) -> false));
        db().executeTransaction(new NicknameStoreTransaction(playerUUID, nickname, (uuid, name) -> true));
    }
    forcePersistenceCheck();
    List<Nickname> fetched = db().query(NicknameQueries.fetchNicknameDataOfPlayer(playerUUID));
    assertEquals(saved, fetched);
}
Also used : PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) Test(org.junit.jupiter.api.Test) List(java.util.List) NicknameQueries(com.djrapitops.plan.storage.database.queries.objects.NicknameQueries) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) UserIdentifierQueries(com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries) Assertions(org.junit.jupiter.api.Assertions) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) RandomData(utilities.RandomData) TestConstants(utilities.TestConstants) Nickname(com.djrapitops.plan.delivery.domain.Nickname) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Aggregations

Nickname (com.djrapitops.plan.delivery.domain.Nickname)18 UUID (java.util.UUID)11 ServerUUID (com.djrapitops.plan.identification.ServerUUID)9 NicknameCache (com.djrapitops.plan.gathering.cache.NicknameCache)8 ServerInfo (com.djrapitops.plan.identification.ServerInfo)8 DBSystem (com.djrapitops.plan.storage.database.DBSystem)8 ErrorContext (com.djrapitops.plan.utilities.logging.ErrorContext)8 ErrorLogger (com.djrapitops.plan.utilities.logging.ErrorLogger)8 Inject (javax.inject.Inject)8 NicknameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction)6 ResultSet (java.sql.ResultSet)6 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)5 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)5 com.djrapitops.plan.storage.database.transactions.events (com.djrapitops.plan.storage.database.transactions.events)5 PreparedStatement (java.sql.PreparedStatement)5 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)4 ServerName (com.djrapitops.plan.delivery.domain.ServerName)4 Exporter (com.djrapitops.plan.delivery.export.Exporter)4 CallEvents (com.djrapitops.plan.extension.CallEvents)4 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)4