/** {@inheritDoc} */ @Override public Cursor find(Session session, SearchRow first, SearchRow last) { if (first == null || last == null || !Objects.equals(id(first), id(last))) return new GridH2Cursor(rows.values().iterator()); return new SingleRowCursor(rows.get(id(first))); }
@Override public Cursor find(Session session, SearchRow first, SearchRow last) { if (first == null || last == null) { // TODO hash index: should additionally check if values are the same throw DbException.throwInternalError(first + " " + last); } Value v = first.getValue(indexColumn); /* * Sometimes the incoming search is a similar, but not the same type * e.g. the search value is INT, but the index column is LONG. In which * case we need to convert, otherwise the ValueHashMap will not find the * result. */ v = v.convertTo(tableData.getColumn(indexColumn).getType()); Row result; Long pos = rows.get(v); if (pos == null) { result = null; } else { result = tableData.getRow(session, pos.intValue()); } return new SingleRowCursor(result); }
/** {@inheritDoc} */ @Override public Cursor findFirstOrLast(Session session, boolean b) { try { H2Tree tree = treeForRead(threadLocalSegment()); GridH2QueryContext qctx = GridH2QueryContext.get(); return new SingleRowCursor(b ? tree.findFirst(filter(qctx)): tree.findLast(filter(qctx))); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** {@inheritDoc} */ @Override public Cursor find(Session ses, SearchRow lower, SearchRow upper) { assert lower == null || lower instanceof GridH2SearchRow : lower; assert upper == null || upper instanceof GridH2SearchRow : upper; try { int seg = threadLocalSegment(); H2Tree tree = treeForRead(seg); if (!cctx.mvccEnabled() && indexType.isPrimaryKey() && lower != null && upper != null && tree.compareRows((GridH2SearchRow)lower, (GridH2SearchRow)upper) == 0) { GridH2Row row = tree.findOne((GridH2SearchRow)lower, filter(GridH2QueryContext.get()), null); return (row == null) ? GridH2Cursor.EMPTY : new SingleRowCursor(row); } else { return new H2Cursor(tree.find((GridH2SearchRow)lower, (GridH2SearchRow)upper, filter(GridH2QueryContext.get()), null)); } } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** {@inheritDoc} */ @Override public Cursor find(Session session, SearchRow first, SearchRow last) { if (first == null || last == null || !Objects.equals(id(first), id(last))) return new GridH2Cursor(rows.values().iterator()); return new SingleRowCursor(rows.get(id(first))); }
/** {@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"); Iterator<GridH2Row> iter = rowIterator(treeMap.keySet().iterator()); return new SingleRowCursor(iter.hasNext() ? iter.next() : null); } finally { l.unlock(); } }
/** {@inheritDoc} */ @Override public Cursor findFirstOrLast(Session ses, boolean first) { ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row> tree = treeForRead(); GridSearchRowPointer res = null; Iterator<GridH2Row> iter = filter(first ? tree.values().iterator() : tree.descendingMap().values().iterator()); if (iter.hasNext()) { GridSearchRowPointer r = iter.next(); if ((first && compare(r, res) < 0) || (!first && compare(r, res) > 0)) res = r; } return new SingleRowCursor((Row)res); }
@Override public Cursor find(Session session, SearchRow first, SearchRow last) { if (first == null || last == null) { // TODO hash index: should additionally check if values are the same throw DbException.throwInternalError(); } Value v = first.getValue(indexColumn); /* * Sometimes the incoming search is a similar, but not the same type * e.g. the search value is INT, but the index column is LONG. In which * case we need to convert, otherwise the ValueHashMap will not find the * result. */ v = v.convertTo(tableData.getColumn(indexColumn).getType()); Row result; Long pos = rows.get(v); if (pos == null) { result = null; } else { result = tableData.getRow(session, pos.intValue()); } return new SingleRowCursor(result); }
@Override public Cursor find(Session session, SearchRow first, SearchRow last) { if (first == null || last == null) { // TODO hash index: should additionally check if values are the same throw DbException.throwInternalError(); } Value v = first.getValue(indexColumn); /* * Sometimes the incoming search is a similar, but not the same type * e.g. the search value is INT, but the index column is LONG. In which * case we need to convert, otherwise the ValueHashMap will not find the * result. */ v = v.convertTo(tableData.getColumn(indexColumn).getType()); Row result; Long pos = rows.get(v); if (pos == null) { result = null; } else { result = tableData.getRow(session, pos.intValue()); } return new SingleRowCursor(result); }
/** {@inheritDoc} */ @Override public Cursor findFirstOrLast(Session session, boolean b) { try { H2Tree tree = treeForRead(threadLocalSegment()); GridH2QueryContext qctx = GridH2QueryContext.get(); return new SingleRowCursor(b ? tree.findFirst(filter(qctx)): tree.findLast(filter(qctx))); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** {@inheritDoc} */ @Override public Cursor find(Session ses, SearchRow lower, SearchRow upper) { try { assert lower == null || lower instanceof GridH2SearchRow : lower; assert upper == null || upper instanceof GridH2SearchRow : upper; int seg = threadLocalSegment(); H2Tree tree = treeForRead(seg); if (!cctx.mvccEnabled() && indexType.isPrimaryKey() && lower != null && upper != null && tree.compareRows((GridH2SearchRow)lower, (GridH2SearchRow)upper) == 0) { GridH2Row row = tree.findOne((GridH2SearchRow)lower, filter(GridH2QueryContext.get()), null); return (row == null) ? GridH2Cursor.EMPTY : new SingleRowCursor(row); } else { return new H2Cursor(tree.find((GridH2SearchRow)lower, (GridH2SearchRow)upper, filter(GridH2QueryContext.get()), null)); } } catch (IgniteCheckedException e) { throw DbException.convert(e); } }