Search in sources :

Example 1 with ServerUUID

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

the class PerServerContainerQuery method executeQuery.

@Override
public PerServerContainer executeQuery(SQLDB db) {
    PerServerContainer perServerContainer = new PerServerContainer();
    userInformation(db, perServerContainer);
    lastSeen(db, perServerContainer);
    playerKillCount(db, perServerContainer);
    mobKillCount(db, perServerContainer);
    totalDeathCount(db, perServerContainer);
    worldTimes(db, perServerContainer);
    Map<ServerUUID, List<FinishedSession>> sessions = db.query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
    for (Map.Entry<ServerUUID, List<FinishedSession>> entry : sessions.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        List<FinishedSession> serverSessions = entry.getValue();
        DataContainer serverContainer = perServerContainer.getOrDefault(serverUUID, new SupplierDataContainer());
        serverContainer.putRawData(PerServerKeys.SESSIONS, serverSessions);
        perServerContainer.put(serverUUID, serverContainer);
    }
    return perServerContainer;
}
Also used : PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) SupplierDataContainer(com.djrapitops.plan.delivery.domain.container.SupplierDataContainer) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) List(java.util.List) Map(java.util.Map) SupplierDataContainer(com.djrapitops.plan.delivery.domain.container.SupplierDataContainer)

Example 2 with ServerUUID

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

the class LargeFetchQueries method fetchAllWorldNames.

/**
 * Query database for world names.
 *
 * @return Map: Server UUID - List of world names
 */
public static Query<Map<ServerUUID, Collection<String>>> fetchAllWorldNames() {
    String sql = SELECT + '*' + FROM + WorldTable.TABLE_NAME;
    return new QueryAllStatement<Map<ServerUUID, Collection<String>>>(sql, 1000) {

        @Override
        public Map<ServerUUID, Collection<String>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Collection<String>> worldMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(WorldTable.SERVER_UUID));
                Collection<String> worlds = worldMap.computeIfAbsent(serverUUID, Maps::createSet);
                worlds.add(set.getString(WorldTable.NAME));
            }
            return worldMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Maps(com.djrapitops.plan.utilities.java.Maps) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) Collection(java.util.Collection)

Example 3 with ServerUUID

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

the class LargeFetchQueries method fetchAllTPSData.

/**
 * Query database for TPS data.
 *
 * @return Map: Server UUID - List of TPS data
 */
public static Query<Map<ServerUUID, List<TPS>>> fetchAllTPSData() {
    String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID;
    String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid";
    String sql = SELECT + TPSTable.DATE + ',' + TPSTable.TPS + ',' + TPSTable.PLAYERS_ONLINE + ',' + TPSTable.CPU_USAGE + ',' + TPSTable.RAM_USAGE + ',' + TPSTable.ENTITIES + ',' + TPSTable.CHUNKS + ',' + TPSTable.FREE_DISK + ',' + serverUUIDColumn + FROM + TPSTable.TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
    return new QueryAllStatement<Map<ServerUUID, List<TPS>>>(sql, 50000) {

        @Override
        public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<TPS>> serverMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString("s_uuid"));
                List<TPS> tpsList = serverMap.computeIfAbsent(serverUUID, Lists::create);
                TPS tps = TPSBuilder.get().date(set.getLong(TPSTable.DATE)).tps(set.getDouble(TPSTable.TPS)).playersOnline(set.getInt(TPSTable.PLAYERS_ONLINE)).usedCPU(set.getDouble(TPSTable.CPU_USAGE)).usedMemory(set.getLong(TPSTable.RAM_USAGE)).entities(set.getInt(TPSTable.ENTITIES)).chunksLoaded(set.getInt(TPSTable.CHUNKS)).freeDiskSpace(set.getLong(TPSTable.FREE_DISK)).toTPS();
                tpsList.add(tps);
            }
            return serverMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) Lists(com.djrapitops.plan.utilities.java.Lists) TPS(com.djrapitops.plan.gathering.domain.TPS) ResultSet(java.sql.ResultSet) List(java.util.List)

Example 4 with ServerUUID

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

the class LargeStoreQueries method storePerServerUserInformation.

/**
 * Execute a big batch of Per server UserInfo insert statements.
 *
 * @param ofServers Map: Server UUID - List of user information
 * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
 */
public static Executable storePerServerUserInformation(Map<ServerUUID, List<UserInfo>> ofServers) {
    if (ofServers == null || ofServers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(UserInfoTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            // Every Server
            for (Map.Entry<ServerUUID, List<UserInfo>> entry : ofServers.entrySet()) {
                ServerUUID serverUUID = entry.getKey();
                // Every User
                for (UserInfo user : entry.getValue()) {
                    statement.setString(1, user.getPlayerUuid().toString());
                    statement.setLong(2, user.getRegistered());
                    statement.setString(3, serverUUID.toString());
                    statement.setBoolean(4, user.isBanned());
                    statement.setString(5, user.getJoinAddress());
                    statement.setBoolean(6, user.isOperator());
                    statement.addBatch();
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 5 with ServerUUID

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

the class ServerSettingsManager method updateConfigInDB.

private void updateConfigInDB(File file) {
    if (!file.exists()) {
        return;
    }
    Database database = dbSystem.getDatabase();
    Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
    if (!serverUUID.isPresent()) {
        return;
    }
    try (ConfigReader reader = new ConfigReader(file.toPath())) {
        Config read = reader.read();
        database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) ConfigReader(com.djrapitops.plan.settings.config.ConfigReader) Database(com.djrapitops.plan.storage.database.Database) UncheckedIOException(java.io.UncheckedIOException) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

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