@Override public void setKeyAndVersion(SearchRow row) { key = row.getKey(); version = row.getVersion(); }
@Override public void setKeyAndVersion(SearchRow row) { key = row.getKey(); version = row.getVersion(); }
@Override public Row get() { if (currentRow == null && currentSearchRow != null) { currentRow = index.getRow(session, currentSearchRow.getKey()); } return currentRow; }
/** * Compare the positions of two rows. * * @param rowData the first row * @param compare the second row * @return 0 if both rows are equal, -1 if the first row is smaller, * otherwise 1 */ int compareKeys(SearchRow rowData, SearchRow compare) { long k1 = rowData.getKey(); long k2 = compare.getKey(); if (k1 == k2) { if (isMultiVersion) { int v1 = rowData.getVersion(); int v2 = compare.getVersion(); return Integer.compare(v2, v1); } return 0; } return k1 > k2 ? 1 : -1; }
@Override public Row get() { if (row == null) { SearchRow r = getSearchRow(); if (r != null) { row = mvTable.getRow(session, r.getKey()); } } return row; }
@Override public Row get() { if (row == null) { SearchRow r = getSearchRow(); if (r != null) { row = mvTable.getRow(session, r.getKey()); } } return row; }
@Override public void setKeyAndVersion(SearchRow row) { setKey(row.getKey()); setVersion(row.getVersion()); }
@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)); }
private SpatialKey getKey(SearchRow row) { Value v = row.getValue(columnIds[0]); if (v == ValueNull.INSTANCE) { return new SpatialKey(row.getKey()); } Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometryNoCopy(); Envelope env = g.getEnvelopeInternal(); return new SpatialKey(row.getKey(), (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY()); }
/** * Get the size of a row (only the part that is stored in the index). * * @param dummy a dummy data page to calculate the size * @param row the row * @param onlyPosition whether only the position of the row is stored * @return the number of bytes */ int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) { int rowsize = Data.getVarLongLen(row.getKey()); if (!onlyPosition) { for (Column col : columns) { Value v = row.getValue(col.getColumnId()); rowsize += dummy.getValueLen(v); } } return rowsize; }
/** * Write a row to the data page at the given offset. * * @param data the data * @param offset the offset * @param onlyPosition whether only the position of the row is stored * @param row the row to write */ void writeRow(Data data, int offset, SearchRow row, boolean onlyPosition) { data.setPos(offset); data.writeVarLong(row.getKey()); if (!onlyPosition) { for (Column col : columns) { int idx = col.getColumnId(); data.writeValue(row.getValue(idx)); } } }
/** * Get the row at this position. * * @param at the index * @return the row */ SearchRow getRow(int at) { SearchRow row = rows[at]; if (row == null) { row = index.readRow(data, offsets[at], onlyPosition, true); memoryChange(); rows[at] = row; } else if (!index.hasData(row)) { row = index.readRow(row.getKey()); memoryChange(); rows[at] = row; } return row; }
private ValueArray convertToKey(SearchRow r) { if (r == null) { return null; } Value[] array = new Value[keyColumns]; for (int i = 0; i < columns.length; i++) { Column c = columns[i]; int idx = c.getColumnId(); Value v = r.getValue(idx); if (v != null) { array[i] = v.convertTo(c.getType()); } } array[keyColumns - 1] = ValueLong.get(r.getKey()); return ValueArray.get(array); }
@Override public Value getValue(Column column) { if (joinBatch != null) { return joinBatch.getValue(joinFilterId, column); } if (currentSearchRow == null) { return null; } int columnId = column.getColumnId(); if (columnId == -1) { return ValueLong.get(currentSearchRow.getKey()); } if (current == null) { Value v = currentSearchRow.getValue(columnId); if (v != null) { return v; } current = cursor.get(); if (current == null) { return ValueNull.INSTANCE; } } return current.getValue(columnId); }
@Override SearchRow remove(SearchRow row) { int at = find(row, false, false, true); SearchRow delete = getRow(at); if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) { throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, index.getSQL() + ": " + row); } index.getPageStore().logUndo(this, data); if (entryCount == 1) { // the page is now empty return row; } removeRow(at); memoryChange(); index.getPageStore().update(this); if (at == entryCount) { // the last row changed return getRow(at - 1); } // the last row didn't change return null; }
private SpatialKey getKey(SearchRow row) { if (row == null) { return null; } Value v = row.getValue(columnIds[0]); if (v == ValueNull.INSTANCE) { return null; } Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometryNoCopy(); Envelope env = g.getEnvelopeInternal(); return new SpatialKey(row.getKey(), (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY()); }
private boolean existsRow(Session session, Index searchIndex, SearchRow check, Row excluding) { Table searchTable = searchIndex.getTable(); searchTable.lock(session, false, false); Cursor cursor = searchIndex.find(session, check, check); while (cursor.next()) { SearchRow found; found = cursor.getSearchRow(); if (excluding != null && found.getKey() == excluding.getKey()) { continue; } Column[] cols = searchIndex.getColumns(); boolean allEqual = true; int len = Math.min(columns.length, cols.length); for (int i = 0; i < len; i++) { int idx = cols[i].getColumnId(); Value c = check.getValue(idx); Value f = found.getValue(idx); if (searchTable.compareTypeSafe(c, f) != 0) { allEqual = false; break; } } if (allEqual) { return true; } } return false; }
long k2 = baseRow.getKey(); compare = Long.compare(k1, k2);
private SHPCursor(H2TableIndex tIndex, SearchRow begin, SearchRow end, Session session) { this.tIndex = tIndex; this.session = session; this.begin = begin; this.end = end; this.rowIndex = begin == null ? 0 : begin.getKey() - 1; }