Search in sources :

Example 11 with ExecBatchStatement

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();
            }
        }
    });
}
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 12 with ExecBatchStatement

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();
                }
            }
        }
    });
}
Also used : WorldTable(com.djrapitops.plan.storage.database.sql.tables.WorldTable) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) java.util(java.util) LargeStoreQueries(com.djrapitops.plan.storage.database.queries.LargeStoreQueries) SessionsTable(com.djrapitops.plan.storage.database.sql.tables.SessionsTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) ServerTable(com.djrapitops.plan.storage.database.sql.tables.ServerTable) PreparedStatement(java.sql.PreparedStatement) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) SQLException(java.sql.SQLException) WorldTimesTable(com.djrapitops.plan.storage.database.sql.tables.WorldTimesTable) ResultSet(java.sql.ResultSet) ServerQueries(com.djrapitops.plan.storage.database.queries.objects.ServerQueries) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)

Example 13 with ExecBatchStatement

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

Example 14 with ExecBatchStatement

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

Example 15 with ExecBatchStatement

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