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++ and enables
7 // calling c++ ROCKSDB_NAMESPACE::Checkpoint methods from Java side.
8
9 #include <jni.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string>
13
14 #include "include/org_rocksdb_Checkpoint.h"
15 #include "rocksdb/db.h"
16 #include "rocksdb/utilities/checkpoint.h"
17 #include "rocksjni/portal.h"
18 /*
19 * Class: org_rocksdb_Checkpoint
20 * Method: newCheckpoint
21 * Signature: (J)J
22 */
Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv *,jclass,jlong jdb_handle)23 jlong Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv* /*env*/,
24 jclass /*jclazz*/,
25 jlong jdb_handle) {
26 auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
27 ROCKSDB_NAMESPACE::Checkpoint* checkpoint;
28 ROCKSDB_NAMESPACE::Checkpoint::Create(db, &checkpoint);
29 return reinterpret_cast<jlong>(checkpoint);
30 }
31
32 /*
33 * Class: org_rocksdb_Checkpoint
34 * Method: dispose
35 * Signature: (J)V
36 */
Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv *,jobject,jlong jhandle)37 void Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv* /*env*/,
38 jobject /*jobj*/,
39 jlong jhandle) {
40 auto* checkpoint = reinterpret_cast<ROCKSDB_NAMESPACE::Checkpoint*>(jhandle);
41 assert(checkpoint != nullptr);
42 delete checkpoint;
43 }
44
45 /*
46 * Class: org_rocksdb_Checkpoint
47 * Method: createCheckpoint
48 * Signature: (JLjava/lang/String;)V
49 */
Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv * env,jobject,jlong jcheckpoint_handle,jstring jcheckpoint_path)50 void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jobject /*jobj*/,
51 jlong jcheckpoint_handle,
52 jstring jcheckpoint_path) {
53 const char* checkpoint_path = env->GetStringUTFChars(jcheckpoint_path, 0);
54 if (checkpoint_path == nullptr) {
55 // exception thrown: OutOfMemoryError
56 return;
57 }
58
59 auto* checkpoint =
60 reinterpret_cast<ROCKSDB_NAMESPACE::Checkpoint*>(jcheckpoint_handle);
61 ROCKSDB_NAMESPACE::Status s = checkpoint->CreateCheckpoint(checkpoint_path);
62
63 env->ReleaseStringUTFChars(jcheckpoint_path, checkpoint_path);
64
65 if (!s.ok()) {
66 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
67 }
68 }
69