Search in sources :

Example 11 with Cursor

use of org.h2.index.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 12 with Cursor

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

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Cursor (org.h2.index.Cursor)5 SingleRowCursor (org.h2.index.SingleRowCursor)5 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)3 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)3 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)3 Index (org.h2.index.Index)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)2 Row (org.h2.result.Row)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Random (java.util.Random)1 Lock (java.util.concurrent.locks.Lock)1