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/cplusplus_to_java_convert.h"
  17. #include "rocksjni/portal.h"
  18. /*
  19. * Class: org_rocksdb_SstFileReader
  20. * Method: newSstFileReader
  21. * Signature: (J)J
  22. */
  23. jlong Java_org_rocksdb_SstFileReader_newSstFileReader(JNIEnv * /*env*/,
  24. jclass /*jcls*/,
  25. jlong joptions) {
  26. auto *options =
  27. reinterpret_cast<const ROCKSDB_NAMESPACE::Options *>(joptions);
  28. ROCKSDB_NAMESPACE::SstFileReader *sst_file_reader =
  29. new ROCKSDB_NAMESPACE::SstFileReader(*options);
  30. return GET_CPLUSPLUS_POINTER(sst_file_reader);
  31. }
  32. /*
  33. * Class: org_rocksdb_SstFileReader
  34. * Method: open
  35. * Signature: (JLjava/lang/String;)V
  36. */
  37. void Java_org_rocksdb_SstFileReader_open(JNIEnv *env, jclass /*jcls*/,
  38. jlong jhandle, jstring jfile_path) {
  39. const char *file_path = env->GetStringUTFChars(jfile_path, nullptr);
  40. if (file_path == nullptr) {
  41. // exception thrown: OutOfMemoryError
  42. return;
  43. }
  44. ROCKSDB_NAMESPACE::Status s =
  45. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle)->Open(
  46. file_path);
  47. env->ReleaseStringUTFChars(jfile_path, file_path);
  48. if (!s.ok()) {
  49. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  50. }
  51. }
  52. /*
  53. * Class: org_rocksdb_SstFileReader
  54. * Method: newIterator
  55. * Signature: (JJ)J
  56. */
  57. jlong Java_org_rocksdb_SstFileReader_newIterator(JNIEnv * /*env*/,
  58. jclass /*jcls*/, 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 GET_CPLUSPLUS_POINTER(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_disposeInternalJni(JNIEnv * /*env*/,
  72. jclass /*jcls*/,
  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, jclass /*jcls*/,
  82. jlong jhandle) {
  83. auto *sst_file_reader =
  84. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
  85. auto s = sst_file_reader->VerifyChecksum();
  86. if (!s.ok()) {
  87. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  88. }
  89. }
  90. /*
  91. * Class: org_rocksdb_SstFileReader
  92. * Method: getTableProperties
  93. * Signature: (J)J
  94. */
  95. jobject Java_org_rocksdb_SstFileReader_getTableProperties(JNIEnv *env,
  96. jclass /*jcls*/,
  97. jlong jhandle) {
  98. auto *sst_file_reader =
  99. reinterpret_cast<ROCKSDB_NAMESPACE::SstFileReader *>(jhandle);
  100. std::shared_ptr<const ROCKSDB_NAMESPACE::TableProperties> tp =
  101. sst_file_reader->GetTableProperties();
  102. jobject jtable_properties =
  103. ROCKSDB_NAMESPACE::TablePropertiesJni::fromCppTableProperties(
  104. env, *(tp.get()));
  105. return jtable_properties;
  106. }