2019-04-18 17:51:19 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2014-09-16 20:58:49 +00:00
|
|
|
// Copyright (c) 2014, Vlad Balan (vlad.gm@gmail.com). 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-09-16 20:58:49 +00:00
|
|
|
//
|
2014-10-06 23:58:24 +00:00
|
|
|
// This file implements the "bridge" between Java and C++
|
2020-02-20 20:07:53 +00:00
|
|
|
// for ROCKSDB_NAMESPACE::MergeOperator.
|
2014-09-16 20:58:49 +00:00
|
|
|
|
2022-03-01 17:02:15 +00:00
|
|
|
#include "rocksdb/merge_operator.h"
|
|
|
|
|
2018-04-13 00:55:14 +00:00
|
|
|
#include <jni.h>
|
2014-09-16 20:58:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2022-03-01 17:02:15 +00:00
|
|
|
|
2014-09-16 20:58:49 +00:00
|
|
|
#include <memory>
|
2018-04-13 00:55:14 +00:00
|
|
|
#include <string>
|
2014-09-16 20:58:49 +00:00
|
|
|
|
|
|
|
#include "include/org_rocksdb_StringAppendOperator.h"
|
2018-10-13 00:33:55 +00:00
|
|
|
#include "include/org_rocksdb_UInt64AddOperator.h"
|
2014-09-16 20:58:49 +00:00
|
|
|
#include "rocksdb/db.h"
|
2018-04-13 00:55:14 +00:00
|
|
|
#include "rocksdb/memtablerep.h"
|
2014-09-16 20:58:49 +00:00
|
|
|
#include "rocksdb/options.h"
|
2018-04-13 00:55:14 +00:00
|
|
|
#include "rocksdb/slice_transform.h"
|
2014-09-16 20:58:49 +00:00
|
|
|
#include "rocksdb/statistics.h"
|
|
|
|
#include "rocksdb/table.h"
|
2022-03-01 17:02:15 +00:00
|
|
|
#include "rocksjni/cplusplus_to_java_convert.h"
|
2018-04-13 00:55:14 +00:00
|
|
|
#include "rocksjni/portal.h"
|
2014-09-16 20:58:49 +00:00
|
|
|
#include "utilities/merge_operators.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_StringAppendOperator
|
2017-02-28 00:26:12 +00:00
|
|
|
* Method: newSharedStringAppendOperator
|
2018-03-08 23:59:51 +00:00
|
|
|
* Signature: (C)J
|
2014-09-16 20:58:49 +00:00
|
|
|
*/
|
2021-08-02 23:49:54 +00:00
|
|
|
jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__C(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* /*env*/, jclass /*jclazz*/, jchar jdelim) {
|
2020-02-20 20:07:53 +00:00
|
|
|
auto* sptr_string_append_op =
|
|
|
|
new std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>(
|
|
|
|
ROCKSDB_NAMESPACE::MergeOperators::CreateStringAppendOperator(
|
|
|
|
(char)jdelim));
|
2022-03-01 17:02:15 +00:00
|
|
|
return GET_CPLUSPLUS_POINTER(sptr_string_append_op);
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 23:49:54 +00:00
|
|
|
jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jclass /*jclass*/, jstring jdelim) {
|
|
|
|
jboolean has_exception = JNI_FALSE;
|
|
|
|
auto delim =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::copyStdString(env, jdelim, &has_exception);
|
|
|
|
if (has_exception == JNI_TRUE) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
auto* sptr_string_append_op =
|
|
|
|
new std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>(
|
|
|
|
ROCKSDB_NAMESPACE::MergeOperators::CreateStringAppendOperator(delim));
|
2022-03-01 17:02:15 +00:00
|
|
|
return GET_CPLUSPLUS_POINTER(sptr_string_append_op);
|
2021-08-02 23:49:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_StringAppendOperator
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2024-01-25 20:36:30 +00:00
|
|
|
void Java_org_rocksdb_StringAppendOperator_disposeInternalJni(JNIEnv* /*env*/,
|
|
|
|
jclass /*jcls*/,
|
|
|
|
jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* sptr_string_append_op =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>*>(
|
|
|
|
jhandle);
|
2017-02-28 00:26:12 +00:00
|
|
|
delete sptr_string_append_op; // delete std::shared_ptr
|
2014-09-16 20:58:49 +00:00
|
|
|
}
|
2018-10-13 00:33:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_UInt64AddOperator
|
|
|
|
* Method: newSharedUInt64AddOperator
|
|
|
|
* Signature: ()J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_UInt64AddOperator_newSharedUInt64AddOperator(
|
|
|
|
JNIEnv* /*env*/, jclass /*jclazz*/) {
|
2020-02-20 20:07:53 +00:00
|
|
|
auto* sptr_uint64_add_op =
|
|
|
|
new std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>(
|
|
|
|
ROCKSDB_NAMESPACE::MergeOperators::CreateUInt64AddOperator());
|
2022-03-01 17:02:15 +00:00
|
|
|
return GET_CPLUSPLUS_POINTER(sptr_uint64_add_op);
|
2018-10-13 00:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_UInt64AddOperator
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2024-01-25 20:36:30 +00:00
|
|
|
void Java_org_rocksdb_UInt64AddOperator_disposeInternalJni(JNIEnv* /*env*/,
|
|
|
|
jclass /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2018-10-13 00:33:55 +00:00
|
|
|
auto* sptr_uint64_add_op =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>*>(
|
|
|
|
jhandle);
|
2018-10-13 00:33:55 +00:00
|
|
|
delete sptr_uint64_add_op; // delete std::shared_ptr
|
|
|
|
}
|