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).
5 //
6 // This file implements the "bridge" between Java and C++
7 // for rocksdb::TransactionNotifier.
8 
9 #include <jni.h>
10 
11 #include "include/org_rocksdb_AbstractTransactionNotifier.h"
12 #include "rocksjni/transaction_notifier_jnicallback.h"
13 
14 /*
15  * Class:     org_rocksdb_AbstractTransactionNotifier
16  * Method:    createNewTransactionNotifier
17  * Signature: ()J
18  */
Java_org_rocksdb_AbstractTransactionNotifier_createNewTransactionNotifier(JNIEnv * env,jobject jobj)19 jlong Java_org_rocksdb_AbstractTransactionNotifier_createNewTransactionNotifier(
20     JNIEnv* env, jobject jobj) {
21   auto* transaction_notifier =
22       new rocksdb::TransactionNotifierJniCallback(env, jobj);
23   auto* sptr_transaction_notifier =
24       new std::shared_ptr<rocksdb::TransactionNotifierJniCallback>(
25           transaction_notifier);
26   return reinterpret_cast<jlong>(sptr_transaction_notifier);
27 }
28 
29 /*
30  * Class:     org_rocksdb_AbstractTransactionNotifier
31  * Method:    disposeInternal
32  * Signature: (J)V
33  */
Java_org_rocksdb_AbstractTransactionNotifier_disposeInternal(JNIEnv *,jobject,jlong jhandle)34 void Java_org_rocksdb_AbstractTransactionNotifier_disposeInternal(
35     JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
36   // TODO(AR) refactor to use JniCallback::JniCallback
37   // when https://github.com/facebook/rocksdb/pull/1241/ is merged
38   std::shared_ptr<rocksdb::TransactionNotifierJniCallback>* handle =
39       reinterpret_cast<
40           std::shared_ptr<rocksdb::TransactionNotifierJniCallback>*>(jhandle);
41   delete handle;
42 }
43