From f6156fb558441387b398b00f8244a50e92e875ef Mon Sep 17 00:00:00 2001 From: Javeme Lee Date: Thu, 8 Mar 2018 15:59:51 -0800 Subject: [PATCH] Support StringAppendOperator(delimiter_char) constructor in java-api Summary: Fixes #3336 Closes https://github.com/facebook/rocksdb/pull/3337 Differential Revision: D7196585 Pulled By: sagar0 fbshipit-source-id: a854f3fc906862ecba685b31946e4ef7c0b421c5 --- java/rocksjni/merge_operator.cc | 6 +++--- java/src/main/java/org/rocksdb/StringAppendOperator.java | 8 ++++++-- utilities/merge_operators.h | 1 + utilities/merge_operators/string_append/stringappend.cc | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/java/rocksjni/merge_operator.cc b/java/rocksjni/merge_operator.cc index 1b94382ef..017790817 100644 --- a/java/rocksjni/merge_operator.cc +++ b/java/rocksjni/merge_operator.cc @@ -26,12 +26,12 @@ /* * Class: org_rocksdb_StringAppendOperator * Method: newSharedStringAppendOperator - * Signature: ()J + * Signature: (C)J */ jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator -(JNIEnv* env, jclass jclazz) { +(JNIEnv* env, jclass jclazz, jchar jdelim) { auto* sptr_string_append_op = new std::shared_ptr( - rocksdb::MergeOperators::CreateFromStringId("stringappend")); + rocksdb::MergeOperators::CreateStringAppendOperator((char) jdelim)); return reinterpret_cast(sptr_string_append_op); } diff --git a/java/src/main/java/org/rocksdb/StringAppendOperator.java b/java/src/main/java/org/rocksdb/StringAppendOperator.java index 85c36adc7..978cad6cc 100644 --- a/java/src/main/java/org/rocksdb/StringAppendOperator.java +++ b/java/src/main/java/org/rocksdb/StringAppendOperator.java @@ -11,9 +11,13 @@ package org.rocksdb; */ public class StringAppendOperator extends MergeOperator { public StringAppendOperator() { - super(newSharedStringAppendOperator()); + this(','); } - private native static long newSharedStringAppendOperator(); + public StringAppendOperator(char delim) { + super(newSharedStringAppendOperator(delim)); + } + + private native static long newSharedStringAppendOperator(final char delim); @Override protected final native void disposeInternal(final long handle); } diff --git a/utilities/merge_operators.h b/utilities/merge_operators.h index 40a19cf86..4c720b822 100644 --- a/utilities/merge_operators.h +++ b/utilities/merge_operators.h @@ -19,6 +19,7 @@ class MergeOperators { static std::shared_ptr CreateDeprecatedPutOperator(); static std::shared_ptr CreateUInt64AddOperator(); static std::shared_ptr CreateStringAppendOperator(); + static std::shared_ptr CreateStringAppendOperator(char delim_char); static std::shared_ptr CreateStringAppendTESTOperator(); static std::shared_ptr CreateMaxOperator(); static std::shared_ptr CreateBytesXOROperator(); diff --git a/utilities/merge_operators/string_append/stringappend.cc b/utilities/merge_operators/string_append/stringappend.cc index e3e755dfd..d9c135fd3 100644 --- a/utilities/merge_operators/string_append/stringappend.cc +++ b/utilities/merge_operators/string_append/stringappend.cc @@ -52,4 +52,8 @@ std::shared_ptr MergeOperators::CreateStringAppendOperator() { return std::make_shared(','); } +std::shared_ptr MergeOperators::CreateStringAppendOperator(char delim_char) { + return std::make_shared(delim_char); +} + } // namespace rocksdb