Search in sources :

Example 21 with ExecBatchStatement

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

the class LargeStoreQueries method storeAllPlanWebUsers.

public static Executable storeAllPlanWebUsers(Collection<User> users) {
    if (users == null || users.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(SecurityTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (User user : users) {
                statement.setString(1, user.getUsername());
                if (user.getLinkedToUUID() == null) {
                    statement.setNull(2, Types.VARCHAR);
                } else {
                    statement.setString(2, user.getLinkedToUUID().toString());
                }
                statement.setString(3, user.getPasswordHash());
                statement.setInt(4, user.getPermissionLevel());
                statement.addBatch();
            }
        }
    };
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 22 with ExecBatchStatement

use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement 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)

Example 23 with ExecBatchStatement

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

the class LargeStoreQueries method storeAllWorldNames.

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

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (Map.Entry<ServerUUID, Collection<String>> entry : ofServers.entrySet()) {
                ServerUUID serverUUID = entry.getKey();
                for (String world : entry.getValue()) {
                    statement.setString(1, StringUtils.truncate(world, 100));
                    statement.setString(2, serverUUID.toString());
                    statement.addBatch();
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) 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