Search in sources :

Example 1 with Executable

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

the class LargeStoreQueries method storeAllWorldNames.

private static Executable storeAllWorldNames(Collection<FinishedSession> sessions, Set<World> existingWorlds) {
    Set<World> worlds = sessions.stream().flatMap(session -> {
        ServerUUID serverUUID = session.getServerUUID();
        return session.getExtraData(WorldTimes.class).map(WorldTimes::getWorldTimes).map(Map::keySet).orElseGet(Collections::emptySet).stream().map(worldName -> new World(worldName, serverUUID));
    }).filter(world -> !existingWorlds.contains(world)).collect(Collectors.toSet());
    if (worlds.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(WorldTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (World world : worlds) {
                statement.setString(1, world.getWorldName());
                statement.setString(2, world.getServerUUID().toString());
                statement.addBatch();
            }
        }
    };
}
Also used : WorldTimesQueries(com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) java.util(java.util) World(com.djrapitops.plan.delivery.domain.World) Executable(com.djrapitops.plan.storage.database.transactions.Executable) com.djrapitops.plan.gathering.domain(com.djrapitops.plan.gathering.domain) ServerUUID(com.djrapitops.plan.identification.ServerUUID) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) com.djrapitops.plan.storage.database.sql.tables(com.djrapitops.plan.storage.database.sql.tables) PreparedStatement(java.sql.PreparedStatement) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) JoinAddressQueries(com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries) DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) SQLException(java.sql.SQLException) Server(com.djrapitops.plan.identification.Server) User(com.djrapitops.plan.delivery.domain.auth.User) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Types(java.sql.Types) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) World(com.djrapitops.plan.delivery.domain.World) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Aggregations

Nickname (com.djrapitops.plan.delivery.domain.Nickname)1 World (com.djrapitops.plan.delivery.domain.World)1 User (com.djrapitops.plan.delivery.domain.auth.User)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 Server (com.djrapitops.plan.identification.Server)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 JoinAddressQueries (com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries)1 WorldTimesQueries (com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries)1 com.djrapitops.plan.storage.database.sql.tables (com.djrapitops.plan.storage.database.sql.tables)1 ExecBatchStatement (com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)1 Executable (com.djrapitops.plan.storage.database.transactions.Executable)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Types (java.sql.Types)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1