]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/rocksjni/merge_operator.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / rocksjni / merge_operator.cc
CommitLineData
f67539c2 1// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
7c673cae 2// Copyright (c) 2014, Vlad Balan (vlad.gm@gmail.com). All rights reserved.
11fdf7f2
TL
3// This source code is licensed under both the GPLv2 (found in the
4// COPYING file in the root directory) and Apache 2.0 License
5// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
6//
7// This file implements the "bridge" between Java and C++
f67539c2 8// for ROCKSDB_NAMESPACE::MergeOperator.
7c673cae 9
1e59de90
TL
10#include "rocksdb/merge_operator.h"
11
11fdf7f2 12#include <jni.h>
7c673cae
FG
13#include <stdio.h>
14#include <stdlib.h>
1e59de90 15
7c673cae 16#include <memory>
11fdf7f2 17#include <string>
7c673cae
FG
18
19#include "include/org_rocksdb_StringAppendOperator.h"
494da23a 20#include "include/org_rocksdb_UInt64AddOperator.h"
7c673cae 21#include "rocksdb/db.h"
11fdf7f2 22#include "rocksdb/memtablerep.h"
7c673cae 23#include "rocksdb/options.h"
11fdf7f2 24#include "rocksdb/slice_transform.h"
7c673cae 25#include "rocksdb/statistics.h"
7c673cae 26#include "rocksdb/table.h"
1e59de90 27#include "rocksjni/cplusplus_to_java_convert.h"
11fdf7f2 28#include "rocksjni/portal.h"
7c673cae
FG
29#include "utilities/merge_operators.h"
30
31/*
32 * Class: org_rocksdb_StringAppendOperator
33 * Method: newSharedStringAppendOperator
11fdf7f2 34 * Signature: (C)J
7c673cae 35 */
1e59de90 36jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__C(
11fdf7f2 37 JNIEnv* /*env*/, jclass /*jclazz*/, jchar jdelim) {
f67539c2
TL
38 auto* sptr_string_append_op =
39 new std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>(
40 ROCKSDB_NAMESPACE::MergeOperators::CreateStringAppendOperator(
41 (char)jdelim));
1e59de90
TL
42 return GET_CPLUSPLUS_POINTER(sptr_string_append_op);
43}
44
45jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator__Ljava_lang_String_2(
46 JNIEnv* env, jclass /*jclass*/, jstring jdelim) {
47 jboolean has_exception = JNI_FALSE;
48 auto delim =
49 ROCKSDB_NAMESPACE::JniUtil::copyStdString(env, jdelim, &has_exception);
50 if (has_exception == JNI_TRUE) {
51 return 0;
52 }
53 auto* sptr_string_append_op =
54 new std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>(
55 ROCKSDB_NAMESPACE::MergeOperators::CreateStringAppendOperator(delim));
56 return GET_CPLUSPLUS_POINTER(sptr_string_append_op);
7c673cae
FG
57}
58
59/*
60 * Class: org_rocksdb_StringAppendOperator
61 * Method: disposeInternal
62 * Signature: (J)V
63 */
11fdf7f2
TL
64void Java_org_rocksdb_StringAppendOperator_disposeInternal(JNIEnv* /*env*/,
65 jobject /*jobj*/,
66 jlong jhandle) {
7c673cae 67 auto* sptr_string_append_op =
f67539c2
TL
68 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>*>(
69 jhandle);
7c673cae
FG
70 delete sptr_string_append_op; // delete std::shared_ptr
71}
494da23a
TL
72
73/*
74 * Class: org_rocksdb_UInt64AddOperator
75 * Method: newSharedUInt64AddOperator
76 * Signature: ()J
77 */
78jlong Java_org_rocksdb_UInt64AddOperator_newSharedUInt64AddOperator(
79 JNIEnv* /*env*/, jclass /*jclazz*/) {
f67539c2
TL
80 auto* sptr_uint64_add_op =
81 new std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>(
82 ROCKSDB_NAMESPACE::MergeOperators::CreateUInt64AddOperator());
1e59de90 83 return GET_CPLUSPLUS_POINTER(sptr_uint64_add_op);
494da23a
TL
84}
85
86/*
87 * Class: org_rocksdb_UInt64AddOperator
88 * Method: disposeInternal
89 * Signature: (J)V
90 */
91void Java_org_rocksdb_UInt64AddOperator_disposeInternal(JNIEnv* /*env*/,
92 jobject /*jobj*/,
93 jlong jhandle) {
94 auto* sptr_uint64_add_op =
f67539c2
TL
95 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::MergeOperator>*>(
96 jhandle);
494da23a
TL
97 delete sptr_uint64_add_op; // delete std::shared_ptr
98}