Class AbstractRocksIterator<P extends RocksObject>
- java.lang.Object
-
- org.rocksdb.AbstractNativeReference
-
- org.rocksdb.AbstractImmutableNativeReference
-
- org.rocksdb.RocksObject
-
- org.rocksdb.AbstractRocksIterator<P>
-
- Type Parameters:
P- The type of the Parent Object from which the Rocks Iterator was created. This is used by disposeInternal to avoid double-free issues with the underlying C++ object.
- All Implemented Interfaces:
java.lang.AutoCloseable,RocksIteratorInterface
- Direct Known Subclasses:
RocksIterator,SstFileReaderIterator,WBWIRocksIterator
public abstract class AbstractRocksIterator<P extends RocksObject> extends RocksObject implements RocksIteratorInterface
Base class implementation for Rocks Iterators in the Java APIMultiple threads can invoke const methods on an RocksIterator without external synchronization, but if any of the threads may call a non-const method, all threads accessing the same RocksIterator must use external synchronization.
- See Also:
RocksObject
-
-
Field Summary
-
Fields inherited from class org.rocksdb.RocksObject
nativeHandle_
-
Fields inherited from class org.rocksdb.AbstractImmutableNativeReference
owningHandle_
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRocksIterator(P parent, long nativeHandle)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddisposeInternal()Deletes underlying C++ iterator pointer.booleanisValid()An iterator is either positioned at an entry, or not valid.voidnext()Moves to the next entry in the source.voidprev()Moves to the previous entry in the source.voidrefresh()If supported, renew the iterator to represent the latest state.voidseek(byte[] target)Position at the first entry in the source whose key is at or past target.voidseek(java.nio.ByteBuffer target)Position at the first entry in the source whose key is that or past target.voidseekForPrev(byte[] target)Position at the first entry in the source whose key is that or before target.voidseekForPrev(java.nio.ByteBuffer target)Position at the last key that is less than or equal to the target key.voidseekToFirst()Position at the first entry in the source.voidseekToLast()Position at the last entry in the source.voidstatus()If an error has occurred, return it.-
Methods inherited from class org.rocksdb.RocksObject
disposeInternal, getNativeHandle
-
Methods inherited from class org.rocksdb.AbstractImmutableNativeReference
close, disOwnNativeHandle, isOwningHandle
-
Methods inherited from class org.rocksdb.AbstractNativeReference
dispose, finalize
-
-
-
-
Constructor Detail
-
AbstractRocksIterator
protected AbstractRocksIterator(P parent, long nativeHandle)
-
-
Method Detail
-
isValid
public boolean isValid()
Description copied from interface:RocksIteratorInterfaceAn iterator is either positioned at an entry, or not valid. This method returns true if the iterator is valid.
- Specified by:
isValidin interfaceRocksIteratorInterface- Returns:
- true if iterator is valid.
-
seekToFirst
public void seekToFirst()
Description copied from interface:RocksIteratorInterfacePosition at the first entry in the source. The iterator is Valid() after this call if the source is not empty.
- Specified by:
seekToFirstin interfaceRocksIteratorInterface
-
seekToLast
public void seekToLast()
Description copied from interface:RocksIteratorInterfacePosition at the last entry in the source. The iterator is valid after this call if the source is not empty.
- Specified by:
seekToLastin interfaceRocksIteratorInterface
-
seek
public void seek(byte[] target)
Description copied from interface:RocksIteratorInterfacePosition at the first entry in the source whose key is at or past target.
The iterator is valid after this call if the source contains a key that comes at or past target.
- Specified by:
seekin interfaceRocksIteratorInterface- Parameters:
target- byte array describing a key or a key prefix to seek for.
-
seekForPrev
public void seekForPrev(byte[] target)
Description copied from interface:RocksIteratorInterfacePosition at the first entry in the source whose key is that or before target.
The iterator is valid after this call if the source contains a key that comes at or before target.
- Specified by:
seekForPrevin interfaceRocksIteratorInterface- Parameters:
target- byte array describing a key or a key prefix to seek for.
-
seek
public void seek(java.nio.ByteBuffer target)
Description copied from interface:RocksIteratorInterfacePosition at the first entry in the source whose key is that or past target.
The iterator is valid after this call if the source contains a key that comes at or past target.
- Specified by:
seekin interfaceRocksIteratorInterface- Parameters:
target- byte array describing a key or a key prefix to seek for. Supports direct buffer only.
-
seekForPrev
public void seekForPrev(java.nio.ByteBuffer target)
Description copied from interface:RocksIteratorInterfacePosition at the last key that is less than or equal to the target key.
The iterator is valid after this call if the source contains a key that comes at or past target.
- Specified by:
seekForPrevin interfaceRocksIteratorInterface- Parameters:
target- byte array describing a key or a key prefix to seek for. Supports direct buffer only.
-
next
public void next()
Description copied from interface:RocksIteratorInterfaceMoves to the next entry in the source. After this call, Valid() is true if the iterator was not positioned at the last entry in the source.
REQUIRES:
RocksIteratorInterface.isValid()- Specified by:
nextin interfaceRocksIteratorInterface
-
prev
public void prev()
Description copied from interface:RocksIteratorInterfaceMoves to the previous entry in the source. After this call, Valid() is true if the iterator was not positioned at the first entry in source.
REQUIRES:
RocksIteratorInterface.isValid()- Specified by:
previn interfaceRocksIteratorInterface
-
refresh
public void refresh() throws RocksDBExceptionDescription copied from interface:RocksIteratorInterfaceIf supported, renew the iterator to represent the latest state. The iterator will be invalidated after the call. Not supported if
ReadOptions.setSnapshot(Snapshot)was specified when creating the iterator.- Specified by:
refreshin interfaceRocksIteratorInterface- Throws:
RocksDBException- thrown if the operation is not supported or an error happens in the underlying native library
-
status
public void status() throws RocksDBExceptionDescription copied from interface:RocksIteratorInterfaceIf an error has occurred, return it. Else return an ok status. If non-blocking IO is requested and this operation cannot be satisfied without doing some IO, then this returns Status::Incomplete().
- Specified by:
statusin interfaceRocksIteratorInterface- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
disposeInternal
protected void disposeInternal()
Deletes underlying C++ iterator pointer.
Note: the underlying handle can only be safely deleted if the parent instance related to a certain RocksIterator is still valid and initialized. Therefore
disposeInternal()checks if the parent is initialized before freeing the native handle.- Overrides:
disposeInternalin classRocksObject
-
-