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::PersistentCache.
12 #include "include/org_rocksdb_PersistentCache.h"
13 #include "rocksdb/persistent_cache.h"
14 #include "loggerjnicallback.h"
18 * Class: org_rocksdb_PersistentCache
19 * Method: newPersistentCache
20 * Signature: (JLjava/lang/String;JJZ)J
22 jlong
Java_org_rocksdb_PersistentCache_newPersistentCache(
23 JNIEnv
* env
, jclass
, jlong jenv_handle
, jstring jpath
,
24 jlong jsz
, jlong jlogger_handle
, jboolean joptimized_for_nvm
) {
25 auto* rocks_env
= reinterpret_cast<rocksdb::Env
*>(jenv_handle
);
26 jboolean has_exception
= JNI_FALSE
;
27 std::string path
= rocksdb::JniUtil::copyStdString(env
, jpath
, &has_exception
);
28 if (has_exception
== JNI_TRUE
) {
32 reinterpret_cast<std::shared_ptr
<rocksdb::LoggerJniCallback
>*>(jlogger_handle
);
33 auto* cache
= new std::shared_ptr
<rocksdb::PersistentCache
>(nullptr);
34 rocksdb::Status s
= rocksdb::NewPersistentCache(
35 rocks_env
, path
, static_cast<uint64_t>(jsz
), *logger
,
36 static_cast<bool>(joptimized_for_nvm
), cache
);
38 rocksdb::RocksDBExceptionJni::ThrowNew(env
, s
);
40 return reinterpret_cast<jlong
>(cache
);
44 * Class: org_rocksdb_PersistentCache
45 * Method: disposeInternal
48 void Java_org_rocksdb_PersistentCache_disposeInternal(
49 JNIEnv
*, jobject
, jlong jhandle
) {
51 reinterpret_cast<std::shared_ptr
<rocksdb::PersistentCache
>*>(jhandle
);
52 delete cache
; // delete std::shared_ptr