Merge pull request #472 from fyrz/RocksJava-Cleanup
[RocksJava] Cleanup portal.h & tests
This commit is contained in:
commit
2113ecd3c2
@ -59,6 +59,7 @@ JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\
|
|||||||
org.rocksdb.test.ColumnFamilyTest\
|
org.rocksdb.test.ColumnFamilyTest\
|
||||||
org.rocksdb.test.ComparatorOptionsTest\
|
org.rocksdb.test.ComparatorOptionsTest\
|
||||||
org.rocksdb.test.ComparatorTest\
|
org.rocksdb.test.ComparatorTest\
|
||||||
|
org.rocksdb.test.CompressionOptionsTest\
|
||||||
org.rocksdb.test.DBOptionsTest\
|
org.rocksdb.test.DBOptionsTest\
|
||||||
org.rocksdb.test.DirectComparatorTest\
|
org.rocksdb.test.DirectComparatorTest\
|
||||||
org.rocksdb.test.DirectSliceTest\
|
org.rocksdb.test.DirectSliceTest\
|
||||||
|
@ -259,7 +259,8 @@ public class ColumnFamilyTest {
|
|||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||||
|
new ColumnFamilyOptions().setMergeOperator(new StringAppendOperator())));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
||||||
@ -268,6 +269,10 @@ public class ColumnFamilyTest {
|
|||||||
WriteBatch writeBatch = new WriteBatch();
|
WriteBatch writeBatch = new WriteBatch();
|
||||||
WriteOptions writeOpt = new WriteOptions();
|
WriteOptions writeOpt = new WriteOptions();
|
||||||
writeBatch.put("key".getBytes(), "value".getBytes());
|
writeBatch.put("key".getBytes(), "value".getBytes());
|
||||||
|
writeBatch.put(db.getDefaultColumnFamily(),
|
||||||
|
"mergeKey".getBytes(), "merge".getBytes());
|
||||||
|
writeBatch.merge(db.getDefaultColumnFamily(), "mergeKey".getBytes(),
|
||||||
|
"merge".getBytes());
|
||||||
writeBatch.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(),
|
writeBatch.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(),
|
||||||
"value".getBytes());
|
"value".getBytes());
|
||||||
writeBatch.put(columnFamilyHandleList.get(1), "newcfkey2".getBytes(),
|
writeBatch.put(columnFamilyHandleList.get(1), "newcfkey2".getBytes(),
|
||||||
@ -283,6 +288,9 @@ public class ColumnFamilyTest {
|
|||||||
assertThat(new String(db.get(columnFamilyHandleList.get(1),
|
assertThat(new String(db.get(columnFamilyHandleList.get(1),
|
||||||
"newcfkey2".getBytes()))).isEqualTo("value2");
|
"newcfkey2".getBytes()))).isEqualTo("value2");
|
||||||
assertThat(new String(db.get("key".getBytes()))).isEqualTo("value");
|
assertThat(new String(db.get("key".getBytes()))).isEqualTo("value");
|
||||||
|
// check if key is merged
|
||||||
|
assertThat(new String(db.get(db.getDefaultColumnFamily(),
|
||||||
|
"mergeKey".getBytes()))).isEqualTo("merge,merge");
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
db.close();
|
db.close();
|
||||||
|
@ -48,8 +48,10 @@ public class DirectSliceTest {
|
|||||||
DirectSlice directSlice = null;
|
DirectSlice directSlice = null;
|
||||||
try {
|
try {
|
||||||
byte[] data = "Some text".getBytes();
|
byte[] data = "Some text".getBytes();
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
|
ByteBuffer buffer = ByteBuffer.allocateDirect(data.length + 1);
|
||||||
buffer.put(data);
|
buffer.put(data);
|
||||||
|
buffer.put(data.length, (byte)0);
|
||||||
|
|
||||||
directSlice = new DirectSlice(buffer);
|
directSlice = new DirectSlice(buffer);
|
||||||
assertThat(directSlice.toString()).isEqualTo("Some text");
|
assertThat(directSlice.toString()).isEqualTo("Some text");
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -36,6 +36,7 @@ public class FlushTest {
|
|||||||
wOpt = new WriteOptions();
|
wOpt = new WriteOptions();
|
||||||
flushOptions = new FlushOptions();
|
flushOptions = new FlushOptions();
|
||||||
flushOptions.setWaitForFlush(true);
|
flushOptions.setWaitForFlush(true);
|
||||||
|
assertThat(flushOptions.waitForFlush()).isTrue();
|
||||||
wOpt.setDisableWAL(true);
|
wOpt.setDisableWAL(true);
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
||||||
db.put(wOpt, "key1".getBytes(), "value1".getBytes());
|
db.put(wOpt, "key1".getBytes(), "value1".getBytes());
|
||||||
|
@ -34,36 +34,45 @@ inline Status check_if_jlong_fits_size_t(const jlong& jvalue) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The portal class for org.rocksdb.RocksDB
|
// Native class template
|
||||||
class RocksDBJni {
|
template<class PTR, class DERIVED> class RocksDBNativeClass {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.RocksDB.
|
// Get the java class id
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env, const char* jclazz_name) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/RocksDB");
|
jclass jclazz = env->FindClass(jclazz_name);
|
||||||
assert(jclazz != nullptr);
|
assert(jclazz != nullptr);
|
||||||
return jclazz;
|
return jclazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.RocksDB
|
// Get the field id of the member variable to store
|
||||||
// that stores the pointer to rocksdb::DB.
|
// the ptr
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
static jfieldID getHandleFieldID(JNIEnv* env) {
|
||||||
static jfieldID fid = env->GetFieldID(
|
static jfieldID fid = env->GetFieldID(
|
||||||
getJClass(env), "nativeHandle_", "J");
|
DERIVED::getJClass(env), "nativeHandle_", "J");
|
||||||
assert(fid != nullptr);
|
assert(fid != nullptr);
|
||||||
return fid;
|
return fid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the pointer to rocksdb::DB of the specified org.rocksdb.RocksDB.
|
// Get the pointer from Java
|
||||||
static rocksdb::DB* getHandle(JNIEnv* env, jobject jdb) {
|
static PTR getHandle(JNIEnv* env, jobject jobj) {
|
||||||
return reinterpret_cast<rocksdb::DB*>(
|
return reinterpret_cast<PTR>(
|
||||||
env->GetLongField(jdb, getHandleFieldID(env)));
|
env->GetLongField(jobj, getHandleFieldID(env)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass the rocksdb::DB pointer to the java side.
|
// Pass the pointer to the java side.
|
||||||
static void setHandle(JNIEnv* env, jobject jdb, rocksdb::DB* db) {
|
static void setHandle(JNIEnv* env, jobject jdb, PTR ptr) {
|
||||||
env->SetLongField(
|
env->SetLongField(
|
||||||
jdb, getHandleFieldID(env),
|
jdb, getHandleFieldID(env),
|
||||||
reinterpret_cast<jlong>(db));
|
reinterpret_cast<jlong>(ptr));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// The portal class for org.rocksdb.RocksDB
|
||||||
|
class RocksDBJni : public RocksDBNativeClass<rocksdb::DB*, RocksDBJni> {
|
||||||
|
public:
|
||||||
|
// Get the java class id of org.rocksdb.RocksDB.
|
||||||
|
static jclass getJClass(JNIEnv* env) {
|
||||||
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/RocksDB");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,67 +105,21 @@ class RocksDBExceptionJni {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class OptionsJni {
|
// The portal class for org.rocksdb.Options
|
||||||
|
class OptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::Options*, OptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.Options.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/Options");
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/Options");
|
||||||
assert(jclazz != nullptr);
|
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.Options
|
|
||||||
// that stores the pointer to rocksdb::Options
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::Options
|
|
||||||
static rocksdb::Options* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::Options*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::Options pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jobj, rocksdb::Options* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DBOptionsJni {
|
// The portal class for org.rocksdb.DBOptions
|
||||||
|
class DBOptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::DBOptions*, DBOptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.DBOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/DBOptions");
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/DBOptions");
|
||||||
assert(jclazz != nullptr);
|
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.DBOptions
|
|
||||||
// that stores the pointer to rocksdb::DBOptions
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::DBOptions
|
|
||||||
static rocksdb::DBOptions* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::DBOptions*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::DBOptions pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jobj, rocksdb::DBOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -188,149 +151,54 @@ class ColumnFamilyDescriptorJni {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ColumnFamilyOptionsJni {
|
// The portal class for org.rocksdb.ColumnFamilyOptions
|
||||||
|
class ColumnFamilyOptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::ColumnFamilyOptions*, ColumnFamilyOptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.ColumnFamilyOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/ColumnFamilyOptions");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/ColumnFamilyOptions");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.DBOptions
|
|
||||||
// that stores the pointer to rocksdb::ColumnFamilyOptions
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::ColumnFamilyOptions
|
|
||||||
static rocksdb::ColumnFamilyOptions* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::ColumnFamilyOptions*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::ColumnFamilyOptions pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jobj,
|
|
||||||
rocksdb::ColumnFamilyOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class WriteOptionsJni {
|
// The portal class for org.rocksdb.WriteOptions
|
||||||
|
class WriteOptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::WriteOptions*, WriteOptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.WriteOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/WriteOptions");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/WriteOptions");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.WriteOptions
|
|
||||||
// that stores the pointer to rocksdb::WriteOptions
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::WriteOptions
|
|
||||||
static rocksdb::WriteOptions* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::WriteOptions*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::WriteOptions pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jobj, rocksdb::WriteOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The portal class for org.rocksdb.ReadOptions
|
||||||
class ReadOptionsJni {
|
class ReadOptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::ReadOptions*, ReadOptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.ReadOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/ReadOptions");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/ReadOptions");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.ReadOptions
|
|
||||||
// that stores the pointer to rocksdb::ReadOptions
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::ReadOptions
|
|
||||||
static rocksdb::ReadOptions* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::ReadOptions*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::ReadOptions pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jobj,
|
|
||||||
rocksdb::ReadOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The portal class for org.rocksdb.ReadOptions
|
||||||
class WriteBatchJni {
|
class WriteBatchJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::WriteBatch*, WriteBatchJni> {
|
||||||
public:
|
public:
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/WriteBatch");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/WriteBatch");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::WriteBatch of the specified
|
|
||||||
// org.rocksdb.WriteBatch.
|
|
||||||
static rocksdb::WriteBatch* getHandle(JNIEnv* env, jobject jwb) {
|
|
||||||
return reinterpret_cast<rocksdb::WriteBatch*>(
|
|
||||||
env->GetLongField(jwb, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::WriteBatch pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jwb, rocksdb::WriteBatch* wb) {
|
|
||||||
env->SetLongField(
|
|
||||||
jwb, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(wb));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class WriteBatchHandlerJni {
|
// The portal class for org.rocksdb.WriteBatch.Handler
|
||||||
|
class WriteBatchHandlerJni : public RocksDBNativeClass<
|
||||||
|
const rocksdb::WriteBatchHandlerJniCallback*,
|
||||||
|
WriteBatchHandlerJni> {
|
||||||
public:
|
public:
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/WriteBatch$Handler");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/WriteBatch$Handler");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the java method `put` of org.rocksdb.WriteBatch.Handler.
|
// Get the java method `put` of org.rocksdb.WriteBatch.Handler.
|
||||||
@ -372,53 +240,15 @@ class WriteBatchHandlerJni {
|
|||||||
assert(mid != nullptr);
|
assert(mid != nullptr);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the pointer to rocksdb::WriteBatchHandlerJniCallback of the specified
|
|
||||||
// org.rocksdb.WriteBatchHandler.
|
|
||||||
static rocksdb::WriteBatchHandlerJniCallback* getHandle(
|
|
||||||
JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::WriteBatchHandlerJniCallback*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::WriteBatchHandlerJniCallback pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj,
|
|
||||||
const rocksdb::WriteBatchHandlerJniCallback* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WriteBatchWithIndexJni {
|
// The portal class for org.rocksdb.WriteBatchWithIndex
|
||||||
|
class WriteBatchWithIndexJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::WriteBatchWithIndex*, WriteBatchWithIndexJni> {
|
||||||
public:
|
public:
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/WriteBatchWithIndex");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/WriteBatch");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::WriteBatchWithIndex of the specified
|
|
||||||
// org.rocksdb.WriteBatchWithIndex.
|
|
||||||
static rocksdb::WriteBatchWithIndex* getHandle(JNIEnv* env, jobject jwbwi) {
|
|
||||||
return reinterpret_cast<rocksdb::WriteBatchWithIndex*>(
|
|
||||||
env->GetLongField(jwbwi, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::WriteBatchWithIndex pointer to the java side.
|
|
||||||
static void setHandle(JNIEnv* env, jobject jwbwi,
|
|
||||||
rocksdb::WriteBatchWithIndex* wbwi) {
|
|
||||||
env->SetLongField(
|
|
||||||
jwbwi, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(wbwi));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -431,212 +261,74 @@ class HistogramDataJni {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BackupableDBOptionsJni {
|
// The portal class for org.rocksdb.WriteBatchWithIndex
|
||||||
|
class BackupableDBOptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::BackupableDBOptions*, BackupableDBOptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.BackupableDBOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/BackupableDBOptions");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/BackupableDBOptions");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.BackupableDBOptions
|
|
||||||
// that stores the pointer to rocksdb::BackupableDBOptions
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::BackupableDBOptions
|
|
||||||
static rocksdb::BackupableDBOptions* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::BackupableDBOptions*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::BackupableDBOptions pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj, rocksdb::BackupableDBOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class IteratorJni {
|
// The portal class for org.rocksdb.RocksIterator
|
||||||
|
class IteratorJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::Iterator*, IteratorJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.Iteartor.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/RocksIterator");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/RocksIterator");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.Iterator
|
|
||||||
// that stores the pointer to rocksdb::Iterator.
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::Iterator.
|
|
||||||
static rocksdb::Iterator* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::Iterator*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::Iterator pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj, rocksdb::Iterator* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilterJni {
|
// The portal class for org.rocksdb.Filter
|
||||||
|
class FilterJni : public RocksDBNativeClass<
|
||||||
|
std::shared_ptr<rocksdb::FilterPolicy>*, FilterJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.FilterPolicy.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/Filter");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/Filter");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.Filter
|
|
||||||
// that stores the pointer to rocksdb::FilterPolicy.
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::FilterPolicy.
|
|
||||||
static std::shared_ptr<rocksdb::FilterPolicy>* getHandle(
|
|
||||||
JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast
|
|
||||||
<std::shared_ptr<rocksdb::FilterPolicy> *>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::FilterPolicy pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj, std::shared_ptr<rocksdb::FilterPolicy>* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ColumnFamilyHandleJni {
|
// The portal class for org.rocksdb.ColumnFamilyHandle
|
||||||
|
class ColumnFamilyHandleJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::ColumnFamilyHandle*, ColumnFamilyHandleJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.ColumnFamilyHandle.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/ColumnFamilyHandle");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/ColumnFamilyHandle");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.ColumnFamilyHandle.
|
|
||||||
// that stores the pointer to rocksdb::ColumnFamilyHandle.
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to rocksdb::ColumnFamilyHandle.
|
|
||||||
static rocksdb::ColumnFamilyHandle* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::ColumnFamilyHandle*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the rocksdb::ColumnFamilyHandle pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj, const rocksdb::ColumnFamilyHandle* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FlushOptionsJni {
|
// The portal class for org.rocksdb.FlushOptions
|
||||||
|
class FlushOptionsJni : public RocksDBNativeClass<
|
||||||
|
rocksdb::FlushOptions*, FlushOptionsJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.FlushOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/FlushOptions");
|
|
||||||
assert(jclazz != nullptr);
|
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.FlushOptions
|
|
||||||
// that stores the pointer to rocksdb::FlushOptions.
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the FlushOptions pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj,
|
|
||||||
const rocksdb::FlushOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ComparatorOptionsJni {
|
|
||||||
public:
|
|
||||||
// Get the java class id of org.rocksdb.ComparatorOptions.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/ComparatorOptions");
|
|
||||||
assert(jclazz != nullptr);
|
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.ComparatorOptions
|
|
||||||
// that stores the pointer to rocksdb::ComparatorJniCallbackOptions.
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the ComparatorJniCallbackOptions pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj,
|
|
||||||
const rocksdb::ComparatorJniCallbackOptions* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class AbstractComparatorJni {
|
|
||||||
public:
|
|
||||||
// Get the java class id of org.rocksdb.Comparator.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/AbstractComparator");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/FlushOptions");
|
||||||
return jclazz;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.Comparator
|
// The portal class for org.rocksdb.ComparatorOptions
|
||||||
// that stores the pointer to rocksdb::Comparator.
|
class ComparatorOptionsJni : public RocksDBNativeClass<
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
rocksdb::ComparatorJniCallbackOptions*, ComparatorOptionsJni> {
|
||||||
static jfieldID fid = env->GetFieldID(
|
public:
|
||||||
getJClass(env), "nativeHandle_", "J");
|
static jclass getJClass(JNIEnv* env) {
|
||||||
assert(fid != nullptr);
|
return RocksDBNativeClass::getJClass(env,
|
||||||
return fid;
|
"org/rocksdb/ComparatorOptions");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// The portal class for org.rocksdb.AbstractComparator
|
||||||
|
class AbstractComparatorJni : public RocksDBNativeClass<
|
||||||
|
const rocksdb::BaseComparatorJniCallback*,
|
||||||
|
AbstractComparatorJni> {
|
||||||
|
public:
|
||||||
|
static jclass getJClass(JNIEnv* env) {
|
||||||
|
return RocksDBNativeClass::getJClass(env,
|
||||||
|
"org/rocksdb/AbstractComparator");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the java method `name` of org.rocksdb.Comparator.
|
// Get the java method `name` of org.rocksdb.Comparator.
|
||||||
@ -673,53 +365,15 @@ class AbstractComparatorJni {
|
|||||||
assert(mid != nullptr);
|
assert(mid != nullptr);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the pointer to ComparatorJniCallback.
|
|
||||||
static rocksdb::BaseComparatorJniCallback* getHandle(
|
|
||||||
JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the ComparatorJniCallback pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj, const rocksdb::BaseComparatorJniCallback* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AbstractSliceJni {
|
// The portal class for org.rocksdb.AbstractSlice
|
||||||
|
class AbstractSliceJni : public RocksDBNativeClass<
|
||||||
|
const rocksdb::Slice*, AbstractSliceJni> {
|
||||||
public:
|
public:
|
||||||
// Get the java class id of org.rocksdb.Slice.
|
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/AbstractSlice");
|
return RocksDBNativeClass::getJClass(env,
|
||||||
assert(jclazz != nullptr);
|
"org/rocksdb/AbstractSlice");
|
||||||
return jclazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the field id of the member variable of org.rocksdb.Slice
|
|
||||||
// that stores the pointer to rocksdb::Slice.
|
|
||||||
static jfieldID getHandleFieldID(JNIEnv* env) {
|
|
||||||
static jfieldID fid = env->GetFieldID(
|
|
||||||
getJClass(env), "nativeHandle_", "J");
|
|
||||||
assert(fid != nullptr);
|
|
||||||
return fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pointer to Slice.
|
|
||||||
static rocksdb::Slice* getHandle(JNIEnv* env, jobject jobj) {
|
|
||||||
return reinterpret_cast<rocksdb::Slice*>(
|
|
||||||
env->GetLongField(jobj, getHandleFieldID(env)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the Slice pointer to the java side.
|
|
||||||
static void setHandle(
|
|
||||||
JNIEnv* env, jobject jobj, const rocksdb::Slice* op) {
|
|
||||||
env->SetLongField(
|
|
||||||
jobj, getHandleFieldID(env),
|
|
||||||
reinterpret_cast<jlong>(op));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -913,9 +567,6 @@ class WriteTypeJni {
|
|||||||
private:
|
private:
|
||||||
// Get the java class id of org.rocksdb.WBWIRocksIterator.WriteType.
|
// Get the java class id of org.rocksdb.WBWIRocksIterator.WriteType.
|
||||||
static jclass getJClass(JNIEnv* env) {
|
static jclass getJClass(JNIEnv* env) {
|
||||||
// TODO(AR) setting the jclazz var to static causes getEnum to fail
|
|
||||||
// occasionally (e.g. in WriteBatchWithIndex#iterator() test) with
|
|
||||||
// SIGSEGV but I have no idea why...
|
|
||||||
jclass jclazz = env->FindClass("org/rocksdb/WBWIRocksIterator$WriteType");
|
jclass jclazz = env->FindClass("org/rocksdb/WBWIRocksIterator$WriteType");
|
||||||
assert(jclazz != nullptr);
|
assert(jclazz != nullptr);
|
||||||
return jclazz;
|
return jclazz;
|
||||||
@ -923,9 +574,6 @@ class WriteTypeJni {
|
|||||||
|
|
||||||
// Get an enum field of org.rocksdb.WBWIRocksIterator.WriteType
|
// Get an enum field of org.rocksdb.WBWIRocksIterator.WriteType
|
||||||
static jobject getEnum(JNIEnv* env, const char name[]) {
|
static jobject getEnum(JNIEnv* env, const char name[]) {
|
||||||
// TODO(AR) setting the jclazz var to static causes getEnum to fail
|
|
||||||
// occasionally (e.g. in WriteBatchWithIndex#iterator() test) with
|
|
||||||
// SIGSEGV but I have no idea why...
|
|
||||||
jclass jclazz = getJClass(env);
|
jclass jclazz = getJClass(env);
|
||||||
jfieldID jfid =
|
jfieldID jfid =
|
||||||
env->GetStaticFieldID(jclazz, name,
|
env->GetStaticFieldID(jclazz, name,
|
||||||
|
Loading…
Reference in New Issue
Block a user