Search in sources :

Example 91 with Row

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

the class Table method validateConvertUpdateSequence.

/**
 * Validate all values in this row, convert the values if required, and
 * update the sequence values if required. This call will also set the
 * default values if required and set the computed column if there are any.
 *
 * @param session the session
 * @param row the row
 */
public void validateConvertUpdateSequence(Session session, Row row) {
    for (int i = 0; i < columns.length; i++) {
        Value value = row.getValue(i);
        Column column = columns[i];
        Value v2;
        if (column.getComputed()) {
            // force updating the value
            value = null;
            v2 = column.computeValue(session, row);
        }
        v2 = column.validateConvertUpdateSequence(session, value);
        if (v2 != value) {
            row.setValue(i, v2);
        }
    }
}
Also used : SimpleRowValue(org.h2.result.SimpleRowValue) Value(org.h2.value.Value) Constraint(org.h2.constraint.Constraint)

Example 92 with Row

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

the class Table method getNullRow.

Row getNullRow() {
    Row row = nullRow;
    if (row == null) {
        // Here can be concurrently produced more than one row, but it must
        // be ok.
        Value[] values = new Value[columns.length];
        Arrays.fill(values, ValueNull.INSTANCE);
        nullRow = row = database.createRow(values, 1);
    }
    return row;
}
Also used : SimpleRowValue(org.h2.result.SimpleRowValue) Value(org.h2.value.Value) Row(org.h2.result.Row) SearchRow(org.h2.result.SearchRow) SimpleRow(org.h2.result.SimpleRow)

Example 93 with Row

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

the class JoinBatch method getValue.

/**
 * Get the value for the given column.
 *
 * @param filterId table filter id
 * @param column the column
 * @return column value for current row
 */
public Value getValue(int filterId, Column column) {
    if (current == null) {
        return null;
    }
    Object x = current.row(filterId);
    assert x != null;
    Row row = current.isRow(filterId) ? (Row) x : ((Cursor) x).get();
    int columnId = column.getColumnId();
    if (columnId == -1) {
        return ValueLong.get(row.getKey());
    }
    Value value = row.getValue(column.getColumnId());
    if (value == null) {
        throw DbException.throwInternalError("value is null: " + column + " " + row);
    }
    return value;
}
Also used : Value(org.h2.value.Value) Row(org.h2.result.Row) SearchRow(org.h2.result.SearchRow)

Example 94 with Row

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

the class JoinBatch method start.

private void start() {
    // initialize current row
    current = new JoinRow(new Object[filters.length]);
    // initialize top cursor
    Cursor cursor;
    if (batchedSubQuery) {
        assert viewTopFutureCursor != null;
        cursor = get(viewTopFutureCursor);
    } else {
        // setup usual index cursor
        TableFilter f = top.filter;
        IndexCursor indexCursor = f.getIndexCursor();
        indexCursor.find(f.getSession(), f.getIndexConditions());
        cursor = indexCursor;
    }
    current.updateRow(top.id, cursor, JoinRow.S_NULL, JoinRow.S_CURSOR);
    // we need fake first row because batchedNext always will move to the
    // next row
    JoinRow fake = new JoinRow(null);
    fake.next = current;
    current = fake;
}
Also used : IndexCursor(org.h2.index.IndexCursor) Cursor(org.h2.index.Cursor) IndexCursor(org.h2.index.IndexCursor) ViewCursor(org.h2.index.ViewCursor)

Example 95 with Row

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

the class JoinBatch method fetchCurrent.

@SuppressWarnings("unchecked")
private void fetchCurrent(final int jfId) {
    assert current.prev == null || current.prev.isRow(jfId) : "prev must be already fetched";
    assert jfId == 0 || current.isRow(jfId - 1) : "left must be already fetched";
    assert !current.isRow(jfId) : "double fetching";
    Object x = current.row(jfId);
    assert x != null : "x null";
    // in case of outer join we don't have any future around empty cursor
    boolean newCursor = x == EMPTY_CURSOR;
    if (newCursor) {
        if (jfId == 0) {
            // the top cursor is new and empty, then the whole select will
            // not produce any rows
            current.drop();
            return;
        }
    } else if (current.isFuture(jfId)) {
        // get cursor from a future
        x = get((Future<Cursor>) x);
        current.updateRow(jfId, x, JoinRow.S_FUTURE, JoinRow.S_CURSOR);
        newCursor = true;
    }
    final JoinFilter jf = filters[jfId];
    Cursor c = (Cursor) x;
    assert c != null;
    JoinFilter join = jf.join;
    while (true) {
        if (c == null || !c.next()) {
            if (newCursor && jf.isOuterJoin()) {
                // replace cursor with null-row
                current.updateRow(jfId, jf.getNullRow(), JoinRow.S_CURSOR, JoinRow.S_ROW);
                c = null;
                newCursor = false;
            } else {
                // cursor is done, drop it
                current.drop();
                return;
            }
        }
        if (!jf.isOk(c == null)) {
            // try another row from the cursor
            continue;
        }
        boolean joinEmpty = false;
        if (join != null && !join.collectSearchRows()) {
            if (join.isOuterJoin()) {
                joinEmpty = true;
            } else {
                // join will fail, try next row in the cursor
                continue;
            }
        }
        if (c != null) {
            current = current.copyBehind(jfId);
            // update jf, set current row from cursor
            current.updateRow(jfId, c.get(), JoinRow.S_CURSOR, JoinRow.S_ROW);
        }
        if (joinEmpty) {
            // update jf.join, set an empty cursor
            current.updateRow(join.id, EMPTY_CURSOR, JoinRow.S_NULL, JoinRow.S_CURSOR);
        }
        return;
    }
}
Also used : Cursor(org.h2.index.Cursor) IndexCursor(org.h2.index.IndexCursor) ViewCursor(org.h2.index.ViewCursor)

Aggregations

Value (org.h2.value.Value)118 Row (org.h2.result.Row)49 Column (org.h2.table.Column)48 DbException (org.h2.message.DbException)44 SearchRow (org.h2.result.SearchRow)37 SQLException (java.sql.SQLException)29 Index (org.h2.index.Index)28 IndexColumn (org.h2.table.IndexColumn)24 Cursor (org.h2.index.Cursor)21 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)20 StatementBuilder (org.h2.util.StatementBuilder)20 ArrayList (java.util.ArrayList)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 Expression (org.h2.expression.Expression)17 Statement (java.sql.Statement)16 Constraint (org.h2.constraint.Constraint)16 ValueString (org.h2.value.ValueString)16 Connection (java.sql.Connection)15 SimpleResultSet (org.h2.tools.SimpleResultSet)15