Search in sources :

Example 36 with Cursor

use of org.h2.mvstore.Cursor in project ignite by apache.

the class GridH2TreeIndex method findFirstOrLast.

/** {@inheritDoc} */
@Override
public Cursor findFirstOrLast(Session ses, boolean first) {
    try {
        int seg = threadLocalSegment();
        IgniteTree t = treeForRead(seg);
        GridH2Row row = (GridH2Row) (first ? t.findFirst() : t.findLast());
        return new SingleRowCursor(row);
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteTree(org.apache.ignite.internal.util.IgniteTree) SingleRowCursor(org.h2.index.SingleRowCursor)

Example 37 with Cursor

use of org.h2.mvstore.Cursor in project ignite by apache.

the class H2TreeIndex method find.

/**
 * {@inheritDoc}
 */
@Override
public Cursor find(Session ses, SearchRow lower, SearchRow upper) {
    try {
        IndexingQueryCacheFilter filter = partitionFilter(threadLocalFilter());
        int seg = threadLocalSegment();
        H2Tree tree = treeForRead(seg);
        if (indexType.isPrimaryKey() && lower != null && upper != null && tree.compareRows(lower, upper) == 0) {
            GridH2Row row = tree.findOne(lower, filter);
            return (row == null) ? EMPTY_CURSOR : new SingleRowCursor(row);
        } else {
            GridCursor<GridH2Row> cursor = tree.find(lower, upper, filter);
            return new H2Cursor(cursor);
        }
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) H2Cursor(org.apache.ignite.internal.processors.query.h2.H2Cursor) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) IndexingQueryCacheFilter(org.apache.ignite.spi.indexing.IndexingQueryCacheFilter) SingleRowCursor(org.h2.index.SingleRowCursor)

Example 38 with Cursor

use of org.h2.mvstore.Cursor in project ignite by apache.

the class GridMergeIndexIterator method advance.

/**
 * Advance iterator.
 */
private void advance() {
    next = null;
    try {
        boolean hasNext = false;
        while (cursor == null || !(hasNext = cursor.next())) {
            if (idxIter.hasNext())
                cursor = idxIter.next().findInStream(null, null);
            else {
                releaseIfNeeded();
                break;
            }
        }
        if (hasNext) {
            Row row = cursor.get();
            int cols = row.getColumnCount();
            List<Object> res = new ArrayList<>(cols);
            for (int c = 0; c < cols; c++) res.add(row.getValue(c).getObject());
            next = res;
        }
    } catch (Exception e) {
        releaseIfNeeded();
        throw e;
    }
}
Also used : ArrayList(java.util.ArrayList) Row(org.h2.result.Row) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NoSuchElementException(java.util.NoSuchElementException)

Example 39 with Cursor

use of org.h2.mvstore.Cursor in project ignite by apache.

the class GridH2SpatialIndex method findFirstOrLast.

/**
 * {@inheritDoc}
 */
@Override
public Cursor findFirstOrLast(Session ses, boolean first) {
    Lock l = lock.readLock();
    l.lock();
    try {
        checkClosed();
        if (!first)
            throw DbException.throwInternalError("Spatial Index can only be fetch by ascending order");
        final int seg = threadLocalSegment();
        final MVRTreeMap<Long> segment = segments[seg];
        GridCursor<GridH2Row> iter = rowIterator(segment.keySet().iterator(), null);
        return new SingleRowCursor(iter.next() ? iter.get() : null);
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    } finally {
        l.unlock();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SingleRowCursor(org.h2.index.SingleRowCursor) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 40 with Cursor

use of org.h2.mvstore.Cursor in project ignite by apache.

the class H2PkHashIndex method getRowCount.

/**
 * {@inheritDoc}
 */
@Override
public long getRowCount(Session ses) {
    Cursor cursor = find(ses, null, null);
    long res = 0;
    while (cursor.next()) res++;
    return res;
}
Also used : GridCursor(org.apache.ignite.internal.util.lang.GridCursor) Cursor(org.h2.index.Cursor)

Aggregations

Cursor (org.h2.index.Cursor)24 Value (org.h2.value.Value)20 Index (org.h2.index.Index)11 Row (org.h2.result.Row)11 SearchRow (org.h2.result.SearchRow)11 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Constraint (org.h2.constraint.Constraint)5 SingleRowCursor (org.h2.index.SingleRowCursor)5 Column (org.h2.table.Column)5 Session (org.h2.engine.Session)4 MultiVersionIndex (org.h2.index.MultiVersionIndex)4 IndexColumn (org.h2.table.IndexColumn)4 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)3 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)3 Database (org.h2.engine.Database)3 ValueLong (org.h2.value.ValueLong)3 PreparedStatement (java.sql.PreparedStatement)2 BitSet (java.util.BitSet)2 UUID (java.util.UUID)2