Search in sources :

Example 1 with SessionIDServerIDRelationQuery

use of com.djrapitops.plan.storage.database.queries.schema.SessionIDServerIDRelationQuery 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 2 with SessionIDServerIDRelationQuery

use of com.djrapitops.plan.storage.database.queries.schema.SessionIDServerIDRelationQuery 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)

Aggregations

SessionIDServerIDRelationQuery (com.djrapitops.plan.storage.database.queries.schema.SessionIDServerIDRelationQuery)2 ExecBatchStatement (com.djrapitops.plan.storage.database.transactions.ExecBatchStatement)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2