2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-10-23 15:19:38 +00:00
|
|
|
//
|
|
|
|
// This file implements the callback "bridge" between Java and C++ for
|
|
|
|
// rocksdb::WriteBatch::Handler.
|
|
|
|
|
|
|
|
#ifndef JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_
|
|
|
|
#define JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_
|
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
#include <functional>
|
2014-10-23 15:19:38 +00:00
|
|
|
#include <jni.h>
|
2018-03-02 23:33:08 +00:00
|
|
|
#include <memory>
|
2017-10-12 18:06:51 +00:00
|
|
|
#include "rocksjni/jnicallback.h"
|
2014-10-23 15:19:38 +00:00
|
|
|
#include "rocksdb/write_batch.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
/**
|
|
|
|
* This class acts as a bridge between C++
|
|
|
|
* and Java. The methods in this class will be
|
|
|
|
* called back from the RocksDB storage engine (C++)
|
2014-11-05 18:56:45 +00:00
|
|
|
* which calls the appropriate Java method.
|
|
|
|
* This enables Write Batch Handlers to be implemented in Java.
|
2014-10-23 15:19:38 +00:00
|
|
|
*/
|
2017-10-12 18:06:51 +00:00
|
|
|
class WriteBatchHandlerJniCallback : public JniCallback, public WriteBatch::Handler {
|
2014-10-23 15:19:38 +00:00
|
|
|
public:
|
|
|
|
WriteBatchHandlerJniCallback(
|
|
|
|
JNIEnv* env, jobject jWriteBackHandler);
|
2018-03-02 23:33:08 +00:00
|
|
|
Status PutCF(uint32_t column_family_id, const Slice& key,
|
|
|
|
const Slice& value);
|
2014-10-23 15:19:38 +00:00
|
|
|
void Put(const Slice& key, const Slice& value);
|
2018-03-02 23:33:08 +00:00
|
|
|
Status MergeCF(uint32_t column_family_id, const Slice& key,
|
|
|
|
const Slice& value);
|
2014-10-23 15:19:38 +00:00
|
|
|
void Merge(const Slice& key, const Slice& value);
|
2018-03-02 23:33:08 +00:00
|
|
|
Status DeleteCF(uint32_t column_family_id, const Slice& key);
|
2014-10-23 15:19:38 +00:00
|
|
|
void Delete(const Slice& key);
|
2018-03-02 23:33:08 +00:00
|
|
|
Status SingleDeleteCF(uint32_t column_family_id, const Slice& key);
|
|
|
|
void SingleDelete(const Slice& key);
|
|
|
|
Status DeleteRangeCF(uint32_t column_family_id, const Slice& beginKey,
|
|
|
|
const Slice& endKey);
|
2017-03-07 06:13:53 +00:00
|
|
|
void DeleteRange(const Slice& beginKey, const Slice& endKey);
|
2014-10-23 15:19:38 +00:00
|
|
|
void LogData(const Slice& blob);
|
2018-03-02 23:33:08 +00:00
|
|
|
Status PutBlobIndexCF(uint32_t column_family_id, const Slice& key,
|
|
|
|
const Slice& value);
|
|
|
|
Status MarkBeginPrepare();
|
|
|
|
Status MarkEndPrepare(const Slice& xid);
|
|
|
|
Status MarkNoop(bool empty_batch);
|
|
|
|
Status MarkRollback(const Slice& xid);
|
|
|
|
Status MarkCommit(const Slice& xid);
|
2014-10-23 15:19:38 +00:00
|
|
|
bool Continue();
|
|
|
|
|
|
|
|
private:
|
2014-11-05 18:56:45 +00:00
|
|
|
JNIEnv* m_env;
|
2018-03-02 23:33:08 +00:00
|
|
|
jmethodID m_jPutCfMethodId;
|
2014-10-23 15:19:38 +00:00
|
|
|
jmethodID m_jPutMethodId;
|
2018-03-02 23:33:08 +00:00
|
|
|
jmethodID m_jMergeCfMethodId;
|
2014-10-23 15:19:38 +00:00
|
|
|
jmethodID m_jMergeMethodId;
|
2018-03-02 23:33:08 +00:00
|
|
|
jmethodID m_jDeleteCfMethodId;
|
2014-10-23 15:19:38 +00:00
|
|
|
jmethodID m_jDeleteMethodId;
|
2018-03-02 23:33:08 +00:00
|
|
|
jmethodID m_jSingleDeleteCfMethodId;
|
|
|
|
jmethodID m_jSingleDeleteMethodId;
|
|
|
|
jmethodID m_jDeleteRangeCfMethodId;
|
2017-03-07 06:13:53 +00:00
|
|
|
jmethodID m_jDeleteRangeMethodId;
|
2014-10-23 15:19:38 +00:00
|
|
|
jmethodID m_jLogDataMethodId;
|
2018-03-02 23:33:08 +00:00
|
|
|
jmethodID m_jPutBlobIndexCfMethodId;
|
|
|
|
jmethodID m_jMarkBeginPrepareMethodId;
|
|
|
|
jmethodID m_jMarkEndPrepareMethodId;
|
|
|
|
jmethodID m_jMarkNoopMethodId;
|
|
|
|
jmethodID m_jMarkRollbackMethodId;
|
|
|
|
jmethodID m_jMarkCommitMethodId;
|
2014-10-23 15:19:38 +00:00
|
|
|
jmethodID m_jContinueMethodId;
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* @return A pointer to a rocksdb::Status or nullptr if an unexpected exception occurred
|
|
|
|
*/
|
|
|
|
std::unique_ptr<rocksdb::Status> kv_op(const Slice& key, const Slice& value, std::function<void(jbyteArray, jbyteArray)> kvFn);
|
|
|
|
/**
|
|
|
|
* @return A pointer to a rocksdb::Status or nullptr if an unexpected exception occurred
|
|
|
|
*/
|
|
|
|
std::unique_ptr<rocksdb::Status> k_op(const Slice& key, std::function<void(jbyteArray)> kFn);
|
2014-10-23 15:19:38 +00:00
|
|
|
};
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
#endif // JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_
|