Search in sources :

Example 6 with ExecBatchStatement

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();
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 7 with ExecBatchStatement

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();
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 8 with ExecBatchStatement

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();
            }
        }
    });
}
Also used : SessionIDServerIDRelationQuery(com.djrapitops.plan.storage.database.queries.schema.SessionIDServerIDRelationQuery) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 9 with ExecBatchStatement

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();
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 10 with ExecBatchStatement

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();
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) UUID(java.util.UUID) 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