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