public Cursor findFirstOrLast(Session session, boolean first) throws SQLException { Cursor cursor; if (first) { cursor = mainIndex.find(session, Long.MIN_VALUE, Long.MAX_VALUE, false); } else { long x = mainIndex.getLastKey(); cursor = mainIndex.find(session, x, x, false); } cursor.next(); return cursor; }