mirror of https://github.com/facebook/rocksdb.git
Extract the interface for a RocksIterator
This commit is contained in:
parent
a8cfa7ace8
commit
2241e3f4d5
|
@ -6,9 +6,9 @@
|
|||
package org.rocksdb;
|
||||
|
||||
/**
|
||||
* <p>An iterator yields a sequence of key/value pairs from a source.
|
||||
* The following class defines the interface. Multiple implementations
|
||||
* are provided by this library. In particular, iterators are provided
|
||||
* <p>An iterator that yields a sequence of key/value pairs from a source.
|
||||
* Multiple implementations are provided by this library.
|
||||
* In particular, iterators are provided
|
||||
* to access the contents of a Table or a DB.</p>
|
||||
*
|
||||
* <p>Multiple threads can invoke const methods on an RocksIterator without
|
||||
|
@ -18,7 +18,7 @@ package org.rocksdb;
|
|||
*
|
||||
* @see org.rocksdb.RocksObject
|
||||
*/
|
||||
public class RocksIterator extends RocksObject {
|
||||
public class RocksIterator extends RocksObject implements RocksIteratorInterface {
|
||||
public RocksIterator(RocksDB rocksDB, long nativeHandle) {
|
||||
super();
|
||||
nativeHandle_ = nativeHandle;
|
||||
|
@ -30,57 +30,48 @@ public class RocksIterator extends RocksObject {
|
|||
rocksDB_ = rocksDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* An iterator is either positioned at a key/value pair, or
|
||||
* not valid. This method returns true iff the iterator is valid.
|
||||
*
|
||||
* @return true if iterator is valid.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
assert(isInitialized());
|
||||
return isValid0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Position at the first key in the source. The iterator is Valid()
|
||||
* after this call iff the source is not empty.
|
||||
*/
|
||||
@Override
|
||||
public void seekToFirst() {
|
||||
assert(isInitialized());
|
||||
seekToFirst0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Position at the last key in the source. The iterator is
|
||||
* valid after this call iff the source is not empty.
|
||||
*/
|
||||
@Override
|
||||
public void seekToLast() {
|
||||
assert(isInitialized());
|
||||
seekToLast0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Moves to the next entry in the source. After this call, Valid() is
|
||||
* true iff the iterator was not positioned at the last entry in the source.</p>
|
||||
*
|
||||
* <p>REQUIRES: {@link #isValid()}</p>
|
||||
*/
|
||||
@Override
|
||||
public void seek(byte[] target) {
|
||||
assert(isInitialized());
|
||||
seek0(nativeHandle_, target, target.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
assert(isInitialized());
|
||||
next0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Moves to the previous entry in the source. After this call, Valid() is
|
||||
* true iff the iterator was not positioned at the first entry in source.</p>
|
||||
*
|
||||
* <p>REQUIRES: {@link #isValid()}</p>
|
||||
*/
|
||||
@Override
|
||||
public void prev() {
|
||||
assert(isInitialized());
|
||||
prev0(nativeHandle_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void status() throws RocksDBException {
|
||||
assert(isInitialized());
|
||||
status0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return the key for the current entry. The underlying storage for
|
||||
* the returned slice is valid only until the next modification of
|
||||
|
@ -108,32 +99,6 @@ public class RocksIterator extends RocksObject {
|
|||
return value0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Position at the first key in the source that at or past target
|
||||
* The iterator is valid after this call iff the source contains
|
||||
* an entry that comes at or past target.</p>
|
||||
*
|
||||
* @param target byte array describing a key or a
|
||||
* key prefix to seek for.
|
||||
*/
|
||||
public void seek(byte[] target) {
|
||||
assert(isInitialized());
|
||||
seek0(nativeHandle_, target, target.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* If 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().
|
||||
*
|
||||
* @throws RocksDBException thrown if error happens in underlying
|
||||
* native library.
|
||||
*/
|
||||
public void status() throws RocksDBException {
|
||||
assert(isInitialized());
|
||||
status0(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Deletes underlying C++ iterator pointer.</p>
|
||||
*
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
/**
|
||||
* <p>Defines the interface for an Iterator which provides
|
||||
* access to data one entry at a time. Multiple implementations
|
||||
* are provided by this library. In particular, iterators are provided
|
||||
* to access the contents of a DB and Write Batch.</p>
|
||||
* <p/>
|
||||
* <p>Multiple 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.</p>
|
||||
*
|
||||
* @see org.rocksdb.RocksObject
|
||||
*/
|
||||
public interface RocksIteratorInterface {
|
||||
|
||||
/**
|
||||
* <p>An iterator is either positioned at an entry, or
|
||||
* not valid. This method returns true if the iterator is valid.</p>
|
||||
*
|
||||
* @return true if iterator is valid.
|
||||
*/
|
||||
public boolean isValid();
|
||||
|
||||
/**
|
||||
* <p>Position at the first entry in the source. The iterator is Valid()
|
||||
* after this call if the source is not empty.</p>
|
||||
*/
|
||||
public void seekToFirst();
|
||||
|
||||
/**
|
||||
* <p>Position at the last entry in the source. The iterator is
|
||||
* valid after this call if the source is not empty.</p>
|
||||
*/
|
||||
public void seekToLast();
|
||||
|
||||
/**
|
||||
* <p>Position at the first entry in the source whose key is that or
|
||||
* past target.</p>
|
||||
* <p/>
|
||||
* <p>The iterator is valid after this call if the source contains
|
||||
* a key that comes at or past target.</p>
|
||||
*
|
||||
* @param target byte array describing a key or a
|
||||
* key prefix to seek for.
|
||||
*/
|
||||
public void seek(byte[] target);
|
||||
|
||||
/**
|
||||
* <p>Moves 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.</p>
|
||||
* <p/>
|
||||
* <p>REQUIRES: {@link #isValid()}</p>
|
||||
*/
|
||||
public void next();
|
||||
|
||||
/**
|
||||
* <p>Moves 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.</p>
|
||||
* <p/>
|
||||
* <p>REQUIRES: {@link #isValid()}</p>
|
||||
*/
|
||||
public void prev();
|
||||
|
||||
/**
|
||||
* <pIf 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().</p>
|
||||
*
|
||||
* @throws RocksDBException thrown if error happens in underlying
|
||||
* native library.
|
||||
*/
|
||||
public void status() throws RocksDBException;
|
||||
}
|
Loading…
Reference in New Issue