Fix code style problems identified by lint
This commit is contained in:
parent
25641bfc9c
commit
5e25274110
@ -18,7 +18,7 @@
|
|||||||
#include "rocksjni/comparatorjnicallback.h"
|
#include "rocksjni/comparatorjnicallback.h"
|
||||||
#include "rocksjni/portal.h"
|
#include "rocksjni/portal.h"
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.ComparatorOptions">
|
// <editor-fold desc="org.rocksdb.ComparatorOptions">
|
||||||
|
|
||||||
void Java_org_rocksdb_ComparatorOptions_newComparatorOptions(
|
void Java_org_rocksdb_ComparatorOptions_newComparatorOptions(
|
||||||
JNIEnv* env, jobject jobj, jstring jpath, jboolean jshare_table_files,
|
JNIEnv* env, jobject jobj, jstring jpath, jboolean jshare_table_files,
|
||||||
@ -37,10 +37,9 @@ void Java_org_rocksdb_ComparatorOptions_newComparatorOptions(
|
|||||||
|
|
||||||
rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt);
|
rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt);
|
||||||
}
|
}
|
||||||
|
// </editor-fold>
|
||||||
|
|
||||||
//</editor-fold>
|
// <editor-fold desc="org.rocksdb.AbstractComparator>
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.AbstractComparator>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_AbstractComparator
|
* Class: org_rocksdb_AbstractComparator
|
||||||
@ -51,10 +50,9 @@ void Java_org_rocksdb_AbstractComparator_disposeInternal(
|
|||||||
JNIEnv* env, jobject jobj, jlong handle) {
|
JNIEnv* env, jobject jobj, jlong handle) {
|
||||||
delete reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(handle);
|
delete reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(handle);
|
||||||
}
|
}
|
||||||
|
// </editor-fold>
|
||||||
|
|
||||||
//</editor-fold>
|
// <editor-fold desc="org.rocksdb.Comparator>
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.Comparator>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_Comparator
|
* Class: org_rocksdb_Comparator
|
||||||
@ -63,14 +61,15 @@ void Java_org_rocksdb_AbstractComparator_disposeInternal(
|
|||||||
*/
|
*/
|
||||||
void Java_org_rocksdb_Comparator_createNewComparator0(
|
void Java_org_rocksdb_Comparator_createNewComparator0(
|
||||||
JNIEnv* env, jobject jobj, jlong copt_handle) {
|
JNIEnv* env, jobject jobj, jlong copt_handle) {
|
||||||
const rocksdb::ComparatorJniCallbackOptions* copt = reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle);
|
const rocksdb::ComparatorJniCallbackOptions* copt =
|
||||||
const rocksdb::ComparatorJniCallback* c = new rocksdb::ComparatorJniCallback(env, jobj, copt);
|
reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle);
|
||||||
|
const rocksdb::ComparatorJniCallback* c =
|
||||||
|
new rocksdb::ComparatorJniCallback(env, jobj, copt);
|
||||||
rocksdb::AbstractComparatorJni::setHandle(env, jobj, c);
|
rocksdb::AbstractComparatorJni::setHandle(env, jobj, c);
|
||||||
}
|
}
|
||||||
|
// </editor-fold>
|
||||||
|
|
||||||
//</editor-fold>
|
// <editor-fold desc="org.rocksdb.DirectComparator>
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.DirectComparator>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_DirectComparator
|
* Class: org_rocksdb_DirectComparator
|
||||||
@ -79,10 +78,10 @@ void Java_org_rocksdb_Comparator_createNewComparator0(
|
|||||||
*/
|
*/
|
||||||
void Java_org_rocksdb_DirectComparator_createNewDirectComparator0(
|
void Java_org_rocksdb_DirectComparator_createNewDirectComparator0(
|
||||||
JNIEnv* env, jobject jobj, jlong copt_handle) {
|
JNIEnv* env, jobject jobj, jlong copt_handle) {
|
||||||
const rocksdb::ComparatorJniCallbackOptions* copt = reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle);
|
const rocksdb::ComparatorJniCallbackOptions* copt =
|
||||||
const rocksdb::DirectComparatorJniCallback* c = new rocksdb::DirectComparatorJniCallback(env, jobj, copt);
|
reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle);
|
||||||
|
const rocksdb::DirectComparatorJniCallback* c =
|
||||||
|
new rocksdb::DirectComparatorJniCallback(env, jobj, copt);
|
||||||
rocksdb::AbstractComparatorJni::setHandle(env, jobj, c);
|
rocksdb::AbstractComparatorJni::setHandle(env, jobj, c);
|
||||||
}
|
}
|
||||||
|
// </editor-fold>
|
||||||
//</editor-fold>
|
|
||||||
|
|
||||||
|
@ -7,14 +7,15 @@
|
|||||||
// rocksdb::Comparator.
|
// rocksdb::Comparator.
|
||||||
|
|
||||||
#include "rocksjni/comparatorjnicallback.h"
|
#include "rocksjni/comparatorjnicallback.h"
|
||||||
#include "portal.h"
|
#include "rocksjni/portal.h"
|
||||||
|
|
||||||
namespace rocksdb {
|
namespace rocksdb {
|
||||||
BaseComparatorJniCallback::BaseComparatorJniCallback(
|
BaseComparatorJniCallback::BaseComparatorJniCallback(
|
||||||
JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt) {
|
JNIEnv* env, jobject jComparator,
|
||||||
|
const ComparatorJniCallbackOptions* copt) {
|
||||||
|
|
||||||
//mutex is used for synchronisation when we are re-using
|
// mutex is used for synchronisation when we are re-using
|
||||||
//the global java slice objects
|
// the global java slice objects
|
||||||
mutex_ = new port::Mutex(copt->use_adaptive_mutex);
|
mutex_ = new port::Mutex(copt->use_adaptive_mutex);
|
||||||
|
|
||||||
// Note: Comparator methods may be accessed by multiple threads,
|
// Note: Comparator methods may be accessed by multiple threads,
|
||||||
@ -30,11 +31,13 @@ BaseComparatorJniCallback::BaseComparatorJniCallback(
|
|||||||
// so we cache it in a global var
|
// so we cache it in a global var
|
||||||
jmethodID jNameMethodId = AbstractComparatorJni::getNameMethodId(env);
|
jmethodID jNameMethodId = AbstractComparatorJni::getNameMethodId(env);
|
||||||
jstring jsName = (jstring)env->CallObjectMethod(m_jComparator, jNameMethodId);
|
jstring jsName = (jstring)env->CallObjectMethod(m_jComparator, jNameMethodId);
|
||||||
m_name = JniUtil::copyString(env, jsName); //also releases jsName
|
m_name = JniUtil::copyString(env, jsName); // also releases jsName
|
||||||
|
|
||||||
m_jCompareMethodId = AbstractComparatorJni::getCompareMethodId(env);
|
m_jCompareMethodId = AbstractComparatorJni::getCompareMethodId(env);
|
||||||
m_jFindShortestSeparatorMethodId = AbstractComparatorJni::getFindShortestSeparatorMethodId(env);
|
m_jFindShortestSeparatorMethodId =
|
||||||
m_jFindShortSuccessorMethodId = AbstractComparatorJni::getFindShortSuccessorMethodId(env);
|
AbstractComparatorJni::getFindShortestSeparatorMethodId(env);
|
||||||
|
m_jFindShortSuccessorMethodId =
|
||||||
|
AbstractComparatorJni::getFindShortSuccessorMethodId(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,24 +45,25 @@ BaseComparatorJniCallback::BaseComparatorJniCallback(
|
|||||||
*/
|
*/
|
||||||
JNIEnv* BaseComparatorJniCallback::getJniEnv() const {
|
JNIEnv* BaseComparatorJniCallback::getJniEnv() const {
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
jint rs = m_jvm->AttachCurrentThread((void **)&env, NULL);
|
jint rs = m_jvm->AttachCurrentThread(reinterpret_cast<void **>(&env), NULL);
|
||||||
assert(rs == JNI_OK);
|
assert(rs == JNI_OK);
|
||||||
return env;
|
return env;
|
||||||
};
|
}
|
||||||
|
|
||||||
const char* BaseComparatorJniCallback::Name() const {
|
const char* BaseComparatorJniCallback::Name() const {
|
||||||
return m_name.c_str();
|
return m_name.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseComparatorJniCallback::Compare(const Slice& a, const Slice& b) const {
|
int BaseComparatorJniCallback::Compare(const Slice& a, const Slice& b) const {
|
||||||
|
|
||||||
JNIEnv* m_env = getJniEnv();
|
JNIEnv* m_env = getJniEnv();
|
||||||
|
|
||||||
mutex_->Lock();
|
mutex_->Lock();
|
||||||
|
|
||||||
AbstractSliceJni::setHandle(m_env, m_jSliceA, &a);
|
AbstractSliceJni::setHandle(m_env, m_jSliceA, &a);
|
||||||
AbstractSliceJni::setHandle(m_env, m_jSliceB, &b);
|
AbstractSliceJni::setHandle(m_env, m_jSliceB, &b);
|
||||||
jint result = m_env->CallIntMethod(m_jComparator, m_jCompareMethodId, m_jSliceA, m_jSliceB);
|
jint result =
|
||||||
|
m_env->CallIntMethod(m_jComparator, m_jCompareMethodId, m_jSliceA,
|
||||||
|
m_jSliceB);
|
||||||
|
|
||||||
mutex_->Unlock();
|
mutex_->Unlock();
|
||||||
|
|
||||||
@ -68,8 +72,8 @@ int BaseComparatorJniCallback::Compare(const Slice& a, const Slice& b) const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseComparatorJniCallback::FindShortestSeparator(std::string* start, const Slice& limit) const {
|
void BaseComparatorJniCallback::FindShortestSeparator(
|
||||||
|
std::string* start, const Slice& limit) const {
|
||||||
if (start == nullptr) {
|
if (start == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,22 +86,24 @@ void BaseComparatorJniCallback::FindShortestSeparator(std::string* start, const
|
|||||||
mutex_->Lock();
|
mutex_->Lock();
|
||||||
|
|
||||||
AbstractSliceJni::setHandle(m_env, m_jSliceLimit, &limit);
|
AbstractSliceJni::setHandle(m_env, m_jSliceLimit, &limit);
|
||||||
jstring jsResultStart = (jstring)m_env->CallObjectMethod(m_jComparator, m_jFindShortestSeparatorMethodId, jsStart, m_jSliceLimit);
|
jstring jsResultStart =
|
||||||
|
(jstring)m_env->CallObjectMethod(m_jComparator,
|
||||||
|
m_jFindShortestSeparatorMethodId, jsStart, m_jSliceLimit);
|
||||||
|
|
||||||
mutex_->Unlock();
|
mutex_->Unlock();
|
||||||
|
|
||||||
m_env->DeleteLocalRef(jsStart);
|
m_env->DeleteLocalRef(jsStart);
|
||||||
|
|
||||||
if(jsResultStart != nullptr) {
|
if (jsResultStart != nullptr) {
|
||||||
//update start with result
|
// update start with result
|
||||||
*start = JniUtil::copyString(m_env, jsResultStart); //also releases jsResultStart
|
*start =
|
||||||
|
JniUtil::copyString(m_env, jsResultStart); // also releases jsResultStart
|
||||||
}
|
}
|
||||||
|
|
||||||
m_jvm->DetachCurrentThread();
|
m_jvm->DetachCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const {
|
void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const {
|
||||||
|
|
||||||
if (key == nullptr) {
|
if (key == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -107,13 +113,16 @@ void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const {
|
|||||||
const char* keyUtf = key->c_str();
|
const char* keyUtf = key->c_str();
|
||||||
jstring jsKey = m_env->NewStringUTF(keyUtf);
|
jstring jsKey = m_env->NewStringUTF(keyUtf);
|
||||||
|
|
||||||
jstring jsResultKey = (jstring)m_env->CallObjectMethod(m_jComparator, m_jFindShortSuccessorMethodId, jsKey);
|
jstring jsResultKey =
|
||||||
|
(jstring)m_env->CallObjectMethod(m_jComparator,
|
||||||
|
m_jFindShortSuccessorMethodId, jsKey);
|
||||||
|
|
||||||
m_env->DeleteLocalRef(jsKey);
|
m_env->DeleteLocalRef(jsKey);
|
||||||
|
|
||||||
if(jsResultKey != nullptr) {
|
if (jsResultKey != nullptr) {
|
||||||
//update key with result
|
// update key with result
|
||||||
*key = JniUtil::copyString(m_env, jsResultKey); //also releases jsResultKey
|
*key =
|
||||||
|
JniUtil::copyString(m_env, jsResultKey); // also releases jsResultKey
|
||||||
}
|
}
|
||||||
|
|
||||||
m_jvm->DetachCurrentThread();
|
m_jvm->DetachCurrentThread();
|
||||||
@ -121,7 +130,7 @@ void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const {
|
|||||||
|
|
||||||
BaseComparatorJniCallback::~BaseComparatorJniCallback() {
|
BaseComparatorJniCallback::~BaseComparatorJniCallback() {
|
||||||
JNIEnv* m_env = getJniEnv();
|
JNIEnv* m_env = getJniEnv();
|
||||||
|
|
||||||
m_env->DeleteGlobalRef(m_jComparator);
|
m_env->DeleteGlobalRef(m_jComparator);
|
||||||
m_env->DeleteGlobalRef(m_jSliceA);
|
m_env->DeleteGlobalRef(m_jSliceA);
|
||||||
m_env->DeleteGlobalRef(m_jSliceB);
|
m_env->DeleteGlobalRef(m_jSliceB);
|
||||||
@ -129,21 +138,23 @@ BaseComparatorJniCallback::~BaseComparatorJniCallback() {
|
|||||||
|
|
||||||
// Note: do not need to explicitly detach, as this function is effectively
|
// Note: do not need to explicitly detach, as this function is effectively
|
||||||
// called from the Java class's disposeInternal method, and so already
|
// called from the Java class's disposeInternal method, and so already
|
||||||
// has an attached thread, getJniEnv above is just a no-op Attach to get the env
|
// has an attached thread, getJniEnv above is just a no-op Attach to get
|
||||||
//jvm->DetachCurrentThread();
|
// the env jvm->DetachCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
ComparatorJniCallback::ComparatorJniCallback(
|
ComparatorJniCallback::ComparatorJniCallback(
|
||||||
JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt) : BaseComparatorJniCallback(env, jComparator, copt) {
|
JNIEnv* env, jobject jComparator,
|
||||||
|
const ComparatorJniCallbackOptions* copt) :
|
||||||
|
BaseComparatorJniCallback(env, jComparator, copt) {
|
||||||
m_jSliceA = env->NewGlobalRef(SliceJni::construct0(env));
|
m_jSliceA = env->NewGlobalRef(SliceJni::construct0(env));
|
||||||
m_jSliceB = env->NewGlobalRef(SliceJni::construct0(env));
|
m_jSliceB = env->NewGlobalRef(SliceJni::construct0(env));
|
||||||
m_jSliceLimit = env->NewGlobalRef(SliceJni::construct0(env));
|
m_jSliceLimit = env->NewGlobalRef(SliceJni::construct0(env));
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectComparatorJniCallback::DirectComparatorJniCallback(
|
DirectComparatorJniCallback::DirectComparatorJniCallback(
|
||||||
JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt) : BaseComparatorJniCallback(env, jComparator, copt) {
|
JNIEnv* env, jobject jComparator,
|
||||||
|
const ComparatorJniCallbackOptions* copt) :
|
||||||
|
BaseComparatorJniCallback(env, jComparator, copt) {
|
||||||
m_jSliceA = env->NewGlobalRef(DirectSliceJni::construct0(env));
|
m_jSliceA = env->NewGlobalRef(DirectSliceJni::construct0(env));
|
||||||
m_jSliceB = env->NewGlobalRef(DirectSliceJni::construct0(env));
|
m_jSliceB = env->NewGlobalRef(DirectSliceJni::construct0(env));
|
||||||
m_jSliceLimit = env->NewGlobalRef(DirectSliceJni::construct0(env));
|
m_jSliceLimit = env->NewGlobalRef(DirectSliceJni::construct0(env));
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#define JAVA_ROCKSJNI_COMPARATORJNICALLBACK_H_
|
#define JAVA_ROCKSJNI_COMPARATORJNICALLBACK_H_
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
#include <string>
|
||||||
#include "rocksdb/comparator.h"
|
#include "rocksdb/comparator.h"
|
||||||
#include "rocksdb/slice.h"
|
#include "rocksdb/slice.h"
|
||||||
#include "port/port.h"
|
#include "port/port.h"
|
||||||
@ -43,15 +44,18 @@ struct ComparatorJniCallbackOptions {
|
|||||||
* introduce locking in regions of those methods via mutex_.
|
* introduce locking in regions of those methods via mutex_.
|
||||||
*/
|
*/
|
||||||
class BaseComparatorJniCallback : public Comparator {
|
class BaseComparatorJniCallback : public Comparator {
|
||||||
public:
|
public:
|
||||||
BaseComparatorJniCallback(JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt);
|
BaseComparatorJniCallback(
|
||||||
|
JNIEnv* env, jobject jComparator,
|
||||||
|
const ComparatorJniCallbackOptions* copt);
|
||||||
virtual ~BaseComparatorJniCallback();
|
virtual ~BaseComparatorJniCallback();
|
||||||
virtual const char* Name() const;
|
virtual const char* Name() const;
|
||||||
virtual int Compare(const Slice& a, const Slice& b) const;
|
virtual int Compare(const Slice& a, const Slice& b) const;
|
||||||
virtual void FindShortestSeparator(std::string* start, const Slice& limit) const;
|
virtual void FindShortestSeparator(
|
||||||
|
std::string* start, const Slice& limit) const;
|
||||||
virtual void FindShortSuccessor(std::string* key) const;
|
virtual void FindShortSuccessor(std::string* key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
port::Mutex* mutex_;
|
port::Mutex* mutex_;
|
||||||
JavaVM* m_jvm;
|
JavaVM* m_jvm;
|
||||||
jobject m_jComparator;
|
jobject m_jComparator;
|
||||||
@ -61,20 +65,24 @@ class BaseComparatorJniCallback : public Comparator {
|
|||||||
jmethodID m_jFindShortSuccessorMethodId;
|
jmethodID m_jFindShortSuccessorMethodId;
|
||||||
JNIEnv* getJniEnv() const;
|
JNIEnv* getJniEnv() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
jobject m_jSliceA;
|
jobject m_jSliceA;
|
||||||
jobject m_jSliceB;
|
jobject m_jSliceB;
|
||||||
jobject m_jSliceLimit;
|
jobject m_jSliceLimit;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ComparatorJniCallback : public BaseComparatorJniCallback {
|
class ComparatorJniCallback : public BaseComparatorJniCallback {
|
||||||
public:
|
public:
|
||||||
ComparatorJniCallback(JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt);
|
ComparatorJniCallback(
|
||||||
|
JNIEnv* env, jobject jComparator,
|
||||||
|
const ComparatorJniCallbackOptions* copt);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirectComparatorJniCallback : public BaseComparatorJniCallback {
|
class DirectComparatorJniCallback : public BaseComparatorJniCallback {
|
||||||
public:
|
public:
|
||||||
DirectComparatorJniCallback(JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt);
|
DirectComparatorJniCallback(
|
||||||
|
JNIEnv* env, jobject jComparator,
|
||||||
|
const ComparatorJniCallbackOptions* copt);
|
||||||
};
|
};
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "include/org_rocksdb_ReadOptions.h"
|
#include "include/org_rocksdb_ReadOptions.h"
|
||||||
#include "include/org_rocksdb_ComparatorOptions.h"
|
#include "include/org_rocksdb_ComparatorOptions.h"
|
||||||
|
|
||||||
|
#include "rocksjni/comparatorjnicallback.h"
|
||||||
#include "rocksjni/portal.h"
|
#include "rocksjni/portal.h"
|
||||||
#include "rocksdb/db.h"
|
#include "rocksdb/db.h"
|
||||||
#include "rocksdb/options.h"
|
#include "rocksdb/options.h"
|
||||||
@ -25,7 +26,6 @@
|
|||||||
#include "rocksdb/slice_transform.h"
|
#include "rocksdb/slice_transform.h"
|
||||||
#include "rocksdb/rate_limiter.h"
|
#include "rocksdb/rate_limiter.h"
|
||||||
#include "rocksdb/comparator.h"
|
#include "rocksdb/comparator.h"
|
||||||
#include "comparatorjnicallback.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_Options
|
* Class: org_rocksdb_Options
|
||||||
@ -1794,7 +1794,8 @@ void Java_org_rocksdb_ComparatorOptions_newComparatorOptions(
|
|||||||
*/
|
*/
|
||||||
jboolean Java_org_rocksdb_ComparatorOptions_useAdaptiveMutex(
|
jboolean Java_org_rocksdb_ComparatorOptions_useAdaptiveMutex(
|
||||||
JNIEnv * env, jobject jobj, jlong jhandle) {
|
JNIEnv * env, jobject jobj, jlong jhandle) {
|
||||||
return reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)->use_adaptive_mutex;
|
return reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)
|
||||||
|
->use_adaptive_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1804,8 +1805,8 @@ jboolean Java_org_rocksdb_ComparatorOptions_useAdaptiveMutex(
|
|||||||
*/
|
*/
|
||||||
void Java_org_rocksdb_ComparatorOptions_setUseAdaptiveMutex(
|
void Java_org_rocksdb_ComparatorOptions_setUseAdaptiveMutex(
|
||||||
JNIEnv * env, jobject jobj, jlong jhandle, jboolean juse_adaptive_mutex) {
|
JNIEnv * env, jobject jobj, jlong jhandle, jboolean juse_adaptive_mutex) {
|
||||||
reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)->use_adaptive_mutex =
|
reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)
|
||||||
static_cast<bool>(juse_adaptive_mutex);
|
->use_adaptive_mutex = static_cast<bool>(juse_adaptive_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "rocksdb/db.h"
|
#include "rocksdb/db.h"
|
||||||
#include "rocksdb/filter_policy.h"
|
#include "rocksdb/filter_policy.h"
|
||||||
#include "rocksdb/status.h"
|
#include "rocksdb/status.h"
|
||||||
@ -364,7 +366,7 @@ class ColumnFamilyHandleJni {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class ComparatorOptionsJni {
|
class ComparatorOptionsJni {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.ComparatorOptions.
|
// Get the java class id of org.rocksdb.ComparatorOptions.
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/ComparatorOptions");
|
jclass jclazz = env->FindClass("org/rocksdb/ComparatorOptions");
|
||||||
@ -383,7 +385,8 @@ class ComparatorOptionsJni {
|
|||||||
|
|
||||||
// Pass the ComparatorJniCallbackOptions pointer to the java side.
|
// Pass the ComparatorJniCallbackOptions pointer to the java side.
|
||||||
static void setHandle(
|
static void setHandle(
|
||||||
JNIEnv* env, jobject jobj, const rocksdb::ComparatorJniCallbackOptions* op) {
|
JNIEnv* env, jobject jobj,
|
||||||
|
const rocksdb::ComparatorJniCallbackOptions* op) {
|
||||||
env->SetLongField(
|
env->SetLongField(
|
||||||
jobj, getHandleFieldID(env),
|
jobj, getHandleFieldID(env),
|
||||||
reinterpret_cast<jlong>(op));
|
reinterpret_cast<jlong>(op));
|
||||||
@ -418,37 +421,41 @@ class AbstractComparatorJni {
|
|||||||
|
|
||||||
// Get the java method `compare` of org.rocksdb.Comparator.
|
// Get the java method `compare` of org.rocksdb.Comparator.
|
||||||
static jmethodID getCompareMethodId(JNIEnv* env) {
|
static jmethodID getCompareMethodId(JNIEnv* env) {
|
||||||
static jmethodID mid = env->GetMethodID(
|
static jmethodID mid = env->GetMethodID(getJClass(env),
|
||||||
getJClass(env), "compare", "(Lorg/rocksdb/AbstractSlice;Lorg/rocksdb/AbstractSlice;)I");
|
"compare",
|
||||||
|
"(Lorg/rocksdb/AbstractSlice;Lorg/rocksdb/AbstractSlice;)I");
|
||||||
assert(mid != nullptr);
|
assert(mid != nullptr);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the java method `findShortestSeparator` of org.rocksdb.Comparator.
|
// Get the java method `findShortestSeparator` of org.rocksdb.Comparator.
|
||||||
static jmethodID getFindShortestSeparatorMethodId(JNIEnv* env) {
|
static jmethodID getFindShortestSeparatorMethodId(JNIEnv* env) {
|
||||||
static jmethodID mid = env->GetMethodID(
|
static jmethodID mid = env->GetMethodID(getJClass(env),
|
||||||
getJClass(env), "findShortestSeparator", "(Ljava/lang/String;Lorg/rocksdb/AbstractSlice;)Ljava/lang/String;");
|
"findShortestSeparator",
|
||||||
|
"(Ljava/lang/String;Lorg/rocksdb/AbstractSlice;)Ljava/lang/String;");
|
||||||
assert(mid != nullptr);
|
assert(mid != nullptr);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the java method `findShortSuccessor` of org.rocksdb.Comparator.
|
// Get the java method `findShortSuccessor` of org.rocksdb.Comparator.
|
||||||
static jmethodID getFindShortSuccessorMethodId(JNIEnv* env) {
|
static jmethodID getFindShortSuccessorMethodId(JNIEnv* env) {
|
||||||
static jmethodID mid = env->GetMethodID(
|
static jmethodID mid = env->GetMethodID(getJClass(env),
|
||||||
getJClass(env), "findShortSuccessor", "(Ljava/lang/String;)Ljava/lang/String;");
|
"findShortSuccessor",
|
||||||
|
"(Ljava/lang/String;)Ljava/lang/String;");
|
||||||
assert(mid != nullptr);
|
assert(mid != nullptr);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the pointer to ComparatorJniCallback.
|
// Get the pointer to ComparatorJniCallback.
|
||||||
static rocksdb::BaseComparatorJniCallback* getHandle(JNIEnv* env, jobject jobj) {
|
static rocksdb::BaseComparatorJniCallback* getHandle(
|
||||||
|
JNIEnv* env, jobject jobj) {
|
||||||
return reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(
|
return reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
env->GetLongField(jobj, getHandleFieldID(env)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass the ComparatorJniCallback pointer to the java side.
|
// Pass the ComparatorJniCallback pointer to the java side.
|
||||||
static void setHandle(
|
static void setHandle(
|
||||||
JNIEnv* env, jobject jobj, const rocksdb::BaseComparatorJniCallback* op) {
|
JNIEnv* env, jobject jobj, const rocksdb::BaseComparatorJniCallback* op) {
|
||||||
env->SetLongField(
|
env->SetLongField(
|
||||||
jobj, getHandleFieldID(env),
|
jobj, getHandleFieldID(env),
|
||||||
reinterpret_cast<jlong>(op));
|
reinterpret_cast<jlong>(op));
|
||||||
@ -585,8 +592,7 @@ class ListJni {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class JniUtil {
|
class JniUtil {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies a jstring to a std::string
|
* Copies a jstring to a std::string
|
||||||
* and releases the original jstring
|
* and releases the original jstring
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include "rocksdb/slice.h"
|
#include "rocksdb/slice.h"
|
||||||
#include "rocksjni/portal.h"
|
#include "rocksjni/portal.h"
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.AbstractSlice>
|
// <editor-fold desc="org.rocksdb.AbstractSlice>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_AbstractSlice
|
* Class: org_rocksdb_AbstractSlice
|
||||||
@ -73,7 +73,8 @@ jstring Java_org_rocksdb_AbstractSlice_toString0(
|
|||||||
jint Java_org_rocksdb_AbstractSlice_compare0(
|
jint Java_org_rocksdb_AbstractSlice_compare0(
|
||||||
JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) {
|
JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) {
|
||||||
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
||||||
const rocksdb::Slice* otherSlice = reinterpret_cast<rocksdb::Slice*>(otherHandle);
|
const rocksdb::Slice* otherSlice =
|
||||||
|
reinterpret_cast<rocksdb::Slice*>(otherHandle);
|
||||||
return slice->compare(*otherSlice);
|
return slice->compare(*otherSlice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +86,8 @@ jint Java_org_rocksdb_AbstractSlice_compare0(
|
|||||||
jboolean Java_org_rocksdb_AbstractSlice_startsWith0(
|
jboolean Java_org_rocksdb_AbstractSlice_startsWith0(
|
||||||
JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) {
|
JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) {
|
||||||
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
||||||
const rocksdb::Slice* otherSlice = reinterpret_cast<rocksdb::Slice*>(otherHandle);
|
const rocksdb::Slice* otherSlice =
|
||||||
|
reinterpret_cast<rocksdb::Slice*>(otherHandle);
|
||||||
return slice->starts_with(*otherSlice);
|
return slice->starts_with(*otherSlice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +101,9 @@ void Java_org_rocksdb_AbstractSlice_disposeInternal(
|
|||||||
delete reinterpret_cast<rocksdb::Slice*>(handle);
|
delete reinterpret_cast<rocksdb::Slice*>(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.Slice>
|
// <editor-fold desc="org.rocksdb.Slice>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_Slice
|
* Class: org_rocksdb_Slice
|
||||||
@ -113,13 +115,11 @@ void Java_org_rocksdb_Slice_createNewSlice0(
|
|||||||
|
|
||||||
const jsize dataSize = env->GetArrayLength(data);
|
const jsize dataSize = env->GetArrayLength(data);
|
||||||
const int len = dataSize - offset;
|
const int len = dataSize - offset;
|
||||||
//jbyte ptrData[len];
|
|
||||||
jbyte* ptrData = new jbyte[len];
|
jbyte* ptrData = new jbyte[len];
|
||||||
env->GetByteArrayRegion(data, offset, len, ptrData);
|
env->GetByteArrayRegion(data, offset, len, ptrData);
|
||||||
|
|
||||||
const rocksdb::Slice* slice = new rocksdb::Slice((const char*)ptrData, len);
|
const rocksdb::Slice* slice = new rocksdb::Slice((const char*)ptrData, len);
|
||||||
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -135,14 +135,15 @@ void Java_org_rocksdb_Slice_createNewSlice1(
|
|||||||
jboolean isCopy;
|
jboolean isCopy;
|
||||||
jbyte* ptrData = env->GetByteArrayElements(data, &isCopy);
|
jbyte* ptrData = env->GetByteArrayElements(data, &isCopy);
|
||||||
const char* buf = new char[len];
|
const char* buf = new char[len];
|
||||||
memcpy((void*)buf, ptrData, len);
|
memcpy(const_cast<char*>(buf), ptrData, len);
|
||||||
|
|
||||||
const rocksdb::Slice* slice = new rocksdb::Slice(buf, env->GetArrayLength(data));
|
const rocksdb::Slice* slice =
|
||||||
|
new rocksdb::Slice(buf, env->GetArrayLength(data));
|
||||||
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
||||||
|
|
||||||
env->ReleaseByteArrayElements(data, ptrData, JNI_ABORT);
|
env->ReleaseByteArrayElements(data, ptrData, JNI_ABORT);
|
||||||
|
|
||||||
//NOTE: buf will be deleted in the org.rocksdb.Slice#dispose method
|
// NOTE: buf will be deleted in the org.rocksdb.Slice#dispose method
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -155,7 +156,8 @@ jbyteArray Java_org_rocksdb_Slice_data0(
|
|||||||
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
||||||
const int len = slice->size();
|
const int len = slice->size();
|
||||||
const jbyteArray data = env->NewByteArray(len);
|
const jbyteArray data = env->NewByteArray(len);
|
||||||
env->SetByteArrayRegion(data, 0, len, (jbyte*)slice->data());
|
env->SetByteArrayRegion(data, 0, len,
|
||||||
|
reinterpret_cast<jbyte*>(const_cast<char*>(slice->data())));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,9 +172,9 @@ void Java_org_rocksdb_Slice_disposeInternalBuf(
|
|||||||
delete [] slice->data_;
|
delete [] slice->data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
|
|
||||||
//<editor-fold desc="org.rocksdb.DirectSlice>
|
// <editor-fold desc="org.rocksdb.DirectSlice>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_DirectSlice
|
* Class: org_rocksdb_DirectSlice
|
||||||
@ -181,7 +183,8 @@ void Java_org_rocksdb_Slice_disposeInternalBuf(
|
|||||||
*/
|
*/
|
||||||
void Java_org_rocksdb_DirectSlice_createNewDirectSlice0(
|
void Java_org_rocksdb_DirectSlice_createNewDirectSlice0(
|
||||||
JNIEnv* env, jobject jobj, jobject data, jint length) {
|
JNIEnv* env, jobject jobj, jobject data, jint length) {
|
||||||
const char* ptrData = (char*)env->GetDirectBufferAddress(data);
|
const char* ptrData =
|
||||||
|
reinterpret_cast<char*>(env->GetDirectBufferAddress(data));
|
||||||
const rocksdb::Slice* slice = new rocksdb::Slice(ptrData, length);
|
const rocksdb::Slice* slice = new rocksdb::Slice(ptrData, length);
|
||||||
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
||||||
}
|
}
|
||||||
@ -193,7 +196,8 @@ void Java_org_rocksdb_DirectSlice_createNewDirectSlice0(
|
|||||||
*/
|
*/
|
||||||
void Java_org_rocksdb_DirectSlice_createNewDirectSlice1(
|
void Java_org_rocksdb_DirectSlice_createNewDirectSlice1(
|
||||||
JNIEnv* env, jobject jobj, jobject data) {
|
JNIEnv* env, jobject jobj, jobject data) {
|
||||||
const char* ptrData = (char*)env->GetDirectBufferAddress(data);
|
const char* ptrData =
|
||||||
|
reinterpret_cast<char*>(env->GetDirectBufferAddress(data));
|
||||||
const rocksdb::Slice* slice = new rocksdb::Slice(ptrData);
|
const rocksdb::Slice* slice = new rocksdb::Slice(ptrData);
|
||||||
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
|
||||||
}
|
}
|
||||||
@ -206,7 +210,8 @@ void Java_org_rocksdb_DirectSlice_createNewDirectSlice1(
|
|||||||
jobject Java_org_rocksdb_DirectSlice_data0(
|
jobject Java_org_rocksdb_DirectSlice_data0(
|
||||||
JNIEnv* env, jobject jobj, jlong handle) {
|
JNIEnv* env, jobject jobj, jlong handle) {
|
||||||
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
||||||
return env->NewDirectByteBuffer((void*)slice->data(), slice->size());
|
return env->NewDirectByteBuffer(const_cast<char*>(slice->data()),
|
||||||
|
slice->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -228,6 +233,7 @@ jbyte Java_org_rocksdb_DirectSlice_get0(
|
|||||||
void Java_org_rocksdb_DirectSlice_clear0(
|
void Java_org_rocksdb_DirectSlice_clear0(
|
||||||
JNIEnv* env, jobject jobj, jlong handle) {
|
JNIEnv* env, jobject jobj, jlong handle) {
|
||||||
rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
|
||||||
|
delete [] slice->data_;
|
||||||
slice->clear();
|
slice->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,4 +248,4 @@ void Java_org_rocksdb_DirectSlice_removePrefix0(
|
|||||||
slice->remove_prefix(length);
|
slice->remove_prefix(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
|
Loading…
Reference in New Issue
Block a user