Extract the interface for a RocksIterator

main
Adam Retter 10 years ago
parent a8cfa7ace8
commit 2241e3f4d5
  1. 77
      java/org/rocksdb/RocksIterator.java
  2. 80
      java/org/rocksdb/RocksIteratorInterface.java

@ -6,9 +6,9 @@
package org.rocksdb; package org.rocksdb;
/** /**
* <p>An iterator yields a sequence of key/value pairs from a source. * <p>An iterator that yields a sequence of key/value pairs from a source.
* The following class defines the interface. Multiple implementations * Multiple implementations are provided by this library.
* are provided by this library. In particular, iterators are provided * In particular, iterators are provided
* to access the contents of a Table or a DB.</p> * to access the contents of a Table or a DB.</p>
* *
* <p>Multiple threads can invoke const methods on an RocksIterator without * <p>Multiple threads can invoke const methods on an RocksIterator without
@ -18,7 +18,7 @@ package org.rocksdb;
* *
* @see org.rocksdb.RocksObject * @see org.rocksdb.RocksObject
*/ */
public class RocksIterator extends RocksObject { public class RocksIterator extends RocksObject implements RocksIteratorInterface {
public RocksIterator(RocksDB rocksDB, long nativeHandle) { public RocksIterator(RocksDB rocksDB, long nativeHandle) {
super(); super();
nativeHandle_ = nativeHandle; nativeHandle_ = nativeHandle;
@ -30,57 +30,48 @@ public class RocksIterator extends RocksObject {
rocksDB_ = rocksDB; rocksDB_ = rocksDB;
} }
/** @Override
* 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.
*/
public boolean isValid() { public boolean isValid() {
assert(isInitialized()); assert(isInitialized());
return isValid0(nativeHandle_); return isValid0(nativeHandle_);
} }
/** @Override
* Position at the first key in the source. The iterator is Valid()
* after this call iff the source is not empty.
*/
public void seekToFirst() { public void seekToFirst() {
assert(isInitialized()); assert(isInitialized());
seekToFirst0(nativeHandle_); seekToFirst0(nativeHandle_);
} }
/** @Override
* Position at the last key in the source. The iterator is
* valid after this call iff the source is not empty.
*/
public void seekToLast() { public void seekToLast() {
assert(isInitialized()); assert(isInitialized());
seekToLast0(nativeHandle_); seekToLast0(nativeHandle_);
} }
/** @Override
* <p>Moves to the next entry in the source. After this call, Valid() is public void seek(byte[] target) {
* true iff the iterator was not positioned at the last entry in the source.</p> assert(isInitialized());
* seek0(nativeHandle_, target, target.length);
* <p>REQUIRES: {@link #isValid()}</p> }
*/
@Override
public void next() { public void next() {
assert(isInitialized()); assert(isInitialized());
next0(nativeHandle_); next0(nativeHandle_);
} }
/** @Override
* <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>
*/
public void prev() { public void prev() {
assert(isInitialized()); assert(isInitialized());
prev0(nativeHandle_); prev0(nativeHandle_);
} }
@Override
public void status() throws RocksDBException {
assert(isInitialized());
status0(nativeHandle_);
}
/** /**
* <p>Return the key for the current entry. The underlying storage for * <p>Return the key for the current entry. The underlying storage for
* the returned slice is valid only until the next modification of * the returned slice is valid only until the next modification of
@ -108,32 +99,6 @@ public class RocksIterator extends RocksObject {
return value0(nativeHandle_); 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> * <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…
Cancel
Save