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();
}
}
};
}
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();
}
}
};
}
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();
}
}
}
};
}
Aggregations