diff --git a/java/org/rocksdb/RocksIterator.java b/java/org/rocksdb/RocksIterator.java index 1abe7e704..cecf9c309 100644 --- a/java/org/rocksdb/RocksIterator.java +++ b/java/org/rocksdb/RocksIterator.java @@ -6,9 +6,9 @@ package org.rocksdb; /** - *
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 + *
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.
* *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_); } - /** - *
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.
- * - *REQUIRES: {@link #isValid()}
- */ + @Override + public void seek(byte[] target) { + assert(isInitialized()); + seek0(nativeHandle_, target, target.length); + } + + @Override public void next() { assert(isInitialized()); next0(nativeHandle_); } - /** - *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.
- * - *REQUIRES: {@link #isValid()}
- */ + @Override public void prev() { assert(isInitialized()); prev0(nativeHandle_); } + @Override + public void status() throws RocksDBException { + assert(isInitialized()); + status0(nativeHandle_); + } + /** *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_); } - /** - *
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.
- * - * @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_); - } - /** *Deletes underlying C++ iterator pointer.
* diff --git a/java/org/rocksdb/RocksIteratorInterface.java b/java/org/rocksdb/RocksIteratorInterface.java new file mode 100644 index 000000000..15f3a9aa9 --- /dev/null +++ b/java/org/rocksdb/RocksIteratorInterface.java @@ -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; + +/** + *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.
+ * + *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.
+ * + * @see org.rocksdb.RocksObject + */ +public interface RocksIteratorInterface { + + /** + *An iterator is either positioned at an entry, or + * not valid. This method returns true if the iterator is valid.
+ * + * @return true if iterator is valid. + */ + public boolean isValid(); + + /** + *Position at the first entry in the source. The iterator is Valid() + * after this call if the source is not empty.
+ */ + public void seekToFirst(); + + /** + *Position at the last entry in the source. The iterator is + * valid after this call if the source is not empty.
+ */ + public void seekToLast(); + + /** + *Position 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.
+ * + * @param target byte array describing a key or a + * key prefix to seek for. + */ + public void seek(byte[] target); + + /** + *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.
+ * + *REQUIRES: {@link #isValid()}
+ */ + public void next(); + + /** + *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.
+ * + *REQUIRES: {@link #isValid()}
+ */ + public void prev(); + + /** + *