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();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class WorldObj method updateWorldTimesTableWorldIDs.
private void updateWorldTimesTableWorldIDs() {
List<WorldObj> worldObjects = getWorldObjects();
Map<WorldObj, List<WorldObj>> oldToNewMap = worldObjects.stream().filter(worldObj -> worldObj.serverId == 0).collect(Collectors.toMap(Function.identity(), oldWorld -> worldObjects.stream().filter(worldObj -> worldObj.serverId != 0).filter(worldObj -> worldObj.equals(oldWorld)).collect(Collectors.toList())));
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " + WorldTimesTable.WORLD_ID + "=?" + WHERE + WorldTimesTable.WORLD_ID + "=?" + AND + "server_id=?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<WorldObj, List<WorldObj>> entry : oldToNewMap.entrySet()) {
WorldObj old = entry.getKey();
for (WorldObj newWorld : entry.getValue()) {
statement.setInt(1, newWorld.id);
statement.setInt(2, old.id);
statement.setInt(3, newWorld.serverId);
statement.addBatch();
}
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class StorePlayerTableResultTransaction method insertNewRows.
private void insertNewRows(Integer tableID, Integer afterRow, List<Object[]> rows) {
String sql = "INSERT INTO " + TABLE_NAME + '(' + TABLE_ID + ',' + USER_UUID + ',' + VALUE_1 + ',' + VALUE_2 + ',' + VALUE_3 + ',' + VALUE_4 + ',' + TABLE_ROW + ") VALUES (?,?,?,?,?,?,?)";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Limit to maximum 4 columns, or how many column names there are.
int maxColumnSize = Math.min(table.getMaxColumnSize(), 4);
for (int rowNumber = afterRow; rowNumber < rows.size(); rowNumber++) {
Object[] row = rows.get(rowNumber);
statement.setInt(1, tableID);
statement.setString(2, playerUUID.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 4 columns wide.
for (int i = maxColumnSize; i < 4; i++) {
statement.setNull(3 + i, Types.VARCHAR);
}
statement.setInt(7, rowNumber);
statement.addBatch();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class StorePlayerTableResultTransaction method updateRows.
private void updateRows(Integer tableID, Integer untilRow, List<Object[]> rows) {
String sql = "UPDATE " + TABLE_NAME + " SET " + VALUE_1 + "=?," + VALUE_2 + "=?," + VALUE_3 + "=?," + VALUE_4 + "=?" + WHERE + TABLE_ID + "=?" + AND + USER_UUID + "=?" + AND + TABLE_ROW + "=?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Limit to maximum 4 columns, or how many column names there are.
int maxColumnSize = Math.min(table.getMaxColumnSize(), 4);
for (int rowNumber = 0; rowNumber < untilRow; rowNumber++) {
Object[] row = rows.get(rowNumber);
for (int valueIndex = 0; valueIndex < maxColumnSize; valueIndex++) {
Object value = row[valueIndex];
setStringOrNull(statement, 1 + valueIndex, value != null ? StringUtils.truncate(value.toString(), 250) : null);
}
// Rest are set null if not 4 columns wide.
for (int valueIndex = maxColumnSize; valueIndex < 4; valueIndex++) {
statement.setNull(1 + valueIndex, Types.VARCHAR);
}
statement.setInt(5, tableID);
statement.setString(6, playerUUID.toString());
statement.setInt(7, rowNumber);
statement.addBatch();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class StoreServerTableResultTransaction method updateRows.
private void updateRows(Integer tableID, Integer untilRow, List<Object[]> rows) {
String sql = "UPDATE " + TABLE_NAME + " SET " + VALUE_1 + "=?," + VALUE_2 + "=?," + VALUE_3 + "=?," + VALUE_4 + "=?," + VALUE_5 + "=?" + WHERE + TABLE_ID + "=?" + AND + SERVER_UUID + "=?" + AND + TABLE_ROW + "=?";
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 = 0; rowNumber < untilRow; rowNumber++) {
Object[] row = rows.get(rowNumber);
for (int valueIndex = 0; valueIndex < maxColumnSize; valueIndex++) {
Object value = row[valueIndex];
setStringOrNull(statement, 1 + valueIndex, value != null ? StringUtils.truncate(value.toString(), 250) : null);
}
// Rest are set null if not 5 columns wide.
for (int valueIndex = maxColumnSize; valueIndex < 5; valueIndex++) {
statement.setNull(1 + valueIndex, Types.VARCHAR);
}
statement.setInt(6, tableID);
statement.setString(7, serverUUID.toString());
statement.setInt(8, rowNumber);
statement.addBatch();
}
}
});
}
Aggregations