Search in sources :

Example 1 with UpdatableRow

use of org.h2.result.UpdatableRow in project h2database by h2database.

the class JdbcResultSet method updateRow.

/**
 * Updates the current row.
 *
 * @throws SQLException if the result set is closed, if the current row is
 *             the insert row or if not on a valid row, or if the result set
 *             it not updatable
 */
@Override
public void updateRow() throws SQLException {
    try {
        debugCodeCall("updateRow");
        checkUpdatable();
        if (insertRow != null) {
            throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
        }
        checkOnValidRow();
        if (updateRow != null) {
            UpdatableRow row = getUpdatableRow();
            Value[] current = new Value[columnCount];
            for (int i = 0; i < updateRow.length; i++) {
                current[i] = get(i + 1);
            }
            row.updateRow(current, updateRow);
            for (int i = 0; i < updateRow.length; i++) {
                if (updateRow[i] == null) {
                    updateRow[i] = current[i];
                }
            }
            Value[] patch = row.readRow(updateRow);
            patchCurrentRow(patch);
            updateRow = null;
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) UpdatableRow(org.h2.result.UpdatableRow) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 2 with UpdatableRow

use of org.h2.result.UpdatableRow in project h2database by h2database.

the class JdbcResultSet method getConcurrency.

/**
 * Gets the result set concurrency. Result sets are only updatable if the
 * statement was created with updatable concurrency, and if the result set
 * contains all columns of the primary key or of a unique index of a table.
 *
 * @return ResultSet.CONCUR_UPDATABLE if the result set is updatable, or
 *         ResultSet.CONCUR_READ_ONLY otherwise
 */
@Override
public int getConcurrency() throws SQLException {
    try {
        debugCodeCall("getConcurrency");
        checkClosed();
        if (!updatable) {
            return ResultSet.CONCUR_READ_ONLY;
        }
        UpdatableRow row = new UpdatableRow(conn, result);
        return row.isUpdatable() ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : UpdatableRow(org.h2.result.UpdatableRow) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)2 DbException (org.h2.message.DbException)2 UpdatableRow (org.h2.result.UpdatableRow)2 Value (org.h2.value.Value)1