use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement 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();
}
}
}
};
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class StoreServerTableResultTransaction method insertNewRows.
private void insertNewRows(Integer tableID, Integer afterRow, List<Object[]> rows) {
String sql = "INSERT INTO " + TABLE_NAME + '(' + TABLE_ID + ',' + SERVER_UUID + ',' + VALUE_1 + ',' + VALUE_2 + ',' + VALUE_3 + ',' + VALUE_4 + ',' + VALUE_5 + ',' + TABLE_ROW + ") VALUES (?,?,?,?,?,?,?,?)";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Limit to maximum 5 columns, or how many column names there are.
int maxColumnSize = Math.min(table.getMaxColumnSize(), 5);
for (int rowNumber = afterRow; rowNumber < rows.size(); rowNumber++) {
Object[] row = rows.get(rowNumber);
statement.setInt(1, tableID);
statement.setString(2, serverUUID.toString());
for (int i = 0; i < maxColumnSize; i++) {
Object value = row[i];
setStringOrNull(statement, 3 + i, value != null ? StringUtils.truncate(value.toString(), 250) : null);
}
// Rest are set null if not 5 columns wide.
for (int i = maxColumnSize; i < 5; i++) {
statement.setNull(3 + i, Types.VARCHAR);
}
statement.setInt(8, rowNumber);
statement.addBatch();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class NicknameLastSeenPatch method updateLastUsed.
private void updateLastUsed(Map<ServerUUID, Integer> serverIDsByUUID, Map<Integer, Set<Nickname>> nicknames) {
String updateSQL = "UPDATE " + NicknamesTable.TABLE_NAME + " SET " + NicknamesTable.LAST_USED + "=?" + WHERE + NicknamesTable.NICKNAME + "=?" + AND + "user_id=?" + AND + "server_id=?";
execute(new ExecBatchStatement(updateSQL) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<Integer, Set<Nickname>> entry : nicknames.entrySet()) {
Integer userId = entry.getKey();
Set<Nickname> nicks = entry.getValue();
for (Nickname nick : nicks) {
Integer serverID = serverIDsByUUID.get(nick.getServerUUID());
statement.setLong(1, nick.getDate());
statement.setString(2, nick.getName());
statement.setInt(3, userId);
statement.setInt(4, serverID);
statement.addBatch();
}
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class LinkUsersToPlayersSecurityTablePatch method applyPatch.
@Override
protected void applyPatch() {
String querySQL = SELECT + UsersTable.USER_UUID + ',' + SecurityTable.USERNAME + FROM + SecurityTable.TABLE_NAME + LEFT_JOIN + UsersTable.TABLE_NAME + " on " + UsersTable.USER_NAME + "=" + SecurityTable.USERNAME + WHERE + SecurityTable.LINKED_TO + "=''";
String sql = "UPDATE " + SecurityTable.TABLE_NAME + " SET " + SecurityTable.LINKED_TO + "=?" + WHERE + SecurityTable.USERNAME + "=?";
Map<String, String> byUsername = query(new QueryAllStatement<Map<String, String>>(querySQL) {
@Override
public Map<String, String> processResults(ResultSet set) throws SQLException {
Map<String, String> byUsername = new HashMap<>();
while (set.next()) {
byUsername.put(set.getString(SecurityTable.USERNAME), set.getString(UsersTable.USER_UUID));
}
return byUsername;
}
});
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<String, String> usernameUUIDPair : byUsername.entrySet()) {
Sql.setStringOrNull(statement, 1, usernameUUIDPair.getValue());
statement.setString(2, usernameUUIDPair.getKey());
statement.addBatch();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class WorldTimesSeverIDPatch method applyPatch.
@Override
protected void applyPatch() {
Map<Integer, Integer> sessionIDServerIDRelation = query(new SessionIDServerIDRelationQuery());
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " + "server_id=?" + WHERE + WorldTimesTable.SESSION_ID + "=?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<Integer, Integer> entry : sessionIDServerIDRelation.entrySet()) {
Integer sessionID = entry.getKey();
Integer serverID = entry.getValue();
statement.setInt(1, serverID);
statement.setInt(2, sessionID);
statement.addBatch();
}
}
});
}
Aggregations