mirror of https://github.com/facebook/rocksdb.git
Pass by pointer from/to Java from JNI not by object
This commit is contained in:
parent
0e7e6f6e4b
commit
76e8beeeb9
|
@ -58,12 +58,6 @@ template<class PTR, class DERIVED> class RocksDBNativeClass {
|
|||
assert(fid != nullptr);
|
||||
return fid;
|
||||
}
|
||||
|
||||
// Get the pointer from Java
|
||||
static PTR getHandle(JNIEnv* env, jobject jobj) {
|
||||
return reinterpret_cast<PTR>(
|
||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
||||
}
|
||||
};
|
||||
|
||||
// Native class template for sub-classes of RocksMutableObject
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -323,12 +324,12 @@ void Java_org_rocksdb_RocksDB_put__JJ_3BI_3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: write0
|
||||
* Signature: (JJ)V
|
||||
* Signature: (JJJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_RocksDB_write0(
|
||||
JNIEnv* env, jobject jdb,
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jlong jwrite_options_handle, jlong jwb_handle) {
|
||||
rocksdb::DB* db = rocksdb::RocksDBJni::getHandle(env, jdb);
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
auto* write_options = reinterpret_cast<rocksdb::WriteOptions*>(
|
||||
jwrite_options_handle);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
|
@ -343,12 +344,12 @@ void Java_org_rocksdb_RocksDB_write0(
|
|||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: write1
|
||||
* Signature: (JJ)V
|
||||
* Signature: (JJJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_RocksDB_write1(
|
||||
JNIEnv* env, jobject jdb,
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jlong jwrite_options_handle, jlong jwbwi_handle) {
|
||||
rocksdb::DB* db = rocksdb::RocksDBJni::getHandle(env, jdb);
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
auto* write_options = reinterpret_cast<rocksdb::WriteOptions*>(
|
||||
jwrite_options_handle);
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
|
@ -392,52 +393,16 @@ jboolean key_may_exist_helper(JNIEnv* env, rocksdb::DB* db,
|
|||
return static_cast<jboolean>(keyMayExist);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: keyMayExist
|
||||
* Signature: ([BILjava/lang/StringBuffer;)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_RocksDB_keyMayExist___3BILjava_lang_StringBuffer_2(
|
||||
JNIEnv* env, jobject jdb, jbyteArray jkey, jint jkey_len,
|
||||
jobject jstring_buffer) {
|
||||
rocksdb::DB* db = rocksdb::RocksDBJni::getHandle(env, jdb);
|
||||
return key_may_exist_helper(env, db, rocksdb::ReadOptions(),
|
||||
nullptr, jkey, jkey_len, jstring_buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: keyMayExist
|
||||
* Signature: ([BIJLjava/lang/StringBuffer;)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_RocksDB_keyMayExist___3BIJLjava_lang_StringBuffer_2(
|
||||
JNIEnv* env, jobject jdb, jbyteArray jkey, jint jkey_len,
|
||||
jlong jcf_handle, jobject jstring_buffer) {
|
||||
rocksdb::DB* db = rocksdb::RocksDBJni::getHandle(env, jdb);
|
||||
auto cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(
|
||||
jcf_handle);
|
||||
if (cf_handle != nullptr) {
|
||||
return key_may_exist_helper(env, db, rocksdb::ReadOptions(),
|
||||
cf_handle, jkey, jkey_len, jstring_buffer);
|
||||
} else {
|
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env,
|
||||
rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: keyMayExist
|
||||
* Signature: (J[BILjava/lang/StringBuffer;)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_RocksDB_keyMayExist__J_3BILjava_lang_StringBuffer_2(
|
||||
JNIEnv* env, jobject jdb, jlong jread_options_handle,
|
||||
jbyteArray jkey, jint jkey_len, jobject jstring_buffer) {
|
||||
rocksdb::DB* db = rocksdb::RocksDBJni::getHandle(env, jdb);
|
||||
auto& read_options = *reinterpret_cast<rocksdb::ReadOptions*>(
|
||||
jread_options_handle);
|
||||
return key_may_exist_helper(env, db, read_options,
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jbyteArray jkey, jint jkey_len,
|
||||
jobject jstring_buffer) {
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
return key_may_exist_helper(env, db, rocksdb::ReadOptions(),
|
||||
nullptr, jkey, jkey_len, jstring_buffer);
|
||||
}
|
||||
|
||||
|
@ -447,12 +412,48 @@ jboolean Java_org_rocksdb_RocksDB_keyMayExist__J_3BILjava_lang_StringBuffer_2(
|
|||
* Signature: (J[BIJLjava/lang/StringBuffer;)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_RocksDB_keyMayExist__J_3BIJLjava_lang_StringBuffer_2(
|
||||
JNIEnv* env, jobject jdb, jlong jread_options_handle,
|
||||
jbyteArray jkey, jint jkey_len, jlong jcf_handle, jobject jstring_buffer) {
|
||||
rocksdb::DB* db = rocksdb::RocksDBJni::getHandle(env, jdb);
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jbyteArray jkey, jint jkey_len,
|
||||
jlong jcf_handle, jobject jstring_buffer) {
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(
|
||||
jcf_handle);
|
||||
if (cf_handle != nullptr) {
|
||||
return key_may_exist_helper(env, db, rocksdb::ReadOptions(),
|
||||
cf_handle, jkey, jkey_len, jstring_buffer);
|
||||
} else {
|
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env,
|
||||
rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: keyMayExist
|
||||
* Signature: (JJ[BILjava/lang/StringBuffer;)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_RocksDB_keyMayExist__JJ_3BILjava_lang_StringBuffer_2(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jlong jread_options_handle,
|
||||
jbyteArray jkey, jint jkey_len, jobject jstring_buffer) {
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
auto& read_options = *reinterpret_cast<rocksdb::ReadOptions*>(
|
||||
jread_options_handle);
|
||||
auto cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(
|
||||
return key_may_exist_helper(env, db, read_options,
|
||||
nullptr, jkey, jkey_len, jstring_buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: keyMayExist
|
||||
* Signature: (JJ[BIJLjava/lang/StringBuffer;)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_RocksDB_keyMayExist__JJ_3BIJLjava_lang_StringBuffer_2(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jlong jread_options_handle,
|
||||
jbyteArray jkey, jint jkey_len, jlong jcf_handle, jobject jstring_buffer) {
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
auto& read_options = *reinterpret_cast<rocksdb::ReadOptions*>(
|
||||
jread_options_handle);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(
|
||||
jcf_handle);
|
||||
if (cf_handle != nullptr) {
|
||||
return key_may_exist_helper(env, db, read_options, cf_handle,
|
||||
|
@ -460,8 +461,8 @@ jboolean Java_org_rocksdb_RocksDB_keyMayExist__J_3BIJLjava_lang_StringBuffer_2(
|
|||
} else {
|
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env,
|
||||
rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -628,49 +629,38 @@ jint rocksdb_get_helper(
|
|||
}
|
||||
|
||||
// cf multi get
|
||||
jobject multi_get_helper(JNIEnv* env, jobject jdb, rocksdb::DB* db,
|
||||
const rocksdb::ReadOptions& rOpt, jobject jkey_list, jint jkeys_count,
|
||||
jobject jcfhandle_list) {
|
||||
std::vector<rocksdb::Slice> keys;
|
||||
std::vector<jbyte*> keys_to_free;
|
||||
jobjectArray multi_get_helper(JNIEnv* env, jobject jdb, rocksdb::DB* db,
|
||||
const rocksdb::ReadOptions& rOpt, jobjectArray jkeys,
|
||||
jlongArray jcolumn_family_handles) {
|
||||
std::vector<rocksdb::ColumnFamilyHandle*> cf_handles;
|
||||
|
||||
if (jcfhandle_list != nullptr) {
|
||||
// get cf iterator
|
||||
jobject cfIteratorObj = env->CallObjectMethod(
|
||||
jcfhandle_list, rocksdb::ListJni::getIteratorMethod(env));
|
||||
|
||||
// iterate over keys and convert java byte array to slice
|
||||
while (env->CallBooleanMethod(
|
||||
cfIteratorObj, rocksdb::ListJni::getHasNextMethod(env)) == JNI_TRUE) {
|
||||
jobject jobj = (jbyteArray) env->CallObjectMethod(
|
||||
cfIteratorObj, rocksdb::ListJni::getNextMethod(env));
|
||||
rocksdb::ColumnFamilyHandle* cfHandle =
|
||||
rocksdb::ColumnFamilyHandleJni::getHandle(env, jobj);
|
||||
cf_handles.push_back(cfHandle);
|
||||
if (jcolumn_family_handles != nullptr) {
|
||||
jsize len_cols = env->GetArrayLength(jcolumn_family_handles);
|
||||
jlong* jcfh = env->GetLongArrayElements(jcolumn_family_handles, NULL);
|
||||
for (int i = 0; i < len_cols; i++) {
|
||||
auto* cf_handle =
|
||||
reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcfh[i]);
|
||||
cf_handles.push_back(cf_handle);
|
||||
}
|
||||
env->ReleaseLongArrayElements(jcolumn_family_handles, jcfh, JNI_ABORT);
|
||||
}
|
||||
|
||||
// Process key list
|
||||
// get iterator
|
||||
jobject iteratorObj = env->CallObjectMethod(
|
||||
jkey_list, rocksdb::ListJni::getIteratorMethod(env));
|
||||
std::vector<rocksdb::Slice> keys;
|
||||
std::vector<std::tuple<jbyteArray, jbyte*, jobject>> keys_to_free;
|
||||
jsize len_keys = env->GetArrayLength(jkeys);
|
||||
if(env->EnsureLocalCapacity(len_keys) != 0) {
|
||||
// out of memory
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < len_keys; i++) {
|
||||
jobject jk = env->GetObjectArrayElement(jkeys, i);
|
||||
jbyteArray jk_ba = reinterpret_cast<jbyteArray>(jk);
|
||||
jsize len_key = env->GetArrayLength(jk_ba);
|
||||
jbyte* jk_val = env->GetByteArrayElements(jk_ba, NULL);
|
||||
|
||||
// iterate over keys and convert java byte array to slice
|
||||
while (env->CallBooleanMethod(
|
||||
iteratorObj, rocksdb::ListJni::getHasNextMethod(env)) == JNI_TRUE) {
|
||||
jbyteArray jkey = (jbyteArray) env->CallObjectMethod(
|
||||
iteratorObj, rocksdb::ListJni::getNextMethod(env));
|
||||
jint key_length = env->GetArrayLength(jkey);
|
||||
|
||||
jbyte* key = new jbyte[key_length];
|
||||
env->GetByteArrayRegion(jkey, 0, key_length, key);
|
||||
// store allocated jbyte to free it after multiGet call
|
||||
keys_to_free.push_back(key);
|
||||
|
||||
rocksdb::Slice key_slice(
|
||||
reinterpret_cast<char*>(key), key_length);
|
||||
rocksdb::Slice key_slice(reinterpret_cast<char*>(jk_val), len_key);
|
||||
keys.push_back(key_slice);
|
||||
|
||||
keys_to_free.push_back(std::make_tuple(jk_ba, jk_val, jk));
|
||||
}
|
||||
|
||||
std::vector<std::string> values;
|
||||
|
@ -681,13 +671,23 @@ jobject multi_get_helper(JNIEnv* env, jobject jdb, rocksdb::DB* db,
|
|||
s = db->MultiGet(rOpt, cf_handles, keys, &values);
|
||||
}
|
||||
|
||||
// Don't reuse class pointer
|
||||
jclass jclazz = env->FindClass("java/util/ArrayList");
|
||||
jmethodID mid = rocksdb::ListJni::getArrayListConstructorMethodId(
|
||||
env, jclazz);
|
||||
jobject jvalue_list = env->NewObject(jclazz, mid, jkeys_count);
|
||||
// free up allocated byte arrays
|
||||
for (std::vector<std::tuple<jbyteArray, jbyte*, jobject>>::size_type i = 0;
|
||||
i < keys_to_free.size(); i++) {
|
||||
jobject jk;
|
||||
jbyteArray jk_ba;
|
||||
jbyte* jk_val;
|
||||
std::tie(jk_ba, jk_val, jk) = keys_to_free[i];
|
||||
env->ReleaseByteArrayElements(jk_ba, jk_val, JNI_ABORT);
|
||||
env->DeleteLocalRef(jk);
|
||||
}
|
||||
|
||||
// insert in java list
|
||||
// prepare the results
|
||||
jclass jcls_ba = env->FindClass("[B");
|
||||
jobjectArray jresults =
|
||||
env->NewObjectArray(static_cast<jsize>(s.size()), jcls_ba, NULL);
|
||||
|
||||
// add to the jresults
|
||||
for (std::vector<rocksdb::Status>::size_type i = 0; i != s.size(); i++) {
|
||||
if (s[i].ok()) {
|
||||
jbyteArray jentry_value =
|
||||
|
@ -695,73 +695,60 @@ jobject multi_get_helper(JNIEnv* env, jobject jdb, rocksdb::DB* db,
|
|||
env->SetByteArrayRegion(
|
||||
jentry_value, 0, static_cast<jsize>(values[i].size()),
|
||||
reinterpret_cast<const jbyte*>(values[i].c_str()));
|
||||
env->CallBooleanMethod(
|
||||
jvalue_list, rocksdb::ListJni::getListAddMethodId(env),
|
||||
jentry_value);
|
||||
} else {
|
||||
env->CallBooleanMethod(
|
||||
jvalue_list, rocksdb::ListJni::getListAddMethodId(env), nullptr);
|
||||
env->SetObjectArrayElement(jresults, static_cast<jsize>(i), jentry_value);
|
||||
env->DeleteLocalRef(jentry_value);
|
||||
}
|
||||
}
|
||||
// free up allocated byte arrays
|
||||
for (std::vector<jbyte*>::size_type i = 0; i != keys_to_free.size(); i++) {
|
||||
delete[] keys_to_free[i];
|
||||
}
|
||||
keys_to_free.clear();
|
||||
return jvalue_list;
|
||||
|
||||
return jresults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: multiGet
|
||||
* Signature: (JLjava/util/List;I)Ljava/util/List;
|
||||
* Signature: (J[[B)[[B
|
||||
*/
|
||||
jobject Java_org_rocksdb_RocksDB_multiGet__JLjava_util_List_2I(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jobject jkey_list, jint jkeys_count) {
|
||||
jobjectArray Java_org_rocksdb_RocksDB_multiGet__J_3_3B(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jobjectArray jkeys) {
|
||||
return multi_get_helper(env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
||||
rocksdb::ReadOptions(), jkey_list, jkeys_count, nullptr);
|
||||
rocksdb::ReadOptions(), jkeys, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: multiGet
|
||||
* Signature: (JLjava/util/List;ILjava/util/List;)Ljava/util/List;
|
||||
* Signature: (J[[B[J)[[B
|
||||
*/
|
||||
jobject
|
||||
Java_org_rocksdb_RocksDB_multiGet__JLjava_util_List_2ILjava_util_List_2(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jobject jkey_list, jint jkeys_count, jobject jcfhandle_list) {
|
||||
jobjectArray Java_org_rocksdb_RocksDB_multiGet__J_3_3B_3J(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jobjectArray jkeys,
|
||||
jlongArray jcolumn_family_handles) {
|
||||
return multi_get_helper(env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
||||
rocksdb::ReadOptions(), jkey_list, jkeys_count, jcfhandle_list);
|
||||
rocksdb::ReadOptions(), jkeys, jcolumn_family_handles);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: multiGet
|
||||
* Signature: (JJLjava/util/List;I)Ljava/util/List;
|
||||
* Signature: (JJ[[B)[[B
|
||||
*/
|
||||
jobject Java_org_rocksdb_RocksDB_multiGet__JJLjava_util_List_2I(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jlong jropt_handle, jobject jkey_list, jint jkeys_count) {
|
||||
jobjectArray Java_org_rocksdb_RocksDB_multiGet__JJ_3_3B(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jlong jropt_handle,
|
||||
jobjectArray jkeys) {
|
||||
return multi_get_helper(env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
||||
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), jkey_list,
|
||||
jkeys_count, nullptr);
|
||||
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), jkeys, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: multiGet
|
||||
* Signature: (JJLjava/util/List;ILjava/util/List;)Ljava/util/List;
|
||||
* Signature: (JJ[[B[J)[[B
|
||||
*/
|
||||
jobject
|
||||
Java_org_rocksdb_RocksDB_multiGet__JJLjava_util_List_2ILjava_util_List_2(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jlong jropt_handle, jobject jkey_list, jint jkeys_count,
|
||||
jobject jcfhandle_list) {
|
||||
jobjectArray Java_org_rocksdb_RocksDB_multiGet__JJ_3_3B_3J(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle, jlong jropt_handle,
|
||||
jobjectArray jkeys, jlongArray jcolumn_family_handles) {
|
||||
return multi_get_helper(env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
||||
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), jkey_list,
|
||||
jkeys_count, jcfhandle_list);
|
||||
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), jkeys,
|
||||
jcolumn_family_handles);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1129,47 +1116,42 @@ jlong Java_org_rocksdb_RocksDB_iteratorCF__JJJ(
|
|||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: iterators
|
||||
* Signature: (JLjava/util/List;J)[J
|
||||
* Signature: (J[JJ)[J
|
||||
*/
|
||||
jlongArray Java_org_rocksdb_RocksDB_iterators(
|
||||
JNIEnv* env, jobject jdb, jlong db_handle, jobject jcfhandle_list,
|
||||
jlong jread_options_handle) {
|
||||
auto db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
||||
JNIEnv* env, jobject jdb, jlong db_handle,
|
||||
jlongArray jcolumn_family_handles, jlong jread_options_handle) {
|
||||
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
||||
auto& read_options = *reinterpret_cast<rocksdb::ReadOptions*>(
|
||||
jread_options_handle);
|
||||
std::vector<rocksdb::ColumnFamilyHandle*> cf_handles;
|
||||
std::vector<rocksdb::Iterator*> iterators;
|
||||
|
||||
if (jcfhandle_list != nullptr) {
|
||||
// get cf iterator
|
||||
jobject cfIteratorObj = env->CallObjectMethod(
|
||||
jcfhandle_list, rocksdb::ListJni::getIteratorMethod(env));
|
||||
|
||||
// iterate over keys and convert java byte array to slice
|
||||
while (env->CallBooleanMethod(
|
||||
cfIteratorObj, rocksdb::ListJni::getHasNextMethod(env)) == JNI_TRUE) {
|
||||
jobject jobj = (jbyteArray) env->CallObjectMethod(
|
||||
cfIteratorObj, rocksdb::ListJni::getNextMethod(env));
|
||||
rocksdb::ColumnFamilyHandle* cfHandle =
|
||||
rocksdb::ColumnFamilyHandleJni::getHandle(env, jobj);
|
||||
cf_handles.push_back(cfHandle);
|
||||
if (jcolumn_family_handles != nullptr) {
|
||||
jsize len_cols = env->GetArrayLength(jcolumn_family_handles);
|
||||
jlong* jcfh = env->GetLongArrayElements(jcolumn_family_handles, NULL);
|
||||
for (int i = 0; i < len_cols; i++) {
|
||||
auto* cf_handle =
|
||||
reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcfh[i]);
|
||||
cf_handles.push_back(cf_handle);
|
||||
}
|
||||
env->ReleaseLongArrayElements(jcolumn_family_handles, jcfh, JNI_ABORT);
|
||||
}
|
||||
|
||||
std::vector<rocksdb::Iterator*> iterators;
|
||||
rocksdb::Status s = db->NewIterators(read_options,
|
||||
cf_handles, &iterators);
|
||||
if (s.ok()) {
|
||||
jlongArray jLongArray =
|
||||
env->NewLongArray(static_cast<jsize>(iterators.size()));
|
||||
for (std::vector<rocksdb::Iterator*>::size_type i = 0; i < iterators.size();
|
||||
i++) {
|
||||
for (std::vector<rocksdb::Iterator*>::size_type i = 0;
|
||||
i < iterators.size(); i++) {
|
||||
env->SetLongArrayRegion(jLongArray, static_cast<jsize>(i), 1,
|
||||
reinterpret_cast<const jlong*>(&iterators[i]));
|
||||
}
|
||||
return jLongArray;
|
||||
} else {
|
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
||||
return NULL;
|
||||
}
|
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
||||
return env->NewLongArray(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1187,32 +1169,23 @@ jlong Java_org_rocksdb_RocksDB_getDefaultColumnFamily(
|
|||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: createColumnFamily
|
||||
* Signature: (JLorg/rocksdb/ColumnFamilyDescriptor;)J;
|
||||
* Signature: (J[BJ)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_RocksDB_createColumnFamily(
|
||||
JNIEnv* env, jobject jdb, jlong jdb_handle,
|
||||
jobject jcf_descriptor) {
|
||||
jbyteArray jcolumn_name, jlong jcolumn_options) {
|
||||
rocksdb::ColumnFamilyHandle* handle;
|
||||
auto db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
|
||||
// get ColumnFamilyName
|
||||
jbyteArray byteArray = static_cast<jbyteArray>(env->CallObjectMethod(
|
||||
jcf_descriptor,
|
||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
||||
env)));
|
||||
// get CF Options
|
||||
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
||||
env));
|
||||
rocksdb::ColumnFamilyOptions* cfOptions =
|
||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||
jbyte* cfname = env->GetByteArrayElements(jcolumn_name, 0);
|
||||
const int len = env->GetArrayLength(jcolumn_name);
|
||||
|
||||
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||
const int len = env->GetArrayLength(byteArray);
|
||||
auto* cfOptions =
|
||||
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jcolumn_options);
|
||||
|
||||
rocksdb::Status s = db_handle->CreateColumnFamily(
|
||||
*cfOptions, std::string(reinterpret_cast<char *>(cfname), len), &handle);
|
||||
env->ReleaseByteArrayElements(byteArray, cfname, 0);
|
||||
env->ReleaseByteArrayElements(jcolumn_name, cfname, 0);
|
||||
|
||||
if (s.ok()) {
|
||||
return reinterpret_cast<jlong>(handle);
|
||||
|
|
|
@ -113,33 +113,24 @@ jlongArray
|
|||
/*
|
||||
* Class: org_rocksdb_TtlDB
|
||||
* Method: createColumnFamilyWithTtl
|
||||
* Signature: (JLorg/rocksdb/ColumnFamilyDescriptor;I)J;
|
||||
* Signature: (JLorg/rocksdb/ColumnFamilyDescriptor;[BJI)J;
|
||||
*/
|
||||
jlong Java_org_rocksdb_TtlDB_createColumnFamilyWithTtl(
|
||||
JNIEnv* env, jobject jobj, jlong jdb_handle,
|
||||
jobject jcf_descriptor, jint jttl) {
|
||||
jbyteArray jcolumn_name, jlong jcolumn_options, jint jttl) {
|
||||
rocksdb::ColumnFamilyHandle* handle;
|
||||
auto* db_handle = reinterpret_cast<rocksdb::DBWithTTL*>(jdb_handle);
|
||||
|
||||
// get ColumnFamilyName
|
||||
jbyteArray byteArray = static_cast<jbyteArray>(env->CallObjectMethod(
|
||||
jcf_descriptor,
|
||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
||||
env)));
|
||||
// get CF Options
|
||||
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
||||
env));
|
||||
rocksdb::ColumnFamilyOptions* cfOptions =
|
||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||
jbyte* cfname = env->GetByteArrayElements(jcolumn_name, 0);
|
||||
const int len = env->GetArrayLength(jcolumn_name);
|
||||
|
||||
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||
const int len = env->GetArrayLength(byteArray);
|
||||
auto* cfOptions =
|
||||
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jcolumn_options);
|
||||
|
||||
rocksdb::Status s = db_handle->CreateColumnFamilyWithTtl(
|
||||
*cfOptions, std::string(reinterpret_cast<char *>(cfname),
|
||||
len), &handle, jttl);
|
||||
env->ReleaseByteArrayElements(byteArray, cfname, 0);
|
||||
env->ReleaseByteArrayElements(jcolumn_name, cfname, 0);
|
||||
|
||||
if (s.ok()) {
|
||||
return reinterpret_cast<jlong>(handle);
|
||||
|
|
|
@ -39,10 +39,11 @@ jlong Java_org_rocksdb_WriteBatch_newWriteBatch(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: count0
|
||||
* Signature: ()I
|
||||
* Signature: (J)I
|
||||
*/
|
||||
jint Java_org_rocksdb_WriteBatch_count0(JNIEnv* env, jobject jobj) {
|
||||
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
jint Java_org_rocksdb_WriteBatch_count0(JNIEnv* env, jobject jobj,
|
||||
jlong jwb_handle) {
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
|
||||
return static_cast<jint>(wb->Count());
|
||||
|
@ -51,10 +52,11 @@ jint Java_org_rocksdb_WriteBatch_count0(JNIEnv* env, jobject jobj) {
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: clear0
|
||||
* Signature: ()V
|
||||
* Signature: (J)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_clear0(JNIEnv* env, jobject jobj) {
|
||||
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatch_clear0(JNIEnv* env, jobject jobj,
|
||||
jlong jwb_handle) {
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
|
||||
wb->Clear();
|
||||
|
@ -63,13 +65,13 @@ void Java_org_rocksdb_WriteBatch_clear0(JNIEnv* env, jobject jobj) {
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: put
|
||||
* Signature: ([BI[BI)V
|
||||
* Signature: (J[BI[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_put___3BI_3BI(
|
||||
JNIEnv* env, jobject jobj,
|
||||
void Java_org_rocksdb_WriteBatch_put__J_3BI_3BI(
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle,
|
||||
jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto put = [&wb] (rocksdb::Slice key, rocksdb::Slice value) {
|
||||
wb->Put(key, value);
|
||||
|
@ -81,13 +83,13 @@ void Java_org_rocksdb_WriteBatch_put___3BI_3BI(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: put
|
||||
* Signature: ([BI[BIJ)V
|
||||
* Signature: (J[BI[BIJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_put___3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj,
|
||||
void Java_org_rocksdb_WriteBatch_put__J_3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle,
|
||||
jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len, jlong jcf_handle) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
assert(cf_handle != nullptr);
|
||||
|
@ -101,13 +103,13 @@ void Java_org_rocksdb_WriteBatch_put___3BI_3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: merge
|
||||
* Signature: ([BI[BI)V
|
||||
* Signature: (J[BI[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_merge___3BI_3BI(
|
||||
JNIEnv* env, jobject jobj,
|
||||
void Java_org_rocksdb_WriteBatch_merge__J_3BI_3BI(
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle,
|
||||
jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto merge = [&wb] (rocksdb::Slice key, rocksdb::Slice value) {
|
||||
wb->Merge(key, value);
|
||||
|
@ -119,13 +121,13 @@ void Java_org_rocksdb_WriteBatch_merge___3BI_3BI(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: merge
|
||||
* Signature: ([BI[BIJ)V
|
||||
* Signature: (J[BI[BIJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_merge___3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj,
|
||||
void Java_org_rocksdb_WriteBatch_merge__J_3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle,
|
||||
jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len, jlong jcf_handle) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
assert(cf_handle != nullptr);
|
||||
|
@ -139,12 +141,12 @@ void Java_org_rocksdb_WriteBatch_merge___3BI_3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: remove
|
||||
* Signature: ([BI)V
|
||||
* Signature: (J[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_remove___3BI(
|
||||
JNIEnv* env, jobject jobj,
|
||||
void Java_org_rocksdb_WriteBatch_remove__J_3BI(
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle,
|
||||
jbyteArray jkey, jint jkey_len) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto remove = [&wb] (rocksdb::Slice key) {
|
||||
wb->Delete(key);
|
||||
|
@ -155,12 +157,12 @@ void Java_org_rocksdb_WriteBatch_remove___3BI(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: remove
|
||||
* Signature: ([BIJ)V
|
||||
* Signature: (J[BIJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_remove___3BIJ(
|
||||
JNIEnv* env, jobject jobj,
|
||||
void Java_org_rocksdb_WriteBatch_remove__J_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle,
|
||||
jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
assert(cf_handle != nullptr);
|
||||
|
@ -173,11 +175,12 @@ void Java_org_rocksdb_WriteBatch_remove___3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: putLogData
|
||||
* Signature: ([BI)V
|
||||
* Signature: (J[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_putLogData(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jblob, jint jblob_len) {
|
||||
auto* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwb_handle, jbyteArray jblob,
|
||||
jint jblob_len) {
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
auto putLogData = [&wb] (rocksdb::Slice blob) {
|
||||
wb->PutLogData(blob);
|
||||
|
@ -188,11 +191,11 @@ void Java_org_rocksdb_WriteBatch_putLogData(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatch
|
||||
* Method: iterate
|
||||
* Signature: (J)V
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatch_iterate(
|
||||
JNIEnv* env , jobject jobj, jlong handlerHandle) {
|
||||
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
JNIEnv* env , jobject jobj, jlong jwb_handle, jlong handlerHandle) {
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
|
||||
rocksdb::Status s = wb->Iterate(
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchTest
|
||||
* Method: getContents
|
||||
* Signature: (Lorg/rocksdb/WriteBatch;)[B
|
||||
* Signature: (J)[B
|
||||
*/
|
||||
jbyteArray Java_org_rocksdb_WriteBatchTest_getContents(
|
||||
JNIEnv* env, jclass jclazz, jobject jobj) {
|
||||
rocksdb::WriteBatch* b = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jclass jclazz, jlong jwb_handle) {
|
||||
auto* b = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(b != nullptr);
|
||||
|
||||
// todo: Currently the following code is directly copied from
|
||||
|
@ -109,11 +109,11 @@ jbyteArray Java_org_rocksdb_WriteBatchTest_getContents(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchTestInternalHelper
|
||||
* Method: setSequence
|
||||
* Signature: (Lorg/rocksdb/WriteBatch;J)V
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchTestInternalHelper_setSequence(
|
||||
JNIEnv* env, jclass jclazz, jobject jobj, jlong jsn) {
|
||||
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jclass jclazz, jlong jwb_handle, jlong jsn) {
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
|
||||
rocksdb::WriteBatchInternal::SetSequence(
|
||||
|
@ -123,11 +123,11 @@ void Java_org_rocksdb_WriteBatchTestInternalHelper_setSequence(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchTestInternalHelper
|
||||
* Method: sequence
|
||||
* Signature: (Lorg/rocksdb/WriteBatch;)J
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_WriteBatchTestInternalHelper_sequence(
|
||||
JNIEnv* env, jclass jclazz, jobject jobj) {
|
||||
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jclass jclazz, jlong jwb_handle) {
|
||||
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
||||
assert(wb != nullptr);
|
||||
|
||||
return static_cast<jlong>(rocksdb::WriteBatchInternal::Sequence(wb));
|
||||
|
@ -136,13 +136,13 @@ jlong Java_org_rocksdb_WriteBatchTestInternalHelper_sequence(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchTestInternalHelper
|
||||
* Method: append
|
||||
* Signature: (Lorg/rocksdb/WriteBatch;Lorg/rocksdb/WriteBatch;)V
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchTestInternalHelper_append(
|
||||
JNIEnv* env, jclass jclazz, jobject jwb1, jobject jwb2) {
|
||||
rocksdb::WriteBatch* wb1 = rocksdb::WriteBatchJni::getHandle(env, jwb1);
|
||||
JNIEnv* env, jclass jclazz, jlong jwb_handle_1, jlong jwb_handle_2) {
|
||||
auto* wb1 = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle_1);
|
||||
assert(wb1 != nullptr);
|
||||
rocksdb::WriteBatch* wb2 = rocksdb::WriteBatchJni::getHandle(env, jwb2);
|
||||
auto* wb2 = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle_2);
|
||||
assert(wb2 != nullptr);
|
||||
|
||||
rocksdb::WriteBatchInternal::Append(wb1, wb2);
|
||||
|
|
|
@ -53,13 +53,12 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__JIZ(
|
|||
|
||||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: count
|
||||
* Signature: ()I
|
||||
* Method: count0
|
||||
* Signature: (J)I
|
||||
*/
|
||||
jint Java_org_rocksdb_WriteBatchWithIndex_count0(
|
||||
JNIEnv* env, jobject jobj) {
|
||||
rocksdb::WriteBatchWithIndex* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
|
||||
return static_cast<jint>(wbwi->GetWriteBatch()->Count());
|
||||
|
@ -68,13 +67,12 @@ jint Java_org_rocksdb_WriteBatchWithIndex_count0(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: put
|
||||
* Signature: ([BI[BI)V
|
||||
* Signature: (J[BI[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_put___3BI_3BI(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BI(
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
||||
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto put = [&wbwi] (rocksdb::Slice key, rocksdb::Slice value) {
|
||||
wbwi->Put(key, value);
|
||||
|
@ -86,13 +84,13 @@ void Java_org_rocksdb_WriteBatchWithIndex_put___3BI_3BI(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: put
|
||||
* Signature: ([BI[BIJ)V
|
||||
* Signature: (J[BI[BIJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_put___3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len, jlong jcf_handle) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
||||
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
|
||||
jlong jcf_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
assert(cf_handle != nullptr);
|
||||
|
@ -106,13 +104,12 @@ void Java_org_rocksdb_WriteBatchWithIndex_put___3BI_3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: merge
|
||||
* Signature: ([BI[BI)V
|
||||
* Signature: (J[BI[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_merge___3BI_3BI(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BI(
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
||||
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto merge = [&wbwi] (rocksdb::Slice key, rocksdb::Slice value) {
|
||||
wbwi->Merge(key, value);
|
||||
|
@ -124,13 +121,13 @@ void Java_org_rocksdb_WriteBatchWithIndex_merge___3BI_3BI(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: merge
|
||||
* Signature: ([BI[BIJ)V
|
||||
* Signature: (J[BI[BIJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_merge___3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jkey, jint jkey_len,
|
||||
jbyteArray jentry_value, jint jentry_value_len, jlong jcf_handle) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
||||
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
|
||||
jlong jcf_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
assert(cf_handle != nullptr);
|
||||
|
@ -144,12 +141,12 @@ void Java_org_rocksdb_WriteBatchWithIndex_merge___3BI_3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: remove
|
||||
* Signature: ([BI)V
|
||||
* Signature: (J[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_remove___3BI(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jkey, jint jkey_len) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_remove__J_3BI(
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
||||
jint jkey_len) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto remove = [&wbwi] (rocksdb::Slice key) {
|
||||
wbwi->Delete(key);
|
||||
|
@ -160,13 +157,12 @@ void Java_org_rocksdb_WriteBatchWithIndex_remove___3BI(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: remove
|
||||
* Signature: ([BIJ)V
|
||||
* Signature: (J[BIJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_remove___3BIJ(
|
||||
JNIEnv* env, jobject jobj,
|
||||
jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_remove__J_3BIJ(
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
||||
jint jkey_len, jlong jcf_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
assert(cf_handle != nullptr);
|
||||
|
@ -179,12 +175,12 @@ void Java_org_rocksdb_WriteBatchWithIndex_remove___3BIJ(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: putLogData
|
||||
* Signature: ([BI)V
|
||||
* Signature: (J[BI)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_putLogData(
|
||||
JNIEnv* env, jobject jobj, jbyteArray jblob, jint jblob_len) {
|
||||
auto* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jblob,
|
||||
jint jblob_len) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
auto putLogData = [&wbwi] (rocksdb::Slice blob) {
|
||||
wbwi->PutLogData(blob);
|
||||
|
@ -195,12 +191,11 @@ void Java_org_rocksdb_WriteBatchWithIndex_putLogData(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: clear
|
||||
* Signature: ()V
|
||||
* Signature: (J)V
|
||||
*/
|
||||
void Java_org_rocksdb_WriteBatchWithIndex_clear0(
|
||||
JNIEnv* env, jobject jobj) {
|
||||
rocksdb::WriteBatchWithIndex* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
assert(wbwi != nullptr);
|
||||
|
||||
wbwi->GetWriteBatch()->Clear();
|
||||
|
@ -209,12 +204,11 @@ void Java_org_rocksdb_WriteBatchWithIndex_clear0(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: iterator0
|
||||
* Signature: ()J
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_WriteBatchWithIndex_iterator0(
|
||||
JNIEnv* env, jobject jobj) {
|
||||
rocksdb::WriteBatchWithIndex* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
rocksdb::WBWIIterator* wbwi_iterator = wbwi->NewIterator();
|
||||
return reinterpret_cast<jlong>(wbwi_iterator);
|
||||
}
|
||||
|
@ -222,12 +216,11 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_iterator0(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: iterator1
|
||||
* Signature: (J)J
|
||||
* Signature: (JJ)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_WriteBatchWithIndex_iterator1(
|
||||
JNIEnv* env, jobject jobj, jlong jcf_handle) {
|
||||
rocksdb::WriteBatchWithIndex* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jcf_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
rocksdb::WBWIIterator* wbwi_iterator = wbwi->NewIterator(cf_handle);
|
||||
return reinterpret_cast<jlong>(wbwi_iterator);
|
||||
|
@ -236,12 +229,12 @@ jlong Java_org_rocksdb_WriteBatchWithIndex_iterator1(
|
|||
/*
|
||||
* Class: org_rocksdb_WriteBatchWithIndex
|
||||
* Method: iteratorWithBase
|
||||
* Signature: (JJ)J
|
||||
* Signature: (JJJ)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_WriteBatchWithIndex_iteratorWithBase(
|
||||
JNIEnv* env, jobject jobj, jlong jcf_handle, jlong jbi_handle) {
|
||||
rocksdb::WriteBatchWithIndex* wbwi =
|
||||
rocksdb::WriteBatchWithIndexJni::getHandle(env, jobj);
|
||||
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jcf_handle,
|
||||
jlong jbi_handle) {
|
||||
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
||||
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
||||
auto* base_iterator = reinterpret_cast<rocksdb::Iterator*>(jbi_handle);
|
||||
auto* iterator = wbwi->NewIteratorWithBase(cf_handle, base_iterator);
|
||||
|
|
|
@ -14,72 +14,79 @@ public abstract class AbstractWriteBatch extends RocksObject implements WriteBat
|
|||
@Override
|
||||
public int count() {
|
||||
assert (isOwningHandle());
|
||||
return count0();
|
||||
return count0(nativeHandle_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(byte[] key, byte[] value) {
|
||||
assert (isOwningHandle());
|
||||
put(key, key.length, value, value.length);
|
||||
put(nativeHandle_, key, key.length, value, value.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) {
|
||||
assert (isOwningHandle());
|
||||
put(key, key.length, value, value.length, columnFamilyHandle.nativeHandle_);
|
||||
put(nativeHandle_, key, key.length, value, value.length, columnFamilyHandle.nativeHandle_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(byte[] key, byte[] value) {
|
||||
assert (isOwningHandle());
|
||||
merge(key, key.length, value, value.length);
|
||||
merge(nativeHandle_, key, key.length, value, value.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) {
|
||||
assert (isOwningHandle());
|
||||
merge(key, key.length, value, value.length, columnFamilyHandle.nativeHandle_);
|
||||
merge(nativeHandle_, key, key.length, value, value.length, columnFamilyHandle.nativeHandle_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(byte[] key) {
|
||||
assert (isOwningHandle());
|
||||
remove(key, key.length);
|
||||
remove(nativeHandle_, key, key.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key) {
|
||||
assert (isOwningHandle());
|
||||
remove(key, key.length, columnFamilyHandle.nativeHandle_);
|
||||
remove(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putLogData(byte[] blob) {
|
||||
assert (isOwningHandle());
|
||||
putLogData(blob, blob.length);
|
||||
putLogData(nativeHandle_, blob, blob.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
assert (isOwningHandle());
|
||||
clear0();
|
||||
clear0(nativeHandle_);
|
||||
}
|
||||
|
||||
abstract int count0();
|
||||
abstract int count0(final long handle);
|
||||
|
||||
abstract void put(byte[] key, int keyLen, byte[] value, int valueLen);
|
||||
abstract void put(final long handle, final byte[] key, final int keyLen,
|
||||
final byte[] value, final int valueLen);
|
||||
|
||||
abstract void put(byte[] key, int keyLen, byte[] value, int valueLen, long cfHandle);
|
||||
abstract void put(final long handle, final byte[] key, final int keyLen,
|
||||
final byte[] value, final int valueLen, final long cfHandle);
|
||||
|
||||
abstract void merge(byte[] key, int keyLen, byte[] value, int valueLen);
|
||||
abstract void merge(final long handle, final byte[] key, final int keyLen,
|
||||
final byte[] value, final int valueLen);
|
||||
|
||||
abstract void merge(byte[] key, int keyLen, byte[] value, int valueLen, long cfHandle);
|
||||
abstract void merge(final long handle, final byte[] key, final int keyLen,
|
||||
final byte[] value, final int valueLen, final long cfHandle);
|
||||
|
||||
abstract void remove(byte[] key, int keyLen);
|
||||
abstract void remove(final long handle, final byte[] key,
|
||||
final int keyLen);
|
||||
|
||||
abstract void remove(byte[] key, int keyLen, long cfHandle);
|
||||
abstract void remove(final long handle, final byte[] key,
|
||||
final int keyLen, final long cfHandle);
|
||||
|
||||
abstract void putLogData(byte[] blob, int blobLen);
|
||||
abstract void putLogData(final long handle, final byte[] blob,
|
||||
final int blobLen);
|
||||
|
||||
abstract void clear0();
|
||||
abstract void clear0(final long handle);
|
||||
}
|
||||
|
|
|
@ -477,7 +477,7 @@ public class RocksDB extends RocksObject {
|
|||
* @return boolean value indicating if key does not exist or might exist.
|
||||
*/
|
||||
public boolean keyMayExist(final byte[] key, final StringBuffer value){
|
||||
return keyMayExist(key, key.length, value);
|
||||
return keyMayExist(nativeHandle_, key, key.length, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -495,7 +495,7 @@ public class RocksDB extends RocksObject {
|
|||
*/
|
||||
public boolean keyMayExist(final ColumnFamilyHandle columnFamilyHandle,
|
||||
final byte[] key, final StringBuffer value){
|
||||
return keyMayExist(key, key.length, columnFamilyHandle.nativeHandle_,
|
||||
return keyMayExist(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_,
|
||||
value);
|
||||
}
|
||||
|
||||
|
@ -514,7 +514,7 @@ public class RocksDB extends RocksObject {
|
|||
*/
|
||||
public boolean keyMayExist(final ReadOptions readOptions,
|
||||
final byte[] key, final StringBuffer value){
|
||||
return keyMayExist(readOptions.nativeHandle_,
|
||||
return keyMayExist(nativeHandle_, readOptions.nativeHandle_,
|
||||
key, key.length, value);
|
||||
}
|
||||
|
||||
|
@ -535,7 +535,7 @@ public class RocksDB extends RocksObject {
|
|||
public boolean keyMayExist(final ReadOptions readOptions,
|
||||
final ColumnFamilyHandle columnFamilyHandle, final byte[] key,
|
||||
final StringBuffer value){
|
||||
return keyMayExist(readOptions.nativeHandle_,
|
||||
return keyMayExist(nativeHandle_, readOptions.nativeHandle_,
|
||||
key, key.length, columnFamilyHandle.nativeHandle_,
|
||||
value);
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ public class RocksDB extends RocksObject {
|
|||
*/
|
||||
public void write(final WriteOptions writeOpts, final WriteBatch updates)
|
||||
throws RocksDBException {
|
||||
write0(writeOpts.nativeHandle_, updates.nativeHandle_);
|
||||
write0(nativeHandle_, writeOpts.nativeHandle_, updates.nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -565,7 +565,7 @@ public class RocksDB extends RocksObject {
|
|||
*/
|
||||
public void write(final WriteOptions writeOpts,
|
||||
final WriteBatchWithIndex updates) throws RocksDBException {
|
||||
write1(writeOpts.nativeHandle_, updates.nativeHandle_);
|
||||
write1(nativeHandle_, writeOpts.nativeHandle_, updates.nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -811,16 +811,15 @@ public class RocksDB extends RocksObject {
|
|||
throws RocksDBException {
|
||||
assert(keys.size() != 0);
|
||||
|
||||
List<byte[]> values = multiGet(
|
||||
nativeHandle_, keys, keys.size());
|
||||
final byte[][] values = multiGet(nativeHandle_, keys.toArray(new byte[keys.size()][]));
|
||||
|
||||
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if(values.get(i) == null) {
|
||||
for(int i = 0; i < values.length; i++) {
|
||||
if(values[i] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
keyValueMap.put(keys.get(i), values.get(i));
|
||||
keyValueMap.put(keys.get(i), values[i]);
|
||||
}
|
||||
|
||||
return keyValueMap;
|
||||
|
@ -849,19 +848,23 @@ public class RocksDB extends RocksObject {
|
|||
assert(keys.size() != 0);
|
||||
// Check if key size equals cfList size. If not a exception must be
|
||||
// thrown. If not a Segmentation fault happens.
|
||||
if (keys.size()!=columnFamilyHandleList.size()) {
|
||||
if (keys.size() != columnFamilyHandleList.size()) {
|
||||
throw new IllegalArgumentException(
|
||||
"For each key there must be a ColumnFamilyHandle.");
|
||||
}
|
||||
List<byte[]> values = multiGet(nativeHandle_, keys, keys.size(),
|
||||
columnFamilyHandleList);
|
||||
final long[] cfHandles = new long[columnFamilyHandleList.size()];
|
||||
for (int i = 0; i < columnFamilyHandleList.size(); i++) {
|
||||
cfHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
|
||||
}
|
||||
final byte[][] values = multiGet(nativeHandle_, keys.toArray(new byte[keys.size()][]),
|
||||
cfHandles);
|
||||
|
||||
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if (values.get(i) == null) {
|
||||
for(int i = 0; i < values.length; i++) {
|
||||
if (values[i] == null) {
|
||||
continue;
|
||||
}
|
||||
keyValueMap.put(keys.get(i), values.get(i));
|
||||
keyValueMap.put(keys.get(i), values[i]);
|
||||
}
|
||||
return keyValueMap;
|
||||
}
|
||||
|
@ -881,16 +884,15 @@ public class RocksDB extends RocksObject {
|
|||
final List<byte[]> keys) throws RocksDBException {
|
||||
assert(keys.size() != 0);
|
||||
|
||||
List<byte[]> values = multiGet(
|
||||
nativeHandle_, opt.nativeHandle_, keys, keys.size());
|
||||
final byte[][] values = multiGet(nativeHandle_, opt.nativeHandle_, keys.toArray(new byte[keys.size()][]));
|
||||
|
||||
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if(values.get(i) == null) {
|
||||
for(int i = 0; i < values.length; i++) {
|
||||
if(values[i] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
keyValueMap.put(keys.get(i), values.get(i));
|
||||
keyValueMap.put(keys.get(i), values[i]);
|
||||
}
|
||||
|
||||
return keyValueMap;
|
||||
|
@ -925,16 +927,18 @@ public class RocksDB extends RocksObject {
|
|||
throw new IllegalArgumentException(
|
||||
"For each key there must be a ColumnFamilyHandle.");
|
||||
}
|
||||
|
||||
List<byte[]> values = multiGet(nativeHandle_, opt.nativeHandle_,
|
||||
keys, keys.size(), columnFamilyHandleList);
|
||||
final long[] cfHandles = new long[columnFamilyHandleList.size()];
|
||||
for (int i = 0; i < columnFamilyHandleList.size(); i++) {
|
||||
cfHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
|
||||
}
|
||||
final byte[][] values = multiGet(nativeHandle_, opt.nativeHandle_, keys.toArray(new byte[keys.size()][]), cfHandles);
|
||||
|
||||
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if(values.get(i) == null) {
|
||||
for(int i = 0; i < values.length; i++) {
|
||||
if(values[i] == null) {
|
||||
continue;
|
||||
}
|
||||
keyValueMap.put(keys.get(i), values.get(i));
|
||||
keyValueMap.put(keys.get(i), values[i]);
|
||||
}
|
||||
|
||||
return keyValueMap;
|
||||
|
@ -1261,11 +1265,16 @@ public class RocksDB extends RocksObject {
|
|||
public List<RocksIterator> newIterators(
|
||||
final List<ColumnFamilyHandle> columnFamilyHandleList,
|
||||
final ReadOptions readOptions) throws RocksDBException {
|
||||
List<RocksIterator> iterators =
|
||||
new ArrayList<>(columnFamilyHandleList.size());
|
||||
|
||||
long[] iteratorRefs = iterators(nativeHandle_, columnFamilyHandleList,
|
||||
final long[] columnFamilyHandles = new long[columnFamilyHandleList.size()];
|
||||
for (int i = 0; i < columnFamilyHandleList.size(); i++) {
|
||||
columnFamilyHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
|
||||
}
|
||||
|
||||
final long[] iteratorRefs = iterators(nativeHandle_, columnFamilyHandles,
|
||||
readOptions.nativeHandle_);
|
||||
|
||||
final List<RocksIterator> iterators = new ArrayList<>(columnFamilyHandleList.size());
|
||||
for (int i=0; i<columnFamilyHandleList.size(); i++){
|
||||
iterators.add(new RocksIterator(this, iteratorRefs[i]));
|
||||
}
|
||||
|
@ -1299,7 +1308,7 @@ public class RocksDB extends RocksObject {
|
|||
final ColumnFamilyDescriptor columnFamilyDescriptor)
|
||||
throws RocksDBException {
|
||||
return new ColumnFamilyHandle(this, createColumnFamily(nativeHandle_,
|
||||
columnFamilyDescriptor));
|
||||
columnFamilyDescriptor.columnFamilyName(), columnFamilyDescriptor.columnFamilyOptions().nativeHandle_));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1741,18 +1750,20 @@ public class RocksDB extends RocksObject {
|
|||
long handle, long writeOptHandle,
|
||||
byte[] key, int keyLen,
|
||||
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
||||
protected native void write0(
|
||||
long writeOptHandle, long wbHandle) throws RocksDBException;
|
||||
protected native void write1(
|
||||
long writeOptHandle, long wbwiHandle) throws RocksDBException;
|
||||
protected native boolean keyMayExist(byte[] key, int keyLen,
|
||||
StringBuffer stringBuffer);
|
||||
protected native boolean keyMayExist(byte[] key, int keyLen,
|
||||
long cfHandle, StringBuffer stringBuffer);
|
||||
protected native boolean keyMayExist(long optionsHandle, byte[] key, int keyLen,
|
||||
StringBuffer stringBuffer);
|
||||
protected native boolean keyMayExist(long optionsHandle, byte[] key, int keyLen,
|
||||
long cfHandle, StringBuffer stringBuffer);
|
||||
protected native void write0(final long handle, long writeOptHandle,
|
||||
long wbHandle) throws RocksDBException;
|
||||
protected native void write1(final long handle, long writeOptHandle,
|
||||
long wbwiHandle) throws RocksDBException;
|
||||
protected native boolean keyMayExist(final long handle, final byte[] key,
|
||||
final int keyLen, final StringBuffer stringBuffer);
|
||||
protected native boolean keyMayExist(final long handle, final byte[] key,
|
||||
final int keyLen, final long cfHandle, final StringBuffer stringBuffer);
|
||||
protected native boolean keyMayExist(final long handle,
|
||||
final long optionsHandle, final byte[] key, final int keyLen,
|
||||
final StringBuffer stringBuffer);
|
||||
protected native boolean keyMayExist(final long handle,
|
||||
final long optionsHandle, final byte[] key, final int keyLen,
|
||||
final long cfHandle, final StringBuffer stringBuffer);
|
||||
protected native void merge(
|
||||
long handle, byte[] key, int keyLen,
|
||||
byte[] value, int valueLen) throws RocksDBException;
|
||||
|
@ -1779,16 +1790,10 @@ public class RocksDB extends RocksObject {
|
|||
protected native int get(
|
||||
long handle, long readOptHandle, byte[] key, int keyLen,
|
||||
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
||||
protected native List<byte[]> multiGet(
|
||||
long dbHandle, List<byte[]> keys, int keysCount);
|
||||
protected native List<byte[]> multiGet(
|
||||
long dbHandle, List<byte[]> keys, int keysCount, List<ColumnFamilyHandle>
|
||||
cfHandles);
|
||||
protected native List<byte[]> multiGet(
|
||||
long dbHandle, long rOptHandle, List<byte[]> keys, int keysCount);
|
||||
protected native List<byte[]> multiGet(
|
||||
long dbHandle, long rOptHandle, List<byte[]> keys, int keysCount,
|
||||
List<ColumnFamilyHandle> cfHandles);
|
||||
protected native byte[][] multiGet(final long dbHandle, final byte[][] keys);
|
||||
protected native byte[][] multiGet(final long dbHandle, final byte[][] keys, final long[] columnFamilyHandles);
|
||||
protected native byte[][] multiGet(final long dbHandle, final long rOptHandle, final byte[][] keys);
|
||||
protected native byte[][] multiGet(final long dbHandle, final long rOptHandle, final byte[][] keys, final long[] columnFamilyHandles);
|
||||
protected native byte[] get(
|
||||
long handle, byte[] key, int keyLen) throws RocksDBException;
|
||||
protected native byte[] get(
|
||||
|
@ -1822,16 +1827,16 @@ public class RocksDB extends RocksObject {
|
|||
protected native long iteratorCF(long handle, long cfHandle);
|
||||
protected native long iteratorCF(long handle, long cfHandle,
|
||||
long readOptHandle);
|
||||
protected native long[] iterators(long handle,
|
||||
List<ColumnFamilyHandle> columnFamilyNames, long readOptHandle)
|
||||
protected native long[] iterators(final long handle,
|
||||
final long[] columnFamilyHandles, final long readOptHandle)
|
||||
throws RocksDBException;
|
||||
protected native long getSnapshot(long nativeHandle);
|
||||
protected native void releaseSnapshot(
|
||||
long nativeHandle, long snapshotHandle);
|
||||
@Override protected final native void disposeInternal(final long handle);
|
||||
private native long getDefaultColumnFamily(long handle);
|
||||
private native long createColumnFamily(long handle,
|
||||
ColumnFamilyDescriptor columnFamilyDescriptor) throws RocksDBException;
|
||||
private native long createColumnFamily(final long handle,
|
||||
final byte[] columnFamilyName, final long columnFamilyOptions) throws RocksDBException;
|
||||
private native void dropColumnFamily(long handle, long cfHandle) throws RocksDBException;
|
||||
private native void flush(long handle, long flushOptHandle)
|
||||
throws RocksDBException;
|
||||
|
|
|
@ -159,7 +159,8 @@ public class TtlDB extends RocksDB {
|
|||
final int ttl) throws RocksDBException {
|
||||
return new ColumnFamilyHandle(this,
|
||||
createColumnFamilyWithTtl(nativeHandle_,
|
||||
columnFamilyDescriptor, ttl));
|
||||
columnFamilyDescriptor.columnFamilyName(),
|
||||
columnFamilyDescriptor.columnFamilyOptions().nativeHandle_, ttl));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +204,7 @@ public class TtlDB extends RocksDB {
|
|||
final String db_path, final byte[][] columnFamilyNames,
|
||||
final long[] columnFamilyOptions, final int[] ttlValues,
|
||||
final boolean readOnly) throws RocksDBException;
|
||||
private native long createColumnFamilyWithTtl(long handle,
|
||||
ColumnFamilyDescriptor columnFamilyDescriptor, int ttl)
|
||||
private native long createColumnFamilyWithTtl(final long handle,
|
||||
final byte[] columnFamilyName, final long columnFamilyOptions, int ttl)
|
||||
throws RocksDBException;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class WriteBatch extends AbstractWriteBatch {
|
|||
* @throws RocksDBException If we cannot iterate over the batch
|
||||
*/
|
||||
public void iterate(final Handler handler) throws RocksDBException {
|
||||
iterate(handler.nativeHandle_);
|
||||
iterate(nativeHandle_, handler.nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,20 +64,27 @@ public class WriteBatch extends AbstractWriteBatch {
|
|||
}
|
||||
|
||||
@Override protected final native void disposeInternal(final long handle);
|
||||
@Override final native int count0();
|
||||
@Override final native void put(byte[] key, int keyLen, byte[] value, int valueLen);
|
||||
@Override final native void put(byte[] key, int keyLen, byte[] value, int valueLen,
|
||||
long cfHandle);
|
||||
@Override final native void merge(byte[] key, int keyLen, byte[] value, int valueLen);
|
||||
@Override final native void merge(byte[] key, int keyLen, byte[] value, int valueLen,
|
||||
long cfHandle);
|
||||
@Override final native void remove(byte[] key, int keyLen);
|
||||
@Override final native void remove(byte[] key, int keyLen, long cfHandle);
|
||||
@Override final native void putLogData(byte[] blob, int blobLen);
|
||||
@Override final native void clear0();
|
||||
@Override final native int count0(final long handle);
|
||||
@Override final native void put(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen);
|
||||
@Override final native void put(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen,
|
||||
final long cfHandle);
|
||||
@Override final native void merge(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen);
|
||||
@Override final native void merge(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen,
|
||||
final long cfHandle);
|
||||
@Override final native void remove(final long handle, final byte[] key,
|
||||
final int keyLen);
|
||||
@Override final native void remove(final long handle, final byte[] key,
|
||||
final int keyLen, final long cfHandle);
|
||||
@Override final native void putLogData(final long handle,
|
||||
final byte[] blob, final int blobLen);
|
||||
@Override final native void clear0(final long handle);
|
||||
|
||||
private native static long newWriteBatch(int reserved_bytes);
|
||||
private native void iterate(long handlerHandle) throws RocksDBException;
|
||||
private native static long newWriteBatch(final int reserved_bytes);
|
||||
private native void iterate(final long handle, final long handlerHandle) throws RocksDBException;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,7 +73,8 @@ public class WriteBatchWithIndex extends AbstractWriteBatch {
|
|||
* @return An iterator for the Write Batch contents, restricted to the column family
|
||||
*/
|
||||
public WBWIRocksIterator newIterator(final ColumnFamilyHandle columnFamilyHandle) {
|
||||
return new WBWIRocksIterator(this, iterator1(columnFamilyHandle.nativeHandle_));
|
||||
return new WBWIRocksIterator(this, iterator1(nativeHandle_,
|
||||
columnFamilyHandle.nativeHandle_));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +88,7 @@ public class WriteBatchWithIndex extends AbstractWriteBatch {
|
|||
* @return An iterator for the Write Batch contents
|
||||
*/
|
||||
public WBWIRocksIterator newIterator() {
|
||||
return new WBWIRocksIterator(this, iterator0());
|
||||
return new WBWIRocksIterator(this, iterator0(nativeHandle_));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,7 +105,9 @@ public class WriteBatchWithIndex extends AbstractWriteBatch {
|
|||
final RocksIterator baseIterator) {
|
||||
RocksIterator iterator = new RocksIterator(
|
||||
baseIterator.parent_,
|
||||
iteratorWithBase(columnFamilyHandle.nativeHandle_, baseIterator.nativeHandle_));
|
||||
iteratorWithBase(nativeHandle_,
|
||||
columnFamilyHandle.nativeHandle_,
|
||||
baseIterator.nativeHandle_));
|
||||
//when the iterator is deleted it will also delete the baseIterator
|
||||
baseIterator.disOwnNativeHandle();
|
||||
return iterator;
|
||||
|
@ -124,24 +127,31 @@ public class WriteBatchWithIndex extends AbstractWriteBatch {
|
|||
}
|
||||
|
||||
@Override protected final native void disposeInternal(final long handle);
|
||||
@Override final native int count0();
|
||||
@Override final native void put(byte[] key, int keyLen, byte[] value, int valueLen);
|
||||
@Override final native void put(byte[] key, int keyLen, byte[] value, int valueLen,
|
||||
long cfHandle);
|
||||
@Override final native void merge(byte[] key, int keyLen, byte[] value, int valueLen);
|
||||
@Override final native void merge(byte[] key, int keyLen, byte[] value, int valueLen,
|
||||
long cfHandle);
|
||||
@Override final native void remove(byte[] key, int keyLen);
|
||||
@Override final native void remove(byte[] key, int keyLen, long cfHandle);
|
||||
@Override final native void putLogData(byte[] blob, int blobLen);
|
||||
@Override final native void clear0();
|
||||
@Override final native int count0(final long handle);
|
||||
@Override final native void put(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen);
|
||||
@Override final native void put(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen,
|
||||
final long cfHandle);
|
||||
@Override final native void merge(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen);
|
||||
@Override final native void merge(final long handle, final byte[] key,
|
||||
final int keyLen, final byte[] value, final int valueLen,
|
||||
final long cfHandle);
|
||||
@Override final native void remove(final long handle, final byte[] key,
|
||||
final int keyLen);
|
||||
@Override final native void remove(final long handle, final byte[] key,
|
||||
final int keyLen, final long cfHandle);
|
||||
@Override final native void putLogData(final long handle, final byte[] blob,
|
||||
final int blobLen);
|
||||
@Override final native void clear0(final long handle);
|
||||
|
||||
private native static long newWriteBatchWithIndex();
|
||||
private native static long newWriteBatchWithIndex(final boolean overwriteKey);
|
||||
private native static long newWriteBatchWithIndex(
|
||||
final long fallbackIndexComparatorHandle, final int reservedBytes,
|
||||
final boolean overwriteKey);
|
||||
private native long iterator0();
|
||||
private native long iterator1(long cfHandle);
|
||||
private native long iteratorWithBase(long baseIteratorHandle, long cfHandle);
|
||||
private native long iterator0(final long handle);
|
||||
private native long iterator1(final long handle, final long cfHandle);
|
||||
private native long iteratorWithBase(final long handle, final long baseIteratorHandle, final long cfHandle);
|
||||
}
|
||||
|
|
|
@ -383,9 +383,7 @@ public class ColumnFamilyTest {
|
|||
db.put(columnFamilyHandleList.get(0), "key".getBytes(), "value".getBytes());
|
||||
db.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(), "value".getBytes());
|
||||
|
||||
List<byte[]> keys = new ArrayList<>();
|
||||
keys.add("key".getBytes());
|
||||
keys.add("newcfkey".getBytes());
|
||||
List<byte[]> keys = Arrays.asList(new byte[][]{"key".getBytes(), "newcfkey".getBytes()});
|
||||
Map<byte[], byte[]> retValues = db.multiGet(columnFamilyHandleList, keys);
|
||||
assertThat(retValues.size()).isEqualTo(2);
|
||||
assertThat(new String(retValues.get(keys.get(0))))
|
||||
|
|
|
@ -9,10 +9,7 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -174,7 +171,7 @@ public class RocksDBTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void multiGet() throws RocksDBException {
|
||||
public void multiGet() throws RocksDBException, InterruptedException {
|
||||
RocksDB db = null;
|
||||
ReadOptions rOpt = null;
|
||||
try {
|
||||
|
@ -182,10 +179,9 @@ public class RocksDBTest {
|
|||
rOpt = new ReadOptions();
|
||||
db.put("key1".getBytes(), "value".getBytes());
|
||||
db.put("key2".getBytes(), "12345678".getBytes());
|
||||
List<byte[]> lookupKeys = new ArrayList<byte[]>() {{
|
||||
add("key1".getBytes());
|
||||
add("key2".getBytes());
|
||||
}};
|
||||
List<byte[]> lookupKeys = new ArrayList<>();
|
||||
lookupKeys.add("key1".getBytes());
|
||||
lookupKeys.add("key2".getBytes());
|
||||
Map<byte[], byte[]> results = db.multiGet(lookupKeys);
|
||||
assertThat(results).isNotNull();
|
||||
assertThat(results.values()).isNotNull();
|
||||
|
|
|
@ -109,7 +109,11 @@ public class WriteBatchTest {
|
|||
.equals(new String(getContents(batch), "US-ASCII")));
|
||||
}
|
||||
|
||||
static native byte[] getContents(WriteBatch batch);
|
||||
static byte[] getContents(final WriteBatch wb) {
|
||||
return getContents(wb.nativeHandle_);
|
||||
}
|
||||
|
||||
private static native byte[] getContents(final long writeBatchHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +121,19 @@ public class WriteBatchTest {
|
|||
* c++ WriteBatchInternal.
|
||||
*/
|
||||
class WriteBatchTestInternalHelper {
|
||||
static native void setSequence(WriteBatch batch, long sn);
|
||||
static native long sequence(WriteBatch batch);
|
||||
static native void append(WriteBatch b1, WriteBatch b2);
|
||||
static void setSequence(final WriteBatch wb, final long sn) {
|
||||
setSequence(wb.nativeHandle_, sn);
|
||||
}
|
||||
|
||||
static long sequence(final WriteBatch wb) {
|
||||
return sequence(wb.nativeHandle_);
|
||||
}
|
||||
|
||||
static void append(final WriteBatch wb1, final WriteBatch wb2) {
|
||||
append(wb1.nativeHandle_, wb2.nativeHandle_);
|
||||
}
|
||||
|
||||
private static native void setSequence(final long writeBatchHandle, final long sn);
|
||||
private static native long sequence(final long writeBatchHandle);
|
||||
private static native void append(final long writeBatchHandle1, final long writeBatchHandle2);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue