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).
6 // This file implements the "bridge" between Java and C++ for
7 // ROCKSDB_NAMESPACE::PersistentCache.
9 #include "rocksdb/persistent_cache.h"
15 #include "include/org_rocksdb_PersistentCache.h"
16 #include "loggerjnicallback.h"
18 #include "rocksjni/cplusplus_to_java_convert.h"
21 * Class: org_rocksdb_PersistentCache
22 * Method: newPersistentCache
23 * Signature: (JLjava/lang/String;JJZ)J
25 jlong
Java_org_rocksdb_PersistentCache_newPersistentCache(
26 JNIEnv
* env
, jclass
, jlong jenv_handle
, jstring jpath
, jlong jsz
,
27 jlong jlogger_handle
, jboolean joptimized_for_nvm
) {
28 auto* rocks_env
= reinterpret_cast<ROCKSDB_NAMESPACE::Env
*>(jenv_handle
);
29 jboolean has_exception
= JNI_FALSE
;
31 ROCKSDB_NAMESPACE::JniUtil::copyStdString(env
, jpath
, &has_exception
);
32 if (has_exception
== JNI_TRUE
) {
36 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::LoggerJniCallback
>*>(
39 new std::shared_ptr
<ROCKSDB_NAMESPACE::PersistentCache
>(nullptr);
40 ROCKSDB_NAMESPACE::Status s
= ROCKSDB_NAMESPACE::NewPersistentCache(
41 rocks_env
, path
, static_cast<uint64_t>(jsz
), *logger
,
42 static_cast<bool>(joptimized_for_nvm
), cache
);
44 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env
, s
);
46 return GET_CPLUSPLUS_POINTER(cache
);
50 * Class: org_rocksdb_PersistentCache
51 * Method: disposeInternal
54 void Java_org_rocksdb_PersistentCache_disposeInternal(JNIEnv
*, jobject
,
57 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::PersistentCache
>*>(
59 delete cache
; // delete std::shared_ptr