writebatchhandlerjnicallback.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 callback "bridge" between Java and C++ for
  7. // ROCKSDB_NAMESPACE::WriteBatch::Handler.
  8. #ifndef JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_
  9. #define JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_
  10. #include <functional>
  11. #include <jni.h>
  12. #include <memory>
  13. #include "rocksjni/jnicallback.h"
  14. #include "rocksdb/write_batch.h"
  15. namespace ROCKSDB_NAMESPACE {
  16. /**
  17. * This class acts as a bridge between C++
  18. * and Java. The methods in this class will be
  19. * called back from the RocksDB storage engine (C++)
  20. * which calls the appropriate Java method.
  21. * This enables Write Batch Handlers to be implemented in Java.
  22. */
  23. class WriteBatchHandlerJniCallback : public JniCallback, public WriteBatch::Handler {
  24. public:
  25. WriteBatchHandlerJniCallback(
  26. JNIEnv* env, jobject jWriteBackHandler);
  27. Status PutCF(uint32_t column_family_id, const Slice& key,
  28. const Slice& value);
  29. void Put(const Slice& key, const Slice& value);
  30. Status MergeCF(uint32_t column_family_id, const Slice& key,
  31. const Slice& value);
  32. void Merge(const Slice& key, const Slice& value);
  33. Status DeleteCF(uint32_t column_family_id, const Slice& key);
  34. void Delete(const Slice& key);
  35. Status SingleDeleteCF(uint32_t column_family_id, const Slice& key);
  36. void SingleDelete(const Slice& key);
  37. Status DeleteRangeCF(uint32_t column_family_id, const Slice& beginKey,
  38. const Slice& endKey);
  39. void DeleteRange(const Slice& beginKey, const Slice& endKey);
  40. void LogData(const Slice& blob);
  41. Status PutBlobIndexCF(uint32_t column_family_id, const Slice& key,
  42. const Slice& value);
  43. Status MarkBeginPrepare(bool);
  44. Status MarkEndPrepare(const Slice& xid);
  45. Status MarkNoop(bool empty_batch);
  46. Status MarkRollback(const Slice& xid);
  47. Status MarkCommit(const Slice& xid);
  48. bool Continue();
  49. private:
  50. JNIEnv* m_env;
  51. jmethodID m_jPutCfMethodId;
  52. jmethodID m_jPutMethodId;
  53. jmethodID m_jMergeCfMethodId;
  54. jmethodID m_jMergeMethodId;
  55. jmethodID m_jDeleteCfMethodId;
  56. jmethodID m_jDeleteMethodId;
  57. jmethodID m_jSingleDeleteCfMethodId;
  58. jmethodID m_jSingleDeleteMethodId;
  59. jmethodID m_jDeleteRangeCfMethodId;
  60. jmethodID m_jDeleteRangeMethodId;
  61. jmethodID m_jLogDataMethodId;
  62. jmethodID m_jPutBlobIndexCfMethodId;
  63. jmethodID m_jMarkBeginPrepareMethodId;
  64. jmethodID m_jMarkEndPrepareMethodId;
  65. jmethodID m_jMarkNoopMethodId;
  66. jmethodID m_jMarkRollbackMethodId;
  67. jmethodID m_jMarkCommitMethodId;
  68. jmethodID m_jContinueMethodId;
  69. /**
  70. * @return A pointer to a ROCKSDB_NAMESPACE::Status or nullptr if an
  71. * unexpected exception occurred
  72. */
  73. std::unique_ptr<ROCKSDB_NAMESPACE::Status> kv_op(
  74. const Slice& key, const Slice& value,
  75. std::function<void(jbyteArray, jbyteArray)> kvFn);
  76. /**
  77. * @return A pointer to a ROCKSDB_NAMESPACE::Status or nullptr if an
  78. * unexpected exception occurred
  79. */
  80. std::unique_ptr<ROCKSDB_NAMESPACE::Status> k_op(
  81. const Slice& key, std::function<void(jbyteArray)> kFn);
  82. };
  83. } // namespace ROCKSDB_NAMESPACE
  84. #endif // JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_