sst_file_readerjni.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // This file implements the "bridge" between Java and C++ and enables
  7. // calling C++ ROCKSDB_NAMESPACE::SstFileReader methods
  8. // from Java side.
  9. #include <jni.h>
  10. #include <string>
  11. #include "include/org_rocksdb_SstFileReader.h"
  12. #include "rocksdb/comparator.h"
  13. #include "rocksdb/env.h"
  14. #include "rocksdb/options.h"
  15. #include "rocksdb/sst_file_reader.h"
  16. #include "rocksjni/portal.h"
  17. /*
  18. * Class: org_rocksdb_SstFileReader
  19. * Method: newSstFileReader
  20. * Signature: (J)J
  21. */
  22. jlong Java_org_rocksdb_SstFileReader_newSstFileReader(JNIEnv * /*env*/,
  23. jclass /*jcls*/,
  24. jlong joptions) {
  25. auto *options =
  26. reinterpret_cast<const ROCKSDB_NAMESPACE::Options *>(joptions);
  27. ROCKSDB_NAMESPACE::SstFileReader *sst_file_reader =
  28. new ROCKSDB_NAMESPACE::SstFileReader(*options);
  29. return reinterpret_cast<jlong>(sst_file_reader);
  30. }
  31. /*
  32. * Class: org_rocksdb_SstFileReader
  33. * Method: open
  34. * Signature: (JLjava/lang/String;)V
  35. */
  36. void Java_org_rocksdb_SstFileReader_open(JNIEnv *env, jobject /*jobj*/,
  37. jlong jhandle, jstring jfile_path) {
  38. const char *file_path = env->GetStringUTFChars(jfile_path, nullptr);
  39. if (file_path == nullptr) {
  40. // exception thrown: OutOfMemoryError
  41. return;
  42. }
  43. ROCKSDB_NAMESPACE::Status s =
  44. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle)->Open(
  45. file_path);
  46. env->ReleaseStringUTFChars(jfile_path, file_path);
  47. if (!s.ok()) {
  48. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  49. }
  50. }
  51. /*
  52. * Class: org_rocksdb_SstFileReader
  53. * Method: newIterator
  54. * Signature: (JJ)J
  55. */
  56. jlong Java_org_rocksdb_SstFileReader_newIterator(JNIEnv * /*env*/,
  57. jobject /*jobj*/,
  58. jlong jhandle,
  59. jlong jread_options_handle) {
  60. auto *sst_file_reader =
  61. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
  62. auto *read_options =
  63. reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions *>(jread_options_handle);
  64. return reinterpret_cast<jlong>(sst_file_reader->NewIterator(*read_options));
  65. }
  66. /*
  67. * Class: org_rocksdb_SstFileReader
  68. * Method: disposeInternal
  69. * Signature: (J)V
  70. */
  71. void Java_org_rocksdb_SstFileReader_disposeInternal(JNIEnv * /*env*/,
  72. jobject /*jobj*/,
  73. jlong jhandle) {
  74. delete reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
  75. }
  76. /*
  77. * Class: org_rocksdb_SstFileReader
  78. * Method: verifyChecksum
  79. * Signature: (J)V
  80. */
  81. void Java_org_rocksdb_SstFileReader_verifyChecksum(JNIEnv *env,
  82. jobject /*jobj*/,
  83. jlong jhandle) {
  84. auto *sst_file_reader =
  85. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
  86. auto s = sst_file_reader->VerifyChecksum();
  87. if (!s.ok()) {
  88. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  89. }
  90. }
  91. /*
  92. * Class: org_rocksdb_SstFileReader
  93. * Method: getTableProperties
  94. * Signature: (J)J
  95. */
  96. jobject Java_org_rocksdb_SstFileReader_getTableProperties(JNIEnv *env,
  97. jobject /*jobj*/,
  98. jlong jhandle) {
  99. auto *sst_file_reader =
  100. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
  101. std::shared_ptr<const ROCKSDB_NAMESPACE::TableProperties> tp =
  102. sst_file_reader->GetTableProperties();
  103. jobject jtable_properties =
  104. ROCKSDB_NAMESPACE::TablePropertiesJni::fromCppTableProperties(
  105. env, *(tp.get()));
  106. return jtable_properties;
  107. }