mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Adding iterator JNI binding
This commit is contained in:
42
java/org/rocksdb/Iterator.java
Normal file
42
java/org/rocksdb/Iterator.java
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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;
|
||||
|
||||
public class Iterator {
|
||||
private long nativeHandle_;
|
||||
|
||||
public Iterator(long nativeHandle) {
|
||||
nativeHandle_ = nativeHandle;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
assert(isInitialized());
|
||||
return isValid0(nativeHandle_);
|
||||
}
|
||||
|
||||
public void seekToFirst() {
|
||||
assert(isInitialized());
|
||||
seekToFirst0(nativeHandle_);
|
||||
}
|
||||
|
||||
public synchronized void close() {
|
||||
if(nativeHandle_ != 0) {
|
||||
close0(nativeHandle_);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void finalize() {
|
||||
close();
|
||||
}
|
||||
|
||||
private boolean isInitialized() {
|
||||
return (nativeHandle_ != 0);
|
||||
}
|
||||
|
||||
private native boolean isValid0(long handle);
|
||||
private native void close0(long handle);
|
||||
private native void seekToFirst0(long handle);
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -136,6 +135,10 @@ public class RocksDB {
|
||||
throws RocksDBException {
|
||||
remove(nativeHandle_, writeOpt.nativeHandle_, key, key.length);
|
||||
}
|
||||
|
||||
public Iterator iterator() {
|
||||
return new Iterator(iterator0(nativeHandle_));
|
||||
}
|
||||
|
||||
@Override protected void finalize() {
|
||||
close();
|
||||
@@ -170,6 +173,7 @@ public class RocksDB {
|
||||
protected native void remove(
|
||||
long handle, long writeOptHandle,
|
||||
byte[] key, int keyLen) throws RocksDBException;
|
||||
protected native long iterator0(long optHandle);
|
||||
protected native void close0();
|
||||
|
||||
protected long nativeHandle_;
|
||||
|
||||
Reference in New Issue
Block a user