use of jetbrains.exodus.tree.ITreeCursor in project xodus by JetBrains.
the class PatriciaCursorDecorator method getNextNoDup.
@Override
public boolean getNextNoDup() {
if (keyBytes == null) {
// init
return getNext();
}
if (getNextLazy() && ByteIterableUtil.compare(keyBytes, keyLength, nextKeyBytes, nextKeyLength) != 0) {
advance();
return true;
}
// we must create new cursor 'cause we don't know if next "no dup" pair exists
final ITreeCursor cursor = patriciaCursor.getTree().openCursor();
ITreeCursor cursorToClose = cursor;
try {
if (cursor.getSearchKeyRange(getEscapedKeyValue(getKey(), getValue())) != null) {
while (cursor.getNext()) {
final ByteIterable keyLengthIterable = cursor.getValue();
final ByteIterable noDupKey = new UnEscapingByteIterable(cursor.getKey());
final int keyLength = CompressedUnsignedLongByteIterable.getInt(keyLengthIterable);
final byte[] noDupKeyBytes = noDupKey.getBytesUnsafe();
if (ByteIterableUtil.compare(keyBytes, this.keyLength, noDupKeyBytes, keyLength) != 0) {
keyBytes = noDupKey.getBytesUnsafe();
this.keyLength = keyLength;
valueLength = noDupKey.getLength() - keyLength - 1;
cursorToClose = patriciaCursor;
patriciaCursor = cursor;
// forget computed next pair
nextKeyLength = UNKNOWN;
// forget computed prev pair
prevKeyLength = UNKNOWN;
return true;
}
}
}
} finally {
cursorToClose.close();
}
return false;
}
use of jetbrains.exodus.tree.ITreeCursor in project xodus by JetBrains.
the class CursorImpl method deleteCurrent.
@Override
public boolean deleteCurrent() {
final ReadWriteTransaction txn = EnvironmentImpl.throwIfReadonly(this.txn, "Can't delete a key/value pair of cursor in read-only transaction");
if (treeCursor == null) {
treeCursor = txn.getMutableTree(store).openCursor();
} else {
if (!treeCursor.isMutable()) {
final ByteIterable key = treeCursor.getKey();
final ByteIterable value = treeCursor.getValue();
final ITreeCursor newCursor = txn.getMutableTree(store).openCursor();
if (newCursor.getSearchBoth(key, value)) {
// navigated to same pair, ready to delete
treeCursor = newCursor;
} else {
throw new ConcurrentModificationException(CANT_DELETE_MODIFIED_MSG);
}
}
}
return treeCursor.deleteCurrent();
}
Aggregations