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 RemoveDuplicateUserInfoTransaction method performOperations.
@Override
protected void performOperations() {
Collection<Integer> duplicateIDs = getDuplicates();
if (duplicateIDs.isEmpty())
return;
execute(new ExecBatchStatement(DELETE_FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.ID + "=?") {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Integer id : duplicateIDs) {
statement.setInt(1, id);
statement.addBatch();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class KillsServerIDPatch method applyPatch.
@Override
protected void applyPatch() {
if (hasColumn(KillsTable.TABLE_NAME, KillsTable.SERVER_UUID)) {
return;
}
addColumn(KillsTable.TABLE_NAME, "server_id integer NOT NULL DEFAULT 0");
Map<Integer, Integer> sessionIDServerIDRelation = query(new SessionIDServerIDRelationQuery());
String sql = "UPDATE " + KillsTable.TABLE_NAME + " SET server_id=? WHERE " + KillsTable.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 LitebansTableHeaderPatch method applyPatch.
@Override
protected void applyPatch() {
String sql = DELETE_FROM + ExtensionServerTableValueTable.TABLE_NAME + WHERE + ExtensionServerTableValueTable.TABLE_ID + "=?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Integer id : found) {
statement.setInt(1, id);
statement.addBatch();
}
}
});
}
use of com.djrapitops.plan.storage.database.transactions.ExecBatchStatement in project Plan by plan-player-analytics.
the class RegisterDateMinimizationPatch method applyPatch.
@Override
protected void applyPatch() {
if (registerDates.isEmpty())
return;
String sql = "UPDATE " + UsersTable.TABLE_NAME + " SET " + UsersTable.REGISTERED + "=?" + WHERE + UsersTable.USER_UUID + "=?" + AND + UsersTable.REGISTERED + ">?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<UUID, Long> entry : registerDates.entrySet()) {
UUID playerUUID = entry.getKey();
Long registerDate = entry.getValue();
statement.setLong(1, registerDate);
statement.setString(2, playerUUID.toString());
statement.setLong(3, registerDate);
statement.addBatch();
}
}
});
}
Aggregations