use of org.h2.mvstore.Cursor in project h2database by h2database.
the class MultiVersionIndex method findFirstOrLast.
@Override
public Cursor findFirstOrLast(Session session, boolean first) {
if (first) {
// TODO optimization: this loops through NULL elements
Cursor cursor = find(session, null, null);
while (cursor.next()) {
SearchRow row = cursor.getSearchRow();
Value v = row.getValue(firstColumn.getColumnId());
if (v != ValueNull.INSTANCE) {
return cursor;
}
}
return cursor;
}
Cursor baseCursor = base.findFirstOrLast(session, false);
Cursor deltaCursor = delta.findFirstOrLast(session, false);
MultiVersionCursor cursor = new MultiVersionCursor(session, this, baseCursor, deltaCursor, sync);
cursor.loadCurrent();
// TODO optimization: this loops through NULL elements
while (cursor.previous()) {
SearchRow row = cursor.getSearchRow();
if (row == null) {
break;
}
Value v = row.getValue(firstColumn.getColumnId());
if (v != ValueNull.INSTANCE) {
return cursor;
}
}
return cursor;
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class MVSecondaryIndex method findFirstOrLast.
@Override
public Cursor findFirstOrLast(Session session, boolean first) {
TransactionMap<Value, Value> map = getMap(session);
Value key = first ? map.firstKey() : map.lastKey();
while (true) {
if (key == null) {
return new MVStoreCursor(session, Collections.<Value>emptyList().iterator(), null);
}
if (((ValueArray) key).getList()[0] != ValueNull.INSTANCE) {
break;
}
key = first ? map.higherKey(key) : map.lowerKey(key);
}
ArrayList<Value> list = New.arrayList();
list.add(key);
MVStoreCursor cursor = new MVStoreCursor(session, list.iterator(), null);
cursor.next();
return cursor;
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class MVDelegateIndex method find.
@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min = mainIndex.getKey(first, ValueLong.MIN, ValueLong.MIN);
// ifNull is MIN as well, because the column is never NULL
// so avoid returning all rows (returning one row is OK)
ValueLong max = mainIndex.getKey(last, ValueLong.MAX, ValueLong.MIN);
return mainIndex.find(session, min, max);
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class MVPrimaryIndex method findFirstOrLast.
@Override
public Cursor findFirstOrLast(Session session, boolean first) {
TransactionMap<Value, Value> map = getMap(session);
ValueLong v = (ValueLong) (first ? map.firstKey() : map.lastKey());
if (v == null) {
return new MVStoreCursor(session, Collections.<Entry<Value, Value>>emptyList().iterator());
}
Value value = map.get(v);
Entry<Value, Value> e = new DataUtils.MapEntry<Value, Value>(v, value);
List<Entry<Value, Value>> list = Collections.singletonList(e);
MVStoreCursor c = new MVStoreCursor(session, list.iterator());
c.next();
return c;
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class MVPrimaryIndex method find.
@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min, max;
if (first == null) {
min = ValueLong.MIN;
} else if (mainIndexColumn < 0) {
min = ValueLong.get(first.getKey());
} else {
ValueLong v = (ValueLong) first.getValue(mainIndexColumn);
if (v == null) {
min = ValueLong.get(first.getKey());
} else {
min = v;
}
}
if (last == null) {
max = ValueLong.MAX;
} else if (mainIndexColumn < 0) {
max = ValueLong.get(last.getKey());
} else {
ValueLong v = (ValueLong) last.getValue(mainIndexColumn);
if (v == null) {
max = ValueLong.get(last.getKey());
} else {
max = v;
}
}
TransactionMap<Value, Value> map = getMap(session);
return new MVStoreCursor(session, map.entryIterator(min, max));
}
Aggregations