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