Search in sources :

Example 96 with Index

use of org.h2.index.Index in project h2database by h2database.

the class RegularTable method addRowsToIndex.

private static void addRowsToIndex(Session session, ArrayList<Row> list, Index index) {
    final Index idx = index;
    Collections.sort(list, new Comparator<Row>() {

        @Override
        public int compare(Row r1, Row r2) {
            return idx.compareRows(r1, r2);
        }
    });
    for (Row row : list) {
        index.add(session, row);
    }
    list.clear();
}
Also used : NonUniqueHashIndex(org.h2.index.NonUniqueHashIndex) Index(org.h2.index.Index) HashIndex(org.h2.index.HashIndex) ScanIndex(org.h2.index.ScanIndex) PageBtreeIndex(org.h2.index.PageBtreeIndex) TreeIndex(org.h2.index.TreeIndex) PageDataIndex(org.h2.index.PageDataIndex) PageDelegateIndex(org.h2.index.PageDelegateIndex) MultiVersionIndex(org.h2.index.MultiVersionIndex) SpatialTreeIndex(org.h2.index.SpatialTreeIndex) Row(org.h2.result.Row)

Example 97 with Index

use of org.h2.index.Index in project h2database by h2database.

the class RegularTable method removeRow.

@Override
public void removeRow(Session session, Row row) {
    if (database.isMultiVersion()) {
        if (row.isDeleted()) {
            throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, getName());
        }
        int old = row.getSessionId();
        int newId = session.getId();
        if (old == 0) {
            row.setSessionId(newId);
        } else if (old != newId) {
            throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, getName());
        }
    }
    lastModificationId = database.getNextModificationDataId();
    int i = indexes.size() - 1;
    try {
        for (; i >= 0; i--) {
            Index index = indexes.get(i);
            index.remove(session, row);
            checkRowCount(session, index, -1);
        }
        rowCount--;
    } catch (Throwable e) {
        try {
            while (++i < indexes.size()) {
                Index index = indexes.get(i);
                index.add(session, row);
                checkRowCount(session, index, 0);
            }
        } catch (DbException e2) {
            // this could happen, for example on failure in the storage
            // but if that is not the case it means there is something wrong
            // with the database
            trace.error(e2, "could not undo operation");
            throw e2;
        }
        throw DbException.convert(e);
    }
    analyzeIfRequired(session);
}
Also used : NonUniqueHashIndex(org.h2.index.NonUniqueHashIndex) Index(org.h2.index.Index) HashIndex(org.h2.index.HashIndex) ScanIndex(org.h2.index.ScanIndex) PageBtreeIndex(org.h2.index.PageBtreeIndex) TreeIndex(org.h2.index.TreeIndex) PageDataIndex(org.h2.index.PageDataIndex) PageDelegateIndex(org.h2.index.PageDelegateIndex) MultiVersionIndex(org.h2.index.MultiVersionIndex) SpatialTreeIndex(org.h2.index.SpatialTreeIndex) Constraint(org.h2.constraint.Constraint) DbException(org.h2.message.DbException)

Example 98 with Index

use of org.h2.index.Index in project h2database by h2database.

the class Table method getChildren.

@Override
public ArrayList<DbObject> getChildren() {
    ArrayList<DbObject> children = New.arrayList();
    ArrayList<Index> indexes = getIndexes();
    if (indexes != null) {
        children.addAll(indexes);
    }
    if (constraints != null) {
        children.addAll(constraints);
    }
    if (triggers != null) {
        children.addAll(triggers);
    }
    if (sequences != null) {
        children.addAll(sequences);
    }
    children.addAll(dependentViews);
    if (synonyms != null) {
        children.addAll(synonyms);
    }
    ArrayList<Right> rights = database.getAllRights();
    for (Right right : rights) {
        if (right.getGrantedObject() == this) {
            children.add(right);
        }
    }
    return children;
}
Also used : DbObject(org.h2.engine.DbObject) Right(org.h2.engine.Right) Index(org.h2.index.Index)

Example 99 with Index

use of org.h2.index.Index 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 100 with Index

use of org.h2.index.Index in project h2database by h2database.

the class JoinBatch method createViewIndexLookupBatch.

/**
 * Create index lookup batch for a view index.
 *
 * @param viewIndex view index
 * @return index lookup batch or {@code null} if batching is not supported
 *         for this query
 */
public static IndexLookupBatch createViewIndexLookupBatch(ViewIndex viewIndex) {
    Query query = viewIndex.getQuery();
    if (query.isUnion()) {
        ViewIndexLookupBatchUnion unionBatch = new ViewIndexLookupBatchUnion(viewIndex);
        return unionBatch.initialize() ? unionBatch : null;
    }
    JoinBatch jb = ((Select) query).getJoinBatch();
    if (jb == null || jb.getLookupBatch(0) == null) {
        // our sub-query is not batched or is top batched sub-query
        return null;
    }
    assert !jb.batchedSubQuery;
    jb.batchedSubQuery = true;
    return jb.viewIndexLookupBatch(viewIndex);
}
Also used : Query(org.h2.command.dml.Query) Select(org.h2.command.dml.Select)

Aggregations

ResultSet (java.sql.ResultSet)77 Index (org.h2.index.Index)75 Statement (java.sql.Statement)64 SimpleResultSet (org.h2.tools.SimpleResultSet)61 SQLException (java.sql.SQLException)60 Value (org.h2.value.Value)58 DbException (org.h2.message.DbException)57 Connection (java.sql.Connection)56 PreparedStatement (java.sql.PreparedStatement)56 Column (org.h2.table.Column)53 IndexColumn (org.h2.table.IndexColumn)45 ArrayList (java.util.ArrayList)31 ValueString (org.h2.value.ValueString)29 Constraint (org.h2.constraint.Constraint)25 Row (org.h2.result.Row)22 MultiVersionIndex (org.h2.index.MultiVersionIndex)19 JdbcConnection (org.h2.jdbc.JdbcConnection)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 Table (org.h2.table.Table)18 HashSet (java.util.HashSet)17