@ -6,13 +6,13 @@
// This file implements the "bridge" between Java and C++ and enables
// calling c++ rocksdb::Iterator methods from Java side.
# include <jni.h>
# include <stdio.h>
# include <stdlib.h>
# include <jni.h>
# include "include/org_rocksdb_SstFileReaderIterator.h"
# include "rocksjni/portal.h"
# include "rocksdb/iterator.h"
# include "rocksjni/portal.h"
/*
* Class : org_rocksdb_SstFileReaderIterator
@ -65,7 +65,8 @@ void Java_org_rocksdb_SstFileReaderIterator_seekToLast0(JNIEnv* /*env*/,
* Method : next0
* Signature : ( J ) V
*/
void Java_org_rocksdb_SstFileReaderIterator_next0 ( JNIEnv * /*env*/ , jobject /*jobj*/ ,
void Java_org_rocksdb_SstFileReaderIterator_next0 ( JNIEnv * /*env*/ ,
jobject /*jobj*/ ,
jlong handle ) {
reinterpret_cast < rocksdb : : Iterator * > ( handle ) - > Next ( ) ;
}
@ -75,7 +76,8 @@ void Java_org_rocksdb_SstFileReaderIterator_next0(JNIEnv* /*env*/, jobject /*job
* Method : prev0
* Signature : ( J ) V
*/
void Java_org_rocksdb_SstFileReaderIterator_prev0 ( JNIEnv * /*env*/ , jobject /*jobj*/ ,
void Java_org_rocksdb_SstFileReaderIterator_prev0 ( JNIEnv * /*env*/ ,
jobject /*jobj*/ ,
jlong handle ) {
reinterpret_cast < rocksdb : : Iterator * > ( handle ) - > Prev ( ) ;
}
@ -86,16 +88,16 @@ void Java_org_rocksdb_SstFileReaderIterator_prev0(JNIEnv* /*env*/, jobject /*job
* Signature : ( J [ BI ) V
*/
void Java_org_rocksdb_SstFileReaderIterator_seek0 ( JNIEnv * env , jobject /*jobj*/ ,
jlong handle , jbyteArray jtarget ,
jlong handle ,
jbyteArray jtarget ,
jint jtarget_len ) {
jbyte * target = env - > GetByteArrayElements ( jtarget , nullptr ) ;
if ( target = = nullptr ) {
if ( target = = nullptr ) {
// exception thrown: OutOfMemoryError
return ;
}
rocksdb : : Slice target_slice (
reinterpret_cast < char * > ( target ) , jtarget_len ) ;
rocksdb : : Slice target_slice ( reinterpret_cast < char * > ( target ) , jtarget_len ) ;
auto * it = reinterpret_cast < rocksdb : : Iterator * > ( handle ) ;
it - > Seek ( target_slice ) ;
@ -108,18 +110,18 @@ void Java_org_rocksdb_SstFileReaderIterator_seek0(JNIEnv* env, jobject /*jobj*/,
* Method : seekForPrev0
* Signature : ( J [ BI ) V
*/
void Java_org_rocksdb_SstFileReaderIterator_seekForPrev0 ( JNIEnv * env , jobject /*jobj*/ ,
void Java_org_rocksdb_SstFileReaderIterator_seekForPrev0 ( JNIEnv * env ,
jobject /*jobj*/ ,
jlong handle ,
jbyteArray jtarget ,
jint jtarget_len ) {
jbyte * target = env - > GetByteArrayElements ( jtarget , nullptr ) ;
if ( target = = nullptr ) {
if ( target = = nullptr ) {
// exception thrown: OutOfMemoryError
return ;
}
rocksdb : : Slice target_slice (
reinterpret_cast < char * > ( target ) , jtarget_len ) ;
rocksdb : : Slice target_slice ( reinterpret_cast < char * > ( target ) , jtarget_len ) ;
auto * it = reinterpret_cast < rocksdb : : Iterator * > ( handle ) ;
it - > SeekForPrev ( target_slice ) ;
@ -132,7 +134,8 @@ void Java_org_rocksdb_SstFileReaderIterator_seekForPrev0(JNIEnv* env, jobject /*
* Method : status0
* Signature : ( J ) V
*/
void Java_org_rocksdb_SstFileReaderIterator_status0 ( JNIEnv * env , jobject /*jobj*/ ,
void Java_org_rocksdb_SstFileReaderIterator_status0 ( JNIEnv * env ,
jobject /*jobj*/ ,
jlong handle ) {
auto * it = reinterpret_cast < rocksdb : : Iterator * > ( handle ) ;
rocksdb : : Status s = it - > status ( ) ;
@ -149,17 +152,19 @@ void Java_org_rocksdb_SstFileReaderIterator_status0(JNIEnv* env, jobject /*jobj*
* Method : key0
* Signature : ( J ) [ B
*/
jbyteArray Java_org_rocksdb_SstFileReaderIterator_key0 ( JNIEnv * env , jobject /*jobj*/ ,
jbyteArray Java_org_rocksdb_SstFileReaderIterator_key0 ( JNIEnv * env ,
jobject /*jobj*/ ,
jlong handle ) {
auto * it = reinterpret_cast < rocksdb : : Iterator * > ( handle ) ;
rocksdb : : Slice key_slice = it - > key ( ) ;
jbyteArray jkey = env - > NewByteArray ( static_cast < jsize > ( key_slice . size ( ) ) ) ;
if ( jkey = = nullptr ) {
if ( jkey = = nullptr ) {
// exception thrown: OutOfMemoryError
return nullptr ;
}
env - > SetByteArrayRegion ( jkey , 0 , static_cast < jsize > ( key_slice . size ( ) ) ,
env - > SetByteArrayRegion (
jkey , 0 , static_cast < jsize > ( key_slice . size ( ) ) ,
const_cast < jbyte * > ( reinterpret_cast < const jbyte * > ( key_slice . data ( ) ) ) ) ;
return jkey ;
}