2019-09-10 03:11:02 +02:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
2020-02-20 21:07:53 +01:00
|
|
|
// calling C++ ROCKSDB_NAMESPACE::SstFileReader methods
|
2019-09-10 03:11:02 +02:00
|
|
|
// from Java side.
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "include/org_rocksdb_SstFileReader.h"
|
|
|
|
#include "rocksdb/comparator.h"
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/sst_file_reader.h"
|
|
|
|
#include "rocksjni/portal.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileReader
|
|
|
|
* Method: newSstFileReader
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_SstFileReader_newSstFileReader(JNIEnv * /*env*/,
|
2019-09-19 21:32:33 +02:00
|
|
|
jclass /*jcls*/,
|
|
|
|
jlong joptions) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto *options =
|
|
|
|
reinterpret_cast<const ROCKSDB_NAMESPACE::Options *>(joptions);
|
|
|
|
ROCKSDB_NAMESPACE::SstFileReader *sst_file_reader =
|
|
|
|
new ROCKSDB_NAMESPACE::SstFileReader(*options);
|
2019-09-10 03:11:02 +02:00
|
|
|
return reinterpret_cast<jlong>(sst_file_reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileReader
|
|
|
|
* Method: open
|
|
|
|
* Signature: (JLjava/lang/String;)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_SstFileReader_open(JNIEnv *env, jobject /*jobj*/,
|
|
|
|
jlong jhandle, jstring jfile_path) {
|
|
|
|
const char *file_path = env->GetStringUTFChars(jfile_path, nullptr);
|
|
|
|
if (file_path == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return;
|
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status s =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle)->Open(
|
|
|
|
file_path);
|
2019-09-10 03:11:02 +02:00
|
|
|
env->ReleaseStringUTFChars(jfile_path, file_path);
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2019-09-10 03:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-09-19 21:32:33 +02:00
|
|
|
* Class: org_rocksdb_SstFileReader
|
|
|
|
* Method: newIterator
|
|
|
|
* Signature: (JJ)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_SstFileReader_newIterator(JNIEnv * /*env*/,
|
2019-09-10 03:11:02 +02:00
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle,
|
|
|
|
jlong jread_options_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto *sst_file_reader =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
|
2019-09-19 21:32:33 +02:00
|
|
|
auto *read_options =
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions *>(jread_options_handle);
|
2019-09-19 21:32:33 +02:00
|
|
|
return reinterpret_cast<jlong>(sst_file_reader->NewIterator(*read_options));
|
2019-09-10 03:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileReader
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_SstFileReader_disposeInternal(JNIEnv * /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
delete reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
|
2019-09-10 03:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileReader
|
|
|
|
* Method: verifyChecksum
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_SstFileReader_verifyChecksum(JNIEnv *env,
|
2019-09-19 21:32:33 +02:00
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto *sst_file_reader =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
|
2019-09-10 03:11:02 +02:00
|
|
|
auto s = sst_file_reader->VerifyChecksum();
|
|
|
|
if (!s.ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2019-09-10 03:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileReader
|
|
|
|
* Method: getTableProperties
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jobject Java_org_rocksdb_SstFileReader_getTableProperties(JNIEnv *env,
|
2019-09-19 21:32:33 +02:00
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto *sst_file_reader =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
|
|
|
|
std::shared_ptr<const ROCKSDB_NAMESPACE::TableProperties> tp =
|
2019-09-19 21:32:33 +02:00
|
|
|
sst_file_reader->GetTableProperties();
|
|
|
|
jobject jtable_properties =
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::TablePropertiesJni::fromCppTableProperties(
|
|
|
|
env, *(tp.get()));
|
2019-09-10 03:11:02 +02:00
|
|
|
return jtable_properties;
|
|
|
|
}
|