Search in sources :

Example 16 with ExecBatchStatement

use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllPlanServerInformation.

/**
 * Execute a big batch of server information insert statements.
 *
 * @param servers Collection of Plan Servers.
 * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
 */
public static Executable storeAllPlanServerInformation(Collection<Server> servers) {
    if (servers == null || servers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(ServerTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (Server server : servers) {
                ServerUUID serverUUID = server.getUuid();
                if (serverUUID == null) {
                    continue;
                }
                statement.setString(1, serverUUID.toString());
                statement.setString(2, server.getName());
                statement.setString(3, server.getWebAddress());
                statement.setBoolean(4, true);
                statement.setBoolean(5, server.isProxy());
                statement.setString(6, server.getPlanVersion());
                statement.addBatch();
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 17 with ExecBatchStatement

use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllNicknameData.

/**
 * Execute a big batch of nickname insert statements.
 *
 * @param ofServersAndUsers Multimap: Server UUID - (Player UUID - List of nicknames)
 * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
 */
public static Executable storeAllNicknameData(Map<ServerUUID, Map<UUID, List<Nickname>>> ofServersAndUsers) {
    if (ofServersAndUsers == null || ofServersAndUsers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(NicknamesTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            // Every Server
            for (Map.Entry<ServerUUID, Map<UUID, List<Nickname>>> serverEntry : ofServersAndUsers.entrySet()) {
                ServerUUID serverUUID = serverEntry.getKey();
                // Every User
                for (Map.Entry<UUID, List<Nickname>> entry : serverEntry.getValue().entrySet()) {
                    UUID uuid = entry.getKey();
                    // Every Nickname
                    List<Nickname> nicknames = entry.getValue();
                    for (Nickname nickname : nicknames) {
                        statement.setString(1, uuid.toString());
                        statement.setString(2, serverUUID.toString());
                        statement.setString(3, nickname.getName());
                        statement.setLong(4, nickname.getDate());
                        statement.addBatch();
                    }
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 18 with ExecBatchStatement

use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllGeoInformation.

/**
 * Execute a big batch of GeoInfo insert statements.
 *
 * @param ofUsers Map: Player UUID - List of GeoInfo
 * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
 */
public static Executable storeAllGeoInformation(Map<UUID, List<GeoInfo>> ofUsers) {
    if (ofUsers == null || ofUsers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(GeoInfoTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            // Every User
            for (Map.Entry<UUID, List<GeoInfo>> playerEntry : ofUsers.entrySet()) {
                UUID playerUUID = playerEntry.getKey();
                // Every GeoInfo
                for (GeoInfo info : playerEntry.getValue()) {
                    String geoLocation = info.getGeolocation();
                    long lastUsed = info.getDate();
                    statement.setString(1, playerUUID.toString());
                    statement.setString(2, geoLocation);
                    statement.setLong(3, lastUsed);
                    statement.addBatch();
                }
            }
        }
    };
}
Also used : PreparedStatement(java.sql.PreparedStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 19 with ExecBatchStatement

use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllTPSData.

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

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            // Every Server
            for (Map.Entry<ServerUUID, List<TPS>> entry : ofServers.entrySet()) {
                ServerUUID serverUUID = entry.getKey();
                // Every TPS Data point
                List<TPS> tpsList = entry.getValue();
                for (TPS tps : tpsList) {
                    statement.setString(1, serverUUID.toString());
                    statement.setLong(2, tps.getDate());
                    statement.setDouble(3, tps.getTicksPerSecond());
                    statement.setInt(4, tps.getPlayers());
                    statement.setDouble(5, tps.getCPUUsage());
                    statement.setLong(6, tps.getUsedMemory());
                    statement.setDouble(7, tps.getEntityCount());
                    statement.setDouble(8, tps.getChunksLoaded());
                    statement.setLong(9, tps.getFreeDiskSpace());
                    statement.addBatch();
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 20 with ExecBatchStatement

use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllPingData.

public static Executable storeAllPingData(Map<UUID, List<Ping>> ofUsers) {
    if (ofUsers == null || ofUsers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(PingTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (Map.Entry<UUID, List<Ping>> entry : ofUsers.entrySet()) {
                UUID uuid = entry.getKey();
                List<Ping> pings = entry.getValue();
                for (Ping ping : pings) {
                    ServerUUID serverUUID = ping.getServerUUID();
                    long date = ping.getDate();
                    int minPing = ping.getMin();
                    int maxPing = ping.getMax();
                    double avgPing = ping.getAverage();
                    statement.setString(1, uuid.toString());
                    statement.setString(2, serverUUID.toString());
                    statement.setLong(3, date);
                    statement.setInt(4, minPing);
                    statement.setInt(5, maxPing);
                    statement.setDouble(6, avgPing);
                    statement.addBatch();
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Aggregations

ExecBatchStatement (com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)23 PreparedStatement (java.sql.PreparedStatement)23 SQLException (java.sql.SQLException)15 ServerUUID (com.djrapitops.plan.identification.ServerUUID)9 ResultSet (java.sql.ResultSet)4 Nickname (com.djrapitops.plan.delivery.domain.Nickname)3 User (com.djrapitops.plan.delivery.domain.auth.User)2 Server (com.djrapitops.plan.identification.Server)2 SessionIDServerIDRelationQuery (com.djrapitops.plan.storage.database.queries.schema.SessionIDServerIDRelationQuery)2 java.util (java.util)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 World (com.djrapitops.plan.delivery.domain.World)1 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1 com.djrapitops.plan.gathering.domain (com.djrapitops.plan.gathering.domain)1 JoinAddress (com.djrapitops.plan.gathering.domain.event.JoinAddress)1 LargeStoreQueries (com.djrapitops.plan.storage.database.queries.LargeStoreQueries)1 QueryAllStatement (com.djrapitops.plan.storage.database.queries.QueryAllStatement)1 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)1 JoinAddressQueries (com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries)1