Search in sources :

Example 1 with MVPrimaryIndex

use of org.h2.mvstore.db.MVPrimaryIndex in project h2database by h2database.

the class Insert method prepareUpdateCondition.

private Expression prepareUpdateCondition(Index foundIndex) {
    // MVPrimaryIndex is playing fast and loose with it's implementation of
    // the Index interface.
    // It returns all of the columns in the table when we call
    // getIndexColumns() or getColumns().
    // Don't have time right now to fix that, so just special-case it.
    final Column[] indexedColumns;
    if (foundIndex instanceof MVPrimaryIndex) {
        MVPrimaryIndex foundMV = (MVPrimaryIndex) foundIndex;
        indexedColumns = new Column[] { foundMV.getIndexColumns()[foundMV.getMainIndexColumn()].column };
    } else {
        indexedColumns = foundIndex.getColumns();
    }
    Expression[] row = list.get(getCurrentRowNumber() - 1);
    Expression condition = null;
    for (Column column : indexedColumns) {
        ExpressionColumn expr = new ExpressionColumn(session.getDatabase(), table.getSchema().getName(), table.getName(), column.getName());
        for (int i = 0; i < columns.length; i++) {
            if (expr.getColumnName().equals(columns[i].getName())) {
                if (condition == null) {
                    condition = new Comparison(session, Comparison.EQUAL, expr, row[i]);
                } else {
                    condition = new ConditionAndOr(ConditionAndOr.AND, condition, new Comparison(session, Comparison.EQUAL, expr, row[i]));
                }
                break;
            }
        }
    }
    return condition;
}
Also used : Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) Expression(org.h2.expression.Expression) Comparison(org.h2.expression.Comparison) MVPrimaryIndex(org.h2.mvstore.db.MVPrimaryIndex) ConditionAndOr(org.h2.expression.ConditionAndOr) ExpressionColumn(org.h2.expression.ExpressionColumn)

Aggregations

Comparison (org.h2.expression.Comparison)1 ConditionAndOr (org.h2.expression.ConditionAndOr)1 Expression (org.h2.expression.Expression)1 ExpressionColumn (org.h2.expression.ExpressionColumn)1 MVPrimaryIndex (org.h2.mvstore.db.MVPrimaryIndex)1 Column (org.h2.table.Column)1