use of org.h2.index.Cursor in project ignite by apache.
the class GridMergeIndex method getRowCount.
/**
* {@inheritDoc}
*/
@Override
public long getRowCount(Session ses) {
Cursor c = find(ses, null, null);
long cnt = 0;
while (c.next()) cnt++;
return cnt;
}
use of org.h2.index.Cursor in project ignite by apache.
the class GridH2TableSelfTest method testIndexFindFirstOrLast.
/**
* @throws Exception If failed.
*/
public void testIndexFindFirstOrLast() throws Exception {
Index index = tbl.getIndexes().get(2);
assertTrue(index instanceof GridH2TreeIndex);
assertTrue(index.canGetFirstOrLast());
//find first on empty data
Cursor cursor = index.findFirstOrLast(null, true);
assertFalse(cursor.next());
assertNull(cursor.get());
//find last on empty data
cursor = index.findFirstOrLast(null, false);
assertFalse(cursor.next());
assertNull(cursor.get());
//fill with data
int rows = 100;
long t = System.currentTimeMillis();
Random rnd = new Random();
UUID min = null;
UUID max = null;
for (int i = 0; i < rows; i++) {
UUID id = UUID.randomUUID();
if (min == null || id.compareTo(min) < 0)
min = id;
if (max == null || id.compareTo(max) > 0)
max = id;
GridH2Row row = row(id, t++, id.toString(), rnd.nextInt(100));
((GridH2TreeIndex) index).put(row);
}
//find first
cursor = index.findFirstOrLast(null, true);
assertTrue(cursor.next());
assertEquals(min, cursor.get().getValue(0).getObject());
assertFalse(cursor.next());
//find last
cursor = index.findFirstOrLast(null, false);
assertTrue(cursor.next());
assertEquals(max, cursor.get().getValue(0).getObject());
assertFalse(cursor.next());
}
use of org.h2.index.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);
}
}
use of org.h2.index.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);
}
}
use of org.h2.index.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;
}
}
Aggregations