]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | // This file is designed for caching those frequently used IDs and provide | |
7 | // efficient portal (i.e, a set of static functions) to access java code | |
8 | // from c++. | |
9 | ||
10 | #ifndef JAVA_ROCKSJNI_PORTAL_H_ | |
11 | #define JAVA_ROCKSJNI_PORTAL_H_ | |
12 | ||
494da23a | 13 | #include <algorithm> |
11fdf7f2 | 14 | #include <cstring> |
7c673cae FG |
15 | #include <functional> |
16 | #include <iostream> | |
11fdf7f2 | 17 | #include <iterator> |
494da23a | 18 | #include <jni.h> |
7c673cae | 19 | #include <limits> |
11fdf7f2 | 20 | #include <memory> |
7c673cae | 21 | #include <string> |
11fdf7f2 | 22 | #include <type_traits> |
7c673cae FG |
23 | #include <vector> |
24 | ||
25 | #include "rocksdb/db.h" | |
26 | #include "rocksdb/filter_policy.h" | |
11fdf7f2 | 27 | #include "rocksdb/rate_limiter.h" |
7c673cae | 28 | #include "rocksdb/status.h" |
494da23a | 29 | #include "rocksdb/table.h" |
7c673cae | 30 | #include "rocksdb/utilities/backupable_db.h" |
494da23a | 31 | #include "rocksdb/utilities/memory_util.h" |
11fdf7f2 | 32 | #include "rocksdb/utilities/transaction_db.h" |
7c673cae | 33 | #include "rocksdb/utilities/write_batch_with_index.h" |
11fdf7f2 | 34 | #include "rocksjni/compaction_filter_factory_jnicallback.h" |
7c673cae FG |
35 | #include "rocksjni/comparatorjnicallback.h" |
36 | #include "rocksjni/loggerjnicallback.h" | |
494da23a TL |
37 | #include "rocksjni/table_filter_jnicallback.h" |
38 | #include "rocksjni/trace_writer_jnicallback.h" | |
11fdf7f2 | 39 | #include "rocksjni/transaction_notifier_jnicallback.h" |
494da23a | 40 | #include "rocksjni/wal_filter_jnicallback.h" |
7c673cae FG |
41 | #include "rocksjni/writebatchhandlerjnicallback.h" |
42 | ||
43 | // Remove macro on windows | |
44 | #ifdef DELETE | |
45 | #undef DELETE | |
46 | #endif | |
47 | ||
48 | namespace rocksdb { | |
49 | ||
7c673cae FG |
50 | class JavaClass { |
51 | public: | |
52 | /** | |
53 | * Gets and initializes a Java Class | |
54 | * | |
55 | * @param env A pointer to the Java environment | |
56 | * @param jclazz_name The fully qualified JNI name of the Java Class | |
57 | * e.g. "java/lang/String" | |
58 | * | |
59 | * @return The Java Class or nullptr if one of the | |
60 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
61 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
62 | */ | |
63 | static jclass getJClass(JNIEnv* env, const char* jclazz_name) { | |
64 | jclass jclazz = env->FindClass(jclazz_name); | |
65 | assert(jclazz != nullptr); | |
66 | return jclazz; | |
67 | } | |
68 | }; | |
69 | ||
70 | // Native class template | |
71 | template<class PTR, class DERIVED> class RocksDBNativeClass : public JavaClass { | |
72 | }; | |
73 | ||
74 | // Native class template for sub-classes of RocksMutableObject | |
75 | template<class PTR, class DERIVED> class NativeRocksMutableObject | |
76 | : public RocksDBNativeClass<PTR, DERIVED> { | |
77 | public: | |
78 | ||
79 | /** | |
80 | * Gets the Java Method ID for the | |
81 | * RocksMutableObject#setNativeHandle(long, boolean) method | |
82 | * | |
83 | * @param env A pointer to the Java environment | |
84 | * @return The Java Method ID or nullptr the RocksMutableObject class cannot | |
85 | * be accessed, or if one of the NoSuchMethodError, | |
86 | * ExceptionInInitializerError or OutOfMemoryError exceptions is thrown | |
87 | */ | |
88 | static jmethodID getSetNativeHandleMethod(JNIEnv* env) { | |
89 | static jclass jclazz = DERIVED::getJClass(env); | |
90 | if(jclazz == nullptr) { | |
91 | return nullptr; | |
92 | } | |
93 | ||
94 | static jmethodID mid = env->GetMethodID( | |
95 | jclazz, "setNativeHandle", "(JZ)V"); | |
96 | assert(mid != nullptr); | |
97 | return mid; | |
98 | } | |
99 | ||
100 | /** | |
101 | * Sets the C++ object pointer handle in the Java object | |
102 | * | |
103 | * @param env A pointer to the Java environment | |
104 | * @param jobj The Java object on which to set the pointer handle | |
105 | * @param ptr The C++ object pointer | |
106 | * @param java_owns_handle JNI_TRUE if ownership of the C++ object is | |
107 | * managed by the Java object | |
108 | * | |
109 | * @return true if a Java exception is pending, false otherwise | |
110 | */ | |
111 | static bool setHandle(JNIEnv* env, jobject jobj, PTR ptr, | |
112 | jboolean java_owns_handle) { | |
113 | assert(jobj != nullptr); | |
114 | static jmethodID mid = getSetNativeHandleMethod(env); | |
115 | if(mid == nullptr) { | |
116 | return true; // signal exception | |
117 | } | |
118 | ||
119 | env->CallVoidMethod(jobj, mid, reinterpret_cast<jlong>(ptr), java_owns_handle); | |
120 | if(env->ExceptionCheck()) { | |
121 | return true; // signal exception | |
122 | } | |
123 | ||
124 | return false; | |
125 | } | |
126 | }; | |
127 | ||
128 | // Java Exception template | |
129 | template<class DERIVED> class JavaException : public JavaClass { | |
130 | public: | |
131 | /** | |
132 | * Create and throw a java exception with the provided message | |
133 | * | |
134 | * @param env A pointer to the Java environment | |
135 | * @param msg The message for the exception | |
136 | * | |
137 | * @return true if an exception was thrown, false otherwise | |
138 | */ | |
139 | static bool ThrowNew(JNIEnv* env, const std::string& msg) { | |
140 | jclass jclazz = DERIVED::getJClass(env); | |
141 | if(jclazz == nullptr) { | |
142 | // exception occurred accessing class | |
143 | std::cerr << "JavaException::ThrowNew - Error: unexpected exception!" << std::endl; | |
144 | return env->ExceptionCheck(); | |
145 | } | |
146 | ||
147 | const jint rs = env->ThrowNew(jclazz, msg.c_str()); | |
148 | if(rs != JNI_OK) { | |
149 | // exception could not be thrown | |
150 | std::cerr << "JavaException::ThrowNew - Fatal: could not throw exception!" << std::endl; | |
151 | return env->ExceptionCheck(); | |
152 | } | |
153 | ||
154 | return true; | |
155 | } | |
156 | }; | |
157 | ||
494da23a TL |
158 | // The portal class for java.lang.IllegalArgumentException |
159 | class IllegalArgumentExceptionJni : | |
160 | public JavaException<IllegalArgumentExceptionJni> { | |
7c673cae FG |
161 | public: |
162 | /** | |
494da23a | 163 | * Get the Java Class java.lang.IllegalArgumentException |
7c673cae FG |
164 | * |
165 | * @param env A pointer to the Java environment | |
166 | * | |
167 | * @return The Java Class or nullptr if one of the | |
168 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
169 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
170 | */ | |
171 | static jclass getJClass(JNIEnv* env) { | |
494da23a TL |
172 | return JavaException::getJClass(env, "java/lang/IllegalArgumentException"); |
173 | } | |
174 | ||
175 | /** | |
176 | * Create and throw a Java IllegalArgumentException with the provided status | |
177 | * | |
178 | * If s.ok() == true, then this function will not throw any exception. | |
179 | * | |
180 | * @param env A pointer to the Java environment | |
181 | * @param s The status for the exception | |
182 | * | |
183 | * @return true if an exception was thrown, false otherwise | |
184 | */ | |
185 | static bool ThrowNew(JNIEnv* env, const Status& s) { | |
186 | assert(!s.ok()); | |
187 | if (s.ok()) { | |
188 | return false; | |
189 | } | |
190 | ||
191 | // get the IllegalArgumentException class | |
192 | jclass jclazz = getJClass(env); | |
193 | if(jclazz == nullptr) { | |
194 | // exception occurred accessing class | |
195 | std::cerr << "IllegalArgumentExceptionJni::ThrowNew/class - Error: unexpected exception!" << std::endl; | |
196 | return env->ExceptionCheck(); | |
197 | } | |
198 | ||
199 | return JavaException::ThrowNew(env, s.ToString()); | |
7c673cae FG |
200 | } |
201 | }; | |
202 | ||
11fdf7f2 TL |
203 | // The portal class for org.rocksdb.Status.Code |
204 | class CodeJni : public JavaClass { | |
205 | public: | |
206 | /** | |
207 | * Get the Java Class org.rocksdb.Status.Code | |
208 | * | |
209 | * @param env A pointer to the Java environment | |
210 | * | |
211 | * @return The Java Class or nullptr if one of the | |
212 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
213 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
214 | */ | |
215 | static jclass getJClass(JNIEnv* env) { | |
216 | return JavaClass::getJClass(env, "org/rocksdb/Status$Code"); | |
217 | } | |
218 | ||
219 | /** | |
220 | * Get the Java Method: Status.Code#getValue | |
221 | * | |
222 | * @param env A pointer to the Java environment | |
223 | * | |
224 | * @return The Java Method ID or nullptr if the class or method id could not | |
225 | * be retieved | |
226 | */ | |
227 | static jmethodID getValueMethod(JNIEnv* env) { | |
228 | jclass jclazz = getJClass(env); | |
229 | if(jclazz == nullptr) { | |
230 | // exception occurred accessing class | |
231 | return nullptr; | |
232 | } | |
233 | ||
234 | static jmethodID mid = | |
235 | env->GetMethodID(jclazz, "getValue", "()b"); | |
236 | assert(mid != nullptr); | |
237 | return mid; | |
238 | } | |
239 | }; | |
240 | ||
241 | // The portal class for org.rocksdb.Status.SubCode | |
242 | class SubCodeJni : public JavaClass { | |
243 | public: | |
244 | /** | |
245 | * Get the Java Class org.rocksdb.Status.SubCode | |
246 | * | |
247 | * @param env A pointer to the Java environment | |
248 | * | |
249 | * @return The Java Class or nullptr if one of the | |
250 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
251 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
252 | */ | |
253 | static jclass getJClass(JNIEnv* env) { | |
254 | return JavaClass::getJClass(env, "org/rocksdb/Status$SubCode"); | |
255 | } | |
256 | ||
257 | /** | |
258 | * Get the Java Method: Status.SubCode#getValue | |
259 | * | |
260 | * @param env A pointer to the Java environment | |
261 | * | |
262 | * @return The Java Method ID or nullptr if the class or method id could not | |
263 | * be retieved | |
264 | */ | |
265 | static jmethodID getValueMethod(JNIEnv* env) { | |
266 | jclass jclazz = getJClass(env); | |
267 | if(jclazz == nullptr) { | |
268 | // exception occurred accessing class | |
269 | return nullptr; | |
270 | } | |
271 | ||
272 | static jmethodID mid = | |
273 | env->GetMethodID(jclazz, "getValue", "()b"); | |
274 | assert(mid != nullptr); | |
275 | return mid; | |
276 | } | |
277 | ||
278 | static rocksdb::Status::SubCode toCppSubCode(const jbyte jsub_code) { | |
279 | switch (jsub_code) { | |
280 | case 0x0: | |
281 | return rocksdb::Status::SubCode::kNone; | |
282 | case 0x1: | |
283 | return rocksdb::Status::SubCode::kMutexTimeout; | |
284 | case 0x2: | |
285 | return rocksdb::Status::SubCode::kLockTimeout; | |
286 | case 0x3: | |
287 | return rocksdb::Status::SubCode::kLockLimit; | |
288 | case 0x4: | |
289 | return rocksdb::Status::SubCode::kNoSpace; | |
290 | case 0x5: | |
291 | return rocksdb::Status::SubCode::kDeadlock; | |
292 | case 0x6: | |
293 | return rocksdb::Status::SubCode::kStaleFile; | |
294 | case 0x7: | |
295 | return rocksdb::Status::SubCode::kMemoryLimit; | |
296 | ||
297 | case 0x7F: | |
298 | default: | |
299 | return rocksdb::Status::SubCode::kNone; | |
300 | } | |
301 | } | |
302 | }; | |
303 | ||
7c673cae FG |
304 | // The portal class for org.rocksdb.Status |
305 | class StatusJni : public RocksDBNativeClass<rocksdb::Status*, StatusJni> { | |
306 | public: | |
307 | /** | |
308 | * Get the Java Class org.rocksdb.Status | |
309 | * | |
310 | * @param env A pointer to the Java environment | |
311 | * | |
312 | * @return The Java Class or nullptr if one of the | |
313 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
314 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
315 | */ | |
316 | static jclass getJClass(JNIEnv* env) { | |
317 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/Status"); | |
318 | } | |
319 | ||
11fdf7f2 TL |
320 | /** |
321 | * Get the Java Method: Status#getCode | |
322 | * | |
323 | * @param env A pointer to the Java environment | |
324 | * | |
325 | * @return The Java Method ID or nullptr if the class or method id could not | |
326 | * be retieved | |
327 | */ | |
328 | static jmethodID getCodeMethod(JNIEnv* env) { | |
329 | jclass jclazz = getJClass(env); | |
330 | if(jclazz == nullptr) { | |
331 | // exception occurred accessing class | |
332 | return nullptr; | |
333 | } | |
334 | ||
335 | static jmethodID mid = | |
336 | env->GetMethodID(jclazz, "getCode", "()Lorg/rocksdb/Status$Code;"); | |
337 | assert(mid != nullptr); | |
338 | return mid; | |
339 | } | |
340 | ||
341 | /** | |
342 | * Get the Java Method: Status#getSubCode | |
343 | * | |
344 | * @param env A pointer to the Java environment | |
345 | * | |
346 | * @return The Java Method ID or nullptr if the class or method id could not | |
347 | * be retieved | |
348 | */ | |
349 | static jmethodID getSubCodeMethod(JNIEnv* env) { | |
350 | jclass jclazz = getJClass(env); | |
351 | if(jclazz == nullptr) { | |
352 | // exception occurred accessing class | |
353 | return nullptr; | |
354 | } | |
355 | ||
356 | static jmethodID mid = | |
357 | env->GetMethodID(jclazz, "getSubCode", "()Lorg/rocksdb/Status$SubCode;"); | |
358 | assert(mid != nullptr); | |
359 | return mid; | |
360 | } | |
361 | ||
362 | /** | |
363 | * Get the Java Method: Status#getState | |
364 | * | |
365 | * @param env A pointer to the Java environment | |
366 | * | |
367 | * @return The Java Method ID or nullptr if the class or method id could not | |
368 | * be retieved | |
369 | */ | |
370 | static jmethodID getStateMethod(JNIEnv* env) { | |
371 | jclass jclazz = getJClass(env); | |
372 | if(jclazz == nullptr) { | |
373 | // exception occurred accessing class | |
374 | return nullptr; | |
375 | } | |
376 | ||
377 | static jmethodID mid = | |
378 | env->GetMethodID(jclazz, "getState", "()Ljava/lang/String;"); | |
379 | assert(mid != nullptr); | |
380 | return mid; | |
381 | } | |
382 | ||
7c673cae FG |
383 | /** |
384 | * Create a new Java org.rocksdb.Status object with the same properties as | |
385 | * the provided C++ rocksdb::Status object | |
386 | * | |
387 | * @param env A pointer to the Java environment | |
388 | * @param status The rocksdb::Status object | |
389 | * | |
390 | * @return A reference to a Java org.rocksdb.Status object, or nullptr | |
391 | * if an an exception occurs | |
392 | */ | |
393 | static jobject construct(JNIEnv* env, const Status& status) { | |
394 | jclass jclazz = getJClass(env); | |
395 | if(jclazz == nullptr) { | |
396 | // exception occurred accessing class | |
397 | return nullptr; | |
398 | } | |
399 | ||
400 | jmethodID mid = | |
401 | env->GetMethodID(jclazz, "<init>", "(BBLjava/lang/String;)V"); | |
402 | if(mid == nullptr) { | |
403 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
404 | return nullptr; | |
405 | } | |
406 | ||
407 | // convert the Status state for Java | |
408 | jstring jstate = nullptr; | |
409 | if (status.getState() != nullptr) { | |
410 | const char* const state = status.getState(); | |
411 | jstate = env->NewStringUTF(state); | |
412 | if(env->ExceptionCheck()) { | |
413 | if(jstate != nullptr) { | |
414 | env->DeleteLocalRef(jstate); | |
415 | } | |
416 | return nullptr; | |
417 | } | |
418 | } | |
419 | ||
420 | jobject jstatus = | |
421 | env->NewObject(jclazz, mid, toJavaStatusCode(status.code()), | |
422 | toJavaStatusSubCode(status.subcode()), jstate); | |
423 | if(env->ExceptionCheck()) { | |
424 | // exception occurred | |
425 | if(jstate != nullptr) { | |
426 | env->DeleteLocalRef(jstate); | |
427 | } | |
428 | return nullptr; | |
429 | } | |
430 | ||
431 | if(jstate != nullptr) { | |
432 | env->DeleteLocalRef(jstate); | |
433 | } | |
434 | ||
435 | return jstatus; | |
436 | } | |
437 | ||
438 | // Returns the equivalent org.rocksdb.Status.Code for the provided | |
439 | // C++ rocksdb::Status::Code enum | |
440 | static jbyte toJavaStatusCode(const rocksdb::Status::Code& code) { | |
441 | switch (code) { | |
442 | case rocksdb::Status::Code::kOk: | |
443 | return 0x0; | |
444 | case rocksdb::Status::Code::kNotFound: | |
445 | return 0x1; | |
446 | case rocksdb::Status::Code::kCorruption: | |
447 | return 0x2; | |
448 | case rocksdb::Status::Code::kNotSupported: | |
449 | return 0x3; | |
450 | case rocksdb::Status::Code::kInvalidArgument: | |
451 | return 0x4; | |
452 | case rocksdb::Status::Code::kIOError: | |
453 | return 0x5; | |
454 | case rocksdb::Status::Code::kMergeInProgress: | |
455 | return 0x6; | |
456 | case rocksdb::Status::Code::kIncomplete: | |
457 | return 0x7; | |
458 | case rocksdb::Status::Code::kShutdownInProgress: | |
459 | return 0x8; | |
460 | case rocksdb::Status::Code::kTimedOut: | |
461 | return 0x9; | |
462 | case rocksdb::Status::Code::kAborted: | |
463 | return 0xA; | |
464 | case rocksdb::Status::Code::kBusy: | |
465 | return 0xB; | |
466 | case rocksdb::Status::Code::kExpired: | |
467 | return 0xC; | |
468 | case rocksdb::Status::Code::kTryAgain: | |
469 | return 0xD; | |
470 | default: | |
471 | return 0x7F; // undefined | |
472 | } | |
473 | } | |
474 | ||
475 | // Returns the equivalent org.rocksdb.Status.SubCode for the provided | |
476 | // C++ rocksdb::Status::SubCode enum | |
477 | static jbyte toJavaStatusSubCode(const rocksdb::Status::SubCode& subCode) { | |
478 | switch (subCode) { | |
479 | case rocksdb::Status::SubCode::kNone: | |
480 | return 0x0; | |
481 | case rocksdb::Status::SubCode::kMutexTimeout: | |
482 | return 0x1; | |
483 | case rocksdb::Status::SubCode::kLockTimeout: | |
484 | return 0x2; | |
485 | case rocksdb::Status::SubCode::kLockLimit: | |
486 | return 0x3; | |
11fdf7f2 TL |
487 | case rocksdb::Status::SubCode::kNoSpace: |
488 | return 0x4; | |
489 | case rocksdb::Status::SubCode::kDeadlock: | |
490 | return 0x5; | |
491 | case rocksdb::Status::SubCode::kStaleFile: | |
492 | return 0x6; | |
493 | case rocksdb::Status::SubCode::kMemoryLimit: | |
494 | return 0x7; | |
7c673cae FG |
495 | default: |
496 | return 0x7F; // undefined | |
497 | } | |
498 | } | |
11fdf7f2 | 499 | |
494da23a TL |
500 | static std::unique_ptr<rocksdb::Status> toCppStatus( |
501 | const jbyte jcode_value, const jbyte jsub_code_value) { | |
502 | std::unique_ptr<rocksdb::Status> status; | |
503 | switch (jcode_value) { | |
504 | case 0x0: | |
505 | //Ok | |
506 | status = std::unique_ptr<rocksdb::Status>( | |
507 | new rocksdb::Status(rocksdb::Status::OK())); | |
508 | break; | |
509 | case 0x1: | |
510 | //NotFound | |
511 | status = std::unique_ptr<rocksdb::Status>( | |
512 | new rocksdb::Status(rocksdb::Status::NotFound( | |
513 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
514 | break; | |
515 | case 0x2: | |
516 | //Corruption | |
517 | status = std::unique_ptr<rocksdb::Status>( | |
518 | new rocksdb::Status(rocksdb::Status::Corruption( | |
519 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
520 | break; | |
521 | case 0x3: | |
522 | //NotSupported | |
523 | status = std::unique_ptr<rocksdb::Status>( | |
524 | new rocksdb::Status(rocksdb::Status::NotSupported( | |
525 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
526 | break; | |
527 | case 0x4: | |
528 | //InvalidArgument | |
529 | status = std::unique_ptr<rocksdb::Status>( | |
530 | new rocksdb::Status(rocksdb::Status::InvalidArgument( | |
531 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
532 | break; | |
533 | case 0x5: | |
534 | //IOError | |
535 | status = std::unique_ptr<rocksdb::Status>( | |
536 | new rocksdb::Status(rocksdb::Status::IOError( | |
537 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
538 | break; | |
539 | case 0x6: | |
540 | //MergeInProgress | |
541 | status = std::unique_ptr<rocksdb::Status>( | |
542 | new rocksdb::Status(rocksdb::Status::MergeInProgress( | |
543 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
544 | break; | |
545 | case 0x7: | |
546 | //Incomplete | |
547 | status = std::unique_ptr<rocksdb::Status>( | |
548 | new rocksdb::Status(rocksdb::Status::Incomplete( | |
549 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
550 | break; | |
551 | case 0x8: | |
552 | //ShutdownInProgress | |
553 | status = std::unique_ptr<rocksdb::Status>( | |
554 | new rocksdb::Status(rocksdb::Status::ShutdownInProgress( | |
555 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
556 | break; | |
557 | case 0x9: | |
558 | //TimedOut | |
559 | status = std::unique_ptr<rocksdb::Status>( | |
560 | new rocksdb::Status(rocksdb::Status::TimedOut( | |
561 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
562 | break; | |
563 | case 0xA: | |
564 | //Aborted | |
565 | status = std::unique_ptr<rocksdb::Status>( | |
566 | new rocksdb::Status(rocksdb::Status::Aborted( | |
567 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
568 | break; | |
569 | case 0xB: | |
570 | //Busy | |
571 | status = std::unique_ptr<rocksdb::Status>( | |
572 | new rocksdb::Status(rocksdb::Status::Busy( | |
573 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
574 | break; | |
575 | case 0xC: | |
576 | //Expired | |
577 | status = std::unique_ptr<rocksdb::Status>( | |
578 | new rocksdb::Status(rocksdb::Status::Expired( | |
579 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
580 | break; | |
581 | case 0xD: | |
582 | //TryAgain | |
583 | status = std::unique_ptr<rocksdb::Status>( | |
584 | new rocksdb::Status(rocksdb::Status::TryAgain( | |
585 | rocksdb::SubCodeJni::toCppSubCode(jsub_code_value)))); | |
586 | break; | |
587 | case 0x7F: | |
588 | default: | |
589 | return nullptr; | |
590 | } | |
591 | return status; | |
592 | } | |
593 | ||
11fdf7f2 TL |
594 | // Returns the equivalent rocksdb::Status for the Java org.rocksdb.Status |
595 | static std::unique_ptr<rocksdb::Status> toCppStatus(JNIEnv* env, const jobject jstatus) { | |
596 | jmethodID mid_code = getCodeMethod(env); | |
597 | if (mid_code == nullptr) { | |
598 | // exception occurred | |
599 | return nullptr; | |
600 | } | |
601 | jobject jcode = env->CallObjectMethod(jstatus, mid_code); | |
602 | if (env->ExceptionCheck()) { | |
603 | // exception occurred | |
604 | return nullptr; | |
605 | } | |
606 | ||
607 | jmethodID mid_code_value = rocksdb::CodeJni::getValueMethod(env); | |
608 | if (mid_code_value == nullptr) { | |
609 | // exception occurred | |
610 | return nullptr; | |
611 | } | |
612 | jbyte jcode_value = env->CallByteMethod(jcode, mid_code_value); | |
613 | if (env->ExceptionCheck()) { | |
614 | // exception occurred | |
615 | if (jcode != nullptr) { | |
616 | env->DeleteLocalRef(jcode); | |
617 | } | |
618 | return nullptr; | |
619 | } | |
620 | ||
621 | jmethodID mid_subCode = getSubCodeMethod(env); | |
622 | if (mid_subCode == nullptr) { | |
623 | // exception occurred | |
624 | return nullptr; | |
625 | } | |
626 | jobject jsubCode = env->CallObjectMethod(jstatus, mid_subCode); | |
627 | if (env->ExceptionCheck()) { | |
628 | // exception occurred | |
629 | if (jcode != nullptr) { | |
630 | env->DeleteLocalRef(jcode); | |
631 | } | |
632 | return nullptr; | |
633 | } | |
634 | ||
494da23a | 635 | jbyte jsub_code_value = 0x0; // None |
11fdf7f2 TL |
636 | if (jsubCode != nullptr) { |
637 | jmethodID mid_subCode_value = rocksdb::SubCodeJni::getValueMethod(env); | |
638 | if (mid_subCode_value == nullptr) { | |
639 | // exception occurred | |
640 | return nullptr; | |
641 | } | |
494da23a | 642 | jsub_code_value = env->CallByteMethod(jsubCode, mid_subCode_value); |
11fdf7f2 TL |
643 | if (env->ExceptionCheck()) { |
644 | // exception occurred | |
645 | if (jcode != nullptr) { | |
646 | env->DeleteLocalRef(jcode); | |
647 | } | |
648 | return nullptr; | |
649 | } | |
650 | } | |
651 | ||
652 | jmethodID mid_state = getStateMethod(env); | |
653 | if (mid_state == nullptr) { | |
654 | // exception occurred | |
655 | return nullptr; | |
656 | } | |
657 | jobject jstate = env->CallObjectMethod(jstatus, mid_state); | |
658 | if (env->ExceptionCheck()) { | |
659 | // exception occurred | |
660 | if (jsubCode != nullptr) { | |
661 | env->DeleteLocalRef(jsubCode); | |
662 | } | |
663 | if (jcode != nullptr) { | |
664 | env->DeleteLocalRef(jcode); | |
665 | } | |
666 | return nullptr; | |
667 | } | |
668 | ||
494da23a TL |
669 | std::unique_ptr<rocksdb::Status> status = |
670 | toCppStatus(jcode_value, jsub_code_value); | |
11fdf7f2 TL |
671 | |
672 | // delete all local refs | |
673 | if (jstate != nullptr) { | |
674 | env->DeleteLocalRef(jstate); | |
675 | } | |
676 | if (jsubCode != nullptr) { | |
677 | env->DeleteLocalRef(jsubCode); | |
678 | } | |
679 | if (jcode != nullptr) { | |
680 | env->DeleteLocalRef(jcode); | |
681 | } | |
682 | ||
683 | return status; | |
684 | } | |
7c673cae FG |
685 | }; |
686 | ||
687 | // The portal class for org.rocksdb.RocksDBException | |
688 | class RocksDBExceptionJni : | |
689 | public JavaException<RocksDBExceptionJni> { | |
690 | public: | |
691 | /** | |
692 | * Get the Java Class org.rocksdb.RocksDBException | |
693 | * | |
694 | * @param env A pointer to the Java environment | |
695 | * | |
696 | * @return The Java Class or nullptr if one of the | |
697 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
698 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
699 | */ | |
700 | static jclass getJClass(JNIEnv* env) { | |
701 | return JavaException::getJClass(env, "org/rocksdb/RocksDBException"); | |
702 | } | |
703 | ||
704 | /** | |
705 | * Create and throw a Java RocksDBException with the provided message | |
706 | * | |
707 | * @param env A pointer to the Java environment | |
708 | * @param msg The message for the exception | |
709 | * | |
710 | * @return true if an exception was thrown, false otherwise | |
711 | */ | |
712 | static bool ThrowNew(JNIEnv* env, const std::string& msg) { | |
713 | return JavaException::ThrowNew(env, msg); | |
714 | } | |
715 | ||
11fdf7f2 TL |
716 | /** |
717 | * Create and throw a Java RocksDBException with the provided status | |
718 | * | |
719 | * If s->ok() == true, then this function will not throw any exception. | |
720 | * | |
721 | * @param env A pointer to the Java environment | |
722 | * @param s The status for the exception | |
723 | * | |
724 | * @return true if an exception was thrown, false otherwise | |
725 | */ | |
726 | static bool ThrowNew(JNIEnv* env, std::unique_ptr<Status>& s) { | |
727 | return rocksdb::RocksDBExceptionJni::ThrowNew(env, *(s.get())); | |
728 | } | |
729 | ||
7c673cae FG |
730 | /** |
731 | * Create and throw a Java RocksDBException with the provided status | |
732 | * | |
733 | * If s.ok() == true, then this function will not throw any exception. | |
734 | * | |
735 | * @param env A pointer to the Java environment | |
736 | * @param s The status for the exception | |
737 | * | |
738 | * @return true if an exception was thrown, false otherwise | |
739 | */ | |
740 | static bool ThrowNew(JNIEnv* env, const Status& s) { | |
7c673cae FG |
741 | if (s.ok()) { |
742 | return false; | |
743 | } | |
744 | ||
745 | // get the RocksDBException class | |
746 | jclass jclazz = getJClass(env); | |
747 | if(jclazz == nullptr) { | |
748 | // exception occurred accessing class | |
749 | std::cerr << "RocksDBExceptionJni::ThrowNew/class - Error: unexpected exception!" << std::endl; | |
750 | return env->ExceptionCheck(); | |
751 | } | |
752 | ||
753 | // get the constructor of org.rocksdb.RocksDBException | |
754 | jmethodID mid = | |
755 | env->GetMethodID(jclazz, "<init>", "(Lorg/rocksdb/Status;)V"); | |
756 | if(mid == nullptr) { | |
757 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
758 | std::cerr << "RocksDBExceptionJni::ThrowNew/cstr - Error: unexpected exception!" << std::endl; | |
759 | return env->ExceptionCheck(); | |
760 | } | |
761 | ||
762 | // get the Java status object | |
763 | jobject jstatus = StatusJni::construct(env, s); | |
764 | if(jstatus == nullptr) { | |
765 | // exception occcurred | |
766 | std::cerr << "RocksDBExceptionJni::ThrowNew/StatusJni - Error: unexpected exception!" << std::endl; | |
767 | return env->ExceptionCheck(); | |
768 | } | |
769 | ||
770 | // construct the RocksDBException | |
771 | jthrowable rocksdb_exception = reinterpret_cast<jthrowable>(env->NewObject(jclazz, mid, jstatus)); | |
772 | if(env->ExceptionCheck()) { | |
773 | if(jstatus != nullptr) { | |
774 | env->DeleteLocalRef(jstatus); | |
775 | } | |
776 | if(rocksdb_exception != nullptr) { | |
777 | env->DeleteLocalRef(rocksdb_exception); | |
778 | } | |
779 | std::cerr << "RocksDBExceptionJni::ThrowNew/NewObject - Error: unexpected exception!" << std::endl; | |
780 | return true; | |
781 | } | |
782 | ||
783 | // throw the RocksDBException | |
784 | const jint rs = env->Throw(rocksdb_exception); | |
785 | if(rs != JNI_OK) { | |
786 | // exception could not be thrown | |
787 | std::cerr << "RocksDBExceptionJni::ThrowNew - Fatal: could not throw exception!" << std::endl; | |
788 | if(jstatus != nullptr) { | |
789 | env->DeleteLocalRef(jstatus); | |
790 | } | |
791 | if(rocksdb_exception != nullptr) { | |
792 | env->DeleteLocalRef(rocksdb_exception); | |
793 | } | |
794 | return env->ExceptionCheck(); | |
795 | } | |
796 | ||
797 | if(jstatus != nullptr) { | |
798 | env->DeleteLocalRef(jstatus); | |
799 | } | |
800 | if(rocksdb_exception != nullptr) { | |
801 | env->DeleteLocalRef(rocksdb_exception); | |
802 | } | |
803 | ||
804 | return true; | |
805 | } | |
806 | ||
807 | /** | |
808 | * Create and throw a Java RocksDBException with the provided message | |
809 | * and status | |
810 | * | |
811 | * If s.ok() == true, then this function will not throw any exception. | |
812 | * | |
813 | * @param env A pointer to the Java environment | |
814 | * @param msg The message for the exception | |
815 | * @param s The status for the exception | |
816 | * | |
817 | * @return true if an exception was thrown, false otherwise | |
818 | */ | |
819 | static bool ThrowNew(JNIEnv* env, const std::string& msg, const Status& s) { | |
820 | assert(!s.ok()); | |
821 | if (s.ok()) { | |
822 | return false; | |
823 | } | |
824 | ||
825 | // get the RocksDBException class | |
826 | jclass jclazz = getJClass(env); | |
827 | if(jclazz == nullptr) { | |
828 | // exception occurred accessing class | |
829 | std::cerr << "RocksDBExceptionJni::ThrowNew/class - Error: unexpected exception!" << std::endl; | |
830 | return env->ExceptionCheck(); | |
831 | } | |
832 | ||
833 | // get the constructor of org.rocksdb.RocksDBException | |
834 | jmethodID mid = | |
835 | env->GetMethodID(jclazz, "<init>", "(Ljava/lang/String;Lorg/rocksdb/Status;)V"); | |
836 | if(mid == nullptr) { | |
837 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
838 | std::cerr << "RocksDBExceptionJni::ThrowNew/cstr - Error: unexpected exception!" << std::endl; | |
839 | return env->ExceptionCheck(); | |
840 | } | |
841 | ||
842 | jstring jmsg = env->NewStringUTF(msg.c_str()); | |
843 | if(jmsg == nullptr) { | |
844 | // exception thrown: OutOfMemoryError | |
845 | std::cerr << "RocksDBExceptionJni::ThrowNew/msg - Error: unexpected exception!" << std::endl; | |
846 | return env->ExceptionCheck(); | |
847 | } | |
848 | ||
849 | // get the Java status object | |
850 | jobject jstatus = StatusJni::construct(env, s); | |
851 | if(jstatus == nullptr) { | |
852 | // exception occcurred | |
853 | std::cerr << "RocksDBExceptionJni::ThrowNew/StatusJni - Error: unexpected exception!" << std::endl; | |
854 | if(jmsg != nullptr) { | |
855 | env->DeleteLocalRef(jmsg); | |
856 | } | |
857 | return env->ExceptionCheck(); | |
858 | } | |
859 | ||
860 | // construct the RocksDBException | |
861 | jthrowable rocksdb_exception = reinterpret_cast<jthrowable>(env->NewObject(jclazz, mid, jmsg, jstatus)); | |
862 | if(env->ExceptionCheck()) { | |
863 | if(jstatus != nullptr) { | |
864 | env->DeleteLocalRef(jstatus); | |
865 | } | |
866 | if(jmsg != nullptr) { | |
867 | env->DeleteLocalRef(jmsg); | |
868 | } | |
869 | if(rocksdb_exception != nullptr) { | |
870 | env->DeleteLocalRef(rocksdb_exception); | |
871 | } | |
872 | std::cerr << "RocksDBExceptionJni::ThrowNew/NewObject - Error: unexpected exception!" << std::endl; | |
873 | return true; | |
874 | } | |
875 | ||
876 | // throw the RocksDBException | |
877 | const jint rs = env->Throw(rocksdb_exception); | |
878 | if(rs != JNI_OK) { | |
879 | // exception could not be thrown | |
880 | std::cerr << "RocksDBExceptionJni::ThrowNew - Fatal: could not throw exception!" << std::endl; | |
881 | if(jstatus != nullptr) { | |
882 | env->DeleteLocalRef(jstatus); | |
883 | } | |
884 | if(jmsg != nullptr) { | |
885 | env->DeleteLocalRef(jmsg); | |
886 | } | |
887 | if(rocksdb_exception != nullptr) { | |
888 | env->DeleteLocalRef(rocksdb_exception); | |
889 | } | |
890 | return env->ExceptionCheck(); | |
891 | } | |
892 | ||
893 | if(jstatus != nullptr) { | |
894 | env->DeleteLocalRef(jstatus); | |
895 | } | |
896 | if(jmsg != nullptr) { | |
897 | env->DeleteLocalRef(jmsg); | |
898 | } | |
899 | if(rocksdb_exception != nullptr) { | |
900 | env->DeleteLocalRef(rocksdb_exception); | |
901 | } | |
902 | ||
903 | return true; | |
904 | } | |
11fdf7f2 TL |
905 | |
906 | /** | |
907 | * Get the Java Method: RocksDBException#getStatus | |
908 | * | |
909 | * @param env A pointer to the Java environment | |
910 | * | |
911 | * @return The Java Method ID or nullptr if the class or method id could not | |
912 | * be retieved | |
913 | */ | |
914 | static jmethodID getStatusMethod(JNIEnv* env) { | |
915 | jclass jclazz = getJClass(env); | |
916 | if(jclazz == nullptr) { | |
917 | // exception occurred accessing class | |
918 | return nullptr; | |
919 | } | |
920 | ||
921 | static jmethodID mid = | |
922 | env->GetMethodID(jclazz, "getStatus", "()Lorg/rocksdb/Status;"); | |
923 | assert(mid != nullptr); | |
924 | return mid; | |
925 | } | |
926 | ||
927 | static std::unique_ptr<rocksdb::Status> toCppStatus( | |
928 | JNIEnv* env, jthrowable jrocksdb_exception) { | |
929 | if(!env->IsInstanceOf(jrocksdb_exception, getJClass(env))) { | |
930 | // not an instance of RocksDBException | |
931 | return nullptr; | |
932 | } | |
933 | ||
934 | // get the java status object | |
935 | jmethodID mid = getStatusMethod(env); | |
936 | if(mid == nullptr) { | |
937 | // exception occurred accessing class or method | |
938 | return nullptr; | |
939 | } | |
940 | ||
941 | jobject jstatus = env->CallObjectMethod(jrocksdb_exception, mid); | |
942 | if(env->ExceptionCheck()) { | |
943 | // exception occurred | |
944 | return nullptr; | |
945 | } | |
946 | ||
947 | if(jstatus == nullptr) { | |
948 | return nullptr; // no status available | |
949 | } | |
950 | ||
951 | return rocksdb::StatusJni::toCppStatus(env, jstatus); | |
952 | } | |
7c673cae FG |
953 | }; |
954 | ||
494da23a TL |
955 | // The portal class for java.util.List |
956 | class ListJni : public JavaClass { | |
7c673cae FG |
957 | public: |
958 | /** | |
494da23a | 959 | * Get the Java Class java.util.List |
7c673cae FG |
960 | * |
961 | * @param env A pointer to the Java environment | |
962 | * | |
963 | * @return The Java Class or nullptr if one of the | |
964 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
965 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
966 | */ | |
494da23a TL |
967 | static jclass getListClass(JNIEnv* env) { |
968 | return JavaClass::getJClass(env, "java/util/List"); | |
7c673cae FG |
969 | } |
970 | ||
971 | /** | |
494da23a | 972 | * Get the Java Class java.util.ArrayList |
7c673cae FG |
973 | * |
974 | * @param env A pointer to the Java environment | |
7c673cae | 975 | * |
494da23a TL |
976 | * @return The Java Class or nullptr if one of the |
977 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
978 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 979 | */ |
494da23a TL |
980 | static jclass getArrayListClass(JNIEnv* env) { |
981 | return JavaClass::getJClass(env, "java/util/ArrayList"); | |
7c673cae | 982 | } |
7c673cae | 983 | |
7c673cae | 984 | /** |
494da23a | 985 | * Get the Java Class java.util.Iterator |
7c673cae FG |
986 | * |
987 | * @param env A pointer to the Java environment | |
988 | * | |
989 | * @return The Java Class or nullptr if one of the | |
990 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
991 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
992 | */ | |
494da23a TL |
993 | static jclass getIteratorClass(JNIEnv* env) { |
994 | return JavaClass::getJClass(env, "java/util/Iterator"); | |
7c673cae | 995 | } |
7c673cae | 996 | |
7c673cae | 997 | /** |
494da23a | 998 | * Get the Java Method: List#iterator |
7c673cae FG |
999 | * |
1000 | * @param env A pointer to the Java environment | |
1001 | * | |
494da23a TL |
1002 | * @return The Java Method ID or nullptr if the class or method id could not |
1003 | * be retieved | |
7c673cae | 1004 | */ |
494da23a TL |
1005 | static jmethodID getIteratorMethod(JNIEnv* env) { |
1006 | jclass jlist_clazz = getListClass(env); | |
1007 | if(jlist_clazz == nullptr) { | |
1008 | // exception occurred accessing class | |
1009 | return nullptr; | |
1010 | } | |
1011 | ||
1012 | static jmethodID mid = | |
1013 | env->GetMethodID(jlist_clazz, "iterator", "()Ljava/util/Iterator;"); | |
1014 | assert(mid != nullptr); | |
1015 | return mid; | |
7c673cae | 1016 | } |
7c673cae | 1017 | |
7c673cae | 1018 | /** |
494da23a | 1019 | * Get the Java Method: Iterator#hasNext |
7c673cae FG |
1020 | * |
1021 | * @param env A pointer to the Java environment | |
1022 | * | |
494da23a TL |
1023 | * @return The Java Method ID or nullptr if the class or method id could not |
1024 | * be retieved | |
7c673cae | 1025 | */ |
494da23a TL |
1026 | static jmethodID getHasNextMethod(JNIEnv* env) { |
1027 | jclass jiterator_clazz = getIteratorClass(env); | |
1028 | if(jiterator_clazz == nullptr) { | |
1029 | // exception occurred accessing class | |
1030 | return nullptr; | |
1031 | } | |
1032 | ||
1033 | static jmethodID mid = env->GetMethodID(jiterator_clazz, "hasNext", "()Z"); | |
1034 | assert(mid != nullptr); | |
1035 | return mid; | |
7c673cae FG |
1036 | } |
1037 | ||
1038 | /** | |
494da23a | 1039 | * Get the Java Method: Iterator#next |
7c673cae FG |
1040 | * |
1041 | * @param env A pointer to the Java environment | |
1042 | * | |
494da23a TL |
1043 | * @return The Java Method ID or nullptr if the class or method id could not |
1044 | * be retieved | |
7c673cae | 1045 | */ |
494da23a TL |
1046 | static jmethodID getNextMethod(JNIEnv* env) { |
1047 | jclass jiterator_clazz = getIteratorClass(env); | |
1048 | if(jiterator_clazz == nullptr) { | |
7c673cae FG |
1049 | // exception occurred accessing class |
1050 | return nullptr; | |
1051 | } | |
1052 | ||
494da23a TL |
1053 | static jmethodID mid = |
1054 | env->GetMethodID(jiterator_clazz, "next", "()Ljava/lang/Object;"); | |
1055 | assert(mid != nullptr); | |
1056 | return mid; | |
1057 | } | |
1058 | ||
1059 | /** | |
1060 | * Get the Java Method: ArrayList constructor | |
1061 | * | |
1062 | * @param env A pointer to the Java environment | |
1063 | * | |
1064 | * @return The Java Method ID or nullptr if the class or method id could not | |
1065 | * be retieved | |
1066 | */ | |
1067 | static jmethodID getArrayListConstructorMethodId(JNIEnv* env) { | |
1068 | jclass jarray_list_clazz = getArrayListClass(env); | |
1069 | if(jarray_list_clazz == nullptr) { | |
1070 | // exception occurred accessing class | |
7c673cae FG |
1071 | return nullptr; |
1072 | } | |
494da23a TL |
1073 | static jmethodID mid = |
1074 | env->GetMethodID(jarray_list_clazz, "<init>", "(I)V"); | |
1075 | assert(mid != nullptr); | |
1076 | return mid; | |
1077 | } | |
7c673cae | 1078 | |
494da23a TL |
1079 | /** |
1080 | * Get the Java Method: List#add | |
1081 | * | |
1082 | * @param env A pointer to the Java environment | |
1083 | * | |
1084 | * @return The Java Method ID or nullptr if the class or method id could not | |
1085 | * be retieved | |
1086 | */ | |
1087 | static jmethodID getListAddMethodId(JNIEnv* env) { | |
1088 | jclass jlist_clazz = getListClass(env); | |
1089 | if(jlist_clazz == nullptr) { | |
1090 | // exception occurred accessing class | |
11fdf7f2 TL |
1091 | return nullptr; |
1092 | } | |
7c673cae | 1093 | |
494da23a TL |
1094 | static jmethodID mid = |
1095 | env->GetMethodID(jlist_clazz, "add", "(Ljava/lang/Object;)Z"); | |
1096 | assert(mid != nullptr); | |
1097 | return mid; | |
7c673cae FG |
1098 | } |
1099 | }; | |
1100 | ||
494da23a TL |
1101 | // The portal class for java.lang.Byte |
1102 | class ByteJni : public JavaClass { | |
7c673cae FG |
1103 | public: |
1104 | /** | |
494da23a | 1105 | * Get the Java Class java.lang.Byte |
7c673cae FG |
1106 | * |
1107 | * @param env A pointer to the Java environment | |
1108 | * | |
1109 | * @return The Java Class or nullptr if one of the | |
1110 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
1111 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
1112 | */ | |
1113 | static jclass getJClass(JNIEnv* env) { | |
494da23a | 1114 | return JavaClass::getJClass(env, "java/lang/Byte"); |
7c673cae | 1115 | } |
7c673cae | 1116 | |
7c673cae | 1117 | /** |
494da23a | 1118 | * Get the Java Class byte[] |
7c673cae FG |
1119 | * |
1120 | * @param env A pointer to the Java environment | |
1121 | * | |
1122 | * @return The Java Class or nullptr if one of the | |
1123 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
1124 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
1125 | */ | |
494da23a TL |
1126 | static jclass getArrayJClass(JNIEnv* env) { |
1127 | return JavaClass::getJClass(env, "[B"); | |
7c673cae | 1128 | } |
7c673cae | 1129 | |
7c673cae | 1130 | /** |
494da23a | 1131 | * Creates a new 2-dimensional Java Byte Array byte[][] |
7c673cae FG |
1132 | * |
1133 | * @param env A pointer to the Java environment | |
494da23a | 1134 | * @param len The size of the first dimension |
7c673cae | 1135 | * |
494da23a | 1136 | * @return A reference to the Java byte[][] or nullptr if an exception occurs |
7c673cae | 1137 | */ |
494da23a TL |
1138 | static jobjectArray new2dByteArray(JNIEnv* env, const jsize len) { |
1139 | jclass clazz = getArrayJClass(env); | |
1140 | if(clazz == nullptr) { | |
1141 | // exception occurred accessing class | |
1142 | return nullptr; | |
1143 | } | |
1144 | ||
1145 | return env->NewObjectArray(len, clazz, nullptr); | |
7c673cae | 1146 | } |
11fdf7f2 TL |
1147 | |
1148 | /** | |
494da23a | 1149 | * Get the Java Method: Byte#byteValue |
11fdf7f2 TL |
1150 | * |
1151 | * @param env A pointer to the Java environment | |
11fdf7f2 | 1152 | * |
494da23a TL |
1153 | * @return The Java Method ID or nullptr if the class or method id could not |
1154 | * be retrieved | |
11fdf7f2 | 1155 | */ |
494da23a TL |
1156 | static jmethodID getByteValueMethod(JNIEnv* env) { |
1157 | jclass clazz = getJClass(env); | |
1158 | if(clazz == nullptr) { | |
11fdf7f2 TL |
1159 | // exception occurred accessing class |
1160 | return nullptr; | |
1161 | } | |
1162 | ||
494da23a TL |
1163 | static jmethodID mid = env->GetMethodID(clazz, "byteValue", "()B"); |
1164 | assert(mid != nullptr); | |
1165 | return mid; | |
1166 | } | |
1167 | ||
1168 | /** | |
1169 | * Calls the Java Method: Byte#valueOf, returning a constructed Byte jobject | |
1170 | * | |
1171 | * @param env A pointer to the Java environment | |
1172 | * | |
1173 | * @return A constructing Byte object or nullptr if the class or method id could not | |
1174 | * be retrieved, or an exception occurred | |
1175 | */ | |
1176 | static jobject valueOf(JNIEnv* env, jbyte jprimitive_byte) { | |
1177 | jclass clazz = getJClass(env); | |
1178 | if (clazz == nullptr) { | |
1179 | // exception occurred accessing class | |
1180 | return nullptr; | |
1181 | } | |
1182 | ||
1183 | static jmethodID mid = | |
1184 | env->GetStaticMethodID(clazz, "valueOf", "(B)Ljava/lang/Byte;"); | |
11fdf7f2 TL |
1185 | if (mid == nullptr) { |
1186 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
1187 | return nullptr; | |
1188 | } | |
1189 | ||
494da23a TL |
1190 | const jobject jbyte_obj = |
1191 | env->CallStaticObjectMethod(clazz, mid, jprimitive_byte); | |
11fdf7f2 | 1192 | if (env->ExceptionCheck()) { |
494da23a | 1193 | // exception occurred |
11fdf7f2 TL |
1194 | return nullptr; |
1195 | } | |
1196 | ||
494da23a | 1197 | return jbyte_obj; |
11fdf7f2 | 1198 | } |
494da23a | 1199 | |
7c673cae FG |
1200 | }; |
1201 | ||
494da23a TL |
1202 | // The portal class for java.lang.Integer |
1203 | class IntegerJni : public JavaClass { | |
7c673cae FG |
1204 | public: |
1205 | /** | |
494da23a | 1206 | * Get the Java Class java.lang.Integer |
7c673cae FG |
1207 | * |
1208 | * @param env A pointer to the Java environment | |
1209 | * | |
1210 | * @return The Java Class or nullptr if one of the | |
1211 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
1212 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
1213 | */ | |
1214 | static jclass getJClass(JNIEnv* env) { | |
494da23a | 1215 | return JavaClass::getJClass(env, "java/lang/Integer"); |
7c673cae FG |
1216 | } |
1217 | ||
494da23a | 1218 | static jobject valueOf(JNIEnv* env, jint jprimitive_int) { |
7c673cae | 1219 | jclass jclazz = getJClass(env); |
494da23a | 1220 | if (jclazz == nullptr) { |
7c673cae FG |
1221 | // exception occurred accessing class |
1222 | return nullptr; | |
1223 | } | |
1224 | ||
494da23a TL |
1225 | jmethodID mid = |
1226 | env->GetStaticMethodID(jclazz, "valueOf", "(I)Ljava/lang/Integer;"); | |
1227 | if (mid == nullptr) { | |
1228 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
1229 | return nullptr; | |
1230 | } | |
7c673cae | 1231 | |
494da23a TL |
1232 | const jobject jinteger_obj = |
1233 | env->CallStaticObjectMethod(jclazz, mid, jprimitive_int); | |
1234 | if (env->ExceptionCheck()) { | |
1235 | // exception occurred | |
7c673cae FG |
1236 | return nullptr; |
1237 | } | |
1238 | ||
494da23a | 1239 | return jinteger_obj; |
7c673cae | 1240 | } |
494da23a | 1241 | }; |
7c673cae | 1242 | |
494da23a TL |
1243 | // The portal class for java.lang.Long |
1244 | class LongJni : public JavaClass { | |
1245 | public: | |
7c673cae | 1246 | /** |
494da23a | 1247 | * Get the Java Class java.lang.Long |
7c673cae FG |
1248 | * |
1249 | * @param env A pointer to the Java environment | |
1250 | * | |
494da23a TL |
1251 | * @return The Java Class or nullptr if one of the |
1252 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
1253 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 1254 | */ |
494da23a TL |
1255 | static jclass getJClass(JNIEnv* env) { |
1256 | return JavaClass::getJClass(env, "java/lang/Long"); | |
1257 | } | |
1258 | ||
1259 | static jobject valueOf(JNIEnv* env, jlong jprimitive_long) { | |
7c673cae | 1260 | jclass jclazz = getJClass(env); |
494da23a | 1261 | if (jclazz == nullptr) { |
7c673cae FG |
1262 | // exception occurred accessing class |
1263 | return nullptr; | |
1264 | } | |
1265 | ||
494da23a TL |
1266 | jmethodID mid = |
1267 | env->GetStaticMethodID(jclazz, "valueOf", "(J)Ljava/lang/Long;"); | |
1268 | if (mid == nullptr) { | |
1269 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
1270 | return nullptr; | |
1271 | } | |
7c673cae | 1272 | |
494da23a TL |
1273 | const jobject jlong_obj = |
1274 | env->CallStaticObjectMethod(jclazz, mid, jprimitive_long); | |
1275 | if (env->ExceptionCheck()) { | |
1276 | // exception occurred | |
7c673cae FG |
1277 | return nullptr; |
1278 | } | |
1279 | ||
494da23a | 1280 | return jlong_obj; |
7c673cae | 1281 | } |
494da23a | 1282 | }; |
7c673cae | 1283 | |
494da23a TL |
1284 | // The portal class for java.lang.StringBuilder |
1285 | class StringBuilderJni : public JavaClass { | |
1286 | public: | |
7c673cae | 1287 | /** |
494da23a | 1288 | * Get the Java Class java.lang.StringBuilder |
7c673cae FG |
1289 | * |
1290 | * @param env A pointer to the Java environment | |
1291 | * | |
494da23a TL |
1292 | * @return The Java Class or nullptr if one of the |
1293 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
1294 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 1295 | */ |
494da23a TL |
1296 | static jclass getJClass(JNIEnv* env) { |
1297 | return JavaClass::getJClass(env, "java/lang/StringBuilder"); | |
7c673cae FG |
1298 | } |
1299 | ||
1300 | /** | |
494da23a | 1301 | * Get the Java Method: StringBuilder#append |
7c673cae FG |
1302 | * |
1303 | * @param env A pointer to the Java environment | |
1304 | * | |
1305 | * @return The Java Method ID or nullptr if the class or method id could not | |
1306 | * be retieved | |
1307 | */ | |
494da23a | 1308 | static jmethodID getListAddMethodId(JNIEnv* env) { |
7c673cae FG |
1309 | jclass jclazz = getJClass(env); |
1310 | if(jclazz == nullptr) { | |
1311 | // exception occurred accessing class | |
1312 | return nullptr; | |
1313 | } | |
1314 | ||
494da23a TL |
1315 | static jmethodID mid = |
1316 | env->GetMethodID(jclazz, "append", | |
1317 | "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); | |
7c673cae FG |
1318 | assert(mid != nullptr); |
1319 | return mid; | |
1320 | } | |
7c673cae | 1321 | |
7c673cae | 1322 | /** |
494da23a | 1323 | * Appends a C-style string to a StringBuilder |
7c673cae FG |
1324 | * |
1325 | * @param env A pointer to the Java environment | |
494da23a TL |
1326 | * @param jstring_builder Reference to a java.lang.StringBuilder |
1327 | * @param c_str A C-style string to append to the StringBuilder | |
7c673cae | 1328 | * |
494da23a TL |
1329 | * @return A reference to the updated StringBuilder, or a nullptr if |
1330 | * an exception occurs | |
7c673cae | 1331 | */ |
494da23a TL |
1332 | static jobject append(JNIEnv* env, jobject jstring_builder, |
1333 | const char* c_str) { | |
1334 | jmethodID mid = getListAddMethodId(env); | |
1335 | if(mid == nullptr) { | |
1336 | // exception occurred accessing class or method | |
11fdf7f2 TL |
1337 | return nullptr; |
1338 | } | |
1339 | ||
494da23a TL |
1340 | jstring new_value_str = env->NewStringUTF(c_str); |
1341 | if(new_value_str == nullptr) { | |
1342 | // exception thrown: OutOfMemoryError | |
7c673cae FG |
1343 | return nullptr; |
1344 | } | |
1345 | ||
494da23a TL |
1346 | jobject jresult_string_builder = |
1347 | env->CallObjectMethod(jstring_builder, mid, new_value_str); | |
1348 | if(env->ExceptionCheck()) { | |
1349 | // exception occurred | |
1350 | env->DeleteLocalRef(new_value_str); | |
11fdf7f2 TL |
1351 | return nullptr; |
1352 | } | |
1353 | ||
494da23a | 1354 | return jresult_string_builder; |
7c673cae | 1355 | } |
494da23a | 1356 | }; |
7c673cae | 1357 | |
494da23a TL |
1358 | // various utility functions for working with RocksDB and JNI |
1359 | class JniUtil { | |
1360 | public: | |
1361 | /** | |
1362 | * Detect if jlong overflows size_t | |
1363 | * | |
1364 | * @param jvalue the jlong value | |
1365 | * | |
1366 | * @return | |
1367 | */ | |
1368 | inline static Status check_if_jlong_fits_size_t(const jlong& jvalue) { | |
1369 | Status s = Status::OK(); | |
1370 | if (static_cast<uint64_t>(jvalue) > std::numeric_limits<size_t>::max()) { | |
1371 | s = Status::InvalidArgument(Slice("jlong overflows 32 bit value.")); | |
1372 | } | |
1373 | return s; | |
11fdf7f2 TL |
1374 | } |
1375 | ||
494da23a TL |
1376 | /** |
1377 | * Obtains a reference to the JNIEnv from | |
1378 | * the JVM | |
1379 | * | |
1380 | * If the current thread is not attached to the JavaVM | |
1381 | * then it will be attached so as to retrieve the JNIEnv | |
1382 | * | |
1383 | * If a thread is attached, it must later be manually | |
1384 | * released by calling JavaVM::DetachCurrentThread. | |
1385 | * This can be handled by always matching calls to this | |
1386 | * function with calls to {@link JniUtil::releaseJniEnv(JavaVM*, jboolean)} | |
1387 | * | |
1388 | * @param jvm (IN) A pointer to the JavaVM instance | |
1389 | * @param attached (OUT) A pointer to a boolean which | |
1390 | * will be set to JNI_TRUE if we had to attach the thread | |
1391 | * | |
1392 | * @return A pointer to the JNIEnv or nullptr if a fatal error | |
1393 | * occurs and the JNIEnv cannot be retrieved | |
1394 | */ | |
1395 | static JNIEnv* getJniEnv(JavaVM* jvm, jboolean* attached) { | |
1396 | assert(jvm != nullptr); | |
11fdf7f2 | 1397 | |
494da23a TL |
1398 | JNIEnv *env; |
1399 | const jint env_rs = jvm->GetEnv(reinterpret_cast<void**>(&env), | |
1400 | JNI_VERSION_1_2); | |
7c673cae | 1401 | |
494da23a TL |
1402 | if(env_rs == JNI_OK) { |
1403 | // current thread is already attached, return the JNIEnv | |
1404 | *attached = JNI_FALSE; | |
1405 | return env; | |
1406 | } else if(env_rs == JNI_EDETACHED) { | |
1407 | // current thread is not attached, attempt to attach | |
1408 | const jint rs_attach = jvm->AttachCurrentThread(reinterpret_cast<void**>(&env), NULL); | |
1409 | if(rs_attach == JNI_OK) { | |
1410 | *attached = JNI_TRUE; | |
1411 | return env; | |
1412 | } else { | |
1413 | // error, could not attach the thread | |
1414 | std::cerr << "JniUtil::getJniEnv - Fatal: could not attach current thread to JVM!" << std::endl; | |
1415 | return nullptr; | |
1416 | } | |
1417 | } else if(env_rs == JNI_EVERSION) { | |
1418 | // error, JDK does not support JNI_VERSION_1_2+ | |
1419 | std::cerr << "JniUtil::getJniEnv - Fatal: JDK does not support JNI_VERSION_1_2" << std::endl; | |
1420 | return nullptr; | |
1421 | } else { | |
1422 | std::cerr << "JniUtil::getJniEnv - Fatal: Unknown error: env_rs=" << env_rs << std::endl; | |
1423 | return nullptr; | |
1424 | } | |
11fdf7f2 TL |
1425 | } |
1426 | ||
494da23a TL |
1427 | /** |
1428 | * Counterpart to {@link JniUtil::getJniEnv(JavaVM*, jboolean*)} | |
1429 | * | |
1430 | * Detachess the current thread from the JVM if it was previously | |
1431 | * attached | |
1432 | * | |
1433 | * @param jvm (IN) A pointer to the JavaVM instance | |
1434 | * @param attached (IN) JNI_TRUE if we previously had to attach the thread | |
1435 | * to the JavaVM to get the JNIEnv | |
1436 | */ | |
1437 | static void releaseJniEnv(JavaVM* jvm, jboolean& attached) { | |
1438 | assert(jvm != nullptr); | |
1439 | if(attached == JNI_TRUE) { | |
1440 | const jint rs_detach = jvm->DetachCurrentThread(); | |
1441 | assert(rs_detach == JNI_OK); | |
1442 | if(rs_detach != JNI_OK) { | |
1443 | std::cerr << "JniUtil::getJniEnv - Warn: Unable to detach current thread from JVM!" << std::endl; | |
1444 | } | |
1445 | } | |
11fdf7f2 TL |
1446 | } |
1447 | ||
494da23a TL |
1448 | /** |
1449 | * Copies a Java String[] to a C++ std::vector<std::string> | |
1450 | * | |
1451 | * @param env (IN) A pointer to the java environment | |
1452 | * @param jss (IN) The Java String array to copy | |
1453 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1454 | * if an OutOfMemoryError or ArrayIndexOutOfBoundsException | |
1455 | * exception occurs | |
1456 | * | |
1457 | * @return A std::vector<std:string> containing copies of the Java strings | |
1458 | */ | |
1459 | static std::vector<std::string> copyStrings(JNIEnv* env, | |
1460 | jobjectArray jss, jboolean* has_exception) { | |
1461 | return rocksdb::JniUtil::copyStrings(env, jss, | |
1462 | env->GetArrayLength(jss), has_exception); | |
11fdf7f2 | 1463 | } |
7c673cae | 1464 | |
494da23a TL |
1465 | /** |
1466 | * Copies a Java String[] to a C++ std::vector<std::string> | |
1467 | * | |
1468 | * @param env (IN) A pointer to the java environment | |
1469 | * @param jss (IN) The Java String array to copy | |
1470 | * @param jss_len (IN) The length of the Java String array to copy | |
1471 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1472 | * if an OutOfMemoryError or ArrayIndexOutOfBoundsException | |
1473 | * exception occurs | |
1474 | * | |
1475 | * @return A std::vector<std:string> containing copies of the Java strings | |
1476 | */ | |
1477 | static std::vector<std::string> copyStrings(JNIEnv* env, | |
1478 | jobjectArray jss, const jsize jss_len, jboolean* has_exception) { | |
1479 | std::vector<std::string> strs; | |
1480 | strs.reserve(jss_len); | |
1481 | for (jsize i = 0; i < jss_len; i++) { | |
1482 | jobject js = env->GetObjectArrayElement(jss, i); | |
1483 | if(env->ExceptionCheck()) { | |
1484 | // exception thrown: ArrayIndexOutOfBoundsException | |
1485 | *has_exception = JNI_TRUE; | |
1486 | return strs; | |
1487 | } | |
11fdf7f2 | 1488 | |
494da23a TL |
1489 | jstring jstr = static_cast<jstring>(js); |
1490 | const char* str = env->GetStringUTFChars(jstr, nullptr); | |
1491 | if(str == nullptr) { | |
1492 | // exception thrown: OutOfMemoryError | |
1493 | env->DeleteLocalRef(js); | |
1494 | *has_exception = JNI_TRUE; | |
1495 | return strs; | |
1496 | } | |
7c673cae | 1497 | |
494da23a | 1498 | strs.push_back(std::string(str)); |
7c673cae | 1499 | |
494da23a TL |
1500 | env->ReleaseStringUTFChars(jstr, str); |
1501 | env->DeleteLocalRef(js); | |
1502 | } | |
7c673cae | 1503 | |
494da23a TL |
1504 | *has_exception = JNI_FALSE; |
1505 | return strs; | |
7c673cae FG |
1506 | } |
1507 | ||
494da23a TL |
1508 | /** |
1509 | * Copies a jstring to a C-style null-terminated byte string | |
1510 | * and releases the original jstring | |
1511 | * | |
1512 | * The jstring is copied as UTF-8 | |
1513 | * | |
1514 | * If an exception occurs, then JNIEnv::ExceptionCheck() | |
1515 | * will have been called | |
1516 | * | |
1517 | * @param env (IN) A pointer to the java environment | |
1518 | * @param js (IN) The java string to copy | |
1519 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1520 | * if an OutOfMemoryError exception occurs | |
1521 | * | |
1522 | * @return A pointer to the copied string, or a | |
1523 | * nullptr if has_exception == JNI_TRUE | |
1524 | */ | |
1525 | static std::unique_ptr<char[]> copyString(JNIEnv* env, jstring js, | |
1526 | jboolean* has_exception) { | |
1527 | const char *utf = env->GetStringUTFChars(js, nullptr); | |
1528 | if(utf == nullptr) { | |
1529 | // exception thrown: OutOfMemoryError | |
1530 | env->ExceptionCheck(); | |
1531 | *has_exception = JNI_TRUE; | |
1532 | return nullptr; | |
1533 | } else if(env->ExceptionCheck()) { | |
1534 | // exception thrown | |
1535 | env->ReleaseStringUTFChars(js, utf); | |
1536 | *has_exception = JNI_TRUE; | |
1537 | return nullptr; | |
1538 | } | |
11fdf7f2 | 1539 | |
494da23a TL |
1540 | const jsize utf_len = env->GetStringUTFLength(js); |
1541 | std::unique_ptr<char[]> str(new char[utf_len + 1]); // Note: + 1 is needed for the c_str null terminator | |
1542 | std::strcpy(str.get(), utf); | |
1543 | env->ReleaseStringUTFChars(js, utf); | |
1544 | *has_exception = JNI_FALSE; | |
1545 | return str; | |
7c673cae FG |
1546 | } |
1547 | ||
494da23a TL |
1548 | /** |
1549 | * Copies a jstring to a std::string | |
1550 | * and releases the original jstring | |
1551 | * | |
1552 | * If an exception occurs, then JNIEnv::ExceptionCheck() | |
1553 | * will have been called | |
1554 | * | |
1555 | * @param env (IN) A pointer to the java environment | |
1556 | * @param js (IN) The java string to copy | |
1557 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1558 | * if an OutOfMemoryError exception occurs | |
1559 | * | |
1560 | * @return A std:string copy of the jstring, or an | |
1561 | * empty std::string if has_exception == JNI_TRUE | |
1562 | */ | |
1563 | static std::string copyStdString(JNIEnv* env, jstring js, | |
1564 | jboolean* has_exception) { | |
1565 | const char *utf = env->GetStringUTFChars(js, nullptr); | |
1566 | if(utf == nullptr) { | |
1567 | // exception thrown: OutOfMemoryError | |
1568 | env->ExceptionCheck(); | |
1569 | *has_exception = JNI_TRUE; | |
1570 | return std::string(); | |
1571 | } else if(env->ExceptionCheck()) { | |
1572 | // exception thrown | |
1573 | env->ReleaseStringUTFChars(js, utf); | |
1574 | *has_exception = JNI_TRUE; | |
1575 | return std::string(); | |
1576 | } | |
7c673cae | 1577 | |
494da23a TL |
1578 | std::string name(utf); |
1579 | env->ReleaseStringUTFChars(js, utf); | |
1580 | *has_exception = JNI_FALSE; | |
1581 | return name; | |
7c673cae FG |
1582 | } |
1583 | ||
494da23a TL |
1584 | /** |
1585 | * Copies bytes from a std::string to a jByteArray | |
1586 | * | |
1587 | * @param env A pointer to the java environment | |
1588 | * @param bytes The bytes to copy | |
1589 | * | |
1590 | * @return the Java byte[], or nullptr if an exception occurs | |
1591 | * | |
1592 | * @throws RocksDBException thrown | |
1593 | * if memory size to copy exceeds general java specific array size limitation. | |
1594 | */ | |
1595 | static jbyteArray copyBytes(JNIEnv* env, std::string bytes) { | |
1596 | return createJavaByteArrayWithSizeCheck(env, bytes.c_str(), bytes.size()); | |
11fdf7f2 TL |
1597 | } |
1598 | ||
494da23a TL |
1599 | /** |
1600 | * Given a Java byte[][] which is an array of java.lang.Strings | |
1601 | * where each String is a byte[], the passed function `string_fn` | |
1602 | * will be called on each String, the result is the collected by | |
1603 | * calling the passed function `collector_fn` | |
1604 | * | |
1605 | * @param env (IN) A pointer to the java environment | |
1606 | * @param jbyte_strings (IN) A Java array of Strings expressed as bytes | |
1607 | * @param string_fn (IN) A transform function to call for each String | |
1608 | * @param collector_fn (IN) A collector which is called for the result | |
1609 | * of each `string_fn` | |
1610 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1611 | * if an ArrayIndexOutOfBoundsException or OutOfMemoryError | |
1612 | * exception occurs | |
1613 | */ | |
1614 | template <typename T> static void byteStrings(JNIEnv* env, | |
1615 | jobjectArray jbyte_strings, | |
1616 | std::function<T(const char*, const size_t)> string_fn, | |
1617 | std::function<void(size_t, T)> collector_fn, | |
1618 | jboolean *has_exception) { | |
1619 | const jsize jlen = env->GetArrayLength(jbyte_strings); | |
11fdf7f2 | 1620 | |
494da23a TL |
1621 | for(jsize i = 0; i < jlen; i++) { |
1622 | jobject jbyte_string_obj = env->GetObjectArrayElement(jbyte_strings, i); | |
1623 | if(env->ExceptionCheck()) { | |
1624 | // exception thrown: ArrayIndexOutOfBoundsException | |
1625 | *has_exception = JNI_TRUE; // signal error | |
1626 | return; | |
1627 | } | |
7c673cae | 1628 | |
494da23a TL |
1629 | jbyteArray jbyte_string_ary = |
1630 | reinterpret_cast<jbyteArray>(jbyte_string_obj); | |
1631 | T result = byteString(env, jbyte_string_ary, string_fn, has_exception); | |
1632 | ||
1633 | env->DeleteLocalRef(jbyte_string_obj); | |
1634 | ||
1635 | if(*has_exception == JNI_TRUE) { | |
1636 | // exception thrown: OutOfMemoryError | |
1637 | return; | |
1638 | } | |
1639 | ||
1640 | collector_fn(i, result); | |
1641 | } | |
1642 | ||
1643 | *has_exception = JNI_FALSE; | |
1644 | } | |
1645 | ||
1646 | /** | |
1647 | * Given a Java String which is expressed as a Java Byte Array byte[], | |
1648 | * the passed function `string_fn` will be called on the String | |
1649 | * and the result returned | |
1650 | * | |
1651 | * @param env (IN) A pointer to the java environment | |
1652 | * @param jbyte_string_ary (IN) A Java String expressed in bytes | |
1653 | * @param string_fn (IN) A transform function to call on the String | |
1654 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1655 | * if an OutOfMemoryError exception occurs | |
1656 | */ | |
1657 | template <typename T> static T byteString(JNIEnv* env, | |
1658 | jbyteArray jbyte_string_ary, | |
1659 | std::function<T(const char*, const size_t)> string_fn, | |
1660 | jboolean* has_exception) { | |
1661 | const jsize jbyte_string_len = env->GetArrayLength(jbyte_string_ary); | |
1662 | return byteString<T>(env, jbyte_string_ary, jbyte_string_len, string_fn, | |
1663 | has_exception); | |
1664 | } | |
1665 | ||
1666 | /** | |
1667 | * Given a Java String which is expressed as a Java Byte Array byte[], | |
1668 | * the passed function `string_fn` will be called on the String | |
1669 | * and the result returned | |
1670 | * | |
1671 | * @param env (IN) A pointer to the java environment | |
1672 | * @param jbyte_string_ary (IN) A Java String expressed in bytes | |
1673 | * @param jbyte_string_len (IN) The length of the Java String | |
1674 | * expressed in bytes | |
1675 | * @param string_fn (IN) A transform function to call on the String | |
1676 | * @param has_exception (OUT) will be set to JNI_TRUE | |
1677 | * if an OutOfMemoryError exception occurs | |
1678 | */ | |
1679 | template <typename T> static T byteString(JNIEnv* env, | |
1680 | jbyteArray jbyte_string_ary, const jsize jbyte_string_len, | |
1681 | std::function<T(const char*, const size_t)> string_fn, | |
1682 | jboolean* has_exception) { | |
1683 | jbyte* jbyte_string = | |
1684 | env->GetByteArrayElements(jbyte_string_ary, nullptr); | |
1685 | if(jbyte_string == nullptr) { | |
1686 | // exception thrown: OutOfMemoryError | |
1687 | *has_exception = JNI_TRUE; | |
1688 | return nullptr; // signal error | |
1689 | } | |
1690 | ||
1691 | T result = | |
1692 | string_fn(reinterpret_cast<char *>(jbyte_string), jbyte_string_len); | |
1693 | ||
1694 | env->ReleaseByteArrayElements(jbyte_string_ary, jbyte_string, JNI_ABORT); | |
1695 | ||
1696 | *has_exception = JNI_FALSE; | |
1697 | return result; | |
1698 | } | |
1699 | ||
1700 | /** | |
1701 | * Converts a std::vector<string> to a Java byte[][] where each Java String | |
1702 | * is expressed as a Java Byte Array byte[]. | |
1703 | * | |
1704 | * @param env A pointer to the java environment | |
1705 | * @param strings A vector of Strings | |
1706 | * | |
1707 | * @return A Java array of Strings expressed as bytes, | |
1708 | * or nullptr if an exception is thrown | |
1709 | */ | |
1710 | static jobjectArray stringsBytes(JNIEnv* env, std::vector<std::string> strings) { | |
1711 | jclass jcls_ba = ByteJni::getArrayJClass(env); | |
1712 | if(jcls_ba == nullptr) { | |
1713 | // exception occurred | |
1714 | return nullptr; | |
1715 | } | |
1716 | ||
1717 | const jsize len = static_cast<jsize>(strings.size()); | |
1718 | ||
1719 | jobjectArray jbyte_strings = env->NewObjectArray(len, jcls_ba, nullptr); | |
1720 | if(jbyte_strings == nullptr) { | |
1721 | // exception thrown: OutOfMemoryError | |
1722 | return nullptr; | |
1723 | } | |
1724 | ||
1725 | for (jsize i = 0; i < len; i++) { | |
1726 | std::string *str = &strings[i]; | |
1727 | const jsize str_len = static_cast<jsize>(str->size()); | |
1728 | ||
1729 | jbyteArray jbyte_string_ary = env->NewByteArray(str_len); | |
1730 | if(jbyte_string_ary == nullptr) { | |
1731 | // exception thrown: OutOfMemoryError | |
1732 | env->DeleteLocalRef(jbyte_strings); | |
1733 | return nullptr; | |
1734 | } | |
1735 | ||
1736 | env->SetByteArrayRegion( | |
1737 | jbyte_string_ary, 0, str_len, | |
1738 | const_cast<jbyte*>(reinterpret_cast<const jbyte*>(str->c_str()))); | |
1739 | if(env->ExceptionCheck()) { | |
1740 | // exception thrown: ArrayIndexOutOfBoundsException | |
1741 | env->DeleteLocalRef(jbyte_string_ary); | |
1742 | env->DeleteLocalRef(jbyte_strings); | |
1743 | return nullptr; | |
1744 | } | |
1745 | ||
1746 | env->SetObjectArrayElement(jbyte_strings, i, jbyte_string_ary); | |
1747 | if(env->ExceptionCheck()) { | |
1748 | // exception thrown: ArrayIndexOutOfBoundsException | |
1749 | // or ArrayStoreException | |
1750 | env->DeleteLocalRef(jbyte_string_ary); | |
1751 | env->DeleteLocalRef(jbyte_strings); | |
1752 | return nullptr; | |
1753 | } | |
1754 | ||
1755 | env->DeleteLocalRef(jbyte_string_ary); | |
1756 | } | |
1757 | ||
1758 | return jbyte_strings; | |
1759 | } | |
1760 | ||
1761 | /** | |
1762 | * Converts a std::vector<std::string> to a Java String[]. | |
1763 | * | |
1764 | * @param env A pointer to the java environment | |
1765 | * @param strings A vector of Strings | |
1766 | * | |
1767 | * @return A Java array of Strings, | |
1768 | * or nullptr if an exception is thrown | |
1769 | */ | |
1770 | static jobjectArray toJavaStrings(JNIEnv* env, | |
1771 | const std::vector<std::string>* strings) { | |
1772 | jclass jcls_str = env->FindClass("java/lang/String"); | |
1773 | if(jcls_str == nullptr) { | |
1774 | // exception occurred | |
1775 | return nullptr; | |
1776 | } | |
1777 | ||
1778 | const jsize len = static_cast<jsize>(strings->size()); | |
1779 | ||
1780 | jobjectArray jstrings = env->NewObjectArray(len, jcls_str, nullptr); | |
1781 | if(jstrings == nullptr) { | |
1782 | // exception thrown: OutOfMemoryError | |
1783 | return nullptr; | |
1784 | } | |
1785 | ||
1786 | for (jsize i = 0; i < len; i++) { | |
1787 | const std::string *str = &((*strings)[i]); | |
1788 | jstring js = rocksdb::JniUtil::toJavaString(env, str); | |
1789 | if (js == nullptr) { | |
1790 | env->DeleteLocalRef(jstrings); | |
1791 | return nullptr; | |
1792 | } | |
1793 | ||
1794 | env->SetObjectArrayElement(jstrings, i, js); | |
1795 | if(env->ExceptionCheck()) { | |
1796 | // exception thrown: ArrayIndexOutOfBoundsException | |
1797 | // or ArrayStoreException | |
1798 | env->DeleteLocalRef(js); | |
1799 | env->DeleteLocalRef(jstrings); | |
1800 | return nullptr; | |
1801 | } | |
1802 | } | |
1803 | ||
1804 | return jstrings; | |
1805 | } | |
1806 | ||
1807 | /** | |
1808 | * Creates a Java UTF String from a C++ std::string | |
1809 | * | |
1810 | * @param env A pointer to the java environment | |
1811 | * @param string the C++ std::string | |
1812 | * @param treat_empty_as_null true if empty strings should be treated as null | |
1813 | * | |
1814 | * @return the Java UTF string, or nullptr if the provided string | |
1815 | * is null (or empty and treat_empty_as_null is set), or if an | |
1816 | * exception occurs allocating the Java String. | |
1817 | */ | |
1818 | static jstring toJavaString(JNIEnv* env, const std::string* string, | |
1819 | const bool treat_empty_as_null = false) { | |
1820 | if (string == nullptr) { | |
1821 | return nullptr; | |
1822 | } | |
1823 | ||
1824 | if (treat_empty_as_null && string->empty()) { | |
1825 | return nullptr; | |
1826 | } | |
1827 | ||
1828 | return env->NewStringUTF(string->c_str()); | |
1829 | } | |
1830 | ||
1831 | /** | |
1832 | * Copies bytes to a new jByteArray with the check of java array size limitation. | |
1833 | * | |
1834 | * @param bytes pointer to memory to copy to a new jByteArray | |
1835 | * @param size number of bytes to copy | |
1836 | * | |
1837 | * @return the Java byte[], or nullptr if an exception occurs | |
1838 | * | |
1839 | * @throws RocksDBException thrown | |
1840 | * if memory size to copy exceeds general java array size limitation to avoid overflow. | |
1841 | */ | |
1842 | static jbyteArray createJavaByteArrayWithSizeCheck(JNIEnv* env, const char* bytes, const size_t size) { | |
1843 | // Limitation for java array size is vm specific | |
1844 | // In general it cannot exceed Integer.MAX_VALUE (2^31 - 1) | |
1845 | // Current HotSpot VM limitation for array size is Integer.MAX_VALUE - 5 (2^31 - 1 - 5) | |
1846 | // It means that the next call to env->NewByteArray can still end with | |
1847 | // OutOfMemoryError("Requested array size exceeds VM limit") coming from VM | |
1848 | static const size_t MAX_JARRAY_SIZE = (static_cast<size_t>(1)) << 31; | |
1849 | if(size > MAX_JARRAY_SIZE) { | |
1850 | rocksdb::RocksDBExceptionJni::ThrowNew(env, "Requested array size exceeds VM limit"); | |
1851 | return nullptr; | |
1852 | } | |
1853 | ||
1854 | const jsize jlen = static_cast<jsize>(size); | |
1855 | jbyteArray jbytes = env->NewByteArray(jlen); | |
1856 | if(jbytes == nullptr) { | |
1857 | // exception thrown: OutOfMemoryError | |
1858 | return nullptr; | |
1859 | } | |
1860 | ||
1861 | env->SetByteArrayRegion(jbytes, 0, jlen, | |
1862 | const_cast<jbyte*>(reinterpret_cast<const jbyte*>(bytes))); | |
1863 | if(env->ExceptionCheck()) { | |
1864 | // exception thrown: ArrayIndexOutOfBoundsException | |
1865 | env->DeleteLocalRef(jbytes); | |
1866 | return nullptr; | |
1867 | } | |
1868 | ||
1869 | return jbytes; | |
1870 | } | |
1871 | ||
1872 | /** | |
1873 | * Copies bytes from a rocksdb::Slice to a jByteArray | |
1874 | * | |
1875 | * @param env A pointer to the java environment | |
1876 | * @param bytes The bytes to copy | |
1877 | * | |
1878 | * @return the Java byte[] or nullptr if an exception occurs | |
1879 | * | |
1880 | * @throws RocksDBException thrown | |
1881 | * if memory size to copy exceeds general java specific array size limitation. | |
1882 | */ | |
1883 | static jbyteArray copyBytes(JNIEnv* env, const Slice& bytes) { | |
1884 | return createJavaByteArrayWithSizeCheck(env, bytes.data(), bytes.size()); | |
1885 | } | |
1886 | ||
1887 | /* | |
1888 | * Helper for operations on a key and value | |
1889 | * for example WriteBatch->Put | |
1890 | * | |
1891 | * TODO(AR) could be used for RocksDB->Put etc. | |
1892 | */ | |
1893 | static std::unique_ptr<rocksdb::Status> kv_op( | |
1894 | std::function<rocksdb::Status(rocksdb::Slice, rocksdb::Slice)> op, | |
1895 | JNIEnv* env, jobject /*jobj*/, | |
1896 | jbyteArray jkey, jint jkey_len, | |
1897 | jbyteArray jvalue, jint jvalue_len) { | |
1898 | jbyte* key = env->GetByteArrayElements(jkey, nullptr); | |
1899 | if(env->ExceptionCheck()) { | |
1900 | // exception thrown: OutOfMemoryError | |
1901 | return nullptr; | |
1902 | } | |
1903 | ||
1904 | jbyte* value = env->GetByteArrayElements(jvalue, nullptr); | |
1905 | if(env->ExceptionCheck()) { | |
1906 | // exception thrown: OutOfMemoryError | |
1907 | if(key != nullptr) { | |
1908 | env->ReleaseByteArrayElements(jkey, key, JNI_ABORT); | |
1909 | } | |
1910 | return nullptr; | |
1911 | } | |
1912 | ||
1913 | rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len); | |
1914 | rocksdb::Slice value_slice(reinterpret_cast<char*>(value), | |
1915 | jvalue_len); | |
1916 | ||
1917 | auto status = op(key_slice, value_slice); | |
1918 | ||
1919 | if(value != nullptr) { | |
1920 | env->ReleaseByteArrayElements(jvalue, value, JNI_ABORT); | |
1921 | } | |
1922 | if(key != nullptr) { | |
1923 | env->ReleaseByteArrayElements(jkey, key, JNI_ABORT); | |
1924 | } | |
1925 | ||
1926 | return std::unique_ptr<rocksdb::Status>(new rocksdb::Status(status)); | |
1927 | } | |
1928 | ||
1929 | /* | |
1930 | * Helper for operations on a key | |
1931 | * for example WriteBatch->Delete | |
1932 | * | |
1933 | * TODO(AR) could be used for RocksDB->Delete etc. | |
1934 | */ | |
1935 | static std::unique_ptr<rocksdb::Status> k_op( | |
1936 | std::function<rocksdb::Status(rocksdb::Slice)> op, | |
1937 | JNIEnv* env, jobject /*jobj*/, | |
1938 | jbyteArray jkey, jint jkey_len) { | |
1939 | jbyte* key = env->GetByteArrayElements(jkey, nullptr); | |
1940 | if(env->ExceptionCheck()) { | |
1941 | // exception thrown: OutOfMemoryError | |
1942 | return nullptr; | |
1943 | } | |
1944 | ||
1945 | rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len); | |
1946 | ||
1947 | auto status = op(key_slice); | |
1948 | ||
1949 | if(key != nullptr) { | |
1950 | env->ReleaseByteArrayElements(jkey, key, JNI_ABORT); | |
1951 | } | |
1952 | ||
1953 | return std::unique_ptr<rocksdb::Status>(new rocksdb::Status(status)); | |
1954 | } | |
1955 | ||
1956 | /* | |
1957 | * Helper for operations on a value | |
1958 | * for example WriteBatchWithIndex->GetFromBatch | |
1959 | */ | |
1960 | static jbyteArray v_op( | |
1961 | std::function<rocksdb::Status(rocksdb::Slice, std::string*)> op, | |
1962 | JNIEnv* env, jbyteArray jkey, jint jkey_len) { | |
1963 | jbyte* key = env->GetByteArrayElements(jkey, nullptr); | |
1964 | if(env->ExceptionCheck()) { | |
1965 | // exception thrown: OutOfMemoryError | |
1966 | return nullptr; | |
1967 | } | |
1968 | ||
1969 | rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len); | |
1970 | ||
1971 | std::string value; | |
1972 | rocksdb::Status s = op(key_slice, &value); | |
1973 | ||
1974 | if(key != nullptr) { | |
1975 | env->ReleaseByteArrayElements(jkey, key, JNI_ABORT); | |
1976 | } | |
1977 | ||
1978 | if (s.IsNotFound()) { | |
1979 | return nullptr; | |
1980 | } | |
1981 | ||
1982 | if (s.ok()) { | |
1983 | jbyteArray jret_value = | |
1984 | env->NewByteArray(static_cast<jsize>(value.size())); | |
1985 | if(jret_value == nullptr) { | |
1986 | // exception thrown: OutOfMemoryError | |
1987 | return nullptr; | |
1988 | } | |
1989 | ||
1990 | env->SetByteArrayRegion(jret_value, 0, static_cast<jsize>(value.size()), | |
1991 | const_cast<jbyte*>(reinterpret_cast<const jbyte*>(value.c_str()))); | |
1992 | if(env->ExceptionCheck()) { | |
1993 | // exception thrown: ArrayIndexOutOfBoundsException | |
1994 | if(jret_value != nullptr) { | |
1995 | env->DeleteLocalRef(jret_value); | |
1996 | } | |
1997 | return nullptr; | |
1998 | } | |
1999 | ||
2000 | return jret_value; | |
2001 | } | |
2002 | ||
2003 | rocksdb::RocksDBExceptionJni::ThrowNew(env, s); | |
2004 | return nullptr; | |
2005 | } | |
2006 | ||
2007 | /** | |
2008 | * Creates a vector<T*> of C++ pointers from | |
2009 | * a Java array of C++ pointer addresses. | |
2010 | * | |
2011 | * @param env (IN) A pointer to the java environment | |
2012 | * @param pointers (IN) A Java array of C++ pointer addresses | |
2013 | * @param has_exception (OUT) will be set to JNI_TRUE | |
2014 | * if an ArrayIndexOutOfBoundsException or OutOfMemoryError | |
2015 | * exception occurs. | |
2016 | * | |
2017 | * @return A vector of C++ pointers. | |
2018 | */ | |
2019 | template<typename T> static std::vector<T*> fromJPointers( | |
2020 | JNIEnv* env, jlongArray jptrs, jboolean *has_exception) { | |
2021 | const jsize jptrs_len = env->GetArrayLength(jptrs); | |
2022 | std::vector<T*> ptrs; | |
2023 | jlong* jptr = env->GetLongArrayElements(jptrs, nullptr); | |
2024 | if (jptr == nullptr) { | |
2025 | // exception thrown: OutOfMemoryError | |
2026 | *has_exception = JNI_TRUE; | |
2027 | return ptrs; | |
2028 | } | |
2029 | ptrs.reserve(jptrs_len); | |
2030 | for (jsize i = 0; i < jptrs_len; i++) { | |
2031 | ptrs.push_back(reinterpret_cast<T*>(jptr[i])); | |
2032 | } | |
2033 | env->ReleaseLongArrayElements(jptrs, jptr, JNI_ABORT); | |
2034 | return ptrs; | |
2035 | } | |
2036 | ||
2037 | /** | |
2038 | * Creates a Java array of C++ pointer addresses | |
2039 | * from a vector of C++ pointers. | |
2040 | * | |
2041 | * @param env (IN) A pointer to the java environment | |
2042 | * @param pointers (IN) A vector of C++ pointers | |
2043 | * @param has_exception (OUT) will be set to JNI_TRUE | |
2044 | * if an ArrayIndexOutOfBoundsException or OutOfMemoryError | |
2045 | * exception occurs | |
2046 | * | |
2047 | * @return Java array of C++ pointer addresses. | |
2048 | */ | |
2049 | template<typename T> static jlongArray toJPointers(JNIEnv* env, | |
2050 | const std::vector<T*> &pointers, | |
2051 | jboolean *has_exception) { | |
2052 | const jsize len = static_cast<jsize>(pointers.size()); | |
2053 | std::unique_ptr<jlong[]> results(new jlong[len]); | |
2054 | std::transform(pointers.begin(), pointers.end(), results.get(), [](T* pointer) -> jlong { | |
2055 | return reinterpret_cast<jlong>(pointer); | |
2056 | }); | |
2057 | ||
2058 | jlongArray jpointers = env->NewLongArray(len); | |
2059 | if (jpointers == nullptr) { | |
2060 | // exception thrown: OutOfMemoryError | |
2061 | *has_exception = JNI_TRUE; | |
2062 | return nullptr; | |
2063 | } | |
2064 | ||
2065 | env->SetLongArrayRegion(jpointers, 0, len, results.get()); | |
2066 | if (env->ExceptionCheck()) { | |
2067 | // exception thrown: ArrayIndexOutOfBoundsException | |
2068 | *has_exception = JNI_TRUE; | |
2069 | env->DeleteLocalRef(jpointers); | |
2070 | return nullptr; | |
2071 | } | |
2072 | ||
2073 | *has_exception = JNI_FALSE; | |
2074 | ||
2075 | return jpointers; | |
2076 | } | |
2077 | }; | |
2078 | ||
2079 | class MapJni : public JavaClass { | |
2080 | public: | |
2081 | /** | |
2082 | * Get the Java Class java.util.Map | |
2083 | * | |
2084 | * @param env A pointer to the Java environment | |
2085 | * | |
2086 | * @return The Java Class or nullptr if one of the | |
2087 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2088 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2089 | */ | |
2090 | static jclass getJClass(JNIEnv* env) { | |
2091 | return JavaClass::getJClass(env, "java/util/Map"); | |
2092 | } | |
2093 | ||
2094 | /** | |
2095 | * Get the Java Method: Map#put | |
2096 | * | |
2097 | * @param env A pointer to the Java environment | |
2098 | * | |
2099 | * @return The Java Method ID or nullptr if the class or method id could not | |
2100 | * be retieved | |
2101 | */ | |
2102 | static jmethodID getMapPutMethodId(JNIEnv* env) { | |
2103 | jclass jlist_clazz = getJClass(env); | |
2104 | if(jlist_clazz == nullptr) { | |
2105 | // exception occurred accessing class | |
2106 | return nullptr; | |
2107 | } | |
2108 | ||
2109 | static jmethodID mid = | |
2110 | env->GetMethodID(jlist_clazz, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); | |
2111 | assert(mid != nullptr); | |
2112 | return mid; | |
2113 | } | |
2114 | }; | |
2115 | ||
2116 | class HashMapJni : public JavaClass { | |
2117 | public: | |
2118 | /** | |
2119 | * Get the Java Class java.util.HashMap | |
2120 | * | |
2121 | * @param env A pointer to the Java environment | |
2122 | * | |
2123 | * @return The Java Class or nullptr if one of the | |
2124 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2125 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2126 | */ | |
2127 | static jclass getJClass(JNIEnv* env) { | |
2128 | return JavaClass::getJClass(env, "java/util/HashMap"); | |
2129 | } | |
2130 | ||
2131 | /** | |
2132 | * Create a new Java java.util.HashMap object. | |
2133 | * | |
2134 | * @param env A pointer to the Java environment | |
2135 | * | |
2136 | * @return A reference to a Java java.util.HashMap object, or | |
2137 | * nullptr if an an exception occurs | |
2138 | */ | |
2139 | static jobject construct(JNIEnv* env, const uint32_t initial_capacity = 16) { | |
2140 | jclass jclazz = getJClass(env); | |
2141 | if (jclazz == nullptr) { | |
2142 | // exception occurred accessing class | |
2143 | return nullptr; | |
2144 | } | |
2145 | ||
2146 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(I)V"); | |
2147 | if (mid == nullptr) { | |
2148 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
2149 | return nullptr; | |
2150 | } | |
2151 | ||
2152 | jobject jhash_map = env->NewObject(jclazz, mid, static_cast<jint>(initial_capacity)); | |
2153 | if (env->ExceptionCheck()) { | |
2154 | return nullptr; | |
2155 | } | |
2156 | ||
2157 | return jhash_map; | |
2158 | } | |
2159 | ||
2160 | /** | |
2161 | * A function which maps a std::pair<K,V> to a std::pair<JK, JV> | |
2162 | * | |
2163 | * @return Either a pointer to a std::pair<jobject, jobject>, or nullptr | |
2164 | * if an error occurs during the mapping | |
2165 | */ | |
2166 | template <typename K, typename V, typename JK, typename JV> | |
2167 | using FnMapKV = std::function<std::unique_ptr<std::pair<JK, JV>> (const std::pair<K, V>&)>; | |
2168 | ||
2169 | // template <class I, typename K, typename V, typename K1, typename V1, typename std::enable_if<std::is_same<typename std::iterator_traits<I>::value_type, std::pair<const K,V>>::value, int32_t>::type = 0> | |
2170 | // static void putAll(JNIEnv* env, const jobject jhash_map, I iterator, const FnMapKV<const K,V,K1,V1> &fn_map_kv) { | |
2171 | /** | |
2172 | * Returns true if it succeeds, false if an error occurs | |
2173 | */ | |
2174 | template<class iterator_type, typename K, typename V> | |
2175 | static bool putAll(JNIEnv* env, const jobject jhash_map, iterator_type iterator, iterator_type end, const FnMapKV<K, V, jobject, jobject> &fn_map_kv) { | |
2176 | const jmethodID jmid_put = rocksdb::MapJni::getMapPutMethodId(env); | |
2177 | if (jmid_put == nullptr) { | |
2178 | return false; | |
2179 | } | |
2180 | ||
2181 | for (auto it = iterator; it != end; ++it) { | |
2182 | const std::unique_ptr<std::pair<jobject, jobject>> result = fn_map_kv(*it); | |
2183 | if (result == nullptr) { | |
2184 | // an error occurred during fn_map_kv | |
2185 | return false; | |
2186 | } | |
2187 | env->CallObjectMethod(jhash_map, jmid_put, result->first, result->second); | |
2188 | if (env->ExceptionCheck()) { | |
2189 | // exception occurred | |
2190 | env->DeleteLocalRef(result->second); | |
2191 | env->DeleteLocalRef(result->first); | |
2192 | return false; | |
2193 | } | |
2194 | ||
2195 | // release local references | |
2196 | env->DeleteLocalRef(result->second); | |
2197 | env->DeleteLocalRef(result->first); | |
2198 | } | |
2199 | ||
2200 | return true; | |
2201 | } | |
2202 | ||
2203 | /** | |
2204 | * Creates a java.util.Map<String, String> from a std::map<std::string, std::string> | |
2205 | * | |
2206 | * @param env A pointer to the Java environment | |
2207 | * @param map the Cpp map | |
2208 | * | |
2209 | * @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred | |
2210 | */ | |
2211 | static jobject fromCppMap(JNIEnv* env, const std::map<std::string, std::string>* map) { | |
2212 | if (map == nullptr) { | |
2213 | return nullptr; | |
2214 | } | |
2215 | ||
2216 | jobject jhash_map = construct(env, static_cast<uint32_t>(map->size())); | |
2217 | if (jhash_map == nullptr) { | |
2218 | // exception occurred | |
2219 | return nullptr; | |
2220 | } | |
2221 | ||
2222 | const rocksdb::HashMapJni::FnMapKV<const std::string, const std::string, jobject, jobject> fn_map_kv = | |
2223 | [env](const std::pair<const std::string, const std::string>& kv) { | |
2224 | jstring jkey = rocksdb::JniUtil::toJavaString(env, &(kv.first), false); | |
2225 | if (env->ExceptionCheck()) { | |
2226 | // an error occurred | |
2227 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2228 | } | |
2229 | ||
2230 | jstring jvalue = rocksdb::JniUtil::toJavaString(env, &(kv.second), true); | |
2231 | if (env->ExceptionCheck()) { | |
2232 | // an error occurred | |
2233 | env->DeleteLocalRef(jkey); | |
2234 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2235 | } | |
2236 | ||
2237 | return std::unique_ptr<std::pair<jobject, jobject>>(new std::pair<jobject, jobject>(static_cast<jobject>(jkey), static_cast<jobject>(jvalue))); | |
2238 | }; | |
2239 | ||
2240 | if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) { | |
2241 | // exception occurred | |
2242 | return nullptr; | |
2243 | } | |
2244 | ||
2245 | return jhash_map; | |
2246 | } | |
2247 | ||
2248 | /** | |
2249 | * Creates a java.util.Map<String, Long> from a std::map<std::string, uint32_t> | |
2250 | * | |
2251 | * @param env A pointer to the Java environment | |
2252 | * @param map the Cpp map | |
2253 | * | |
2254 | * @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred | |
2255 | */ | |
2256 | static jobject fromCppMap(JNIEnv* env, const std::map<std::string, uint32_t>* map) { | |
2257 | if (map == nullptr) { | |
2258 | return nullptr; | |
2259 | } | |
2260 | ||
2261 | if (map == nullptr) { | |
2262 | return nullptr; | |
2263 | } | |
2264 | ||
2265 | jobject jhash_map = construct(env, static_cast<uint32_t>(map->size())); | |
2266 | if (jhash_map == nullptr) { | |
2267 | // exception occurred | |
2268 | return nullptr; | |
2269 | } | |
2270 | ||
2271 | const rocksdb::HashMapJni::FnMapKV<const std::string, const uint32_t, jobject, jobject> fn_map_kv = | |
2272 | [env](const std::pair<const std::string, const uint32_t>& kv) { | |
2273 | jstring jkey = rocksdb::JniUtil::toJavaString(env, &(kv.first), false); | |
2274 | if (env->ExceptionCheck()) { | |
2275 | // an error occurred | |
2276 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2277 | } | |
2278 | ||
2279 | jobject jvalue = rocksdb::IntegerJni::valueOf(env, static_cast<jint>(kv.second)); | |
2280 | if (env->ExceptionCheck()) { | |
2281 | // an error occurred | |
2282 | env->DeleteLocalRef(jkey); | |
2283 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2284 | } | |
2285 | ||
2286 | return std::unique_ptr<std::pair<jobject, jobject>>(new std::pair<jobject, jobject>(static_cast<jobject>(jkey), jvalue)); | |
2287 | }; | |
2288 | ||
2289 | if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) { | |
2290 | // exception occurred | |
2291 | return nullptr; | |
2292 | } | |
2293 | ||
2294 | return jhash_map; | |
2295 | } | |
2296 | ||
2297 | /** | |
2298 | * Creates a java.util.Map<String, Long> from a std::map<std::string, uint64_t> | |
2299 | * | |
2300 | * @param env A pointer to the Java environment | |
2301 | * @param map the Cpp map | |
2302 | * | |
2303 | * @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred | |
2304 | */ | |
2305 | static jobject fromCppMap(JNIEnv* env, const std::map<std::string, uint64_t>* map) { | |
2306 | if (map == nullptr) { | |
2307 | return nullptr; | |
2308 | } | |
2309 | ||
2310 | jobject jhash_map = construct(env, static_cast<uint32_t>(map->size())); | |
2311 | if (jhash_map == nullptr) { | |
2312 | // exception occurred | |
2313 | return nullptr; | |
2314 | } | |
2315 | ||
2316 | const rocksdb::HashMapJni::FnMapKV<const std::string, const uint64_t, jobject, jobject> fn_map_kv = | |
2317 | [env](const std::pair<const std::string, const uint64_t>& kv) { | |
2318 | jstring jkey = rocksdb::JniUtil::toJavaString(env, &(kv.first), false); | |
2319 | if (env->ExceptionCheck()) { | |
2320 | // an error occurred | |
2321 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2322 | } | |
2323 | ||
2324 | jobject jvalue = rocksdb::LongJni::valueOf(env, static_cast<jlong>(kv.second)); | |
2325 | if (env->ExceptionCheck()) { | |
2326 | // an error occurred | |
2327 | env->DeleteLocalRef(jkey); | |
2328 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2329 | } | |
2330 | ||
2331 | return std::unique_ptr<std::pair<jobject, jobject>>(new std::pair<jobject, jobject>(static_cast<jobject>(jkey), jvalue)); | |
2332 | }; | |
2333 | ||
2334 | if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) { | |
2335 | // exception occurred | |
2336 | return nullptr; | |
2337 | } | |
2338 | ||
2339 | return jhash_map; | |
2340 | } | |
2341 | ||
2342 | /** | |
2343 | * Creates a java.util.Map<String, Long> from a std::map<uint32_t, uint64_t> | |
2344 | * | |
2345 | * @param env A pointer to the Java environment | |
2346 | * @param map the Cpp map | |
2347 | * | |
2348 | * @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred | |
2349 | */ | |
2350 | static jobject fromCppMap(JNIEnv* env, const std::map<uint32_t, uint64_t>* map) { | |
2351 | if (map == nullptr) { | |
2352 | return nullptr; | |
2353 | } | |
2354 | ||
2355 | jobject jhash_map = construct(env, static_cast<uint32_t>(map->size())); | |
2356 | if (jhash_map == nullptr) { | |
2357 | // exception occurred | |
2358 | return nullptr; | |
2359 | } | |
2360 | ||
2361 | const rocksdb::HashMapJni::FnMapKV<const uint32_t, const uint64_t, jobject, jobject> fn_map_kv = | |
2362 | [env](const std::pair<const uint32_t, const uint64_t>& kv) { | |
2363 | jobject jkey = rocksdb::IntegerJni::valueOf(env, static_cast<jint>(kv.first)); | |
2364 | if (env->ExceptionCheck()) { | |
2365 | // an error occurred | |
2366 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2367 | } | |
2368 | ||
2369 | jobject jvalue = rocksdb::LongJni::valueOf(env, static_cast<jlong>(kv.second)); | |
2370 | if (env->ExceptionCheck()) { | |
2371 | // an error occurred | |
2372 | env->DeleteLocalRef(jkey); | |
2373 | return std::unique_ptr<std::pair<jobject, jobject>>(nullptr); | |
2374 | } | |
2375 | ||
2376 | return std::unique_ptr<std::pair<jobject, jobject>>(new std::pair<jobject, jobject>(static_cast<jobject>(jkey), jvalue)); | |
2377 | }; | |
2378 | ||
2379 | if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) { | |
2380 | // exception occurred | |
2381 | return nullptr; | |
2382 | } | |
2383 | ||
2384 | return jhash_map; | |
2385 | } | |
2386 | }; | |
2387 | ||
2388 | // The portal class for org.rocksdb.RocksDB | |
2389 | class RocksDBJni : public RocksDBNativeClass<rocksdb::DB*, RocksDBJni> { | |
2390 | public: | |
2391 | /** | |
2392 | * Get the Java Class org.rocksdb.RocksDB | |
2393 | * | |
2394 | * @param env A pointer to the Java environment | |
2395 | * | |
2396 | * @return The Java Class or nullptr if one of the | |
2397 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2398 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2399 | */ | |
2400 | static jclass getJClass(JNIEnv* env) { | |
2401 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/RocksDB"); | |
2402 | } | |
2403 | }; | |
2404 | ||
2405 | // The portal class for org.rocksdb.Options | |
2406 | class OptionsJni : public RocksDBNativeClass< | |
2407 | rocksdb::Options*, OptionsJni> { | |
2408 | public: | |
2409 | /** | |
2410 | * Get the Java Class org.rocksdb.Options | |
2411 | * | |
2412 | * @param env A pointer to the Java environment | |
2413 | * | |
2414 | * @return The Java Class or nullptr if one of the | |
2415 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2416 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2417 | */ | |
2418 | static jclass getJClass(JNIEnv* env) { | |
2419 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/Options"); | |
2420 | } | |
2421 | }; | |
2422 | ||
2423 | // The portal class for org.rocksdb.DBOptions | |
2424 | class DBOptionsJni : public RocksDBNativeClass< | |
2425 | rocksdb::DBOptions*, DBOptionsJni> { | |
2426 | public: | |
2427 | /** | |
2428 | * Get the Java Class org.rocksdb.DBOptions | |
2429 | * | |
2430 | * @param env A pointer to the Java environment | |
2431 | * | |
2432 | * @return The Java Class or nullptr if one of the | |
2433 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2434 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2435 | */ | |
2436 | static jclass getJClass(JNIEnv* env) { | |
2437 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/DBOptions"); | |
2438 | } | |
2439 | }; | |
2440 | ||
2441 | // The portal class for org.rocksdb.ColumnFamilyOptions | |
2442 | class ColumnFamilyOptionsJni | |
2443 | : public RocksDBNativeClass<rocksdb::ColumnFamilyOptions*, | |
2444 | ColumnFamilyOptionsJni> { | |
2445 | public: | |
2446 | /** | |
2447 | * Get the Java Class org.rocksdb.ColumnFamilyOptions | |
2448 | * | |
2449 | * @param env A pointer to the Java environment | |
2450 | * | |
2451 | * @return The Java Class or nullptr if one of the | |
2452 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2453 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2454 | */ | |
2455 | static jclass getJClass(JNIEnv* env) { | |
2456 | return RocksDBNativeClass::getJClass(env, | |
2457 | "org/rocksdb/ColumnFamilyOptions"); | |
2458 | } | |
2459 | ||
2460 | /** | |
2461 | * Create a new Java org.rocksdb.ColumnFamilyOptions object with the same | |
2462 | * properties as the provided C++ rocksdb::ColumnFamilyOptions object | |
2463 | * | |
2464 | * @param env A pointer to the Java environment | |
2465 | * @param cfoptions A pointer to rocksdb::ColumnFamilyOptions object | |
2466 | * | |
2467 | * @return A reference to a Java org.rocksdb.ColumnFamilyOptions object, or | |
2468 | * nullptr if an an exception occurs | |
2469 | */ | |
2470 | static jobject construct(JNIEnv* env, const ColumnFamilyOptions* cfoptions) { | |
2471 | auto* cfo = new rocksdb::ColumnFamilyOptions(*cfoptions); | |
2472 | jclass jclazz = getJClass(env); | |
2473 | if(jclazz == nullptr) { | |
2474 | // exception occurred accessing class | |
2475 | return nullptr; | |
2476 | } | |
2477 | ||
2478 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(J)V"); | |
2479 | if (mid == nullptr) { | |
2480 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
2481 | return nullptr; | |
2482 | } | |
2483 | ||
2484 | jobject jcfd = env->NewObject(jclazz, mid, reinterpret_cast<jlong>(cfo)); | |
2485 | if (env->ExceptionCheck()) { | |
2486 | return nullptr; | |
2487 | } | |
2488 | ||
2489 | return jcfd; | |
2490 | } | |
2491 | }; | |
2492 | ||
2493 | // The portal class for org.rocksdb.WriteOptions | |
2494 | class WriteOptionsJni : public RocksDBNativeClass< | |
2495 | rocksdb::WriteOptions*, WriteOptionsJni> { | |
2496 | public: | |
2497 | /** | |
2498 | * Get the Java Class org.rocksdb.WriteOptions | |
2499 | * | |
2500 | * @param env A pointer to the Java environment | |
2501 | * | |
2502 | * @return The Java Class or nullptr if one of the | |
2503 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2504 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2505 | */ | |
2506 | static jclass getJClass(JNIEnv* env) { | |
2507 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/WriteOptions"); | |
2508 | } | |
2509 | }; | |
2510 | ||
2511 | // The portal class for org.rocksdb.ReadOptions | |
2512 | class ReadOptionsJni : public RocksDBNativeClass< | |
2513 | rocksdb::ReadOptions*, ReadOptionsJni> { | |
2514 | public: | |
2515 | /** | |
2516 | * Get the Java Class org.rocksdb.ReadOptions | |
2517 | * | |
2518 | * @param env A pointer to the Java environment | |
2519 | * | |
2520 | * @return The Java Class or nullptr if one of the | |
2521 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2522 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2523 | */ | |
2524 | static jclass getJClass(JNIEnv* env) { | |
2525 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/ReadOptions"); | |
2526 | } | |
2527 | }; | |
2528 | ||
2529 | // The portal class for org.rocksdb.WriteBatch | |
2530 | class WriteBatchJni : public RocksDBNativeClass< | |
2531 | rocksdb::WriteBatch*, WriteBatchJni> { | |
2532 | public: | |
2533 | /** | |
2534 | * Get the Java Class org.rocksdb.WriteBatch | |
2535 | * | |
2536 | * @param env A pointer to the Java environment | |
2537 | * | |
2538 | * @return The Java Class or nullptr if one of the | |
2539 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2540 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2541 | */ | |
2542 | static jclass getJClass(JNIEnv* env) { | |
2543 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/WriteBatch"); | |
2544 | } | |
2545 | ||
2546 | /** | |
2547 | * Create a new Java org.rocksdb.WriteBatch object | |
2548 | * | |
2549 | * @param env A pointer to the Java environment | |
2550 | * @param wb A pointer to rocksdb::WriteBatch object | |
2551 | * | |
2552 | * @return A reference to a Java org.rocksdb.WriteBatch object, or | |
2553 | * nullptr if an an exception occurs | |
2554 | */ | |
2555 | static jobject construct(JNIEnv* env, const WriteBatch* wb) { | |
2556 | jclass jclazz = getJClass(env); | |
2557 | if(jclazz == nullptr) { | |
2558 | // exception occurred accessing class | |
2559 | return nullptr; | |
2560 | } | |
2561 | ||
2562 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(J)V"); | |
2563 | if (mid == nullptr) { | |
2564 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
2565 | return nullptr; | |
2566 | } | |
2567 | ||
2568 | jobject jwb = env->NewObject(jclazz, mid, reinterpret_cast<jlong>(wb)); | |
2569 | if (env->ExceptionCheck()) { | |
2570 | return nullptr; | |
2571 | } | |
2572 | ||
2573 | return jwb; | |
2574 | } | |
2575 | }; | |
2576 | ||
2577 | // The portal class for org.rocksdb.WriteBatch.Handler | |
2578 | class WriteBatchHandlerJni : public RocksDBNativeClass< | |
2579 | const rocksdb::WriteBatchHandlerJniCallback*, | |
2580 | WriteBatchHandlerJni> { | |
2581 | public: | |
2582 | /** | |
2583 | * Get the Java Class org.rocksdb.WriteBatch.Handler | |
2584 | * | |
2585 | * @param env A pointer to the Java environment | |
2586 | * | |
2587 | * @return The Java Class or nullptr if one of the | |
2588 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2589 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2590 | */ | |
2591 | static jclass getJClass(JNIEnv* env) { | |
2592 | return RocksDBNativeClass::getJClass(env, | |
2593 | "org/rocksdb/WriteBatch$Handler"); | |
2594 | } | |
2595 | ||
2596 | /** | |
2597 | * Get the Java Method: WriteBatch.Handler#put | |
2598 | * | |
2599 | * @param env A pointer to the Java environment | |
2600 | * | |
2601 | * @return The Java Method ID or nullptr if the class or method id could not | |
2602 | * be retieved | |
2603 | */ | |
2604 | static jmethodID getPutCfMethodId(JNIEnv* env) { | |
2605 | jclass jclazz = getJClass(env); | |
2606 | if(jclazz == nullptr) { | |
2607 | // exception occurred accessing class | |
2608 | return nullptr; | |
2609 | } | |
2610 | ||
2611 | static jmethodID mid = env->GetMethodID(jclazz, "put", "(I[B[B)V"); | |
2612 | assert(mid != nullptr); | |
2613 | return mid; | |
2614 | } | |
2615 | ||
2616 | /** | |
2617 | * Get the Java Method: WriteBatch.Handler#put | |
2618 | * | |
2619 | * @param env A pointer to the Java environment | |
2620 | * | |
2621 | * @return The Java Method ID or nullptr if the class or method id could not | |
2622 | * be retieved | |
2623 | */ | |
2624 | static jmethodID getPutMethodId(JNIEnv* env) { | |
2625 | jclass jclazz = getJClass(env); | |
2626 | if(jclazz == nullptr) { | |
2627 | // exception occurred accessing class | |
2628 | return nullptr; | |
2629 | } | |
2630 | ||
2631 | static jmethodID mid = env->GetMethodID(jclazz, "put", "([B[B)V"); | |
2632 | assert(mid != nullptr); | |
2633 | return mid; | |
2634 | } | |
2635 | ||
2636 | /** | |
2637 | * Get the Java Method: WriteBatch.Handler#merge | |
2638 | * | |
2639 | * @param env A pointer to the Java environment | |
2640 | * | |
2641 | * @return The Java Method ID or nullptr if the class or method id could not | |
2642 | * be retieved | |
2643 | */ | |
2644 | static jmethodID getMergeCfMethodId(JNIEnv* env) { | |
2645 | jclass jclazz = getJClass(env); | |
2646 | if(jclazz == nullptr) { | |
2647 | // exception occurred accessing class | |
2648 | return nullptr; | |
2649 | } | |
2650 | ||
2651 | static jmethodID mid = env->GetMethodID(jclazz, "merge", "(I[B[B)V"); | |
2652 | assert(mid != nullptr); | |
2653 | return mid; | |
2654 | } | |
2655 | ||
2656 | /** | |
2657 | * Get the Java Method: WriteBatch.Handler#merge | |
7c673cae FG |
2658 | * |
2659 | * @param env A pointer to the Java environment | |
2660 | * | |
494da23a TL |
2661 | * @return The Java Method ID or nullptr if the class or method id could not |
2662 | * be retieved | |
7c673cae | 2663 | */ |
494da23a TL |
2664 | static jmethodID getMergeMethodId(JNIEnv* env) { |
2665 | jclass jclazz = getJClass(env); | |
2666 | if(jclazz == nullptr) { | |
2667 | // exception occurred accessing class | |
2668 | return nullptr; | |
2669 | } | |
2670 | ||
2671 | static jmethodID mid = env->GetMethodID(jclazz, "merge", "([B[B)V"); | |
2672 | assert(mid != nullptr); | |
2673 | return mid; | |
7c673cae | 2674 | } |
7c673cae | 2675 | |
7c673cae | 2676 | /** |
494da23a | 2677 | * Get the Java Method: WriteBatch.Handler#delete |
7c673cae FG |
2678 | * |
2679 | * @param env A pointer to the Java environment | |
2680 | * | |
494da23a TL |
2681 | * @return The Java Method ID or nullptr if the class or method id could not |
2682 | * be retieved | |
7c673cae | 2683 | */ |
494da23a TL |
2684 | static jmethodID getDeleteCfMethodId(JNIEnv* env) { |
2685 | jclass jclazz = getJClass(env); | |
2686 | if(jclazz == nullptr) { | |
2687 | // exception occurred accessing class | |
2688 | return nullptr; | |
2689 | } | |
2690 | ||
2691 | static jmethodID mid = env->GetMethodID(jclazz, "delete", "(I[B)V"); | |
2692 | assert(mid != nullptr); | |
2693 | return mid; | |
7c673cae FG |
2694 | } |
2695 | ||
2696 | /** | |
494da23a | 2697 | * Get the Java Method: WriteBatch.Handler#delete |
7c673cae FG |
2698 | * |
2699 | * @param env A pointer to the Java environment | |
2700 | * | |
11fdf7f2 TL |
2701 | * @return The Java Method ID or nullptr if the class or method id could not |
2702 | * be retieved | |
7c673cae | 2703 | */ |
494da23a | 2704 | static jmethodID getDeleteMethodId(JNIEnv* env) { |
7c673cae FG |
2705 | jclass jclazz = getJClass(env); |
2706 | if(jclazz == nullptr) { | |
2707 | // exception occurred accessing class | |
2708 | return nullptr; | |
2709 | } | |
2710 | ||
494da23a | 2711 | static jmethodID mid = env->GetMethodID(jclazz, "delete", "([B)V"); |
11fdf7f2 TL |
2712 | assert(mid != nullptr); |
2713 | return mid; | |
7c673cae | 2714 | } |
7c673cae | 2715 | |
7c673cae | 2716 | /** |
494da23a | 2717 | * Get the Java Method: WriteBatch.Handler#singleDelete |
7c673cae FG |
2718 | * |
2719 | * @param env A pointer to the Java environment | |
2720 | * | |
494da23a TL |
2721 | * @return The Java Method ID or nullptr if the class or method id could not |
2722 | * be retieved | |
7c673cae | 2723 | */ |
494da23a TL |
2724 | static jmethodID getSingleDeleteCfMethodId(JNIEnv* env) { |
2725 | jclass jclazz = getJClass(env); | |
2726 | if(jclazz == nullptr) { | |
2727 | // exception occurred accessing class | |
2728 | return nullptr; | |
2729 | } | |
2730 | ||
2731 | static jmethodID mid = env->GetMethodID(jclazz, "singleDelete", "(I[B)V"); | |
2732 | assert(mid != nullptr); | |
2733 | return mid; | |
7c673cae FG |
2734 | } |
2735 | ||
2736 | /** | |
494da23a | 2737 | * Get the Java Method: WriteBatch.Handler#singleDelete |
7c673cae FG |
2738 | * |
2739 | * @param env A pointer to the Java environment | |
2740 | * | |
494da23a TL |
2741 | * @return The Java Method ID or nullptr if the class or method id could not |
2742 | * be retieved | |
7c673cae | 2743 | */ |
494da23a TL |
2744 | static jmethodID getSingleDeleteMethodId(JNIEnv* env) { |
2745 | jclass jclazz = getJClass(env); | |
2746 | if(jclazz == nullptr) { | |
2747 | // exception occurred accessing class | |
2748 | return nullptr; | |
2749 | } | |
2750 | ||
2751 | static jmethodID mid = env->GetMethodID(jclazz, "singleDelete", "([B)V"); | |
2752 | assert(mid != nullptr); | |
2753 | return mid; | |
7c673cae | 2754 | } |
7c673cae | 2755 | |
7c673cae | 2756 | /** |
494da23a | 2757 | * Get the Java Method: WriteBatch.Handler#deleteRange |
7c673cae FG |
2758 | * |
2759 | * @param env A pointer to the Java environment | |
2760 | * | |
494da23a TL |
2761 | * @return The Java Method ID or nullptr if the class or method id could not |
2762 | * be retieved | |
7c673cae | 2763 | */ |
494da23a TL |
2764 | static jmethodID getDeleteRangeCfMethodId(JNIEnv* env) { |
2765 | jclass jclazz = getJClass(env); | |
2766 | if (jclazz == nullptr) { | |
2767 | // exception occurred accessing class | |
2768 | return nullptr; | |
2769 | } | |
2770 | ||
2771 | static jmethodID mid = env->GetMethodID(jclazz, "deleteRange", "(I[B[B)V"); | |
2772 | assert(mid != nullptr); | |
2773 | return mid; | |
7c673cae FG |
2774 | } |
2775 | ||
2776 | /** | |
494da23a | 2777 | * Get the Java Method: WriteBatch.Handler#deleteRange |
7c673cae FG |
2778 | * |
2779 | * @param env A pointer to the Java environment | |
2780 | * | |
494da23a TL |
2781 | * @return The Java Method ID or nullptr if the class or method id could not |
2782 | * be retieved | |
7c673cae | 2783 | */ |
494da23a TL |
2784 | static jmethodID getDeleteRangeMethodId(JNIEnv* env) { |
2785 | jclass jclazz = getJClass(env); | |
2786 | if (jclazz == nullptr) { | |
2787 | // exception occurred accessing class | |
2788 | return nullptr; | |
2789 | } | |
2790 | ||
2791 | static jmethodID mid = env->GetMethodID(jclazz, "deleteRange", "([B[B)V"); | |
2792 | assert(mid != nullptr); | |
2793 | return mid; | |
7c673cae FG |
2794 | } |
2795 | ||
2796 | /** | |
494da23a | 2797 | * Get the Java Method: WriteBatch.Handler#logData |
7c673cae FG |
2798 | * |
2799 | * @param env A pointer to the Java environment | |
2800 | * | |
494da23a TL |
2801 | * @return The Java Method ID or nullptr if the class or method id could not |
2802 | * be retieved | |
7c673cae | 2803 | */ |
494da23a TL |
2804 | static jmethodID getLogDataMethodId(JNIEnv* env) { |
2805 | jclass jclazz = getJClass(env); | |
2806 | if(jclazz == nullptr) { | |
2807 | // exception occurred accessing class | |
2808 | return nullptr; | |
2809 | } | |
2810 | ||
2811 | static jmethodID mid = env->GetMethodID(jclazz, "logData", "([B)V"); | |
2812 | assert(mid != nullptr); | |
2813 | return mid; | |
7c673cae FG |
2814 | } |
2815 | ||
2816 | /** | |
494da23a | 2817 | * Get the Java Method: WriteBatch.Handler#putBlobIndex |
7c673cae FG |
2818 | * |
2819 | * @param env A pointer to the Java environment | |
2820 | * | |
494da23a TL |
2821 | * @return The Java Method ID or nullptr if the class or method id could not |
2822 | * be retieved | |
7c673cae | 2823 | */ |
494da23a TL |
2824 | static jmethodID getPutBlobIndexCfMethodId(JNIEnv* env) { |
2825 | jclass jclazz = getJClass(env); | |
2826 | if(jclazz == nullptr) { | |
2827 | // exception occurred accessing class | |
2828 | return nullptr; | |
2829 | } | |
2830 | ||
2831 | static jmethodID mid = env->GetMethodID(jclazz, "putBlobIndex", "(I[B[B)V"); | |
2832 | assert(mid != nullptr); | |
2833 | return mid; | |
7c673cae FG |
2834 | } |
2835 | ||
2836 | /** | |
494da23a | 2837 | * Get the Java Method: WriteBatch.Handler#markBeginPrepare |
7c673cae FG |
2838 | * |
2839 | * @param env A pointer to the Java environment | |
2840 | * | |
494da23a TL |
2841 | * @return The Java Method ID or nullptr if the class or method id could not |
2842 | * be retieved | |
7c673cae | 2843 | */ |
494da23a TL |
2844 | static jmethodID getMarkBeginPrepareMethodId(JNIEnv* env) { |
2845 | jclass jclazz = getJClass(env); | |
2846 | if(jclazz == nullptr) { | |
2847 | // exception occurred accessing class | |
2848 | return nullptr; | |
2849 | } | |
2850 | ||
2851 | static jmethodID mid = env->GetMethodID(jclazz, "markBeginPrepare", "()V"); | |
2852 | assert(mid != nullptr); | |
2853 | return mid; | |
7c673cae FG |
2854 | } |
2855 | ||
2856 | /** | |
494da23a | 2857 | * Get the Java Method: WriteBatch.Handler#markEndPrepare |
7c673cae FG |
2858 | * |
2859 | * @param env A pointer to the Java environment | |
2860 | * | |
494da23a TL |
2861 | * @return The Java Method ID or nullptr if the class or method id could not |
2862 | * be retieved | |
2863 | */ | |
2864 | static jmethodID getMarkEndPrepareMethodId(JNIEnv* env) { | |
2865 | jclass jclazz = getJClass(env); | |
2866 | if(jclazz == nullptr) { | |
2867 | // exception occurred accessing class | |
2868 | return nullptr; | |
2869 | } | |
2870 | ||
2871 | static jmethodID mid = env->GetMethodID(jclazz, "markEndPrepare", "([B)V"); | |
2872 | assert(mid != nullptr); | |
2873 | return mid; | |
2874 | } | |
2875 | ||
2876 | /** | |
2877 | * Get the Java Method: WriteBatch.Handler#markNoop | |
2878 | * | |
2879 | * @param env A pointer to the Java environment | |
2880 | * | |
2881 | * @return The Java Method ID or nullptr if the class or method id could not | |
2882 | * be retieved | |
7c673cae | 2883 | */ |
494da23a TL |
2884 | static jmethodID getMarkNoopMethodId(JNIEnv* env) { |
2885 | jclass jclazz = getJClass(env); | |
2886 | if(jclazz == nullptr) { | |
2887 | // exception occurred accessing class | |
2888 | return nullptr; | |
2889 | } | |
2890 | ||
2891 | static jmethodID mid = env->GetMethodID(jclazz, "markNoop", "(Z)V"); | |
2892 | assert(mid != nullptr); | |
2893 | return mid; | |
7c673cae FG |
2894 | } |
2895 | ||
2896 | /** | |
494da23a | 2897 | * Get the Java Method: WriteBatch.Handler#markRollback |
7c673cae FG |
2898 | * |
2899 | * @param env A pointer to the Java environment | |
2900 | * | |
2901 | * @return The Java Method ID or nullptr if the class or method id could not | |
2902 | * be retieved | |
2903 | */ | |
494da23a | 2904 | static jmethodID getMarkRollbackMethodId(JNIEnv* env) { |
11fdf7f2 TL |
2905 | jclass jclazz = getJClass(env); |
2906 | if(jclazz == nullptr) { | |
7c673cae FG |
2907 | // exception occurred accessing class |
2908 | return nullptr; | |
2909 | } | |
11fdf7f2 | 2910 | |
494da23a | 2911 | static jmethodID mid = env->GetMethodID(jclazz, "markRollback", "([B)V"); |
7c673cae FG |
2912 | assert(mid != nullptr); |
2913 | return mid; | |
2914 | } | |
2915 | ||
2916 | /** | |
494da23a | 2917 | * Get the Java Method: WriteBatch.Handler#markCommit |
7c673cae FG |
2918 | * |
2919 | * @param env A pointer to the Java environment | |
2920 | * | |
2921 | * @return The Java Method ID or nullptr if the class or method id could not | |
2922 | * be retieved | |
2923 | */ | |
494da23a | 2924 | static jmethodID getMarkCommitMethodId(JNIEnv* env) { |
11fdf7f2 TL |
2925 | jclass jclazz = getJClass(env); |
2926 | if(jclazz == nullptr) { | |
7c673cae FG |
2927 | // exception occurred accessing class |
2928 | return nullptr; | |
2929 | } | |
2930 | ||
494da23a | 2931 | static jmethodID mid = env->GetMethodID(jclazz, "markCommit", "([B)V"); |
7c673cae FG |
2932 | assert(mid != nullptr); |
2933 | return mid; | |
2934 | } | |
7c673cae | 2935 | |
494da23a TL |
2936 | /** |
2937 | * Get the Java Method: WriteBatch.Handler#shouldContinue | |
2938 | * | |
2939 | * @param env A pointer to the Java environment | |
2940 | * | |
2941 | * @return The Java Method ID or nullptr if the class or method id could not | |
2942 | * be retieved | |
2943 | */ | |
2944 | static jmethodID getContinueMethodId(JNIEnv* env) { | |
11fdf7f2 TL |
2945 | jclass jclazz = getJClass(env); |
2946 | if(jclazz == nullptr) { | |
2947 | // exception occurred accessing class | |
2948 | return nullptr; | |
2949 | } | |
2950 | ||
494da23a | 2951 | static jmethodID mid = env->GetMethodID(jclazz, "shouldContinue", "()Z"); |
11fdf7f2 TL |
2952 | assert(mid != nullptr); |
2953 | return mid; | |
2954 | } | |
2955 | }; | |
2956 | ||
494da23a | 2957 | class WriteBatchSavePointJni : public JavaClass { |
11fdf7f2 | 2958 | public: |
7c673cae | 2959 | /** |
494da23a | 2960 | * Get the Java Class org.rocksdb.WriteBatch.SavePoint |
7c673cae FG |
2961 | * |
2962 | * @param env A pointer to the Java environment | |
2963 | * | |
2964 | * @return The Java Class or nullptr if one of the | |
2965 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
2966 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
2967 | */ | |
11fdf7f2 | 2968 | static jclass getJClass(JNIEnv* env) { |
494da23a | 2969 | return JavaClass::getJClass(env, "org/rocksdb/WriteBatch$SavePoint"); |
7c673cae FG |
2970 | } |
2971 | ||
2972 | /** | |
494da23a | 2973 | * Get the Java Method: HistogramData constructor |
7c673cae FG |
2974 | * |
2975 | * @param env A pointer to the Java environment | |
7c673cae | 2976 | * |
11fdf7f2 TL |
2977 | * @return The Java Method ID or nullptr if the class or method id could not |
2978 | * be retieved | |
7c673cae | 2979 | */ |
494da23a | 2980 | static jmethodID getConstructorMethodId(JNIEnv* env) { |
11fdf7f2 TL |
2981 | jclass jclazz = getJClass(env); |
2982 | if(jclazz == nullptr) { | |
7c673cae FG |
2983 | // exception occurred accessing class |
2984 | return nullptr; | |
2985 | } | |
2986 | ||
494da23a | 2987 | static jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JJJ)V"); |
11fdf7f2 TL |
2988 | assert(mid != nullptr); |
2989 | return mid; | |
7c673cae FG |
2990 | } |
2991 | ||
2992 | /** | |
494da23a | 2993 | * Create a new Java org.rocksdb.WriteBatch.SavePoint object |
7c673cae FG |
2994 | * |
2995 | * @param env A pointer to the Java environment | |
494da23a | 2996 | * @param savePoint A pointer to rocksdb::WriteBatch::SavePoint object |
7c673cae | 2997 | * |
494da23a TL |
2998 | * @return A reference to a Java org.rocksdb.WriteBatch.SavePoint object, or |
2999 | * nullptr if an an exception occurs | |
7c673cae | 3000 | */ |
494da23a | 3001 | static jobject construct(JNIEnv* env, const SavePoint &save_point) { |
11fdf7f2 TL |
3002 | jclass jclazz = getJClass(env); |
3003 | if(jclazz == nullptr) { | |
7c673cae FG |
3004 | // exception occurred accessing class |
3005 | return nullptr; | |
3006 | } | |
3007 | ||
494da23a TL |
3008 | jmethodID mid = getConstructorMethodId(env); |
3009 | if (mid == nullptr) { | |
3010 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
3011 | return nullptr; | |
3012 | } | |
3013 | ||
3014 | jobject jsave_point = env->NewObject(jclazz, mid, | |
3015 | static_cast<jlong>(save_point.size), | |
3016 | static_cast<jlong>(save_point.count), | |
3017 | static_cast<jlong>(save_point.content_flags)); | |
3018 | if (env->ExceptionCheck()) { | |
3019 | return nullptr; | |
3020 | } | |
3021 | ||
3022 | return jsave_point; | |
7c673cae | 3023 | } |
494da23a | 3024 | }; |
7c673cae | 3025 | |
494da23a TL |
3026 | // The portal class for org.rocksdb.WriteBatchWithIndex |
3027 | class WriteBatchWithIndexJni : public RocksDBNativeClass< | |
3028 | rocksdb::WriteBatchWithIndex*, WriteBatchWithIndexJni> { | |
3029 | public: | |
7c673cae | 3030 | /** |
494da23a | 3031 | * Get the Java Class org.rocksdb.WriteBatchWithIndex |
7c673cae FG |
3032 | * |
3033 | * @param env A pointer to the Java environment | |
3034 | * | |
494da23a TL |
3035 | * @return The Java Class or nullptr if one of the |
3036 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3037 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 3038 | */ |
494da23a TL |
3039 | static jclass getJClass(JNIEnv* env) { |
3040 | return RocksDBNativeClass::getJClass(env, | |
3041 | "org/rocksdb/WriteBatchWithIndex"); | |
3042 | } | |
3043 | }; | |
11fdf7f2 | 3044 | |
494da23a TL |
3045 | // The portal class for org.rocksdb.HistogramData |
3046 | class HistogramDataJni : public JavaClass { | |
3047 | public: | |
3048 | /** | |
3049 | * Get the Java Class org.rocksdb.HistogramData | |
3050 | * | |
3051 | * @param env A pointer to the Java environment | |
3052 | * | |
3053 | * @return The Java Class or nullptr if one of the | |
3054 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3055 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3056 | */ | |
3057 | static jclass getJClass(JNIEnv* env) { | |
3058 | return JavaClass::getJClass(env, "org/rocksdb/HistogramData"); | |
7c673cae FG |
3059 | } |
3060 | ||
3061 | /** | |
494da23a | 3062 | * Get the Java Method: HistogramData constructor |
7c673cae FG |
3063 | * |
3064 | * @param env A pointer to the Java environment | |
3065 | * | |
3066 | * @return The Java Method ID or nullptr if the class or method id could not | |
3067 | * be retieved | |
3068 | */ | |
494da23a | 3069 | static jmethodID getConstructorMethodId(JNIEnv* env) { |
7c673cae FG |
3070 | jclass jclazz = getJClass(env); |
3071 | if(jclazz == nullptr) { | |
3072 | // exception occurred accessing class | |
3073 | return nullptr; | |
3074 | } | |
3075 | ||
494da23a | 3076 | static jmethodID mid = env->GetMethodID(jclazz, "<init>", "(DDDDDDJJD)V"); |
7c673cae FG |
3077 | assert(mid != nullptr); |
3078 | return mid; | |
3079 | } | |
11fdf7f2 | 3080 | }; |
7c673cae | 3081 | |
494da23a TL |
3082 | // The portal class for org.rocksdb.BackupableDBOptions |
3083 | class BackupableDBOptionsJni : public RocksDBNativeClass< | |
3084 | rocksdb::BackupableDBOptions*, BackupableDBOptionsJni> { | |
11fdf7f2 | 3085 | public: |
7c673cae | 3086 | /** |
494da23a | 3087 | * Get the Java Class org.rocksdb.BackupableDBOptions |
7c673cae FG |
3088 | * |
3089 | * @param env A pointer to the Java environment | |
7c673cae | 3090 | * |
11fdf7f2 TL |
3091 | * @return The Java Class or nullptr if one of the |
3092 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3093 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 3094 | */ |
11fdf7f2 | 3095 | static jclass getJClass(JNIEnv* env) { |
494da23a TL |
3096 | return RocksDBNativeClass::getJClass(env, |
3097 | "org/rocksdb/BackupableDBOptions"); | |
7c673cae FG |
3098 | } |
3099 | }; | |
3100 | ||
494da23a TL |
3101 | // The portal class for org.rocksdb.BackupEngine |
3102 | class BackupEngineJni : public RocksDBNativeClass< | |
3103 | rocksdb::BackupEngine*, BackupEngineJni> { | |
7c673cae FG |
3104 | public: |
3105 | /** | |
494da23a | 3106 | * Get the Java Class org.rocksdb.BackupableEngine |
7c673cae FG |
3107 | * |
3108 | * @param env A pointer to the Java environment | |
3109 | * | |
3110 | * @return The Java Class or nullptr if one of the | |
3111 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3112 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3113 | */ | |
3114 | static jclass getJClass(JNIEnv* env) { | |
494da23a | 3115 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/BackupEngine"); |
7c673cae | 3116 | } |
494da23a | 3117 | }; |
7c673cae | 3118 | |
494da23a TL |
3119 | // The portal class for org.rocksdb.RocksIterator |
3120 | class IteratorJni : public RocksDBNativeClass< | |
3121 | rocksdb::Iterator*, IteratorJni> { | |
3122 | public: | |
7c673cae | 3123 | /** |
494da23a | 3124 | * Get the Java Class org.rocksdb.RocksIterator |
7c673cae FG |
3125 | * |
3126 | * @param env A pointer to the Java environment | |
7c673cae | 3127 | * |
494da23a TL |
3128 | * @return The Java Class or nullptr if one of the |
3129 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3130 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 3131 | */ |
494da23a TL |
3132 | static jclass getJClass(JNIEnv* env) { |
3133 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/RocksIterator"); | |
7c673cae FG |
3134 | } |
3135 | }; | |
3136 | ||
494da23a TL |
3137 | // The portal class for org.rocksdb.Filter |
3138 | class FilterJni : public RocksDBNativeClass< | |
3139 | std::shared_ptr<rocksdb::FilterPolicy>*, FilterJni> { | |
7c673cae FG |
3140 | public: |
3141 | /** | |
494da23a | 3142 | * Get the Java Class org.rocksdb.Filter |
7c673cae FG |
3143 | * |
3144 | * @param env A pointer to the Java environment | |
7c673cae | 3145 | * |
11fdf7f2 TL |
3146 | * @return The Java Class or nullptr if one of the |
3147 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3148 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 3149 | */ |
11fdf7f2 | 3150 | static jclass getJClass(JNIEnv* env) { |
494da23a | 3151 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/Filter"); |
11fdf7f2 | 3152 | } |
494da23a | 3153 | }; |
11fdf7f2 | 3154 | |
494da23a TL |
3155 | // The portal class for org.rocksdb.ColumnFamilyHandle |
3156 | class ColumnFamilyHandleJni : public RocksDBNativeClass< | |
3157 | rocksdb::ColumnFamilyHandle*, ColumnFamilyHandleJni> { | |
3158 | public: | |
11fdf7f2 | 3159 | /** |
494da23a | 3160 | * Get the Java Class org.rocksdb.ColumnFamilyHandle |
11fdf7f2 TL |
3161 | * |
3162 | * @param env A pointer to the Java environment | |
3163 | * | |
494da23a TL |
3164 | * @return The Java Class or nullptr if one of the |
3165 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3166 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
11fdf7f2 | 3167 | */ |
494da23a TL |
3168 | static jclass getJClass(JNIEnv* env) { |
3169 | return RocksDBNativeClass::getJClass(env, | |
3170 | "org/rocksdb/ColumnFamilyHandle"); | |
3171 | } | |
3172 | }; | |
7c673cae | 3173 | |
494da23a TL |
3174 | // The portal class for org.rocksdb.FlushOptions |
3175 | class FlushOptionsJni : public RocksDBNativeClass< | |
3176 | rocksdb::FlushOptions*, FlushOptionsJni> { | |
3177 | public: | |
3178 | /** | |
3179 | * Get the Java Class org.rocksdb.FlushOptions | |
3180 | * | |
3181 | * @param env A pointer to the Java environment | |
3182 | * | |
3183 | * @return The Java Class or nullptr if one of the | |
3184 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3185 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3186 | */ | |
3187 | static jclass getJClass(JNIEnv* env) { | |
3188 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/FlushOptions"); | |
11fdf7f2 TL |
3189 | } |
3190 | }; | |
3191 | ||
494da23a TL |
3192 | // The portal class for org.rocksdb.ComparatorOptions |
3193 | class ComparatorOptionsJni : public RocksDBNativeClass< | |
3194 | rocksdb::ComparatorJniCallbackOptions*, ComparatorOptionsJni> { | |
11fdf7f2 TL |
3195 | public: |
3196 | /** | |
494da23a | 3197 | * Get the Java Class org.rocksdb.ComparatorOptions |
11fdf7f2 TL |
3198 | * |
3199 | * @param env A pointer to the Java environment | |
3200 | * | |
3201 | * @return The Java Class or nullptr if one of the | |
3202 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3203 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3204 | */ | |
494da23a TL |
3205 | static jclass getJClass(JNIEnv* env) { |
3206 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/ComparatorOptions"); | |
11fdf7f2 | 3207 | } |
494da23a | 3208 | }; |
11fdf7f2 | 3209 | |
494da23a TL |
3210 | // The portal class for org.rocksdb.AbstractCompactionFilterFactory |
3211 | class AbstractCompactionFilterFactoryJni : public RocksDBNativeClass< | |
3212 | const rocksdb::CompactionFilterFactoryJniCallback*, | |
3213 | AbstractCompactionFilterFactoryJni> { | |
3214 | public: | |
11fdf7f2 | 3215 | /** |
494da23a | 3216 | * Get the Java Class org.rocksdb.AbstractCompactionFilterFactory |
11fdf7f2 TL |
3217 | * |
3218 | * @param env A pointer to the Java environment | |
3219 | * | |
3220 | * @return The Java Class or nullptr if one of the | |
3221 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3222 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3223 | */ | |
494da23a TL |
3224 | static jclass getJClass(JNIEnv* env) { |
3225 | return RocksDBNativeClass::getJClass(env, | |
3226 | "org/rocksdb/AbstractCompactionFilterFactory"); | |
11fdf7f2 TL |
3227 | } |
3228 | ||
3229 | /** | |
494da23a | 3230 | * Get the Java Method: AbstractCompactionFilterFactory#name |
11fdf7f2 TL |
3231 | * |
3232 | * @param env A pointer to the Java environment | |
3233 | * | |
494da23a TL |
3234 | * @return The Java Method ID or nullptr if the class or method id could not |
3235 | * be retieved | |
11fdf7f2 | 3236 | */ |
494da23a TL |
3237 | static jmethodID getNameMethodId(JNIEnv* env) { |
3238 | jclass jclazz = getJClass(env); | |
3239 | if(jclazz == nullptr) { | |
3240 | // exception occurred accessing class | |
3241 | return nullptr; | |
3242 | } | |
3243 | ||
3244 | static jmethodID mid = env->GetMethodID( | |
3245 | jclazz, "name", "()Ljava/lang/String;"); | |
3246 | assert(mid != nullptr); | |
3247 | return mid; | |
11fdf7f2 TL |
3248 | } |
3249 | ||
3250 | /** | |
494da23a | 3251 | * Get the Java Method: AbstractCompactionFilterFactory#createCompactionFilter |
11fdf7f2 TL |
3252 | * |
3253 | * @param env A pointer to the Java environment | |
3254 | * | |
3255 | * @return The Java Method ID or nullptr if the class or method id could not | |
3256 | * be retieved | |
3257 | */ | |
494da23a TL |
3258 | static jmethodID getCreateCompactionFilterMethodId(JNIEnv* env) { |
3259 | jclass jclazz = getJClass(env); | |
3260 | if(jclazz == nullptr) { | |
11fdf7f2 | 3261 | // exception occurred accessing class |
7c673cae FG |
3262 | return nullptr; |
3263 | } | |
3264 | ||
494da23a TL |
3265 | static jmethodID mid = env->GetMethodID(jclazz, |
3266 | "createCompactionFilter", | |
3267 | "(ZZ)J"); | |
3268 | assert(mid != nullptr); | |
3269 | return mid; | |
3270 | } | |
3271 | }; | |
3272 | ||
3273 | // The portal class for org.rocksdb.AbstractTransactionNotifier | |
3274 | class AbstractTransactionNotifierJni : public RocksDBNativeClass< | |
3275 | const rocksdb::TransactionNotifierJniCallback*, | |
3276 | AbstractTransactionNotifierJni> { | |
3277 | public: | |
3278 | static jclass getJClass(JNIEnv* env) { | |
3279 | return RocksDBNativeClass::getJClass(env, | |
3280 | "org/rocksdb/AbstractTransactionNotifier"); | |
3281 | } | |
3282 | ||
3283 | // Get the java method `snapshotCreated` | |
3284 | // of org.rocksdb.AbstractTransactionNotifier. | |
3285 | static jmethodID getSnapshotCreatedMethodId(JNIEnv* env) { | |
3286 | jclass jclazz = getJClass(env); | |
3287 | if(jclazz == nullptr) { | |
3288 | // exception occurred accessing class | |
3289 | return nullptr; | |
3290 | } | |
3291 | ||
3292 | static jmethodID mid = env->GetMethodID(jclazz, "snapshotCreated", "(J)V"); | |
11fdf7f2 TL |
3293 | assert(mid != nullptr); |
3294 | return mid; | |
3295 | } | |
494da23a | 3296 | }; |
7c673cae | 3297 | |
494da23a TL |
3298 | // The portal class for org.rocksdb.AbstractComparator |
3299 | class AbstractComparatorJni : public RocksDBNativeClass< | |
3300 | const rocksdb::BaseComparatorJniCallback*, | |
3301 | AbstractComparatorJni> { | |
3302 | public: | |
11fdf7f2 | 3303 | /** |
494da23a TL |
3304 | * Get the Java Class org.rocksdb.AbstractComparator |
3305 | * | |
3306 | * @param env A pointer to the Java environment | |
3307 | * | |
3308 | * @return The Java Class or nullptr if one of the | |
3309 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3310 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3311 | */ | |
3312 | static jclass getJClass(JNIEnv* env) { | |
3313 | return RocksDBNativeClass::getJClass(env, | |
3314 | "org/rocksdb/AbstractComparator"); | |
3315 | } | |
3316 | ||
3317 | /** | |
3318 | * Get the Java Method: Comparator#name | |
11fdf7f2 TL |
3319 | * |
3320 | * @param env A pointer to the Java environment | |
3321 | * | |
3322 | * @return The Java Method ID or nullptr if the class or method id could not | |
3323 | * be retieved | |
3324 | */ | |
494da23a TL |
3325 | static jmethodID getNameMethodId(JNIEnv* env) { |
3326 | jclass jclazz = getJClass(env); | |
3327 | if(jclazz == nullptr) { | |
11fdf7f2 TL |
3328 | // exception occurred accessing class |
3329 | return nullptr; | |
3330 | } | |
7c673cae | 3331 | |
494da23a TL |
3332 | static jmethodID mid = |
3333 | env->GetMethodID(jclazz, "name", "()Ljava/lang/String;"); | |
11fdf7f2 TL |
3334 | assert(mid != nullptr); |
3335 | return mid; | |
3336 | } | |
3337 | ||
3338 | /** | |
494da23a | 3339 | * Get the Java Method: Comparator#compare |
11fdf7f2 TL |
3340 | * |
3341 | * @param env A pointer to the Java environment | |
3342 | * | |
3343 | * @return The Java Method ID or nullptr if the class or method id could not | |
3344 | * be retieved | |
3345 | */ | |
494da23a TL |
3346 | static jmethodID getCompareMethodId(JNIEnv* env) { |
3347 | jclass jclazz = getJClass(env); | |
3348 | if(jclazz == nullptr) { | |
11fdf7f2 TL |
3349 | // exception occurred accessing class |
3350 | return nullptr; | |
7c673cae FG |
3351 | } |
3352 | ||
11fdf7f2 | 3353 | static jmethodID mid = |
494da23a TL |
3354 | env->GetMethodID(jclazz, "compare", |
3355 | "(Lorg/rocksdb/AbstractSlice;Lorg/rocksdb/AbstractSlice;)I"); | |
11fdf7f2 TL |
3356 | assert(mid != nullptr); |
3357 | return mid; | |
3358 | } | |
3359 | ||
3360 | /** | |
494da23a | 3361 | * Get the Java Method: Comparator#findShortestSeparator |
11fdf7f2 TL |
3362 | * |
3363 | * @param env A pointer to the Java environment | |
3364 | * | |
3365 | * @return The Java Method ID or nullptr if the class or method id could not | |
3366 | * be retieved | |
3367 | */ | |
494da23a TL |
3368 | static jmethodID getFindShortestSeparatorMethodId(JNIEnv* env) { |
3369 | jclass jclazz = getJClass(env); | |
3370 | if(jclazz == nullptr) { | |
11fdf7f2 TL |
3371 | // exception occurred accessing class |
3372 | return nullptr; | |
3373 | } | |
494da23a | 3374 | |
11fdf7f2 | 3375 | static jmethodID mid = |
494da23a TL |
3376 | env->GetMethodID(jclazz, "findShortestSeparator", |
3377 | "(Ljava/lang/String;Lorg/rocksdb/AbstractSlice;)Ljava/lang/String;"); | |
11fdf7f2 TL |
3378 | assert(mid != nullptr); |
3379 | return mid; | |
3380 | } | |
3381 | ||
3382 | /** | |
494da23a | 3383 | * Get the Java Method: Comparator#findShortSuccessor |
11fdf7f2 TL |
3384 | * |
3385 | * @param env A pointer to the Java environment | |
3386 | * | |
3387 | * @return The Java Method ID or nullptr if the class or method id could not | |
3388 | * be retieved | |
3389 | */ | |
494da23a TL |
3390 | static jmethodID getFindShortSuccessorMethodId(JNIEnv* env) { |
3391 | jclass jclazz = getJClass(env); | |
3392 | if(jclazz == nullptr) { | |
11fdf7f2 TL |
3393 | // exception occurred accessing class |
3394 | return nullptr; | |
3395 | } | |
3396 | ||
3397 | static jmethodID mid = | |
494da23a TL |
3398 | env->GetMethodID(jclazz, "findShortSuccessor", |
3399 | "(Ljava/lang/String;)Ljava/lang/String;"); | |
11fdf7f2 TL |
3400 | assert(mid != nullptr); |
3401 | return mid; | |
7c673cae FG |
3402 | } |
3403 | }; | |
3404 | ||
494da23a TL |
3405 | // The portal class for org.rocksdb.AbstractSlice |
3406 | class AbstractSliceJni : public NativeRocksMutableObject< | |
3407 | const rocksdb::Slice*, AbstractSliceJni> { | |
7c673cae FG |
3408 | public: |
3409 | /** | |
494da23a | 3410 | * Get the Java Class org.rocksdb.AbstractSlice |
7c673cae FG |
3411 | * |
3412 | * @param env A pointer to the Java environment | |
3413 | * | |
3414 | * @return The Java Class or nullptr if one of the | |
3415 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3416 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3417 | */ | |
3418 | static jclass getJClass(JNIEnv* env) { | |
494da23a | 3419 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/AbstractSlice"); |
7c673cae | 3420 | } |
494da23a | 3421 | }; |
7c673cae | 3422 | |
494da23a TL |
3423 | // The portal class for org.rocksdb.Slice |
3424 | class SliceJni : public NativeRocksMutableObject< | |
3425 | const rocksdb::Slice*, AbstractSliceJni> { | |
3426 | public: | |
7c673cae | 3427 | /** |
494da23a | 3428 | * Get the Java Class org.rocksdb.Slice |
7c673cae FG |
3429 | * |
3430 | * @param env A pointer to the Java environment | |
3431 | * | |
11fdf7f2 TL |
3432 | * @return The Java Class or nullptr if one of the |
3433 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3434 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3435 | */ | |
494da23a TL |
3436 | static jclass getJClass(JNIEnv* env) { |
3437 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/Slice"); | |
11fdf7f2 TL |
3438 | } |
3439 | ||
3440 | /** | |
494da23a | 3441 | * Constructs a Slice object |
11fdf7f2 TL |
3442 | * |
3443 | * @param env A pointer to the Java environment | |
11fdf7f2 | 3444 | * |
494da23a TL |
3445 | * @return A reference to a Java Slice object, or a nullptr if an |
3446 | * exception occurs | |
11fdf7f2 | 3447 | */ |
494da23a TL |
3448 | static jobject construct0(JNIEnv* env) { |
3449 | jclass jclazz = getJClass(env); | |
3450 | if(jclazz == nullptr) { | |
11fdf7f2 TL |
3451 | // exception occurred accessing class |
3452 | return nullptr; | |
3453 | } | |
3454 | ||
494da23a TL |
3455 | static jmethodID mid = env->GetMethodID(jclazz, "<init>", "()V"); |
3456 | if(mid == nullptr) { | |
3457 | // exception occurred accessing method | |
3458 | return nullptr; | |
3459 | } | |
11fdf7f2 | 3460 | |
494da23a TL |
3461 | jobject jslice = env->NewObject(jclazz, mid); |
3462 | if(env->ExceptionCheck()) { | |
7c673cae FG |
3463 | return nullptr; |
3464 | } | |
3465 | ||
494da23a | 3466 | return jslice; |
7c673cae | 3467 | } |
11fdf7f2 | 3468 | }; |
7c673cae | 3469 | |
494da23a TL |
3470 | // The portal class for org.rocksdb.DirectSlice |
3471 | class DirectSliceJni : public NativeRocksMutableObject< | |
3472 | const rocksdb::Slice*, AbstractSliceJni> { | |
3473 | public: | |
7c673cae | 3474 | /** |
494da23a | 3475 | * Get the Java Class org.rocksdb.DirectSlice |
7c673cae | 3476 | * |
11fdf7f2 | 3477 | * @param env A pointer to the Java environment |
7c673cae | 3478 | * |
11fdf7f2 TL |
3479 | * @return The Java Class or nullptr if one of the |
3480 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3481 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
7c673cae | 3482 | */ |
11fdf7f2 | 3483 | static jclass getJClass(JNIEnv* env) { |
494da23a | 3484 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/DirectSlice"); |
11fdf7f2 TL |
3485 | } |
3486 | ||
3487 | /** | |
494da23a | 3488 | * Constructs a DirectSlice object |
11fdf7f2 TL |
3489 | * |
3490 | * @param env A pointer to the Java environment | |
494da23a TL |
3491 | * |
3492 | * @return A reference to a Java DirectSlice object, or a nullptr if an | |
3493 | * exception occurs | |
3494 | */ | |
3495 | static jobject construct0(JNIEnv* env) { | |
3496 | jclass jclazz = getJClass(env); | |
3497 | if(jclazz == nullptr) { | |
3498 | // exception occurred accessing class | |
11fdf7f2 TL |
3499 | return nullptr; |
3500 | } | |
3501 | ||
494da23a TL |
3502 | static jmethodID mid = env->GetMethodID(jclazz, "<init>", "()V"); |
3503 | if(mid == nullptr) { | |
3504 | // exception occurred accessing method | |
11fdf7f2 TL |
3505 | return nullptr; |
3506 | } | |
3507 | ||
494da23a | 3508 | jobject jdirect_slice = env->NewObject(jclazz, mid); |
11fdf7f2 | 3509 | if(env->ExceptionCheck()) { |
11fdf7f2 TL |
3510 | return nullptr; |
3511 | } | |
3512 | ||
494da23a | 3513 | return jdirect_slice; |
11fdf7f2 TL |
3514 | } |
3515 | }; | |
3516 | ||
3517 | // The portal class for org.rocksdb.BackupInfo | |
3518 | class BackupInfoJni : public JavaClass { | |
3519 | public: | |
3520 | /** | |
3521 | * Get the Java Class org.rocksdb.BackupInfo | |
3522 | * | |
3523 | * @param env A pointer to the Java environment | |
3524 | * | |
3525 | * @return The Java Class or nullptr if one of the | |
3526 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3527 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3528 | */ | |
3529 | static jclass getJClass(JNIEnv* env) { | |
3530 | return JavaClass::getJClass(env, "org/rocksdb/BackupInfo"); | |
3531 | } | |
3532 | ||
3533 | /** | |
3534 | * Constructs a BackupInfo object | |
3535 | * | |
3536 | * @param env A pointer to the Java environment | |
3537 | * @param backup_id id of the backup | |
3538 | * @param timestamp timestamp of the backup | |
3539 | * @param size size of the backup | |
3540 | * @param number_files number of files related to the backup | |
3541 | * @param app_metadata application specific metadata | |
3542 | * | |
3543 | * @return A reference to a Java BackupInfo object, or a nullptr if an | |
3544 | * exception occurs | |
3545 | */ | |
3546 | static jobject construct0(JNIEnv* env, uint32_t backup_id, int64_t timestamp, | |
3547 | uint64_t size, uint32_t number_files, | |
3548 | const std::string& app_metadata) { | |
3549 | jclass jclazz = getJClass(env); | |
3550 | if(jclazz == nullptr) { | |
3551 | // exception occurred accessing class | |
3552 | return nullptr; | |
3553 | } | |
3554 | ||
3555 | static jmethodID mid = | |
3556 | env->GetMethodID(jclazz, "<init>", "(IJJILjava/lang/String;)V"); | |
3557 | if(mid == nullptr) { | |
3558 | // exception occurred accessing method | |
3559 | return nullptr; | |
3560 | } | |
3561 | ||
3562 | jstring japp_metadata = nullptr; | |
3563 | if (app_metadata != nullptr) { | |
3564 | japp_metadata = env->NewStringUTF(app_metadata.c_str()); | |
3565 | if (japp_metadata == nullptr) { | |
3566 | // exception occurred creating java string | |
3567 | return nullptr; | |
3568 | } | |
3569 | } | |
3570 | ||
3571 | jobject jbackup_info = env->NewObject(jclazz, mid, backup_id, timestamp, | |
3572 | size, number_files, japp_metadata); | |
3573 | if(env->ExceptionCheck()) { | |
3574 | env->DeleteLocalRef(japp_metadata); | |
3575 | return nullptr; | |
3576 | } | |
3577 | ||
3578 | return jbackup_info; | |
3579 | } | |
3580 | }; | |
3581 | ||
3582 | class BackupInfoListJni { | |
3583 | public: | |
3584 | /** | |
3585 | * Converts a C++ std::vector<BackupInfo> object to | |
3586 | * a Java ArrayList<org.rocksdb.BackupInfo> object | |
3587 | * | |
3588 | * @param env A pointer to the Java environment | |
3589 | * @param backup_infos A vector of BackupInfo | |
3590 | * | |
3591 | * @return Either a reference to a Java ArrayList object, or a nullptr | |
3592 | * if an exception occurs | |
3593 | */ | |
3594 | static jobject getBackupInfo(JNIEnv* env, | |
3595 | std::vector<BackupInfo> backup_infos) { | |
3596 | jclass jarray_list_clazz = rocksdb::ListJni::getArrayListClass(env); | |
3597 | if(jarray_list_clazz == nullptr) { | |
3598 | // exception occurred accessing class | |
3599 | return nullptr; | |
3600 | } | |
3601 | ||
3602 | jmethodID cstr_mid = rocksdb::ListJni::getArrayListConstructorMethodId(env); | |
3603 | if(cstr_mid == nullptr) { | |
3604 | // exception occurred accessing method | |
3605 | return nullptr; | |
3606 | } | |
3607 | ||
3608 | jmethodID add_mid = rocksdb::ListJni::getListAddMethodId(env); | |
3609 | if(add_mid == nullptr) { | |
3610 | // exception occurred accessing method | |
3611 | return nullptr; | |
3612 | } | |
3613 | ||
3614 | // create java list | |
3615 | jobject jbackup_info_handle_list = | |
3616 | env->NewObject(jarray_list_clazz, cstr_mid, backup_infos.size()); | |
3617 | if(env->ExceptionCheck()) { | |
3618 | // exception occurred constructing object | |
3619 | return nullptr; | |
3620 | } | |
3621 | ||
3622 | // insert in java list | |
3623 | auto end = backup_infos.end(); | |
3624 | for (auto it = backup_infos.begin(); it != end; ++it) { | |
3625 | auto backup_info = *it; | |
3626 | ||
3627 | jobject obj = rocksdb::BackupInfoJni::construct0( | |
3628 | env, backup_info.backup_id, backup_info.timestamp, backup_info.size, | |
3629 | backup_info.number_files, backup_info.app_metadata); | |
3630 | if(env->ExceptionCheck()) { | |
3631 | // exception occurred constructing object | |
3632 | if(obj != nullptr) { | |
3633 | env->DeleteLocalRef(obj); | |
3634 | } | |
3635 | if(jbackup_info_handle_list != nullptr) { | |
3636 | env->DeleteLocalRef(jbackup_info_handle_list); | |
3637 | } | |
3638 | return nullptr; | |
3639 | } | |
3640 | ||
3641 | jboolean rs = | |
3642 | env->CallBooleanMethod(jbackup_info_handle_list, add_mid, obj); | |
3643 | if(env->ExceptionCheck() || rs == JNI_FALSE) { | |
3644 | // exception occurred calling method, or could not add | |
3645 | if(obj != nullptr) { | |
3646 | env->DeleteLocalRef(obj); | |
3647 | } | |
3648 | if(jbackup_info_handle_list != nullptr) { | |
3649 | env->DeleteLocalRef(jbackup_info_handle_list); | |
3650 | } | |
3651 | return nullptr; | |
3652 | } | |
3653 | } | |
3654 | ||
3655 | return jbackup_info_handle_list; | |
3656 | } | |
3657 | }; | |
3658 | ||
3659 | // The portal class for org.rocksdb.WBWIRocksIterator | |
3660 | class WBWIRocksIteratorJni : public JavaClass { | |
3661 | public: | |
3662 | /** | |
3663 | * Get the Java Class org.rocksdb.WBWIRocksIterator | |
3664 | * | |
3665 | * @param env A pointer to the Java environment | |
3666 | * | |
3667 | * @return The Java Class or nullptr if one of the | |
3668 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3669 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3670 | */ | |
3671 | static jclass getJClass(JNIEnv* env) { | |
3672 | return JavaClass::getJClass(env, "org/rocksdb/WBWIRocksIterator"); | |
3673 | } | |
3674 | ||
3675 | /** | |
3676 | * Get the Java Field: WBWIRocksIterator#entry | |
3677 | * | |
3678 | * @param env A pointer to the Java environment | |
3679 | * | |
3680 | * @return The Java Field ID or nullptr if the class or field id could not | |
3681 | * be retieved | |
3682 | */ | |
3683 | static jfieldID getWriteEntryField(JNIEnv* env) { | |
3684 | jclass jclazz = getJClass(env); | |
3685 | if(jclazz == nullptr) { | |
3686 | // exception occurred accessing class | |
3687 | return nullptr; | |
3688 | } | |
3689 | ||
3690 | static jfieldID fid = | |
3691 | env->GetFieldID(jclazz, "entry", | |
3692 | "Lorg/rocksdb/WBWIRocksIterator$WriteEntry;"); | |
3693 | assert(fid != nullptr); | |
3694 | return fid; | |
3695 | } | |
3696 | ||
3697 | /** | |
3698 | * Gets the value of the WBWIRocksIterator#entry | |
3699 | * | |
3700 | * @param env A pointer to the Java environment | |
3701 | * @param jwbwi_rocks_iterator A reference to a WBWIIterator | |
3702 | * | |
3703 | * @return A reference to a Java WBWIRocksIterator.WriteEntry object, or | |
3704 | * a nullptr if an exception occurs | |
3705 | */ | |
3706 | static jobject getWriteEntry(JNIEnv* env, jobject jwbwi_rocks_iterator) { | |
3707 | assert(jwbwi_rocks_iterator != nullptr); | |
3708 | ||
3709 | jfieldID jwrite_entry_field = getWriteEntryField(env); | |
3710 | if(jwrite_entry_field == nullptr) { | |
3711 | // exception occurred accessing the field | |
3712 | return nullptr; | |
3713 | } | |
3714 | ||
3715 | jobject jwe = env->GetObjectField(jwbwi_rocks_iterator, jwrite_entry_field); | |
3716 | assert(jwe != nullptr); | |
3717 | return jwe; | |
3718 | } | |
3719 | }; | |
3720 | ||
3721 | // The portal class for org.rocksdb.WBWIRocksIterator.WriteType | |
3722 | class WriteTypeJni : public JavaClass { | |
3723 | public: | |
3724 | /** | |
3725 | * Get the PUT enum field value of WBWIRocksIterator.WriteType | |
3726 | * | |
3727 | * @param env A pointer to the Java environment | |
3728 | * | |
3729 | * @return A reference to the enum field value or a nullptr if | |
3730 | * the enum field value could not be retrieved | |
3731 | */ | |
3732 | static jobject PUT(JNIEnv* env) { | |
3733 | return getEnum(env, "PUT"); | |
3734 | } | |
3735 | ||
3736 | /** | |
3737 | * Get the MERGE enum field value of WBWIRocksIterator.WriteType | |
3738 | * | |
3739 | * @param env A pointer to the Java environment | |
3740 | * | |
3741 | * @return A reference to the enum field value or a nullptr if | |
3742 | * the enum field value could not be retrieved | |
3743 | */ | |
3744 | static jobject MERGE(JNIEnv* env) { | |
3745 | return getEnum(env, "MERGE"); | |
3746 | } | |
3747 | ||
3748 | /** | |
3749 | * Get the DELETE enum field value of WBWIRocksIterator.WriteType | |
3750 | * | |
3751 | * @param env A pointer to the Java environment | |
3752 | * | |
3753 | * @return A reference to the enum field value or a nullptr if | |
3754 | * the enum field value could not be retrieved | |
3755 | */ | |
3756 | static jobject DELETE(JNIEnv* env) { | |
3757 | return getEnum(env, "DELETE"); | |
3758 | } | |
3759 | ||
3760 | /** | |
3761 | * Get the LOG enum field value of WBWIRocksIterator.WriteType | |
3762 | * | |
3763 | * @param env A pointer to the Java environment | |
3764 | * | |
3765 | * @return A reference to the enum field value or a nullptr if | |
3766 | * the enum field value could not be retrieved | |
3767 | */ | |
3768 | static jobject LOG(JNIEnv* env) { | |
3769 | return getEnum(env, "LOG"); | |
3770 | } | |
3771 | ||
3772 | // Returns the equivalent org.rocksdb.WBWIRocksIterator.WriteType for the | |
3773 | // provided C++ rocksdb::WriteType enum | |
3774 | static jbyte toJavaWriteType(const rocksdb::WriteType& writeType) { | |
3775 | switch (writeType) { | |
3776 | case rocksdb::WriteType::kPutRecord: | |
3777 | return 0x0; | |
3778 | case rocksdb::WriteType::kMergeRecord: | |
3779 | return 0x1; | |
3780 | case rocksdb::WriteType::kDeleteRecord: | |
3781 | return 0x2; | |
3782 | case rocksdb::WriteType::kSingleDeleteRecord: | |
3783 | return 0x3; | |
3784 | case rocksdb::WriteType::kDeleteRangeRecord: | |
3785 | return 0x4; | |
3786 | case rocksdb::WriteType::kLogDataRecord: | |
3787 | return 0x5; | |
3788 | case rocksdb::WriteType::kXIDRecord: | |
3789 | return 0x6; | |
3790 | default: | |
3791 | return 0x7F; // undefined | |
3792 | } | |
3793 | } | |
3794 | ||
3795 | private: | |
3796 | /** | |
3797 | * Get the Java Class org.rocksdb.WBWIRocksIterator.WriteType | |
3798 | * | |
3799 | * @param env A pointer to the Java environment | |
3800 | * | |
3801 | * @return The Java Class or nullptr if one of the | |
3802 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3803 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3804 | */ | |
3805 | static jclass getJClass(JNIEnv* env) { | |
3806 | return JavaClass::getJClass(env, "org/rocksdb/WBWIRocksIterator$WriteType"); | |
3807 | } | |
3808 | ||
3809 | /** | |
3810 | * Get an enum field of org.rocksdb.WBWIRocksIterator.WriteType | |
3811 | * | |
3812 | * @param env A pointer to the Java environment | |
3813 | * @param name The name of the enum field | |
3814 | * | |
3815 | * @return A reference to the enum field value or a nullptr if | |
3816 | * the enum field value could not be retrieved | |
3817 | */ | |
3818 | static jobject getEnum(JNIEnv* env, const char name[]) { | |
3819 | jclass jclazz = getJClass(env); | |
3820 | if(jclazz == nullptr) { | |
3821 | // exception occurred accessing class | |
3822 | return nullptr; | |
3823 | } | |
3824 | ||
3825 | jfieldID jfid = | |
3826 | env->GetStaticFieldID(jclazz, name, | |
3827 | "Lorg/rocksdb/WBWIRocksIterator$WriteType;"); | |
3828 | if(env->ExceptionCheck()) { | |
3829 | // exception occurred while getting field | |
3830 | return nullptr; | |
3831 | } else if(jfid == nullptr) { | |
3832 | return nullptr; | |
3833 | } | |
3834 | ||
3835 | jobject jwrite_type = env->GetStaticObjectField(jclazz, jfid); | |
3836 | assert(jwrite_type != nullptr); | |
3837 | return jwrite_type; | |
3838 | } | |
3839 | }; | |
3840 | ||
3841 | // The portal class for org.rocksdb.WBWIRocksIterator.WriteEntry | |
3842 | class WriteEntryJni : public JavaClass { | |
3843 | public: | |
3844 | /** | |
3845 | * Get the Java Class org.rocksdb.WBWIRocksIterator.WriteEntry | |
3846 | * | |
3847 | * @param env A pointer to the Java environment | |
3848 | * | |
3849 | * @return The Java Class or nullptr if one of the | |
3850 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3851 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3852 | */ | |
3853 | static jclass getJClass(JNIEnv* env) { | |
3854 | return JavaClass::getJClass(env, "org/rocksdb/WBWIRocksIterator$WriteEntry"); | |
3855 | } | |
3856 | }; | |
3857 | ||
3858 | // The portal class for org.rocksdb.InfoLogLevel | |
3859 | class InfoLogLevelJni : public JavaClass { | |
3860 | public: | |
3861 | /** | |
3862 | * Get the DEBUG_LEVEL enum field value of InfoLogLevel | |
3863 | * | |
3864 | * @param env A pointer to the Java environment | |
3865 | * | |
3866 | * @return A reference to the enum field value or a nullptr if | |
3867 | * the enum field value could not be retrieved | |
3868 | */ | |
3869 | static jobject DEBUG_LEVEL(JNIEnv* env) { | |
3870 | return getEnum(env, "DEBUG_LEVEL"); | |
3871 | } | |
3872 | ||
3873 | /** | |
3874 | * Get the INFO_LEVEL enum field value of InfoLogLevel | |
3875 | * | |
3876 | * @param env A pointer to the Java environment | |
3877 | * | |
3878 | * @return A reference to the enum field value or a nullptr if | |
3879 | * the enum field value could not be retrieved | |
3880 | */ | |
3881 | static jobject INFO_LEVEL(JNIEnv* env) { | |
3882 | return getEnum(env, "INFO_LEVEL"); | |
3883 | } | |
3884 | ||
3885 | /** | |
3886 | * Get the WARN_LEVEL enum field value of InfoLogLevel | |
3887 | * | |
3888 | * @param env A pointer to the Java environment | |
3889 | * | |
3890 | * @return A reference to the enum field value or a nullptr if | |
3891 | * the enum field value could not be retrieved | |
3892 | */ | |
3893 | static jobject WARN_LEVEL(JNIEnv* env) { | |
3894 | return getEnum(env, "WARN_LEVEL"); | |
3895 | } | |
3896 | ||
3897 | /** | |
3898 | * Get the ERROR_LEVEL enum field value of InfoLogLevel | |
3899 | * | |
3900 | * @param env A pointer to the Java environment | |
3901 | * | |
3902 | * @return A reference to the enum field value or a nullptr if | |
3903 | * the enum field value could not be retrieved | |
3904 | */ | |
3905 | static jobject ERROR_LEVEL(JNIEnv* env) { | |
3906 | return getEnum(env, "ERROR_LEVEL"); | |
3907 | } | |
3908 | ||
3909 | /** | |
3910 | * Get the FATAL_LEVEL enum field value of InfoLogLevel | |
3911 | * | |
3912 | * @param env A pointer to the Java environment | |
3913 | * | |
3914 | * @return A reference to the enum field value or a nullptr if | |
3915 | * the enum field value could not be retrieved | |
3916 | */ | |
3917 | static jobject FATAL_LEVEL(JNIEnv* env) { | |
3918 | return getEnum(env, "FATAL_LEVEL"); | |
3919 | } | |
3920 | ||
3921 | /** | |
3922 | * Get the HEADER_LEVEL enum field value of InfoLogLevel | |
3923 | * | |
3924 | * @param env A pointer to the Java environment | |
3925 | * | |
3926 | * @return A reference to the enum field value or a nullptr if | |
3927 | * the enum field value could not be retrieved | |
3928 | */ | |
3929 | static jobject HEADER_LEVEL(JNIEnv* env) { | |
3930 | return getEnum(env, "HEADER_LEVEL"); | |
3931 | } | |
3932 | ||
3933 | private: | |
3934 | /** | |
3935 | * Get the Java Class org.rocksdb.InfoLogLevel | |
3936 | * | |
3937 | * @param env A pointer to the Java environment | |
3938 | * | |
3939 | * @return The Java Class or nullptr if one of the | |
3940 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3941 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3942 | */ | |
3943 | static jclass getJClass(JNIEnv* env) { | |
3944 | return JavaClass::getJClass(env, "org/rocksdb/InfoLogLevel"); | |
3945 | } | |
3946 | ||
3947 | /** | |
3948 | * Get an enum field of org.rocksdb.InfoLogLevel | |
3949 | * | |
3950 | * @param env A pointer to the Java environment | |
3951 | * @param name The name of the enum field | |
3952 | * | |
3953 | * @return A reference to the enum field value or a nullptr if | |
3954 | * the enum field value could not be retrieved | |
3955 | */ | |
3956 | static jobject getEnum(JNIEnv* env, const char name[]) { | |
3957 | jclass jclazz = getJClass(env); | |
3958 | if(jclazz == nullptr) { | |
3959 | // exception occurred accessing class | |
3960 | return nullptr; | |
3961 | } | |
3962 | ||
3963 | jfieldID jfid = | |
3964 | env->GetStaticFieldID(jclazz, name, "Lorg/rocksdb/InfoLogLevel;"); | |
3965 | if(env->ExceptionCheck()) { | |
3966 | // exception occurred while getting field | |
3967 | return nullptr; | |
3968 | } else if(jfid == nullptr) { | |
3969 | return nullptr; | |
3970 | } | |
3971 | ||
3972 | jobject jinfo_log_level = env->GetStaticObjectField(jclazz, jfid); | |
3973 | assert(jinfo_log_level != nullptr); | |
3974 | return jinfo_log_level; | |
3975 | } | |
3976 | }; | |
3977 | ||
3978 | // The portal class for org.rocksdb.Logger | |
3979 | class LoggerJni : public RocksDBNativeClass< | |
3980 | std::shared_ptr<rocksdb::LoggerJniCallback>*, LoggerJni> { | |
3981 | public: | |
3982 | /** | |
3983 | * Get the Java Class org/rocksdb/Logger | |
3984 | * | |
3985 | * @param env A pointer to the Java environment | |
3986 | * | |
3987 | * @return The Java Class or nullptr if one of the | |
3988 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
3989 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
3990 | */ | |
3991 | static jclass getJClass(JNIEnv* env) { | |
3992 | return RocksDBNativeClass::getJClass(env, "org/rocksdb/Logger"); | |
3993 | } | |
3994 | ||
3995 | /** | |
3996 | * Get the Java Method: Logger#log | |
3997 | * | |
3998 | * @param env A pointer to the Java environment | |
3999 | * | |
4000 | * @return The Java Method ID or nullptr if the class or method id could not | |
4001 | * be retieved | |
4002 | */ | |
4003 | static jmethodID getLogMethodId(JNIEnv* env) { | |
4004 | jclass jclazz = getJClass(env); | |
4005 | if(jclazz == nullptr) { | |
4006 | // exception occurred accessing class | |
4007 | return nullptr; | |
4008 | } | |
4009 | ||
4010 | static jmethodID mid = | |
4011 | env->GetMethodID(jclazz, "log", | |
4012 | "(Lorg/rocksdb/InfoLogLevel;Ljava/lang/String;)V"); | |
4013 | assert(mid != nullptr); | |
4014 | return mid; | |
4015 | } | |
4016 | }; | |
4017 | ||
4018 | // The portal class for org.rocksdb.TransactionLogIterator.BatchResult | |
4019 | class BatchResultJni : public JavaClass { | |
4020 | public: | |
4021 | /** | |
4022 | * Get the Java Class org.rocksdb.TransactionLogIterator.BatchResult | |
4023 | * | |
4024 | * @param env A pointer to the Java environment | |
4025 | * | |
4026 | * @return The Java Class or nullptr if one of the | |
4027 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
4028 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
4029 | */ | |
4030 | static jclass getJClass(JNIEnv* env) { | |
4031 | return JavaClass::getJClass(env, | |
4032 | "org/rocksdb/TransactionLogIterator$BatchResult"); | |
4033 | } | |
4034 | ||
4035 | /** | |
4036 | * Create a new Java org.rocksdb.TransactionLogIterator.BatchResult object | |
4037 | * with the same properties as the provided C++ rocksdb::BatchResult object | |
4038 | * | |
4039 | * @param env A pointer to the Java environment | |
4040 | * @param batch_result The rocksdb::BatchResult object | |
4041 | * | |
4042 | * @return A reference to a Java | |
4043 | * org.rocksdb.TransactionLogIterator.BatchResult object, | |
4044 | * or nullptr if an an exception occurs | |
4045 | */ | |
4046 | static jobject construct(JNIEnv* env, | |
4047 | rocksdb::BatchResult& batch_result) { | |
4048 | jclass jclazz = getJClass(env); | |
4049 | if(jclazz == nullptr) { | |
4050 | // exception occurred accessing class | |
4051 | return nullptr; | |
4052 | } | |
4053 | ||
4054 | jmethodID mid = env->GetMethodID( | |
4055 | jclazz, "<init>", "(JJ)V"); | |
4056 | if(mid == nullptr) { | |
4057 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
4058 | return nullptr; | |
4059 | } | |
4060 | ||
4061 | jobject jbatch_result = env->NewObject(jclazz, mid, | |
4062 | batch_result.sequence, batch_result.writeBatchPtr.get()); | |
4063 | if(jbatch_result == nullptr) { | |
4064 | // exception thrown: InstantiationException or OutOfMemoryError | |
4065 | return nullptr; | |
4066 | } | |
4067 | ||
4068 | batch_result.writeBatchPtr.release(); | |
4069 | return jbatch_result; | |
4070 | } | |
4071 | }; | |
4072 | ||
4073 | // The portal class for org.rocksdb.BottommostLevelCompaction | |
4074 | class BottommostLevelCompactionJni { | |
4075 | public: | |
4076 | // Returns the equivalent org.rocksdb.BottommostLevelCompaction for the provided | |
4077 | // C++ rocksdb::BottommostLevelCompaction enum | |
4078 | static jint toJavaBottommostLevelCompaction( | |
4079 | const rocksdb::BottommostLevelCompaction& bottommost_level_compaction) { | |
4080 | switch(bottommost_level_compaction) { | |
4081 | case rocksdb::BottommostLevelCompaction::kSkip: | |
4082 | return 0x0; | |
4083 | case rocksdb::BottommostLevelCompaction::kIfHaveCompactionFilter: | |
4084 | return 0x1; | |
4085 | case rocksdb::BottommostLevelCompaction::kForce: | |
4086 | return 0x2; | |
4087 | default: | |
4088 | return 0x7F; // undefined | |
4089 | } | |
4090 | } | |
4091 | ||
4092 | // Returns the equivalent C++ rocksdb::BottommostLevelCompaction enum for the | |
4093 | // provided Java org.rocksdb.BottommostLevelCompaction | |
4094 | static rocksdb::BottommostLevelCompaction toCppBottommostLevelCompaction( | |
4095 | jint bottommost_level_compaction) { | |
4096 | switch(bottommost_level_compaction) { | |
4097 | case 0x0: | |
4098 | return rocksdb::BottommostLevelCompaction::kSkip; | |
4099 | case 0x1: | |
4100 | return rocksdb::BottommostLevelCompaction::kIfHaveCompactionFilter; | |
4101 | case 0x2: | |
4102 | return rocksdb::BottommostLevelCompaction::kForce; | |
4103 | default: | |
4104 | // undefined/default | |
4105 | return rocksdb::BottommostLevelCompaction::kIfHaveCompactionFilter; | |
4106 | } | |
4107 | } | |
4108 | }; | |
4109 | ||
4110 | // The portal class for org.rocksdb.CompactionStopStyle | |
4111 | class CompactionStopStyleJni { | |
4112 | public: | |
4113 | // Returns the equivalent org.rocksdb.CompactionStopStyle for the provided | |
4114 | // C++ rocksdb::CompactionStopStyle enum | |
4115 | static jbyte toJavaCompactionStopStyle( | |
4116 | const rocksdb::CompactionStopStyle& compaction_stop_style) { | |
4117 | switch(compaction_stop_style) { | |
4118 | case rocksdb::CompactionStopStyle::kCompactionStopStyleSimilarSize: | |
4119 | return 0x0; | |
4120 | case rocksdb::CompactionStopStyle::kCompactionStopStyleTotalSize: | |
4121 | return 0x1; | |
4122 | default: | |
4123 | return 0x7F; // undefined | |
4124 | } | |
4125 | } | |
4126 | ||
4127 | // Returns the equivalent C++ rocksdb::CompactionStopStyle enum for the | |
4128 | // provided Java org.rocksdb.CompactionStopStyle | |
4129 | static rocksdb::CompactionStopStyle toCppCompactionStopStyle( | |
4130 | jbyte jcompaction_stop_style) { | |
4131 | switch(jcompaction_stop_style) { | |
4132 | case 0x0: | |
4133 | return rocksdb::CompactionStopStyle::kCompactionStopStyleSimilarSize; | |
4134 | case 0x1: | |
4135 | return rocksdb::CompactionStopStyle::kCompactionStopStyleTotalSize; | |
4136 | default: | |
4137 | // undefined/default | |
4138 | return rocksdb::CompactionStopStyle::kCompactionStopStyleSimilarSize; | |
4139 | } | |
4140 | } | |
4141 | }; | |
4142 | ||
4143 | // The portal class for org.rocksdb.CompressionType | |
4144 | class CompressionTypeJni { | |
4145 | public: | |
4146 | // Returns the equivalent org.rocksdb.CompressionType for the provided | |
4147 | // C++ rocksdb::CompressionType enum | |
4148 | static jbyte toJavaCompressionType( | |
4149 | const rocksdb::CompressionType& compression_type) { | |
4150 | switch(compression_type) { | |
4151 | case rocksdb::CompressionType::kNoCompression: | |
4152 | return 0x0; | |
4153 | case rocksdb::CompressionType::kSnappyCompression: | |
4154 | return 0x1; | |
4155 | case rocksdb::CompressionType::kZlibCompression: | |
4156 | return 0x2; | |
4157 | case rocksdb::CompressionType::kBZip2Compression: | |
4158 | return 0x3; | |
4159 | case rocksdb::CompressionType::kLZ4Compression: | |
4160 | return 0x4; | |
4161 | case rocksdb::CompressionType::kLZ4HCCompression: | |
4162 | return 0x5; | |
4163 | case rocksdb::CompressionType::kXpressCompression: | |
4164 | return 0x6; | |
4165 | case rocksdb::CompressionType::kZSTD: | |
4166 | return 0x7; | |
4167 | case rocksdb::CompressionType::kDisableCompressionOption: | |
4168 | default: | |
4169 | return 0x7F; | |
4170 | } | |
4171 | } | |
4172 | ||
4173 | // Returns the equivalent C++ rocksdb::CompressionType enum for the | |
4174 | // provided Java org.rocksdb.CompressionType | |
4175 | static rocksdb::CompressionType toCppCompressionType( | |
4176 | jbyte jcompression_type) { | |
4177 | switch(jcompression_type) { | |
4178 | case 0x0: | |
4179 | return rocksdb::CompressionType::kNoCompression; | |
4180 | case 0x1: | |
4181 | return rocksdb::CompressionType::kSnappyCompression; | |
4182 | case 0x2: | |
4183 | return rocksdb::CompressionType::kZlibCompression; | |
4184 | case 0x3: | |
4185 | return rocksdb::CompressionType::kBZip2Compression; | |
4186 | case 0x4: | |
4187 | return rocksdb::CompressionType::kLZ4Compression; | |
4188 | case 0x5: | |
4189 | return rocksdb::CompressionType::kLZ4HCCompression; | |
4190 | case 0x6: | |
4191 | return rocksdb::CompressionType::kXpressCompression; | |
4192 | case 0x7: | |
4193 | return rocksdb::CompressionType::kZSTD; | |
4194 | case 0x7F: | |
4195 | default: | |
4196 | return rocksdb::CompressionType::kDisableCompressionOption; | |
4197 | } | |
4198 | } | |
4199 | }; | |
4200 | ||
4201 | // The portal class for org.rocksdb.CompactionPriority | |
4202 | class CompactionPriorityJni { | |
4203 | public: | |
4204 | // Returns the equivalent org.rocksdb.CompactionPriority for the provided | |
4205 | // C++ rocksdb::CompactionPri enum | |
4206 | static jbyte toJavaCompactionPriority( | |
4207 | const rocksdb::CompactionPri& compaction_priority) { | |
4208 | switch(compaction_priority) { | |
4209 | case rocksdb::CompactionPri::kByCompensatedSize: | |
4210 | return 0x0; | |
4211 | case rocksdb::CompactionPri::kOldestLargestSeqFirst: | |
4212 | return 0x1; | |
4213 | case rocksdb::CompactionPri::kOldestSmallestSeqFirst: | |
4214 | return 0x2; | |
4215 | case rocksdb::CompactionPri::kMinOverlappingRatio: | |
4216 | return 0x3; | |
4217 | default: | |
4218 | return 0x0; // undefined | |
4219 | } | |
4220 | } | |
4221 | ||
4222 | // Returns the equivalent C++ rocksdb::CompactionPri enum for the | |
4223 | // provided Java org.rocksdb.CompactionPriority | |
4224 | static rocksdb::CompactionPri toCppCompactionPriority( | |
4225 | jbyte jcompaction_priority) { | |
4226 | switch(jcompaction_priority) { | |
4227 | case 0x0: | |
4228 | return rocksdb::CompactionPri::kByCompensatedSize; | |
4229 | case 0x1: | |
4230 | return rocksdb::CompactionPri::kOldestLargestSeqFirst; | |
4231 | case 0x2: | |
4232 | return rocksdb::CompactionPri::kOldestSmallestSeqFirst; | |
4233 | case 0x3: | |
4234 | return rocksdb::CompactionPri::kMinOverlappingRatio; | |
4235 | default: | |
4236 | // undefined/default | |
4237 | return rocksdb::CompactionPri::kByCompensatedSize; | |
4238 | } | |
4239 | } | |
4240 | }; | |
4241 | ||
4242 | // The portal class for org.rocksdb.AccessHint | |
4243 | class AccessHintJni { | |
4244 | public: | |
4245 | // Returns the equivalent org.rocksdb.AccessHint for the provided | |
4246 | // C++ rocksdb::DBOptions::AccessHint enum | |
4247 | static jbyte toJavaAccessHint( | |
4248 | const rocksdb::DBOptions::AccessHint& access_hint) { | |
4249 | switch(access_hint) { | |
4250 | case rocksdb::DBOptions::AccessHint::NONE: | |
4251 | return 0x0; | |
4252 | case rocksdb::DBOptions::AccessHint::NORMAL: | |
4253 | return 0x1; | |
4254 | case rocksdb::DBOptions::AccessHint::SEQUENTIAL: | |
4255 | return 0x2; | |
4256 | case rocksdb::DBOptions::AccessHint::WILLNEED: | |
4257 | return 0x3; | |
4258 | default: | |
4259 | // undefined/default | |
4260 | return 0x1; | |
4261 | } | |
4262 | } | |
4263 | ||
4264 | // Returns the equivalent C++ rocksdb::DBOptions::AccessHint enum for the | |
4265 | // provided Java org.rocksdb.AccessHint | |
4266 | static rocksdb::DBOptions::AccessHint toCppAccessHint(jbyte jaccess_hint) { | |
4267 | switch(jaccess_hint) { | |
4268 | case 0x0: | |
4269 | return rocksdb::DBOptions::AccessHint::NONE; | |
4270 | case 0x1: | |
4271 | return rocksdb::DBOptions::AccessHint::NORMAL; | |
4272 | case 0x2: | |
4273 | return rocksdb::DBOptions::AccessHint::SEQUENTIAL; | |
4274 | case 0x3: | |
4275 | return rocksdb::DBOptions::AccessHint::WILLNEED; | |
4276 | default: | |
4277 | // undefined/default | |
4278 | return rocksdb::DBOptions::AccessHint::NORMAL; | |
4279 | } | |
4280 | } | |
4281 | }; | |
4282 | ||
4283 | // The portal class for org.rocksdb.WALRecoveryMode | |
4284 | class WALRecoveryModeJni { | |
4285 | public: | |
4286 | // Returns the equivalent org.rocksdb.WALRecoveryMode for the provided | |
4287 | // C++ rocksdb::WALRecoveryMode enum | |
4288 | static jbyte toJavaWALRecoveryMode( | |
4289 | const rocksdb::WALRecoveryMode& wal_recovery_mode) { | |
4290 | switch(wal_recovery_mode) { | |
4291 | case rocksdb::WALRecoveryMode::kTolerateCorruptedTailRecords: | |
4292 | return 0x0; | |
4293 | case rocksdb::WALRecoveryMode::kAbsoluteConsistency: | |
4294 | return 0x1; | |
4295 | case rocksdb::WALRecoveryMode::kPointInTimeRecovery: | |
4296 | return 0x2; | |
4297 | case rocksdb::WALRecoveryMode::kSkipAnyCorruptedRecords: | |
4298 | return 0x3; | |
4299 | default: | |
4300 | // undefined/default | |
4301 | return 0x2; | |
4302 | } | |
4303 | } | |
4304 | ||
4305 | // Returns the equivalent C++ rocksdb::WALRecoveryMode enum for the | |
4306 | // provided Java org.rocksdb.WALRecoveryMode | |
4307 | static rocksdb::WALRecoveryMode toCppWALRecoveryMode(jbyte jwal_recovery_mode) { | |
4308 | switch(jwal_recovery_mode) { | |
4309 | case 0x0: | |
4310 | return rocksdb::WALRecoveryMode::kTolerateCorruptedTailRecords; | |
4311 | case 0x1: | |
4312 | return rocksdb::WALRecoveryMode::kAbsoluteConsistency; | |
4313 | case 0x2: | |
4314 | return rocksdb::WALRecoveryMode::kPointInTimeRecovery; | |
4315 | case 0x3: | |
4316 | return rocksdb::WALRecoveryMode::kSkipAnyCorruptedRecords; | |
4317 | default: | |
4318 | // undefined/default | |
4319 | return rocksdb::WALRecoveryMode::kPointInTimeRecovery; | |
4320 | } | |
4321 | } | |
4322 | }; | |
4323 | ||
4324 | // The portal class for org.rocksdb.TickerType | |
4325 | class TickerTypeJni { | |
4326 | public: | |
4327 | // Returns the equivalent org.rocksdb.TickerType for the provided | |
4328 | // C++ rocksdb::Tickers enum | |
4329 | static jbyte toJavaTickerType( | |
4330 | const rocksdb::Tickers& tickers) { | |
4331 | switch(tickers) { | |
4332 | case rocksdb::Tickers::BLOCK_CACHE_MISS: | |
4333 | return 0x0; | |
4334 | case rocksdb::Tickers::BLOCK_CACHE_HIT: | |
4335 | return 0x1; | |
4336 | case rocksdb::Tickers::BLOCK_CACHE_ADD: | |
4337 | return 0x2; | |
4338 | case rocksdb::Tickers::BLOCK_CACHE_ADD_FAILURES: | |
4339 | return 0x3; | |
4340 | case rocksdb::Tickers::BLOCK_CACHE_INDEX_MISS: | |
4341 | return 0x4; | |
4342 | case rocksdb::Tickers::BLOCK_CACHE_INDEX_HIT: | |
4343 | return 0x5; | |
4344 | case rocksdb::Tickers::BLOCK_CACHE_INDEX_ADD: | |
4345 | return 0x6; | |
4346 | case rocksdb::Tickers::BLOCK_CACHE_INDEX_BYTES_INSERT: | |
4347 | return 0x7; | |
4348 | case rocksdb::Tickers::BLOCK_CACHE_INDEX_BYTES_EVICT: | |
4349 | return 0x8; | |
4350 | case rocksdb::Tickers::BLOCK_CACHE_FILTER_MISS: | |
4351 | return 0x9; | |
4352 | case rocksdb::Tickers::BLOCK_CACHE_FILTER_HIT: | |
4353 | return 0xA; | |
4354 | case rocksdb::Tickers::BLOCK_CACHE_FILTER_ADD: | |
4355 | return 0xB; | |
4356 | case rocksdb::Tickers::BLOCK_CACHE_FILTER_BYTES_INSERT: | |
4357 | return 0xC; | |
4358 | case rocksdb::Tickers::BLOCK_CACHE_FILTER_BYTES_EVICT: | |
4359 | return 0xD; | |
4360 | case rocksdb::Tickers::BLOCK_CACHE_DATA_MISS: | |
4361 | return 0xE; | |
4362 | case rocksdb::Tickers::BLOCK_CACHE_DATA_HIT: | |
4363 | return 0xF; | |
4364 | case rocksdb::Tickers::BLOCK_CACHE_DATA_ADD: | |
4365 | return 0x10; | |
4366 | case rocksdb::Tickers::BLOCK_CACHE_DATA_BYTES_INSERT: | |
4367 | return 0x11; | |
4368 | case rocksdb::Tickers::BLOCK_CACHE_BYTES_READ: | |
4369 | return 0x12; | |
4370 | case rocksdb::Tickers::BLOCK_CACHE_BYTES_WRITE: | |
4371 | return 0x13; | |
4372 | case rocksdb::Tickers::BLOOM_FILTER_USEFUL: | |
4373 | return 0x14; | |
4374 | case rocksdb::Tickers::PERSISTENT_CACHE_HIT: | |
4375 | return 0x15; | |
4376 | case rocksdb::Tickers::PERSISTENT_CACHE_MISS: | |
4377 | return 0x16; | |
4378 | case rocksdb::Tickers::SIM_BLOCK_CACHE_HIT: | |
4379 | return 0x17; | |
4380 | case rocksdb::Tickers::SIM_BLOCK_CACHE_MISS: | |
4381 | return 0x18; | |
4382 | case rocksdb::Tickers::MEMTABLE_HIT: | |
4383 | return 0x19; | |
4384 | case rocksdb::Tickers::MEMTABLE_MISS: | |
4385 | return 0x1A; | |
4386 | case rocksdb::Tickers::GET_HIT_L0: | |
4387 | return 0x1B; | |
4388 | case rocksdb::Tickers::GET_HIT_L1: | |
4389 | return 0x1C; | |
4390 | case rocksdb::Tickers::GET_HIT_L2_AND_UP: | |
4391 | return 0x1D; | |
4392 | case rocksdb::Tickers::COMPACTION_KEY_DROP_NEWER_ENTRY: | |
4393 | return 0x1E; | |
4394 | case rocksdb::Tickers::COMPACTION_KEY_DROP_OBSOLETE: | |
4395 | return 0x1F; | |
4396 | case rocksdb::Tickers::COMPACTION_KEY_DROP_RANGE_DEL: | |
4397 | return 0x20; | |
4398 | case rocksdb::Tickers::COMPACTION_KEY_DROP_USER: | |
4399 | return 0x21; | |
4400 | case rocksdb::Tickers::COMPACTION_RANGE_DEL_DROP_OBSOLETE: | |
4401 | return 0x22; | |
4402 | case rocksdb::Tickers::NUMBER_KEYS_WRITTEN: | |
4403 | return 0x23; | |
4404 | case rocksdb::Tickers::NUMBER_KEYS_READ: | |
4405 | return 0x24; | |
4406 | case rocksdb::Tickers::NUMBER_KEYS_UPDATED: | |
4407 | return 0x25; | |
4408 | case rocksdb::Tickers::BYTES_WRITTEN: | |
4409 | return 0x26; | |
4410 | case rocksdb::Tickers::BYTES_READ: | |
4411 | return 0x27; | |
4412 | case rocksdb::Tickers::NUMBER_DB_SEEK: | |
4413 | return 0x28; | |
4414 | case rocksdb::Tickers::NUMBER_DB_NEXT: | |
4415 | return 0x29; | |
4416 | case rocksdb::Tickers::NUMBER_DB_PREV: | |
4417 | return 0x2A; | |
4418 | case rocksdb::Tickers::NUMBER_DB_SEEK_FOUND: | |
4419 | return 0x2B; | |
4420 | case rocksdb::Tickers::NUMBER_DB_NEXT_FOUND: | |
4421 | return 0x2C; | |
4422 | case rocksdb::Tickers::NUMBER_DB_PREV_FOUND: | |
4423 | return 0x2D; | |
4424 | case rocksdb::Tickers::ITER_BYTES_READ: | |
4425 | return 0x2E; | |
4426 | case rocksdb::Tickers::NO_FILE_CLOSES: | |
4427 | return 0x2F; | |
4428 | case rocksdb::Tickers::NO_FILE_OPENS: | |
4429 | return 0x30; | |
4430 | case rocksdb::Tickers::NO_FILE_ERRORS: | |
4431 | return 0x31; | |
4432 | case rocksdb::Tickers::STALL_L0_SLOWDOWN_MICROS: | |
4433 | return 0x32; | |
4434 | case rocksdb::Tickers::STALL_MEMTABLE_COMPACTION_MICROS: | |
4435 | return 0x33; | |
4436 | case rocksdb::Tickers::STALL_L0_NUM_FILES_MICROS: | |
4437 | return 0x34; | |
4438 | case rocksdb::Tickers::STALL_MICROS: | |
4439 | return 0x35; | |
4440 | case rocksdb::Tickers::DB_MUTEX_WAIT_MICROS: | |
4441 | return 0x36; | |
4442 | case rocksdb::Tickers::RATE_LIMIT_DELAY_MILLIS: | |
4443 | return 0x37; | |
4444 | case rocksdb::Tickers::NO_ITERATORS: | |
4445 | return 0x38; | |
4446 | case rocksdb::Tickers::NUMBER_MULTIGET_CALLS: | |
4447 | return 0x39; | |
4448 | case rocksdb::Tickers::NUMBER_MULTIGET_KEYS_READ: | |
4449 | return 0x3A; | |
4450 | case rocksdb::Tickers::NUMBER_MULTIGET_BYTES_READ: | |
4451 | return 0x3B; | |
4452 | case rocksdb::Tickers::NUMBER_FILTERED_DELETES: | |
4453 | return 0x3C; | |
4454 | case rocksdb::Tickers::NUMBER_MERGE_FAILURES: | |
4455 | return 0x3D; | |
4456 | case rocksdb::Tickers::BLOOM_FILTER_PREFIX_CHECKED: | |
4457 | return 0x3E; | |
4458 | case rocksdb::Tickers::BLOOM_FILTER_PREFIX_USEFUL: | |
4459 | return 0x3F; | |
4460 | case rocksdb::Tickers::NUMBER_OF_RESEEKS_IN_ITERATION: | |
4461 | return 0x40; | |
4462 | case rocksdb::Tickers::GET_UPDATES_SINCE_CALLS: | |
4463 | return 0x41; | |
4464 | case rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_MISS: | |
4465 | return 0x42; | |
4466 | case rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_HIT: | |
4467 | return 0x43; | |
4468 | case rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_ADD: | |
4469 | return 0x44; | |
4470 | case rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_ADD_FAILURES: | |
4471 | return 0x45; | |
4472 | case rocksdb::Tickers::WAL_FILE_SYNCED: | |
4473 | return 0x46; | |
4474 | case rocksdb::Tickers::WAL_FILE_BYTES: | |
4475 | return 0x47; | |
4476 | case rocksdb::Tickers::WRITE_DONE_BY_SELF: | |
4477 | return 0x48; | |
4478 | case rocksdb::Tickers::WRITE_DONE_BY_OTHER: | |
4479 | return 0x49; | |
4480 | case rocksdb::Tickers::WRITE_TIMEDOUT: | |
4481 | return 0x4A; | |
4482 | case rocksdb::Tickers::WRITE_WITH_WAL: | |
4483 | return 0x4B; | |
4484 | case rocksdb::Tickers::COMPACT_READ_BYTES: | |
4485 | return 0x4C; | |
4486 | case rocksdb::Tickers::COMPACT_WRITE_BYTES: | |
4487 | return 0x4D; | |
4488 | case rocksdb::Tickers::FLUSH_WRITE_BYTES: | |
4489 | return 0x4E; | |
4490 | case rocksdb::Tickers::NUMBER_DIRECT_LOAD_TABLE_PROPERTIES: | |
4491 | return 0x4F; | |
4492 | case rocksdb::Tickers::NUMBER_SUPERVERSION_ACQUIRES: | |
4493 | return 0x50; | |
4494 | case rocksdb::Tickers::NUMBER_SUPERVERSION_RELEASES: | |
4495 | return 0x51; | |
4496 | case rocksdb::Tickers::NUMBER_SUPERVERSION_CLEANUPS: | |
4497 | return 0x52; | |
4498 | case rocksdb::Tickers::NUMBER_BLOCK_COMPRESSED: | |
4499 | return 0x53; | |
4500 | case rocksdb::Tickers::NUMBER_BLOCK_DECOMPRESSED: | |
4501 | return 0x54; | |
4502 | case rocksdb::Tickers::NUMBER_BLOCK_NOT_COMPRESSED: | |
4503 | return 0x55; | |
4504 | case rocksdb::Tickers::MERGE_OPERATION_TOTAL_TIME: | |
4505 | return 0x56; | |
4506 | case rocksdb::Tickers::FILTER_OPERATION_TOTAL_TIME: | |
4507 | return 0x57; | |
4508 | case rocksdb::Tickers::ROW_CACHE_HIT: | |
4509 | return 0x58; | |
4510 | case rocksdb::Tickers::ROW_CACHE_MISS: | |
4511 | return 0x59; | |
4512 | case rocksdb::Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES: | |
4513 | return 0x5A; | |
4514 | case rocksdb::Tickers::READ_AMP_TOTAL_READ_BYTES: | |
4515 | return 0x5B; | |
4516 | case rocksdb::Tickers::NUMBER_RATE_LIMITER_DRAINS: | |
4517 | return 0x5C; | |
4518 | case rocksdb::Tickers::NUMBER_ITER_SKIP: | |
4519 | return 0x5D; | |
4520 | case rocksdb::Tickers::NUMBER_MULTIGET_KEYS_FOUND: | |
4521 | return 0x5E; | |
494da23a TL |
4522 | case rocksdb::Tickers::NO_ITERATOR_CREATED: |
4523 | // -0x01 to fixate the new value that incorrectly changed TICKER_ENUM_MAX. | |
4524 | return -0x01; | |
4525 | case rocksdb::Tickers::NO_ITERATOR_DELETED: | |
4526 | return 0x60; | |
4527 | case rocksdb::Tickers::COMPACTION_OPTIMIZED_DEL_DROP_OBSOLETE: | |
4528 | return 0x61; | |
4529 | case rocksdb::Tickers::COMPACTION_CANCELLED: | |
4530 | return 0x62; | |
4531 | case rocksdb::Tickers::BLOOM_FILTER_FULL_POSITIVE: | |
4532 | return 0x63; | |
4533 | case rocksdb::Tickers::BLOOM_FILTER_FULL_TRUE_POSITIVE: | |
4534 | return 0x64; | |
4535 | case rocksdb::Tickers::BLOB_DB_NUM_PUT: | |
4536 | return 0x65; | |
4537 | case rocksdb::Tickers::BLOB_DB_NUM_WRITE: | |
4538 | return 0x66; | |
4539 | case rocksdb::Tickers::BLOB_DB_NUM_GET: | |
4540 | return 0x67; | |
4541 | case rocksdb::Tickers::BLOB_DB_NUM_MULTIGET: | |
4542 | return 0x68; | |
4543 | case rocksdb::Tickers::BLOB_DB_NUM_SEEK: | |
4544 | return 0x69; | |
4545 | case rocksdb::Tickers::BLOB_DB_NUM_NEXT: | |
4546 | return 0x6A; | |
4547 | case rocksdb::Tickers::BLOB_DB_NUM_PREV: | |
4548 | return 0x6B; | |
4549 | case rocksdb::Tickers::BLOB_DB_NUM_KEYS_WRITTEN: | |
4550 | return 0x6C; | |
4551 | case rocksdb::Tickers::BLOB_DB_NUM_KEYS_READ: | |
4552 | return 0x6D; | |
4553 | case rocksdb::Tickers::BLOB_DB_BYTES_WRITTEN: | |
4554 | return 0x6E; | |
4555 | case rocksdb::Tickers::BLOB_DB_BYTES_READ: | |
4556 | return 0x6F; | |
4557 | case rocksdb::Tickers::BLOB_DB_WRITE_INLINED: | |
4558 | return 0x70; | |
4559 | case rocksdb::Tickers::BLOB_DB_WRITE_INLINED_TTL: | |
4560 | return 0x71; | |
4561 | case rocksdb::Tickers::BLOB_DB_WRITE_BLOB: | |
4562 | return 0x72; | |
4563 | case rocksdb::Tickers::BLOB_DB_WRITE_BLOB_TTL: | |
4564 | return 0x73; | |
4565 | case rocksdb::Tickers::BLOB_DB_BLOB_FILE_BYTES_WRITTEN: | |
4566 | return 0x74; | |
4567 | case rocksdb::Tickers::BLOB_DB_BLOB_FILE_BYTES_READ: | |
4568 | return 0x75; | |
4569 | case rocksdb::Tickers::BLOB_DB_BLOB_FILE_SYNCED: | |
4570 | return 0x76; | |
4571 | case rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_COUNT: | |
4572 | return 0x77; | |
4573 | case rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_SIZE: | |
4574 | return 0x78; | |
4575 | case rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_COUNT: | |
4576 | return 0x79; | |
4577 | case rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_SIZE: | |
4578 | return 0x7A; | |
4579 | case rocksdb::Tickers::BLOB_DB_GC_NUM_FILES: | |
4580 | return 0x7B; | |
4581 | case rocksdb::Tickers::BLOB_DB_GC_NUM_NEW_FILES: | |
4582 | return 0x7C; | |
4583 | case rocksdb::Tickers::BLOB_DB_GC_FAILURES: | |
4584 | return 0x7D; | |
4585 | case rocksdb::Tickers::BLOB_DB_GC_NUM_KEYS_OVERWRITTEN: | |
4586 | return 0x7E; | |
4587 | case rocksdb::Tickers::BLOB_DB_GC_NUM_KEYS_EXPIRED: | |
4588 | return 0x7F; | |
4589 | case rocksdb::Tickers::BLOB_DB_GC_NUM_KEYS_RELOCATED: | |
4590 | return -0x02; | |
4591 | case rocksdb::Tickers::BLOB_DB_GC_BYTES_OVERWRITTEN: | |
4592 | return -0x03; | |
4593 | case rocksdb::Tickers::BLOB_DB_GC_BYTES_EXPIRED: | |
4594 | return -0x04; | |
4595 | case rocksdb::Tickers::BLOB_DB_GC_BYTES_RELOCATED: | |
4596 | return -0x05; | |
4597 | case rocksdb::Tickers::BLOB_DB_FIFO_NUM_FILES_EVICTED: | |
4598 | return -0x06; | |
4599 | case rocksdb::Tickers::BLOB_DB_FIFO_NUM_KEYS_EVICTED: | |
4600 | return -0x07; | |
4601 | case rocksdb::Tickers::BLOB_DB_FIFO_BYTES_EVICTED: | |
4602 | return -0x08; | |
4603 | case rocksdb::Tickers::TXN_PREPARE_MUTEX_OVERHEAD: | |
4604 | return -0x09; | |
4605 | case rocksdb::Tickers::TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD: | |
4606 | return -0x0A; | |
4607 | case rocksdb::Tickers::TXN_DUPLICATE_KEY_OVERHEAD: | |
4608 | return -0x0B; | |
4609 | case rocksdb::Tickers::TXN_SNAPSHOT_MUTEX_OVERHEAD: | |
4610 | return -0x0C; | |
11fdf7f2 | 4611 | case rocksdb::Tickers::TICKER_ENUM_MAX: |
494da23a | 4612 | // 0x5F for backwards compatibility on current minor version. |
11fdf7f2 | 4613 | return 0x5F; |
11fdf7f2 TL |
4614 | default: |
4615 | // undefined/default | |
4616 | return 0x0; | |
4617 | } | |
4618 | } | |
4619 | ||
4620 | // Returns the equivalent C++ rocksdb::Tickers enum for the | |
4621 | // provided Java org.rocksdb.TickerType | |
4622 | static rocksdb::Tickers toCppTickers(jbyte jticker_type) { | |
4623 | switch(jticker_type) { | |
4624 | case 0x0: | |
4625 | return rocksdb::Tickers::BLOCK_CACHE_MISS; | |
4626 | case 0x1: | |
4627 | return rocksdb::Tickers::BLOCK_CACHE_HIT; | |
4628 | case 0x2: | |
4629 | return rocksdb::Tickers::BLOCK_CACHE_ADD; | |
4630 | case 0x3: | |
4631 | return rocksdb::Tickers::BLOCK_CACHE_ADD_FAILURES; | |
4632 | case 0x4: | |
4633 | return rocksdb::Tickers::BLOCK_CACHE_INDEX_MISS; | |
4634 | case 0x5: | |
4635 | return rocksdb::Tickers::BLOCK_CACHE_INDEX_HIT; | |
4636 | case 0x6: | |
4637 | return rocksdb::Tickers::BLOCK_CACHE_INDEX_ADD; | |
4638 | case 0x7: | |
4639 | return rocksdb::Tickers::BLOCK_CACHE_INDEX_BYTES_INSERT; | |
4640 | case 0x8: | |
4641 | return rocksdb::Tickers::BLOCK_CACHE_INDEX_BYTES_EVICT; | |
4642 | case 0x9: | |
4643 | return rocksdb::Tickers::BLOCK_CACHE_FILTER_MISS; | |
4644 | case 0xA: | |
4645 | return rocksdb::Tickers::BLOCK_CACHE_FILTER_HIT; | |
4646 | case 0xB: | |
4647 | return rocksdb::Tickers::BLOCK_CACHE_FILTER_ADD; | |
4648 | case 0xC: | |
4649 | return rocksdb::Tickers::BLOCK_CACHE_FILTER_BYTES_INSERT; | |
4650 | case 0xD: | |
4651 | return rocksdb::Tickers::BLOCK_CACHE_FILTER_BYTES_EVICT; | |
4652 | case 0xE: | |
4653 | return rocksdb::Tickers::BLOCK_CACHE_DATA_MISS; | |
4654 | case 0xF: | |
4655 | return rocksdb::Tickers::BLOCK_CACHE_DATA_HIT; | |
4656 | case 0x10: | |
4657 | return rocksdb::Tickers::BLOCK_CACHE_DATA_ADD; | |
4658 | case 0x11: | |
4659 | return rocksdb::Tickers::BLOCK_CACHE_DATA_BYTES_INSERT; | |
4660 | case 0x12: | |
4661 | return rocksdb::Tickers::BLOCK_CACHE_BYTES_READ; | |
4662 | case 0x13: | |
4663 | return rocksdb::Tickers::BLOCK_CACHE_BYTES_WRITE; | |
4664 | case 0x14: | |
4665 | return rocksdb::Tickers::BLOOM_FILTER_USEFUL; | |
4666 | case 0x15: | |
4667 | return rocksdb::Tickers::PERSISTENT_CACHE_HIT; | |
4668 | case 0x16: | |
4669 | return rocksdb::Tickers::PERSISTENT_CACHE_MISS; | |
4670 | case 0x17: | |
4671 | return rocksdb::Tickers::SIM_BLOCK_CACHE_HIT; | |
4672 | case 0x18: | |
4673 | return rocksdb::Tickers::SIM_BLOCK_CACHE_MISS; | |
4674 | case 0x19: | |
4675 | return rocksdb::Tickers::MEMTABLE_HIT; | |
4676 | case 0x1A: | |
4677 | return rocksdb::Tickers::MEMTABLE_MISS; | |
4678 | case 0x1B: | |
4679 | return rocksdb::Tickers::GET_HIT_L0; | |
4680 | case 0x1C: | |
4681 | return rocksdb::Tickers::GET_HIT_L1; | |
4682 | case 0x1D: | |
4683 | return rocksdb::Tickers::GET_HIT_L2_AND_UP; | |
4684 | case 0x1E: | |
4685 | return rocksdb::Tickers::COMPACTION_KEY_DROP_NEWER_ENTRY; | |
4686 | case 0x1F: | |
4687 | return rocksdb::Tickers::COMPACTION_KEY_DROP_OBSOLETE; | |
4688 | case 0x20: | |
4689 | return rocksdb::Tickers::COMPACTION_KEY_DROP_RANGE_DEL; | |
4690 | case 0x21: | |
4691 | return rocksdb::Tickers::COMPACTION_KEY_DROP_USER; | |
4692 | case 0x22: | |
4693 | return rocksdb::Tickers::COMPACTION_RANGE_DEL_DROP_OBSOLETE; | |
4694 | case 0x23: | |
4695 | return rocksdb::Tickers::NUMBER_KEYS_WRITTEN; | |
4696 | case 0x24: | |
4697 | return rocksdb::Tickers::NUMBER_KEYS_READ; | |
4698 | case 0x25: | |
4699 | return rocksdb::Tickers::NUMBER_KEYS_UPDATED; | |
4700 | case 0x26: | |
4701 | return rocksdb::Tickers::BYTES_WRITTEN; | |
4702 | case 0x27: | |
4703 | return rocksdb::Tickers::BYTES_READ; | |
4704 | case 0x28: | |
4705 | return rocksdb::Tickers::NUMBER_DB_SEEK; | |
4706 | case 0x29: | |
4707 | return rocksdb::Tickers::NUMBER_DB_NEXT; | |
4708 | case 0x2A: | |
4709 | return rocksdb::Tickers::NUMBER_DB_PREV; | |
4710 | case 0x2B: | |
4711 | return rocksdb::Tickers::NUMBER_DB_SEEK_FOUND; | |
4712 | case 0x2C: | |
4713 | return rocksdb::Tickers::NUMBER_DB_NEXT_FOUND; | |
4714 | case 0x2D: | |
4715 | return rocksdb::Tickers::NUMBER_DB_PREV_FOUND; | |
4716 | case 0x2E: | |
4717 | return rocksdb::Tickers::ITER_BYTES_READ; | |
4718 | case 0x2F: | |
4719 | return rocksdb::Tickers::NO_FILE_CLOSES; | |
4720 | case 0x30: | |
4721 | return rocksdb::Tickers::NO_FILE_OPENS; | |
4722 | case 0x31: | |
4723 | return rocksdb::Tickers::NO_FILE_ERRORS; | |
4724 | case 0x32: | |
4725 | return rocksdb::Tickers::STALL_L0_SLOWDOWN_MICROS; | |
4726 | case 0x33: | |
4727 | return rocksdb::Tickers::STALL_MEMTABLE_COMPACTION_MICROS; | |
4728 | case 0x34: | |
4729 | return rocksdb::Tickers::STALL_L0_NUM_FILES_MICROS; | |
4730 | case 0x35: | |
4731 | return rocksdb::Tickers::STALL_MICROS; | |
4732 | case 0x36: | |
4733 | return rocksdb::Tickers::DB_MUTEX_WAIT_MICROS; | |
4734 | case 0x37: | |
4735 | return rocksdb::Tickers::RATE_LIMIT_DELAY_MILLIS; | |
4736 | case 0x38: | |
4737 | return rocksdb::Tickers::NO_ITERATORS; | |
4738 | case 0x39: | |
4739 | return rocksdb::Tickers::NUMBER_MULTIGET_CALLS; | |
4740 | case 0x3A: | |
4741 | return rocksdb::Tickers::NUMBER_MULTIGET_KEYS_READ; | |
4742 | case 0x3B: | |
4743 | return rocksdb::Tickers::NUMBER_MULTIGET_BYTES_READ; | |
4744 | case 0x3C: | |
4745 | return rocksdb::Tickers::NUMBER_FILTERED_DELETES; | |
4746 | case 0x3D: | |
4747 | return rocksdb::Tickers::NUMBER_MERGE_FAILURES; | |
4748 | case 0x3E: | |
4749 | return rocksdb::Tickers::BLOOM_FILTER_PREFIX_CHECKED; | |
4750 | case 0x3F: | |
4751 | return rocksdb::Tickers::BLOOM_FILTER_PREFIX_USEFUL; | |
4752 | case 0x40: | |
4753 | return rocksdb::Tickers::NUMBER_OF_RESEEKS_IN_ITERATION; | |
4754 | case 0x41: | |
4755 | return rocksdb::Tickers::GET_UPDATES_SINCE_CALLS; | |
4756 | case 0x42: | |
4757 | return rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_MISS; | |
4758 | case 0x43: | |
4759 | return rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_HIT; | |
4760 | case 0x44: | |
4761 | return rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_ADD; | |
4762 | case 0x45: | |
4763 | return rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_ADD_FAILURES; | |
4764 | case 0x46: | |
4765 | return rocksdb::Tickers::WAL_FILE_SYNCED; | |
4766 | case 0x47: | |
4767 | return rocksdb::Tickers::WAL_FILE_BYTES; | |
4768 | case 0x48: | |
4769 | return rocksdb::Tickers::WRITE_DONE_BY_SELF; | |
4770 | case 0x49: | |
4771 | return rocksdb::Tickers::WRITE_DONE_BY_OTHER; | |
4772 | case 0x4A: | |
4773 | return rocksdb::Tickers::WRITE_TIMEDOUT; | |
4774 | case 0x4B: | |
4775 | return rocksdb::Tickers::WRITE_WITH_WAL; | |
4776 | case 0x4C: | |
4777 | return rocksdb::Tickers::COMPACT_READ_BYTES; | |
4778 | case 0x4D: | |
4779 | return rocksdb::Tickers::COMPACT_WRITE_BYTES; | |
4780 | case 0x4E: | |
4781 | return rocksdb::Tickers::FLUSH_WRITE_BYTES; | |
4782 | case 0x4F: | |
4783 | return rocksdb::Tickers::NUMBER_DIRECT_LOAD_TABLE_PROPERTIES; | |
4784 | case 0x50: | |
4785 | return rocksdb::Tickers::NUMBER_SUPERVERSION_ACQUIRES; | |
4786 | case 0x51: | |
4787 | return rocksdb::Tickers::NUMBER_SUPERVERSION_RELEASES; | |
4788 | case 0x52: | |
4789 | return rocksdb::Tickers::NUMBER_SUPERVERSION_CLEANUPS; | |
4790 | case 0x53: | |
4791 | return rocksdb::Tickers::NUMBER_BLOCK_COMPRESSED; | |
4792 | case 0x54: | |
4793 | return rocksdb::Tickers::NUMBER_BLOCK_DECOMPRESSED; | |
4794 | case 0x55: | |
4795 | return rocksdb::Tickers::NUMBER_BLOCK_NOT_COMPRESSED; | |
4796 | case 0x56: | |
4797 | return rocksdb::Tickers::MERGE_OPERATION_TOTAL_TIME; | |
4798 | case 0x57: | |
4799 | return rocksdb::Tickers::FILTER_OPERATION_TOTAL_TIME; | |
4800 | case 0x58: | |
4801 | return rocksdb::Tickers::ROW_CACHE_HIT; | |
4802 | case 0x59: | |
4803 | return rocksdb::Tickers::ROW_CACHE_MISS; | |
4804 | case 0x5A: | |
4805 | return rocksdb::Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES; | |
4806 | case 0x5B: | |
4807 | return rocksdb::Tickers::READ_AMP_TOTAL_READ_BYTES; | |
4808 | case 0x5C: | |
4809 | return rocksdb::Tickers::NUMBER_RATE_LIMITER_DRAINS; | |
4810 | case 0x5D: | |
4811 | return rocksdb::Tickers::NUMBER_ITER_SKIP; | |
4812 | case 0x5E: | |
4813 | return rocksdb::Tickers::NUMBER_MULTIGET_KEYS_FOUND; | |
494da23a TL |
4814 | case -0x01: |
4815 | // -0x01 to fixate the new value that incorrectly changed TICKER_ENUM_MAX. | |
4816 | return rocksdb::Tickers::NO_ITERATOR_CREATED; | |
4817 | case 0x60: | |
4818 | return rocksdb::Tickers::NO_ITERATOR_DELETED; | |
4819 | case 0x61: | |
4820 | return rocksdb::Tickers::COMPACTION_OPTIMIZED_DEL_DROP_OBSOLETE; | |
4821 | case 0x62: | |
4822 | return rocksdb::Tickers::COMPACTION_CANCELLED; | |
4823 | case 0x63: | |
4824 | return rocksdb::Tickers::BLOOM_FILTER_FULL_POSITIVE; | |
4825 | case 0x64: | |
4826 | return rocksdb::Tickers::BLOOM_FILTER_FULL_TRUE_POSITIVE; | |
4827 | case 0x65: | |
4828 | return rocksdb::Tickers::BLOB_DB_NUM_PUT; | |
4829 | case 0x66: | |
4830 | return rocksdb::Tickers::BLOB_DB_NUM_WRITE; | |
4831 | case 0x67: | |
4832 | return rocksdb::Tickers::BLOB_DB_NUM_GET; | |
4833 | case 0x68: | |
4834 | return rocksdb::Tickers::BLOB_DB_NUM_MULTIGET; | |
4835 | case 0x69: | |
4836 | return rocksdb::Tickers::BLOB_DB_NUM_SEEK; | |
4837 | case 0x6A: | |
4838 | return rocksdb::Tickers::BLOB_DB_NUM_NEXT; | |
4839 | case 0x6B: | |
4840 | return rocksdb::Tickers::BLOB_DB_NUM_PREV; | |
4841 | case 0x6C: | |
4842 | return rocksdb::Tickers::BLOB_DB_NUM_KEYS_WRITTEN; | |
4843 | case 0x6D: | |
4844 | return rocksdb::Tickers::BLOB_DB_NUM_KEYS_READ; | |
4845 | case 0x6E: | |
4846 | return rocksdb::Tickers::BLOB_DB_BYTES_WRITTEN; | |
4847 | case 0x6F: | |
4848 | return rocksdb::Tickers::BLOB_DB_BYTES_READ; | |
4849 | case 0x70: | |
4850 | return rocksdb::Tickers::BLOB_DB_WRITE_INLINED; | |
4851 | case 0x71: | |
4852 | return rocksdb::Tickers::BLOB_DB_WRITE_INLINED_TTL; | |
4853 | case 0x72: | |
4854 | return rocksdb::Tickers::BLOB_DB_WRITE_BLOB; | |
4855 | case 0x73: | |
4856 | return rocksdb::Tickers::BLOB_DB_WRITE_BLOB_TTL; | |
4857 | case 0x74: | |
4858 | return rocksdb::Tickers::BLOB_DB_BLOB_FILE_BYTES_WRITTEN; | |
4859 | case 0x75: | |
4860 | return rocksdb::Tickers::BLOB_DB_BLOB_FILE_BYTES_READ; | |
4861 | case 0x76: | |
4862 | return rocksdb::Tickers::BLOB_DB_BLOB_FILE_SYNCED; | |
4863 | case 0x77: | |
4864 | return rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_COUNT; | |
4865 | case 0x78: | |
4866 | return rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_SIZE; | |
4867 | case 0x79: | |
4868 | return rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_COUNT; | |
4869 | case 0x7A: | |
4870 | return rocksdb::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_SIZE; | |
4871 | case 0x7B: | |
4872 | return rocksdb::Tickers::BLOB_DB_GC_NUM_FILES; | |
4873 | case 0x7C: | |
4874 | return rocksdb::Tickers::BLOB_DB_GC_NUM_NEW_FILES; | |
4875 | case 0x7D: | |
4876 | return rocksdb::Tickers::BLOB_DB_GC_FAILURES; | |
4877 | case 0x7E: | |
4878 | return rocksdb::Tickers::BLOB_DB_GC_NUM_KEYS_OVERWRITTEN; | |
4879 | case 0x7F: | |
4880 | return rocksdb::Tickers::BLOB_DB_GC_NUM_KEYS_EXPIRED; | |
4881 | case -0x02: | |
4882 | return rocksdb::Tickers::BLOB_DB_GC_NUM_KEYS_RELOCATED; | |
4883 | case -0x03: | |
4884 | return rocksdb::Tickers::BLOB_DB_GC_BYTES_OVERWRITTEN; | |
4885 | case -0x04: | |
4886 | return rocksdb::Tickers::BLOB_DB_GC_BYTES_EXPIRED; | |
4887 | case -0x05: | |
4888 | return rocksdb::Tickers::BLOB_DB_GC_BYTES_RELOCATED; | |
4889 | case -0x06: | |
4890 | return rocksdb::Tickers::BLOB_DB_FIFO_NUM_FILES_EVICTED; | |
4891 | case -0x07: | |
4892 | return rocksdb::Tickers::BLOB_DB_FIFO_NUM_KEYS_EVICTED; | |
4893 | case -0x08: | |
4894 | return rocksdb::Tickers::BLOB_DB_FIFO_BYTES_EVICTED; | |
4895 | case -0x09: | |
4896 | return rocksdb::Tickers::TXN_PREPARE_MUTEX_OVERHEAD; | |
4897 | case -0x0A: | |
4898 | return rocksdb::Tickers::TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD; | |
4899 | case -0x0B: | |
4900 | return rocksdb::Tickers::TXN_DUPLICATE_KEY_OVERHEAD; | |
4901 | case -0x0C: | |
4902 | return rocksdb::Tickers::TXN_SNAPSHOT_MUTEX_OVERHEAD; | |
11fdf7f2 | 4903 | case 0x5F: |
494da23a | 4904 | // 0x5F for backwards compatibility on current minor version. |
11fdf7f2 TL |
4905 | return rocksdb::Tickers::TICKER_ENUM_MAX; |
4906 | ||
4907 | default: | |
4908 | // undefined/default | |
4909 | return rocksdb::Tickers::BLOCK_CACHE_MISS; | |
4910 | } | |
4911 | } | |
4912 | }; | |
4913 | ||
4914 | // The portal class for org.rocksdb.HistogramType | |
4915 | class HistogramTypeJni { | |
4916 | public: | |
4917 | // Returns the equivalent org.rocksdb.HistogramType for the provided | |
4918 | // C++ rocksdb::Histograms enum | |
4919 | static jbyte toJavaHistogramsType( | |
4920 | const rocksdb::Histograms& histograms) { | |
4921 | switch(histograms) { | |
4922 | case rocksdb::Histograms::DB_GET: | |
4923 | return 0x0; | |
4924 | case rocksdb::Histograms::DB_WRITE: | |
4925 | return 0x1; | |
4926 | case rocksdb::Histograms::COMPACTION_TIME: | |
4927 | return 0x2; | |
4928 | case rocksdb::Histograms::SUBCOMPACTION_SETUP_TIME: | |
4929 | return 0x3; | |
4930 | case rocksdb::Histograms::TABLE_SYNC_MICROS: | |
4931 | return 0x4; | |
4932 | case rocksdb::Histograms::COMPACTION_OUTFILE_SYNC_MICROS: | |
4933 | return 0x5; | |
4934 | case rocksdb::Histograms::WAL_FILE_SYNC_MICROS: | |
4935 | return 0x6; | |
4936 | case rocksdb::Histograms::MANIFEST_FILE_SYNC_MICROS: | |
4937 | return 0x7; | |
4938 | case rocksdb::Histograms::TABLE_OPEN_IO_MICROS: | |
4939 | return 0x8; | |
4940 | case rocksdb::Histograms::DB_MULTIGET: | |
4941 | return 0x9; | |
4942 | case rocksdb::Histograms::READ_BLOCK_COMPACTION_MICROS: | |
4943 | return 0xA; | |
4944 | case rocksdb::Histograms::READ_BLOCK_GET_MICROS: | |
4945 | return 0xB; | |
4946 | case rocksdb::Histograms::WRITE_RAW_BLOCK_MICROS: | |
4947 | return 0xC; | |
4948 | case rocksdb::Histograms::STALL_L0_SLOWDOWN_COUNT: | |
4949 | return 0xD; | |
4950 | case rocksdb::Histograms::STALL_MEMTABLE_COMPACTION_COUNT: | |
4951 | return 0xE; | |
4952 | case rocksdb::Histograms::STALL_L0_NUM_FILES_COUNT: | |
4953 | return 0xF; | |
4954 | case rocksdb::Histograms::HARD_RATE_LIMIT_DELAY_COUNT: | |
4955 | return 0x10; | |
4956 | case rocksdb::Histograms::SOFT_RATE_LIMIT_DELAY_COUNT: | |
4957 | return 0x11; | |
4958 | case rocksdb::Histograms::NUM_FILES_IN_SINGLE_COMPACTION: | |
4959 | return 0x12; | |
4960 | case rocksdb::Histograms::DB_SEEK: | |
4961 | return 0x13; | |
4962 | case rocksdb::Histograms::WRITE_STALL: | |
4963 | return 0x14; | |
4964 | case rocksdb::Histograms::SST_READ_MICROS: | |
4965 | return 0x15; | |
4966 | case rocksdb::Histograms::NUM_SUBCOMPACTIONS_SCHEDULED: | |
4967 | return 0x16; | |
4968 | case rocksdb::Histograms::BYTES_PER_READ: | |
4969 | return 0x17; | |
4970 | case rocksdb::Histograms::BYTES_PER_WRITE: | |
4971 | return 0x18; | |
4972 | case rocksdb::Histograms::BYTES_PER_MULTIGET: | |
4973 | return 0x19; | |
4974 | case rocksdb::Histograms::BYTES_COMPRESSED: | |
4975 | return 0x1A; | |
4976 | case rocksdb::Histograms::BYTES_DECOMPRESSED: | |
4977 | return 0x1B; | |
4978 | case rocksdb::Histograms::COMPRESSION_TIMES_NANOS: | |
4979 | return 0x1C; | |
4980 | case rocksdb::Histograms::DECOMPRESSION_TIMES_NANOS: | |
4981 | return 0x1D; | |
4982 | case rocksdb::Histograms::READ_NUM_MERGE_OPERANDS: | |
4983 | return 0x1E; | |
494da23a | 4984 | // 0x20 to skip 0x1F so TICKER_ENUM_MAX remains unchanged for minor version compatibility. |
11fdf7f2 | 4985 | case rocksdb::Histograms::FLUSH_TIME: |
11fdf7f2 | 4986 | return 0x20; |
494da23a TL |
4987 | case rocksdb::Histograms::BLOB_DB_KEY_SIZE: |
4988 | return 0x21; | |
4989 | case rocksdb::Histograms::BLOB_DB_VALUE_SIZE: | |
4990 | return 0x22; | |
4991 | case rocksdb::Histograms::BLOB_DB_WRITE_MICROS: | |
4992 | return 0x23; | |
4993 | case rocksdb::Histograms::BLOB_DB_GET_MICROS: | |
4994 | return 0x24; | |
4995 | case rocksdb::Histograms::BLOB_DB_MULTIGET_MICROS: | |
4996 | return 0x25; | |
4997 | case rocksdb::Histograms::BLOB_DB_SEEK_MICROS: | |
4998 | return 0x26; | |
4999 | case rocksdb::Histograms::BLOB_DB_NEXT_MICROS: | |
5000 | return 0x27; | |
5001 | case rocksdb::Histograms::BLOB_DB_PREV_MICROS: | |
5002 | return 0x28; | |
5003 | case rocksdb::Histograms::BLOB_DB_BLOB_FILE_WRITE_MICROS: | |
5004 | return 0x29; | |
5005 | case rocksdb::Histograms::BLOB_DB_BLOB_FILE_READ_MICROS: | |
5006 | return 0x2A; | |
5007 | case rocksdb::Histograms::BLOB_DB_BLOB_FILE_SYNC_MICROS: | |
5008 | return 0x2B; | |
5009 | case rocksdb::Histograms::BLOB_DB_GC_MICROS: | |
5010 | return 0x2C; | |
5011 | case rocksdb::Histograms::BLOB_DB_COMPRESSION_MICROS: | |
5012 | return 0x2D; | |
5013 | case rocksdb::Histograms::BLOB_DB_DECOMPRESSION_MICROS: | |
5014 | return 0x2E; | |
5015 | case rocksdb::Histograms::HISTOGRAM_ENUM_MAX: | |
5016 | // 0x1F for backwards compatibility on current minor version. | |
5017 | return 0x1F; | |
11fdf7f2 TL |
5018 | |
5019 | default: | |
5020 | // undefined/default | |
5021 | return 0x0; | |
5022 | } | |
5023 | } | |
5024 | ||
5025 | // Returns the equivalent C++ rocksdb::Histograms enum for the | |
5026 | // provided Java org.rocksdb.HistogramsType | |
5027 | static rocksdb::Histograms toCppHistograms(jbyte jhistograms_type) { | |
5028 | switch(jhistograms_type) { | |
5029 | case 0x0: | |
5030 | return rocksdb::Histograms::DB_GET; | |
5031 | case 0x1: | |
5032 | return rocksdb::Histograms::DB_WRITE; | |
5033 | case 0x2: | |
5034 | return rocksdb::Histograms::COMPACTION_TIME; | |
5035 | case 0x3: | |
5036 | return rocksdb::Histograms::SUBCOMPACTION_SETUP_TIME; | |
5037 | case 0x4: | |
5038 | return rocksdb::Histograms::TABLE_SYNC_MICROS; | |
5039 | case 0x5: | |
5040 | return rocksdb::Histograms::COMPACTION_OUTFILE_SYNC_MICROS; | |
5041 | case 0x6: | |
5042 | return rocksdb::Histograms::WAL_FILE_SYNC_MICROS; | |
5043 | case 0x7: | |
5044 | return rocksdb::Histograms::MANIFEST_FILE_SYNC_MICROS; | |
5045 | case 0x8: | |
5046 | return rocksdb::Histograms::TABLE_OPEN_IO_MICROS; | |
5047 | case 0x9: | |
5048 | return rocksdb::Histograms::DB_MULTIGET; | |
5049 | case 0xA: | |
5050 | return rocksdb::Histograms::READ_BLOCK_COMPACTION_MICROS; | |
5051 | case 0xB: | |
5052 | return rocksdb::Histograms::READ_BLOCK_GET_MICROS; | |
5053 | case 0xC: | |
5054 | return rocksdb::Histograms::WRITE_RAW_BLOCK_MICROS; | |
5055 | case 0xD: | |
5056 | return rocksdb::Histograms::STALL_L0_SLOWDOWN_COUNT; | |
5057 | case 0xE: | |
5058 | return rocksdb::Histograms::STALL_MEMTABLE_COMPACTION_COUNT; | |
5059 | case 0xF: | |
5060 | return rocksdb::Histograms::STALL_L0_NUM_FILES_COUNT; | |
5061 | case 0x10: | |
5062 | return rocksdb::Histograms::HARD_RATE_LIMIT_DELAY_COUNT; | |
5063 | case 0x11: | |
5064 | return rocksdb::Histograms::SOFT_RATE_LIMIT_DELAY_COUNT; | |
5065 | case 0x12: | |
5066 | return rocksdb::Histograms::NUM_FILES_IN_SINGLE_COMPACTION; | |
5067 | case 0x13: | |
5068 | return rocksdb::Histograms::DB_SEEK; | |
5069 | case 0x14: | |
5070 | return rocksdb::Histograms::WRITE_STALL; | |
5071 | case 0x15: | |
5072 | return rocksdb::Histograms::SST_READ_MICROS; | |
5073 | case 0x16: | |
5074 | return rocksdb::Histograms::NUM_SUBCOMPACTIONS_SCHEDULED; | |
5075 | case 0x17: | |
5076 | return rocksdb::Histograms::BYTES_PER_READ; | |
5077 | case 0x18: | |
5078 | return rocksdb::Histograms::BYTES_PER_WRITE; | |
5079 | case 0x19: | |
5080 | return rocksdb::Histograms::BYTES_PER_MULTIGET; | |
5081 | case 0x1A: | |
5082 | return rocksdb::Histograms::BYTES_COMPRESSED; | |
5083 | case 0x1B: | |
5084 | return rocksdb::Histograms::BYTES_DECOMPRESSED; | |
5085 | case 0x1C: | |
5086 | return rocksdb::Histograms::COMPRESSION_TIMES_NANOS; | |
5087 | case 0x1D: | |
5088 | return rocksdb::Histograms::DECOMPRESSION_TIMES_NANOS; | |
5089 | case 0x1E: | |
5090 | return rocksdb::Histograms::READ_NUM_MERGE_OPERANDS; | |
494da23a | 5091 | // 0x20 to skip 0x1F so TICKER_ENUM_MAX remains unchanged for minor version compatibility. |
11fdf7f2 | 5092 | case 0x20: |
494da23a TL |
5093 | return rocksdb::Histograms::FLUSH_TIME; |
5094 | case 0x21: | |
5095 | return rocksdb::Histograms::BLOB_DB_KEY_SIZE; | |
5096 | case 0x22: | |
5097 | return rocksdb::Histograms::BLOB_DB_VALUE_SIZE; | |
5098 | case 0x23: | |
5099 | return rocksdb::Histograms::BLOB_DB_WRITE_MICROS; | |
5100 | case 0x24: | |
5101 | return rocksdb::Histograms::BLOB_DB_GET_MICROS; | |
5102 | case 0x25: | |
5103 | return rocksdb::Histograms::BLOB_DB_MULTIGET_MICROS; | |
5104 | case 0x26: | |
5105 | return rocksdb::Histograms::BLOB_DB_SEEK_MICROS; | |
5106 | case 0x27: | |
5107 | return rocksdb::Histograms::BLOB_DB_NEXT_MICROS; | |
5108 | case 0x28: | |
5109 | return rocksdb::Histograms::BLOB_DB_PREV_MICROS; | |
5110 | case 0x29: | |
5111 | return rocksdb::Histograms::BLOB_DB_BLOB_FILE_WRITE_MICROS; | |
5112 | case 0x2A: | |
5113 | return rocksdb::Histograms::BLOB_DB_BLOB_FILE_READ_MICROS; | |
5114 | case 0x2B: | |
5115 | return rocksdb::Histograms::BLOB_DB_BLOB_FILE_SYNC_MICROS; | |
5116 | case 0x2C: | |
5117 | return rocksdb::Histograms::BLOB_DB_GC_MICROS; | |
5118 | case 0x2D: | |
5119 | return rocksdb::Histograms::BLOB_DB_COMPRESSION_MICROS; | |
5120 | case 0x2E: | |
5121 | return rocksdb::Histograms::BLOB_DB_DECOMPRESSION_MICROS; | |
5122 | case 0x1F: | |
5123 | // 0x1F for backwards compatibility on current minor version. | |
11fdf7f2 TL |
5124 | return rocksdb::Histograms::HISTOGRAM_ENUM_MAX; |
5125 | ||
5126 | default: | |
5127 | // undefined/default | |
5128 | return rocksdb::Histograms::DB_GET; | |
5129 | } | |
5130 | } | |
5131 | }; | |
5132 | ||
5133 | // The portal class for org.rocksdb.StatsLevel | |
5134 | class StatsLevelJni { | |
5135 | public: | |
5136 | // Returns the equivalent org.rocksdb.StatsLevel for the provided | |
5137 | // C++ rocksdb::StatsLevel enum | |
5138 | static jbyte toJavaStatsLevel( | |
5139 | const rocksdb::StatsLevel& stats_level) { | |
5140 | switch(stats_level) { | |
5141 | case rocksdb::StatsLevel::kExceptDetailedTimers: | |
5142 | return 0x0; | |
5143 | case rocksdb::StatsLevel::kExceptTimeForMutex: | |
5144 | return 0x1; | |
5145 | case rocksdb::StatsLevel::kAll: | |
5146 | return 0x2; | |
5147 | ||
5148 | default: | |
5149 | // undefined/default | |
5150 | return 0x0; | |
5151 | } | |
5152 | } | |
5153 | ||
5154 | // Returns the equivalent C++ rocksdb::StatsLevel enum for the | |
5155 | // provided Java org.rocksdb.StatsLevel | |
5156 | static rocksdb::StatsLevel toCppStatsLevel(jbyte jstats_level) { | |
5157 | switch(jstats_level) { | |
5158 | case 0x0: | |
5159 | return rocksdb::StatsLevel::kExceptDetailedTimers; | |
5160 | case 0x1: | |
5161 | return rocksdb::StatsLevel::kExceptTimeForMutex; | |
5162 | case 0x2: | |
5163 | return rocksdb::StatsLevel::kAll; | |
5164 | ||
5165 | default: | |
5166 | // undefined/default | |
5167 | return rocksdb::StatsLevel::kExceptDetailedTimers; | |
5168 | } | |
7c673cae FG |
5169 | } |
5170 | }; | |
5171 | ||
11fdf7f2 TL |
5172 | // The portal class for org.rocksdb.RateLimiterMode |
5173 | class RateLimiterModeJni { | |
7c673cae | 5174 | public: |
11fdf7f2 TL |
5175 | // Returns the equivalent org.rocksdb.RateLimiterMode for the provided |
5176 | // C++ rocksdb::RateLimiter::Mode enum | |
5177 | static jbyte toJavaRateLimiterMode( | |
5178 | const rocksdb::RateLimiter::Mode& rate_limiter_mode) { | |
5179 | switch(rate_limiter_mode) { | |
5180 | case rocksdb::RateLimiter::Mode::kReadsOnly: | |
5181 | return 0x0; | |
5182 | case rocksdb::RateLimiter::Mode::kWritesOnly: | |
5183 | return 0x1; | |
5184 | case rocksdb::RateLimiter::Mode::kAllIo: | |
5185 | return 0x2; | |
7c673cae | 5186 | |
11fdf7f2 TL |
5187 | default: |
5188 | // undefined/default | |
5189 | return 0x1; | |
7c673cae | 5190 | } |
11fdf7f2 | 5191 | } |
7c673cae | 5192 | |
11fdf7f2 TL |
5193 | // Returns the equivalent C++ rocksdb::RateLimiter::Mode enum for the |
5194 | // provided Java org.rocksdb.RateLimiterMode | |
5195 | static rocksdb::RateLimiter::Mode toCppRateLimiterMode(jbyte jrate_limiter_mode) { | |
5196 | switch(jrate_limiter_mode) { | |
5197 | case 0x0: | |
5198 | return rocksdb::RateLimiter::Mode::kReadsOnly; | |
5199 | case 0x1: | |
5200 | return rocksdb::RateLimiter::Mode::kWritesOnly; | |
5201 | case 0x2: | |
5202 | return rocksdb::RateLimiter::Mode::kAllIo; | |
7c673cae | 5203 | |
11fdf7f2 TL |
5204 | default: |
5205 | // undefined/default | |
5206 | return rocksdb::RateLimiter::Mode::kWritesOnly; | |
7c673cae | 5207 | } |
11fdf7f2 TL |
5208 | } |
5209 | }; | |
7c673cae | 5210 | |
494da23a TL |
5211 | // The portal class for org.rocksdb.MemoryUsageType |
5212 | class MemoryUsageTypeJni { | |
5213 | public: | |
5214 | // Returns the equivalent org.rocksdb.MemoryUsageType for the provided | |
5215 | // C++ rocksdb::MemoryUtil::UsageType enum | |
5216 | static jbyte toJavaMemoryUsageType( | |
5217 | const rocksdb::MemoryUtil::UsageType& usage_type) { | |
5218 | switch(usage_type) { | |
5219 | case rocksdb::MemoryUtil::UsageType::kMemTableTotal: | |
5220 | return 0x0; | |
5221 | case rocksdb::MemoryUtil::UsageType::kMemTableUnFlushed: | |
5222 | return 0x1; | |
5223 | case rocksdb::MemoryUtil::UsageType::kTableReadersTotal: | |
5224 | return 0x2; | |
5225 | case rocksdb::MemoryUtil::UsageType::kCacheTotal: | |
5226 | return 0x3; | |
5227 | default: | |
5228 | // undefined: use kNumUsageTypes | |
5229 | return 0x4; | |
5230 | } | |
5231 | } | |
5232 | ||
5233 | // Returns the equivalent C++ rocksdb::MemoryUtil::UsageType enum for the | |
5234 | // provided Java org.rocksdb.MemoryUsageType | |
5235 | static rocksdb::MemoryUtil::UsageType toCppMemoryUsageType( | |
5236 | jbyte usage_type) { | |
5237 | switch(usage_type) { | |
5238 | case 0x0: | |
5239 | return rocksdb::MemoryUtil::UsageType::kMemTableTotal; | |
5240 | case 0x1: | |
5241 | return rocksdb::MemoryUtil::UsageType::kMemTableUnFlushed; | |
5242 | case 0x2: | |
5243 | return rocksdb::MemoryUtil::UsageType::kTableReadersTotal; | |
5244 | case 0x3: | |
5245 | return rocksdb::MemoryUtil::UsageType::kCacheTotal; | |
5246 | default: | |
5247 | // undefined/default: use kNumUsageTypes | |
5248 | return rocksdb::MemoryUtil::UsageType::kNumUsageTypes; | |
5249 | } | |
5250 | } | |
5251 | }; | |
5252 | ||
11fdf7f2 TL |
5253 | // The portal class for org.rocksdb.Transaction |
5254 | class TransactionJni : public JavaClass { | |
5255 | public: | |
7c673cae | 5256 | /** |
11fdf7f2 | 5257 | * Get the Java Class org.rocksdb.Transaction |
7c673cae FG |
5258 | * |
5259 | * @param env A pointer to the Java environment | |
5260 | * | |
5261 | * @return The Java Class or nullptr if one of the | |
5262 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
5263 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
5264 | */ | |
5265 | static jclass getJClass(JNIEnv* env) { | |
11fdf7f2 TL |
5266 | return JavaClass::getJClass(env, |
5267 | "org/rocksdb/Transaction"); | |
7c673cae FG |
5268 | } |
5269 | ||
5270 | /** | |
11fdf7f2 | 5271 | * Create a new Java org.rocksdb.Transaction.WaitingTransactions object |
7c673cae FG |
5272 | * |
5273 | * @param env A pointer to the Java environment | |
11fdf7f2 TL |
5274 | * @param jtransaction A Java org.rocksdb.Transaction object |
5275 | * @param column_family_id The id of the column family | |
5276 | * @param key The key | |
5277 | * @param transaction_ids The transaction ids | |
7c673cae | 5278 | * |
11fdf7f2 TL |
5279 | * @return A reference to a Java |
5280 | * org.rocksdb.Transaction.WaitingTransactions object, | |
5281 | * or nullptr if an an exception occurs | |
7c673cae | 5282 | */ |
11fdf7f2 TL |
5283 | static jobject newWaitingTransactions(JNIEnv* env, jobject jtransaction, |
5284 | const uint32_t column_family_id, const std::string &key, | |
5285 | const std::vector<TransactionID> &transaction_ids) { | |
7c673cae FG |
5286 | jclass jclazz = getJClass(env); |
5287 | if(jclazz == nullptr) { | |
5288 | // exception occurred accessing class | |
5289 | return nullptr; | |
5290 | } | |
5291 | ||
11fdf7f2 TL |
5292 | jmethodID mid = env->GetMethodID( |
5293 | jclazz, "newWaitingTransactions", "(JLjava/lang/String;[J)Lorg/rocksdb/Transaction$WaitingTransactions;"); | |
5294 | if(mid == nullptr) { | |
5295 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
7c673cae | 5296 | return nullptr; |
11fdf7f2 TL |
5297 | } |
5298 | ||
5299 | jstring jkey = env->NewStringUTF(key.c_str()); | |
5300 | if(jkey == nullptr) { | |
5301 | // exception thrown: OutOfMemoryError | |
7c673cae FG |
5302 | return nullptr; |
5303 | } | |
5304 | ||
11fdf7f2 TL |
5305 | const size_t len = transaction_ids.size(); |
5306 | jlongArray jtransaction_ids = env->NewLongArray(static_cast<jsize>(len)); | |
5307 | if(jtransaction_ids == nullptr) { | |
5308 | // exception thrown: OutOfMemoryError | |
5309 | env->DeleteLocalRef(jkey); | |
5310 | return nullptr; | |
5311 | } | |
5312 | ||
5313 | jlong *body = env->GetLongArrayElements(jtransaction_ids, nullptr); | |
5314 | if(body == nullptr) { | |
5315 | // exception thrown: OutOfMemoryError | |
5316 | env->DeleteLocalRef(jkey); | |
5317 | env->DeleteLocalRef(jtransaction_ids); | |
5318 | return nullptr; | |
5319 | } | |
5320 | for(size_t i = 0; i < len; ++i) { | |
5321 | body[i] = static_cast<jlong>(transaction_ids[i]); | |
5322 | } | |
5323 | env->ReleaseLongArrayElements(jtransaction_ids, body, 0); | |
5324 | ||
5325 | jobject jwaiting_transactions = env->CallObjectMethod(jtransaction, | |
5326 | mid, static_cast<jlong>(column_family_id), jkey, jtransaction_ids); | |
5327 | if(env->ExceptionCheck()) { | |
5328 | // exception thrown: InstantiationException or OutOfMemoryError | |
5329 | env->DeleteLocalRef(jkey); | |
5330 | env->DeleteLocalRef(jtransaction_ids); | |
5331 | return nullptr; | |
5332 | } | |
5333 | ||
5334 | return jwaiting_transactions; | |
7c673cae FG |
5335 | } |
5336 | }; | |
5337 | ||
11fdf7f2 TL |
5338 | // The portal class for org.rocksdb.TransactionDB |
5339 | class TransactionDBJni : public JavaClass { | |
7c673cae | 5340 | public: |
11fdf7f2 TL |
5341 | /** |
5342 | * Get the Java Class org.rocksdb.TransactionDB | |
5343 | * | |
5344 | * @param env A pointer to the Java environment | |
5345 | * | |
5346 | * @return The Java Class or nullptr if one of the | |
5347 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
5348 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
5349 | */ | |
5350 | static jclass getJClass(JNIEnv* env) { | |
5351 | return JavaClass::getJClass(env, | |
5352 | "org/rocksdb/TransactionDB"); | |
5353 | } | |
5354 | ||
7c673cae | 5355 | /** |
11fdf7f2 | 5356 | * Create a new Java org.rocksdb.TransactionDB.DeadlockInfo object |
7c673cae FG |
5357 | * |
5358 | * @param env A pointer to the Java environment | |
11fdf7f2 TL |
5359 | * @param jtransaction A Java org.rocksdb.Transaction object |
5360 | * @param column_family_id The id of the column family | |
5361 | * @param key The key | |
5362 | * @param transaction_ids The transaction ids | |
7c673cae | 5363 | * |
11fdf7f2 TL |
5364 | * @return A reference to a Java |
5365 | * org.rocksdb.Transaction.WaitingTransactions object, | |
5366 | * or nullptr if an an exception occurs | |
7c673cae | 5367 | */ |
11fdf7f2 TL |
5368 | static jobject newDeadlockInfo(JNIEnv* env, jobject jtransaction_db, |
5369 | const rocksdb::TransactionID transaction_id, | |
5370 | const uint32_t column_family_id, const std::string &waiting_key, | |
5371 | const bool exclusive) { | |
5372 | jclass jclazz = getJClass(env); | |
5373 | if(jclazz == nullptr) { | |
5374 | // exception occurred accessing class | |
5375 | return nullptr; | |
7c673cae FG |
5376 | } |
5377 | ||
11fdf7f2 TL |
5378 | jmethodID mid = env->GetMethodID( |
5379 | jclazz, "newDeadlockInfo", "(JJLjava/lang/String;Z)Lorg/rocksdb/TransactionDB$DeadlockInfo;"); | |
5380 | if(mid == nullptr) { | |
5381 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
5382 | return nullptr; | |
7c673cae FG |
5383 | } |
5384 | ||
11fdf7f2 TL |
5385 | jstring jwaiting_key = env->NewStringUTF(waiting_key.c_str()); |
5386 | if(jwaiting_key == nullptr) { | |
5387 | // exception thrown: OutOfMemoryError | |
5388 | return nullptr; | |
7c673cae FG |
5389 | } |
5390 | ||
11fdf7f2 TL |
5391 | // resolve the column family id to a ColumnFamilyHandle |
5392 | jobject jdeadlock_info = env->CallObjectMethod(jtransaction_db, | |
5393 | mid, transaction_id, static_cast<jlong>(column_family_id), | |
5394 | jwaiting_key, exclusive); | |
5395 | if(env->ExceptionCheck()) { | |
5396 | // exception thrown: InstantiationException or OutOfMemoryError | |
5397 | env->DeleteLocalRef(jwaiting_key); | |
5398 | return nullptr; | |
7c673cae FG |
5399 | } |
5400 | ||
11fdf7f2 TL |
5401 | return jdeadlock_info; |
5402 | } | |
5403 | }; | |
7c673cae | 5404 | |
11fdf7f2 TL |
5405 | // The portal class for org.rocksdb.TxnDBWritePolicy |
5406 | class TxnDBWritePolicyJni { | |
5407 | public: | |
5408 | // Returns the equivalent org.rocksdb.TxnDBWritePolicy for the provided | |
5409 | // C++ rocksdb::TxnDBWritePolicy enum | |
5410 | static jbyte toJavaTxnDBWritePolicy( | |
5411 | const rocksdb::TxnDBWritePolicy& txndb_write_policy) { | |
5412 | switch(txndb_write_policy) { | |
5413 | case rocksdb::TxnDBWritePolicy::WRITE_COMMITTED: | |
5414 | return 0x0; | |
5415 | case rocksdb::TxnDBWritePolicy::WRITE_PREPARED: | |
5416 | return 0x1; | |
5417 | case rocksdb::TxnDBWritePolicy::WRITE_UNPREPARED: | |
5418 | return 0x2; | |
5419 | default: | |
5420 | return 0x7F; // undefined | |
5421 | } | |
5422 | } | |
5423 | ||
5424 | // Returns the equivalent C++ rocksdb::TxnDBWritePolicy enum for the | |
5425 | // provided Java org.rocksdb.TxnDBWritePolicy | |
5426 | static rocksdb::TxnDBWritePolicy toCppTxnDBWritePolicy( | |
5427 | jbyte jtxndb_write_policy) { | |
5428 | switch(jtxndb_write_policy) { | |
5429 | case 0x0: | |
5430 | return rocksdb::TxnDBWritePolicy::WRITE_COMMITTED; | |
5431 | case 0x1: | |
5432 | return rocksdb::TxnDBWritePolicy::WRITE_PREPARED; | |
5433 | case 0x2: | |
5434 | return rocksdb::TxnDBWritePolicy::WRITE_UNPREPARED; | |
5435 | default: | |
5436 | // undefined/default | |
5437 | return rocksdb::TxnDBWritePolicy::WRITE_COMMITTED; | |
5438 | } | |
5439 | } | |
5440 | }; | |
7c673cae | 5441 | |
11fdf7f2 TL |
5442 | // The portal class for org.rocksdb.TransactionDB.KeyLockInfo |
5443 | class KeyLockInfoJni : public JavaClass { | |
5444 | public: | |
7c673cae | 5445 | /** |
11fdf7f2 | 5446 | * Get the Java Class org.rocksdb.TransactionDB.KeyLockInfo |
7c673cae FG |
5447 | * |
5448 | * @param env A pointer to the Java environment | |
5449 | * | |
5450 | * @return The Java Class or nullptr if one of the | |
5451 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
5452 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
5453 | */ | |
5454 | static jclass getJClass(JNIEnv* env) { | |
11fdf7f2 TL |
5455 | return JavaClass::getJClass(env, |
5456 | "org/rocksdb/TransactionDB$KeyLockInfo"); | |
7c673cae FG |
5457 | } |
5458 | ||
5459 | /** | |
11fdf7f2 TL |
5460 | * Create a new Java org.rocksdb.TransactionDB.KeyLockInfo object |
5461 | * with the same properties as the provided C++ rocksdb::KeyLockInfo object | |
7c673cae FG |
5462 | * |
5463 | * @param env A pointer to the Java environment | |
11fdf7f2 | 5464 | * @param key_lock_info The rocksdb::KeyLockInfo object |
7c673cae | 5465 | * |
11fdf7f2 TL |
5466 | * @return A reference to a Java |
5467 | * org.rocksdb.TransactionDB.KeyLockInfo object, | |
5468 | * or nullptr if an an exception occurs | |
7c673cae | 5469 | */ |
11fdf7f2 TL |
5470 | static jobject construct(JNIEnv* env, |
5471 | const rocksdb::KeyLockInfo& key_lock_info) { | |
7c673cae FG |
5472 | jclass jclazz = getJClass(env); |
5473 | if(jclazz == nullptr) { | |
5474 | // exception occurred accessing class | |
5475 | return nullptr; | |
5476 | } | |
5477 | ||
11fdf7f2 TL |
5478 | jmethodID mid = env->GetMethodID( |
5479 | jclazz, "<init>", "(Ljava/lang/String;[JZ)V"); | |
5480 | if (mid == nullptr) { | |
5481 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
7c673cae | 5482 | return nullptr; |
11fdf7f2 TL |
5483 | } |
5484 | ||
5485 | jstring jkey = env->NewStringUTF(key_lock_info.key.c_str()); | |
5486 | if (jkey == nullptr) { | |
5487 | // exception thrown: OutOfMemoryError | |
7c673cae FG |
5488 | return nullptr; |
5489 | } | |
5490 | ||
11fdf7f2 TL |
5491 | const jsize jtransaction_ids_len = static_cast<jsize>(key_lock_info.ids.size()); |
5492 | jlongArray jtransactions_ids = env->NewLongArray(jtransaction_ids_len); | |
5493 | if (jtransactions_ids == nullptr) { | |
5494 | // exception thrown: OutOfMemoryError | |
5495 | env->DeleteLocalRef(jkey); | |
5496 | return nullptr; | |
5497 | } | |
5498 | ||
5499 | const jobject jkey_lock_info = env->NewObject(jclazz, mid, | |
5500 | jkey, jtransactions_ids, key_lock_info.exclusive); | |
5501 | if(jkey_lock_info == nullptr) { | |
5502 | // exception thrown: InstantiationException or OutOfMemoryError | |
5503 | env->DeleteLocalRef(jtransactions_ids); | |
5504 | env->DeleteLocalRef(jkey); | |
5505 | return nullptr; | |
5506 | } | |
5507 | ||
5508 | return jkey_lock_info; | |
7c673cae FG |
5509 | } |
5510 | }; | |
5511 | ||
11fdf7f2 TL |
5512 | // The portal class for org.rocksdb.TransactionDB.DeadlockInfo |
5513 | class DeadlockInfoJni : public JavaClass { | |
7c673cae FG |
5514 | public: |
5515 | /** | |
11fdf7f2 | 5516 | * Get the Java Class org.rocksdb.TransactionDB.DeadlockInfo |
7c673cae FG |
5517 | * |
5518 | * @param env A pointer to the Java environment | |
5519 | * | |
5520 | * @return The Java Class or nullptr if one of the | |
5521 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
5522 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
5523 | */ | |
11fdf7f2 TL |
5524 | static jclass getJClass(JNIEnv* env) { |
5525 | return JavaClass::getJClass(env,"org/rocksdb/TransactionDB$DeadlockInfo"); | |
7c673cae | 5526 | } |
11fdf7f2 TL |
5527 | }; |
5528 | ||
5529 | // The portal class for org.rocksdb.TransactionDB.DeadlockPath | |
5530 | class DeadlockPathJni : public JavaClass { | |
5531 | public: | |
7c673cae | 5532 | /** |
11fdf7f2 | 5533 | * Get the Java Class org.rocksdb.TransactionDB.DeadlockPath |
7c673cae FG |
5534 | * |
5535 | * @param env A pointer to the Java environment | |
5536 | * | |
5537 | * @return The Java Class or nullptr if one of the | |
5538 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
5539 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
5540 | */ | |
5541 | static jclass getJClass(JNIEnv* env) { | |
5542 | return JavaClass::getJClass(env, | |
11fdf7f2 | 5543 | "org/rocksdb/TransactionDB$DeadlockPath"); |
7c673cae FG |
5544 | } |
5545 | ||
5546 | /** | |
11fdf7f2 | 5547 | * Create a new Java org.rocksdb.TransactionDB.DeadlockPath object |
7c673cae FG |
5548 | * |
5549 | * @param env A pointer to the Java environment | |
7c673cae FG |
5550 | * |
5551 | * @return A reference to a Java | |
11fdf7f2 | 5552 | * org.rocksdb.TransactionDB.DeadlockPath object, |
7c673cae FG |
5553 | * or nullptr if an an exception occurs |
5554 | */ | |
5555 | static jobject construct(JNIEnv* env, | |
11fdf7f2 | 5556 | const jobjectArray jdeadlock_infos, const bool limit_exceeded) { |
7c673cae FG |
5557 | jclass jclazz = getJClass(env); |
5558 | if(jclazz == nullptr) { | |
5559 | // exception occurred accessing class | |
5560 | return nullptr; | |
5561 | } | |
5562 | ||
5563 | jmethodID mid = env->GetMethodID( | |
11fdf7f2 TL |
5564 | jclazz, "<init>", "([LDeadlockInfo;Z)V"); |
5565 | if (mid == nullptr) { | |
7c673cae FG |
5566 | // exception thrown: NoSuchMethodException or OutOfMemoryError |
5567 | return nullptr; | |
5568 | } | |
5569 | ||
11fdf7f2 TL |
5570 | const jobject jdeadlock_path = env->NewObject(jclazz, mid, |
5571 | jdeadlock_infos, limit_exceeded); | |
5572 | if(jdeadlock_path == nullptr) { | |
7c673cae FG |
5573 | // exception thrown: InstantiationException or OutOfMemoryError |
5574 | return nullptr; | |
5575 | } | |
5576 | ||
11fdf7f2 | 5577 | return jdeadlock_path; |
7c673cae FG |
5578 | } |
5579 | }; | |
5580 | ||
494da23a | 5581 | class AbstractTableFilterJni : public RocksDBNativeClass<const rocksdb::TableFilterJniCallback*, AbstractTableFilterJni> { |
7c673cae | 5582 | public: |
494da23a TL |
5583 | /** |
5584 | * Get the Java Method: TableFilter#filter(TableProperties) | |
5585 | * | |
5586 | * @param env A pointer to the Java environment | |
5587 | * | |
5588 | * @return The Java Method ID or nullptr if the class or method id could not | |
5589 | * be retieved | |
5590 | */ | |
5591 | static jmethodID getFilterMethod(JNIEnv* env) { | |
5592 | jclass jclazz = getJClass(env); | |
5593 | if(jclazz == nullptr) { | |
5594 | // exception occurred accessing class | |
5595 | return nullptr; | |
5596 | } | |
7c673cae | 5597 | |
494da23a TL |
5598 | static jmethodID mid = |
5599 | env->GetMethodID(jclazz, "filter", "(Lorg/rocksdb/TableProperties;)Z"); | |
5600 | assert(mid != nullptr); | |
5601 | return mid; | |
5602 | } | |
7c673cae | 5603 | |
494da23a TL |
5604 | private: |
5605 | static jclass getJClass(JNIEnv* env) { | |
5606 | return JavaClass::getJClass(env, "org/rocksdb/TableFilter"); | |
5607 | } | |
5608 | }; | |
5609 | ||
5610 | class TablePropertiesJni : public JavaClass { | |
5611 | public: | |
5612 | /** | |
5613 | * Create a new Java org.rocksdb.TableProperties object. | |
5614 | * | |
5615 | * @param env A pointer to the Java environment | |
5616 | * @param table_properties A Cpp table properties object | |
5617 | * | |
5618 | * @return A reference to a Java org.rocksdb.TableProperties object, or | |
5619 | * nullptr if an an exception occurs | |
5620 | */ | |
5621 | static jobject fromCppTableProperties(JNIEnv* env, const rocksdb::TableProperties& table_properties) { | |
5622 | jclass jclazz = getJClass(env); | |
5623 | if (jclazz == nullptr) { | |
5624 | // exception occurred accessing class | |
5625 | return nullptr; | |
7c673cae FG |
5626 | } |
5627 | ||
494da23a TL |
5628 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JJJJJJJJJJJJJJJJJJJ[BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V"); |
5629 | if (mid == nullptr) { | |
5630 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
5631 | return nullptr; | |
5632 | } | |
5633 | ||
5634 | jbyteArray jcolumn_family_name = rocksdb::JniUtil::copyBytes(env, table_properties.column_family_name); | |
5635 | if (jcolumn_family_name == nullptr) { | |
5636 | // exception occurred creating java string | |
5637 | return nullptr; | |
5638 | } | |
5639 | ||
5640 | jstring jfilter_policy_name = rocksdb::JniUtil::toJavaString(env, &table_properties.filter_policy_name, true); | |
5641 | if (env->ExceptionCheck()) { | |
5642 | // exception occurred creating java string | |
5643 | env->DeleteLocalRef(jcolumn_family_name); | |
5644 | return nullptr; | |
5645 | } | |
5646 | ||
5647 | jstring jcomparator_name = rocksdb::JniUtil::toJavaString(env, &table_properties.comparator_name, true); | |
5648 | if (env->ExceptionCheck()) { | |
5649 | // exception occurred creating java string | |
5650 | env->DeleteLocalRef(jcolumn_family_name); | |
5651 | env->DeleteLocalRef(jfilter_policy_name); | |
5652 | return nullptr; | |
5653 | } | |
5654 | ||
5655 | jstring jmerge_operator_name = rocksdb::JniUtil::toJavaString(env, &table_properties.merge_operator_name, true); | |
5656 | if (env->ExceptionCheck()) { | |
5657 | // exception occurred creating java string | |
5658 | env->DeleteLocalRef(jcolumn_family_name); | |
5659 | env->DeleteLocalRef(jfilter_policy_name); | |
5660 | env->DeleteLocalRef(jcomparator_name); | |
5661 | return nullptr; | |
5662 | } | |
5663 | ||
5664 | jstring jprefix_extractor_name = rocksdb::JniUtil::toJavaString(env, &table_properties.prefix_extractor_name, true); | |
5665 | if (env->ExceptionCheck()) { | |
5666 | // exception occurred creating java string | |
5667 | env->DeleteLocalRef(jcolumn_family_name); | |
5668 | env->DeleteLocalRef(jfilter_policy_name); | |
5669 | env->DeleteLocalRef(jcomparator_name); | |
5670 | env->DeleteLocalRef(jmerge_operator_name); | |
5671 | return nullptr; | |
5672 | } | |
5673 | ||
5674 | jstring jproperty_collectors_names = rocksdb::JniUtil::toJavaString(env, &table_properties.property_collectors_names, true); | |
5675 | if (env->ExceptionCheck()) { | |
5676 | // exception occurred creating java string | |
5677 | env->DeleteLocalRef(jcolumn_family_name); | |
5678 | env->DeleteLocalRef(jfilter_policy_name); | |
5679 | env->DeleteLocalRef(jcomparator_name); | |
5680 | env->DeleteLocalRef(jmerge_operator_name); | |
5681 | env->DeleteLocalRef(jprefix_extractor_name); | |
5682 | return nullptr; | |
5683 | } | |
5684 | ||
5685 | jstring jcompression_name = rocksdb::JniUtil::toJavaString(env, &table_properties.compression_name, true); | |
5686 | if (env->ExceptionCheck()) { | |
5687 | // exception occurred creating java string | |
5688 | env->DeleteLocalRef(jcolumn_family_name); | |
5689 | env->DeleteLocalRef(jfilter_policy_name); | |
5690 | env->DeleteLocalRef(jcomparator_name); | |
5691 | env->DeleteLocalRef(jmerge_operator_name); | |
5692 | env->DeleteLocalRef(jprefix_extractor_name); | |
5693 | env->DeleteLocalRef(jproperty_collectors_names); | |
5694 | return nullptr; | |
5695 | } | |
5696 | ||
5697 | // Map<String, String> | |
5698 | jobject juser_collected_properties = rocksdb::HashMapJni::fromCppMap(env, &table_properties.user_collected_properties); | |
5699 | if (env->ExceptionCheck()) { | |
5700 | // exception occurred creating java map | |
5701 | env->DeleteLocalRef(jcolumn_family_name); | |
5702 | env->DeleteLocalRef(jfilter_policy_name); | |
5703 | env->DeleteLocalRef(jcomparator_name); | |
5704 | env->DeleteLocalRef(jmerge_operator_name); | |
5705 | env->DeleteLocalRef(jprefix_extractor_name); | |
5706 | env->DeleteLocalRef(jproperty_collectors_names); | |
5707 | env->DeleteLocalRef(jcompression_name); | |
5708 | return nullptr; | |
5709 | } | |
5710 | ||
5711 | // Map<String, String> | |
5712 | jobject jreadable_properties = rocksdb::HashMapJni::fromCppMap(env, &table_properties.readable_properties); | |
5713 | if (env->ExceptionCheck()) { | |
5714 | // exception occurred creating java map | |
5715 | env->DeleteLocalRef(jcolumn_family_name); | |
5716 | env->DeleteLocalRef(jfilter_policy_name); | |
5717 | env->DeleteLocalRef(jcomparator_name); | |
5718 | env->DeleteLocalRef(jmerge_operator_name); | |
5719 | env->DeleteLocalRef(jprefix_extractor_name); | |
5720 | env->DeleteLocalRef(jproperty_collectors_names); | |
5721 | env->DeleteLocalRef(jcompression_name); | |
5722 | env->DeleteLocalRef(juser_collected_properties); | |
5723 | return nullptr; | |
5724 | } | |
5725 | ||
5726 | // Map<String, Long> | |
5727 | jobject jproperties_offsets = rocksdb::HashMapJni::fromCppMap(env, &table_properties.properties_offsets); | |
5728 | if (env->ExceptionCheck()) { | |
5729 | // exception occurred creating java map | |
5730 | env->DeleteLocalRef(jcolumn_family_name); | |
5731 | env->DeleteLocalRef(jfilter_policy_name); | |
5732 | env->DeleteLocalRef(jcomparator_name); | |
5733 | env->DeleteLocalRef(jmerge_operator_name); | |
5734 | env->DeleteLocalRef(jprefix_extractor_name); | |
5735 | env->DeleteLocalRef(jproperty_collectors_names); | |
5736 | env->DeleteLocalRef(jcompression_name); | |
5737 | env->DeleteLocalRef(juser_collected_properties); | |
5738 | env->DeleteLocalRef(jreadable_properties); | |
5739 | return nullptr; | |
5740 | } | |
5741 | ||
5742 | jobject jtable_properties = env->NewObject(jclazz, mid, | |
5743 | static_cast<jlong>(table_properties.data_size), | |
5744 | static_cast<jlong>(table_properties.index_size), | |
5745 | static_cast<jlong>(table_properties.index_partitions), | |
5746 | static_cast<jlong>(table_properties.top_level_index_size), | |
5747 | static_cast<jlong>(table_properties.index_key_is_user_key), | |
5748 | static_cast<jlong>(table_properties.index_value_is_delta_encoded), | |
5749 | static_cast<jlong>(table_properties.filter_size), | |
5750 | static_cast<jlong>(table_properties.raw_key_size), | |
5751 | static_cast<jlong>(table_properties.raw_value_size), | |
5752 | static_cast<jlong>(table_properties.num_data_blocks), | |
5753 | static_cast<jlong>(table_properties.num_entries), | |
5754 | static_cast<jlong>(table_properties.num_deletions), | |
5755 | static_cast<jlong>(table_properties.num_merge_operands), | |
5756 | static_cast<jlong>(table_properties.num_range_deletions), | |
5757 | static_cast<jlong>(table_properties.format_version), | |
5758 | static_cast<jlong>(table_properties.fixed_key_len), | |
5759 | static_cast<jlong>(table_properties.column_family_id), | |
5760 | static_cast<jlong>(table_properties.creation_time), | |
5761 | static_cast<jlong>(table_properties.oldest_key_time), | |
5762 | jcolumn_family_name, | |
5763 | jfilter_policy_name, | |
5764 | jcomparator_name, | |
5765 | jmerge_operator_name, | |
5766 | jprefix_extractor_name, | |
5767 | jproperty_collectors_names, | |
5768 | jcompression_name, | |
5769 | juser_collected_properties, | |
5770 | jreadable_properties, | |
5771 | jproperties_offsets | |
5772 | ); | |
5773 | ||
5774 | if (env->ExceptionCheck()) { | |
5775 | return nullptr; | |
5776 | } | |
5777 | ||
5778 | return jtable_properties; | |
5779 | } | |
5780 | ||
5781 | private: | |
5782 | static jclass getJClass(JNIEnv* env) { | |
5783 | return JavaClass::getJClass(env, "org/rocksdb/TableProperties"); | |
5784 | } | |
5785 | }; | |
5786 | ||
5787 | class ColumnFamilyDescriptorJni : public JavaClass { | |
5788 | public: | |
5789 | /** | |
5790 | * Get the Java Class org.rocksdb.ColumnFamilyDescriptor | |
5791 | * | |
5792 | * @param env A pointer to the Java environment | |
5793 | * | |
5794 | * @return The Java Class or nullptr if one of the | |
5795 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
5796 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
5797 | */ | |
5798 | static jclass getJClass(JNIEnv* env) { | |
5799 | return JavaClass::getJClass(env, "org/rocksdb/ColumnFamilyDescriptor"); | |
5800 | } | |
5801 | ||
5802 | /** | |
5803 | * Create a new Java org.rocksdb.ColumnFamilyDescriptor object with the same | |
5804 | * properties as the provided C++ rocksdb::ColumnFamilyDescriptor object | |
5805 | * | |
5806 | * @param env A pointer to the Java environment | |
5807 | * @param cfd A pointer to rocksdb::ColumnFamilyDescriptor object | |
5808 | * | |
5809 | * @return A reference to a Java org.rocksdb.ColumnFamilyDescriptor object, or | |
5810 | * nullptr if an an exception occurs | |
5811 | */ | |
5812 | static jobject construct(JNIEnv* env, ColumnFamilyDescriptor* cfd) { | |
5813 | jbyteArray jcf_name = JniUtil::copyBytes(env, cfd->name); | |
5814 | jobject cfopts = ColumnFamilyOptionsJni::construct(env, &(cfd->options)); | |
5815 | ||
5816 | jclass jclazz = getJClass(env); | |
5817 | if (jclazz == nullptr) { | |
5818 | // exception occurred accessing class | |
5819 | return nullptr; | |
7c673cae FG |
5820 | } |
5821 | ||
494da23a TL |
5822 | jmethodID mid = env->GetMethodID(jclazz, "<init>", |
5823 | "([BLorg/rocksdb/ColumnFamilyOptions;)V"); | |
5824 | if (mid == nullptr) { | |
5825 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
5826 | env->DeleteLocalRef(jcf_name); | |
5827 | return nullptr; | |
7c673cae FG |
5828 | } |
5829 | ||
494da23a TL |
5830 | jobject jcfd = env->NewObject(jclazz, mid, jcf_name, cfopts); |
5831 | if (env->ExceptionCheck()) { | |
5832 | env->DeleteLocalRef(jcf_name); | |
5833 | return nullptr; | |
5834 | } | |
7c673cae | 5835 | |
494da23a TL |
5836 | return jcfd; |
5837 | } | |
7c673cae | 5838 | |
494da23a TL |
5839 | /** |
5840 | * Get the Java Method: ColumnFamilyDescriptor#columnFamilyName | |
5841 | * | |
5842 | * @param env A pointer to the Java environment | |
5843 | * | |
5844 | * @return The Java Method ID or nullptr if the class or method id could not | |
5845 | * be retieved | |
5846 | */ | |
5847 | static jmethodID getColumnFamilyNameMethod(JNIEnv* env) { | |
5848 | jclass jclazz = getJClass(env); | |
5849 | if (jclazz == nullptr) { | |
5850 | // exception occurred accessing class | |
5851 | return nullptr; | |
5852 | } | |
7c673cae | 5853 | |
494da23a TL |
5854 | static jmethodID mid = env->GetMethodID(jclazz, "columnFamilyName", "()[B"); |
5855 | assert(mid != nullptr); | |
5856 | return mid; | |
5857 | } | |
7c673cae | 5858 | |
494da23a TL |
5859 | /** |
5860 | * Get the Java Method: ColumnFamilyDescriptor#columnFamilyOptions | |
5861 | * | |
5862 | * @param env A pointer to the Java environment | |
5863 | * | |
5864 | * @return The Java Method ID or nullptr if the class or method id could not | |
5865 | * be retieved | |
5866 | */ | |
5867 | static jmethodID getColumnFamilyOptionsMethod(JNIEnv* env) { | |
5868 | jclass jclazz = getJClass(env); | |
5869 | if (jclazz == nullptr) { | |
5870 | // exception occurred accessing class | |
5871 | return nullptr; | |
11fdf7f2 TL |
5872 | } |
5873 | ||
494da23a TL |
5874 | static jmethodID mid = env->GetMethodID( |
5875 | jclazz, "columnFamilyOptions", "()Lorg/rocksdb/ColumnFamilyOptions;"); | |
5876 | assert(mid != nullptr); | |
5877 | return mid; | |
5878 | } | |
5879 | }; | |
11fdf7f2 | 5880 | |
494da23a TL |
5881 | // The portal class for org.rocksdb.IndexType |
5882 | class IndexTypeJni { | |
5883 | public: | |
5884 | // Returns the equivalent org.rocksdb.IndexType for the provided | |
5885 | // C++ rocksdb::IndexType enum | |
5886 | static jbyte toJavaIndexType( | |
5887 | const rocksdb::BlockBasedTableOptions::IndexType& index_type) { | |
5888 | switch(index_type) { | |
5889 | case rocksdb::BlockBasedTableOptions::IndexType::kBinarySearch: | |
5890 | return 0x0; | |
5891 | case rocksdb::BlockBasedTableOptions::IndexType::kHashSearch: | |
5892 | return 0x1; | |
5893 | case rocksdb::BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch: | |
5894 | return 0x2; | |
5895 | default: | |
5896 | return 0x7F; // undefined | |
5897 | } | |
5898 | } | |
7c673cae | 5899 | |
494da23a TL |
5900 | // Returns the equivalent C++ rocksdb::IndexType enum for the |
5901 | // provided Java org.rocksdb.IndexType | |
5902 | static rocksdb::BlockBasedTableOptions::IndexType toCppIndexType( | |
5903 | jbyte jindex_type) { | |
5904 | switch(jindex_type) { | |
5905 | case 0x0: | |
5906 | return rocksdb::BlockBasedTableOptions::IndexType::kBinarySearch; | |
5907 | case 0x1: | |
5908 | return rocksdb::BlockBasedTableOptions::IndexType::kHashSearch; | |
5909 | case 0x2: | |
5910 | return rocksdb::BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch; | |
5911 | default: | |
5912 | // undefined/default | |
5913 | return rocksdb::BlockBasedTableOptions::IndexType::kBinarySearch; | |
5914 | } | |
5915 | } | |
5916 | }; | |
7c673cae | 5917 | |
494da23a TL |
5918 | // The portal class for org.rocksdb.DataBlockIndexType |
5919 | class DataBlockIndexTypeJni { | |
5920 | public: | |
5921 | // Returns the equivalent org.rocksdb.DataBlockIndexType for the provided | |
5922 | // C++ rocksdb::DataBlockIndexType enum | |
5923 | static jbyte toJavaDataBlockIndexType( | |
5924 | const rocksdb::BlockBasedTableOptions::DataBlockIndexType& index_type) { | |
5925 | switch(index_type) { | |
5926 | case rocksdb::BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinarySearch: | |
5927 | return 0x0; | |
5928 | case rocksdb::BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinaryAndHash: | |
5929 | return 0x1; | |
5930 | default: | |
5931 | return 0x7F; // undefined | |
5932 | } | |
5933 | } | |
7c673cae | 5934 | |
494da23a TL |
5935 | // Returns the equivalent C++ rocksdb::DataBlockIndexType enum for the |
5936 | // provided Java org.rocksdb.DataBlockIndexType | |
5937 | static rocksdb::BlockBasedTableOptions::DataBlockIndexType toCppDataBlockIndexType( | |
5938 | jbyte jindex_type) { | |
5939 | switch(jindex_type) { | |
5940 | case 0x0: | |
5941 | return rocksdb::BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinarySearch; | |
5942 | case 0x1: | |
5943 | return rocksdb::BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinaryAndHash; | |
5944 | default: | |
5945 | // undefined/default | |
5946 | return rocksdb::BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinarySearch; | |
5947 | } | |
5948 | } | |
5949 | }; | |
7c673cae | 5950 | |
494da23a TL |
5951 | // The portal class for org.rocksdb.ChecksumType |
5952 | class ChecksumTypeJni { | |
5953 | public: | |
5954 | // Returns the equivalent org.rocksdb.ChecksumType for the provided | |
5955 | // C++ rocksdb::ChecksumType enum | |
5956 | static jbyte toJavaChecksumType( | |
5957 | const rocksdb::ChecksumType& checksum_type) { | |
5958 | switch(checksum_type) { | |
5959 | case rocksdb::ChecksumType::kNoChecksum: | |
5960 | return 0x0; | |
5961 | case rocksdb::ChecksumType::kCRC32c: | |
5962 | return 0x1; | |
5963 | case rocksdb::ChecksumType::kxxHash: | |
5964 | return 0x2; | |
5965 | case rocksdb::ChecksumType::kxxHash64: | |
5966 | return 0x3; | |
5967 | default: | |
5968 | return 0x7F; // undefined | |
5969 | } | |
5970 | } | |
5971 | ||
5972 | // Returns the equivalent C++ rocksdb::ChecksumType enum for the | |
5973 | // provided Java org.rocksdb.ChecksumType | |
5974 | static rocksdb::ChecksumType toCppChecksumType( | |
5975 | jbyte jchecksum_type) { | |
5976 | switch(jchecksum_type) { | |
5977 | case 0x0: | |
5978 | return rocksdb::ChecksumType::kNoChecksum; | |
5979 | case 0x1: | |
5980 | return rocksdb::ChecksumType::kCRC32c; | |
5981 | case 0x2: | |
5982 | return rocksdb::ChecksumType::kxxHash; | |
5983 | case 0x3: | |
5984 | return rocksdb::ChecksumType::kxxHash64; | |
5985 | default: | |
5986 | // undefined/default | |
5987 | return rocksdb::ChecksumType::kCRC32c; | |
5988 | } | |
5989 | } | |
5990 | }; | |
7c673cae | 5991 | |
494da23a TL |
5992 | // The portal class for org.rocksdb.Priority |
5993 | class PriorityJni { | |
5994 | public: | |
5995 | // Returns the equivalent org.rocksdb.Priority for the provided | |
5996 | // C++ rocksdb::Env::Priority enum | |
5997 | static jbyte toJavaPriority( | |
5998 | const rocksdb::Env::Priority& priority) { | |
5999 | switch(priority) { | |
6000 | case rocksdb::Env::Priority::BOTTOM: | |
6001 | return 0x0; | |
6002 | case rocksdb::Env::Priority::LOW: | |
6003 | return 0x1; | |
6004 | case rocksdb::Env::Priority::HIGH: | |
6005 | return 0x2; | |
6006 | case rocksdb::Env::Priority::TOTAL: | |
6007 | return 0x3; | |
6008 | default: | |
6009 | return 0x7F; // undefined | |
6010 | } | |
6011 | } | |
7c673cae | 6012 | |
494da23a TL |
6013 | // Returns the equivalent C++ rocksdb::env::Priority enum for the |
6014 | // provided Java org.rocksdb.Priority | |
6015 | static rocksdb::Env::Priority toCppPriority( | |
6016 | jbyte jpriority) { | |
6017 | switch(jpriority) { | |
6018 | case 0x0: | |
6019 | return rocksdb::Env::Priority::BOTTOM; | |
6020 | case 0x1: | |
6021 | return rocksdb::Env::Priority::LOW; | |
6022 | case 0x2: | |
6023 | return rocksdb::Env::Priority::HIGH; | |
6024 | case 0x3: | |
6025 | return rocksdb::Env::Priority::TOTAL; | |
6026 | default: | |
6027 | // undefined/default | |
6028 | return rocksdb::Env::Priority::LOW; | |
6029 | } | |
6030 | } | |
6031 | }; | |
7c673cae | 6032 | |
494da23a TL |
6033 | // The portal class for org.rocksdb.ThreadType |
6034 | class ThreadTypeJni { | |
6035 | public: | |
6036 | // Returns the equivalent org.rocksdb.ThreadType for the provided | |
6037 | // C++ rocksdb::ThreadStatus::ThreadType enum | |
6038 | static jbyte toJavaThreadType( | |
6039 | const rocksdb::ThreadStatus::ThreadType& thread_type) { | |
6040 | switch(thread_type) { | |
6041 | case rocksdb::ThreadStatus::ThreadType::HIGH_PRIORITY: | |
6042 | return 0x0; | |
6043 | case rocksdb::ThreadStatus::ThreadType::LOW_PRIORITY: | |
6044 | return 0x1; | |
6045 | case rocksdb::ThreadStatus::ThreadType::USER: | |
6046 | return 0x2; | |
6047 | case rocksdb::ThreadStatus::ThreadType::BOTTOM_PRIORITY: | |
6048 | return 0x3; | |
6049 | default: | |
6050 | return 0x7F; // undefined | |
6051 | } | |
6052 | } | |
7c673cae | 6053 | |
494da23a TL |
6054 | // Returns the equivalent C++ rocksdb::ThreadStatus::ThreadType enum for the |
6055 | // provided Java org.rocksdb.ThreadType | |
6056 | static rocksdb::ThreadStatus::ThreadType toCppThreadType( | |
6057 | jbyte jthread_type) { | |
6058 | switch(jthread_type) { | |
6059 | case 0x0: | |
6060 | return rocksdb::ThreadStatus::ThreadType::HIGH_PRIORITY; | |
6061 | case 0x1: | |
6062 | return rocksdb::ThreadStatus::ThreadType::LOW_PRIORITY; | |
6063 | case 0x2: | |
6064 | return ThreadStatus::ThreadType::USER; | |
6065 | case 0x3: | |
6066 | return rocksdb::ThreadStatus::ThreadType::BOTTOM_PRIORITY; | |
6067 | default: | |
6068 | // undefined/default | |
6069 | return rocksdb::ThreadStatus::ThreadType::LOW_PRIORITY; | |
6070 | } | |
6071 | } | |
6072 | }; | |
7c673cae | 6073 | |
494da23a TL |
6074 | // The portal class for org.rocksdb.OperationType |
6075 | class OperationTypeJni { | |
6076 | public: | |
6077 | // Returns the equivalent org.rocksdb.OperationType for the provided | |
6078 | // C++ rocksdb::ThreadStatus::OperationType enum | |
6079 | static jbyte toJavaOperationType( | |
6080 | const rocksdb::ThreadStatus::OperationType& operation_type) { | |
6081 | switch(operation_type) { | |
6082 | case rocksdb::ThreadStatus::OperationType::OP_UNKNOWN: | |
6083 | return 0x0; | |
6084 | case rocksdb::ThreadStatus::OperationType::OP_COMPACTION: | |
6085 | return 0x1; | |
6086 | case rocksdb::ThreadStatus::OperationType::OP_FLUSH: | |
6087 | return 0x2; | |
6088 | default: | |
6089 | return 0x7F; // undefined | |
6090 | } | |
6091 | } | |
7c673cae | 6092 | |
494da23a TL |
6093 | // Returns the equivalent C++ rocksdb::ThreadStatus::OperationType enum for the |
6094 | // provided Java org.rocksdb.OperationType | |
6095 | static rocksdb::ThreadStatus::OperationType toCppOperationType( | |
6096 | jbyte joperation_type) { | |
6097 | switch(joperation_type) { | |
6098 | case 0x0: | |
6099 | return rocksdb::ThreadStatus::OperationType::OP_UNKNOWN; | |
6100 | case 0x1: | |
6101 | return rocksdb::ThreadStatus::OperationType::OP_COMPACTION; | |
6102 | case 0x2: | |
6103 | return rocksdb::ThreadStatus::OperationType::OP_FLUSH; | |
6104 | default: | |
6105 | // undefined/default | |
6106 | return rocksdb::ThreadStatus::OperationType::OP_UNKNOWN; | |
6107 | } | |
6108 | } | |
6109 | }; | |
7c673cae | 6110 | |
494da23a TL |
6111 | // The portal class for org.rocksdb.OperationStage |
6112 | class OperationStageJni { | |
6113 | public: | |
6114 | // Returns the equivalent org.rocksdb.OperationStage for the provided | |
6115 | // C++ rocksdb::ThreadStatus::OperationStage enum | |
6116 | static jbyte toJavaOperationStage( | |
6117 | const rocksdb::ThreadStatus::OperationStage& operation_stage) { | |
6118 | switch(operation_stage) { | |
6119 | case rocksdb::ThreadStatus::OperationStage::STAGE_UNKNOWN: | |
6120 | return 0x0; | |
6121 | case rocksdb::ThreadStatus::OperationStage::STAGE_FLUSH_RUN: | |
6122 | return 0x1; | |
6123 | case rocksdb::ThreadStatus::OperationStage::STAGE_FLUSH_WRITE_L0: | |
6124 | return 0x2; | |
6125 | case rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_PREPARE: | |
6126 | return 0x3; | |
6127 | case rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_RUN: | |
6128 | return 0x4; | |
6129 | case rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_PROCESS_KV: | |
6130 | return 0x5; | |
6131 | case rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_INSTALL: | |
6132 | return 0x6; | |
6133 | case rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_SYNC_FILE: | |
6134 | return 0x7; | |
6135 | case rocksdb::ThreadStatus::OperationStage::STAGE_PICK_MEMTABLES_TO_FLUSH: | |
6136 | return 0x8; | |
6137 | case rocksdb::ThreadStatus::OperationStage::STAGE_MEMTABLE_ROLLBACK: | |
6138 | return 0x9; | |
6139 | case rocksdb::ThreadStatus::OperationStage::STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS: | |
6140 | return 0xA; | |
6141 | default: | |
6142 | return 0x7F; // undefined | |
6143 | } | |
6144 | } | |
11fdf7f2 | 6145 | |
494da23a TL |
6146 | // Returns the equivalent C++ rocksdb::ThreadStatus::OperationStage enum for the |
6147 | // provided Java org.rocksdb.OperationStage | |
6148 | static rocksdb::ThreadStatus::OperationStage toCppOperationStage( | |
6149 | jbyte joperation_stage) { | |
6150 | switch(joperation_stage) { | |
6151 | case 0x0: | |
6152 | return rocksdb::ThreadStatus::OperationStage::STAGE_UNKNOWN; | |
6153 | case 0x1: | |
6154 | return rocksdb::ThreadStatus::OperationStage::STAGE_FLUSH_RUN; | |
6155 | case 0x2: | |
6156 | return rocksdb::ThreadStatus::OperationStage::STAGE_FLUSH_WRITE_L0; | |
6157 | case 0x3: | |
6158 | return rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_PREPARE; | |
6159 | case 0x4: | |
6160 | return rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_RUN; | |
6161 | case 0x5: | |
6162 | return rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_PROCESS_KV; | |
6163 | case 0x6: | |
6164 | return rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_INSTALL; | |
6165 | case 0x7: | |
6166 | return rocksdb::ThreadStatus::OperationStage::STAGE_COMPACTION_SYNC_FILE; | |
6167 | case 0x8: | |
6168 | return rocksdb::ThreadStatus::OperationStage::STAGE_PICK_MEMTABLES_TO_FLUSH; | |
6169 | case 0x9: | |
6170 | return rocksdb::ThreadStatus::OperationStage::STAGE_MEMTABLE_ROLLBACK; | |
6171 | case 0xA: | |
6172 | return rocksdb::ThreadStatus::OperationStage::STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS; | |
6173 | default: | |
6174 | // undefined/default | |
6175 | return rocksdb::ThreadStatus::OperationStage::STAGE_UNKNOWN; | |
6176 | } | |
6177 | } | |
6178 | }; | |
7c673cae | 6179 | |
494da23a TL |
6180 | // The portal class for org.rocksdb.StateType |
6181 | class StateTypeJni { | |
6182 | public: | |
6183 | // Returns the equivalent org.rocksdb.StateType for the provided | |
6184 | // C++ rocksdb::ThreadStatus::StateType enum | |
6185 | static jbyte toJavaStateType( | |
6186 | const rocksdb::ThreadStatus::StateType& state_type) { | |
6187 | switch(state_type) { | |
6188 | case rocksdb::ThreadStatus::StateType::STATE_UNKNOWN: | |
6189 | return 0x0; | |
6190 | case rocksdb::ThreadStatus::StateType::STATE_MUTEX_WAIT: | |
6191 | return 0x1; | |
6192 | default: | |
6193 | return 0x7F; // undefined | |
6194 | } | |
6195 | } | |
7c673cae | 6196 | |
494da23a TL |
6197 | // Returns the equivalent C++ rocksdb::ThreadStatus::StateType enum for the |
6198 | // provided Java org.rocksdb.StateType | |
6199 | static rocksdb::ThreadStatus::StateType toCppStateType( | |
6200 | jbyte jstate_type) { | |
6201 | switch(jstate_type) { | |
6202 | case 0x0: | |
6203 | return rocksdb::ThreadStatus::StateType::STATE_UNKNOWN; | |
6204 | case 0x1: | |
6205 | return rocksdb::ThreadStatus::StateType::STATE_MUTEX_WAIT; | |
6206 | default: | |
6207 | // undefined/default | |
6208 | return rocksdb::ThreadStatus::StateType::STATE_UNKNOWN; | |
6209 | } | |
6210 | } | |
6211 | }; | |
7c673cae | 6212 | |
494da23a TL |
6213 | // The portal class for org.rocksdb.ThreadStatus |
6214 | class ThreadStatusJni : public JavaClass { | |
6215 | public: | |
6216 | /** | |
6217 | * Get the Java Class org.rocksdb.ThreadStatus | |
6218 | * | |
6219 | * @param env A pointer to the Java environment | |
6220 | * | |
6221 | * @return The Java Class or nullptr if one of the | |
6222 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
6223 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
6224 | */ | |
6225 | static jclass getJClass(JNIEnv* env) { | |
6226 | return JavaClass::getJClass(env, | |
6227 | "org/rocksdb/ThreadStatus"); | |
6228 | } | |
6229 | ||
6230 | /** | |
6231 | * Create a new Java org.rocksdb.ThreadStatus object with the same | |
6232 | * properties as the provided C++ rocksdb::ThreadStatus object | |
6233 | * | |
6234 | * @param env A pointer to the Java environment | |
6235 | * @param thread_status A pointer to rocksdb::ThreadStatus object | |
6236 | * | |
6237 | * @return A reference to a Java org.rocksdb.ColumnFamilyOptions object, or | |
6238 | * nullptr if an an exception occurs | |
6239 | */ | |
6240 | static jobject construct(JNIEnv* env, | |
6241 | const rocksdb::ThreadStatus* thread_status) { | |
6242 | jclass jclazz = getJClass(env); | |
6243 | if(jclazz == nullptr) { | |
6244 | // exception occurred accessing class | |
6245 | return nullptr; | |
7c673cae FG |
6246 | } |
6247 | ||
494da23a TL |
6248 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JBLjava/lang/String;Ljava/lang/String;BJB[JB)V"); |
6249 | if (mid == nullptr) { | |
6250 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
6251 | return nullptr; | |
6252 | } | |
6253 | ||
6254 | jstring jdb_name = | |
6255 | JniUtil::toJavaString(env, &(thread_status->db_name), true); | |
6256 | if (env->ExceptionCheck()) { | |
6257 | // an error occurred | |
7c673cae | 6258 | return nullptr; |
494da23a | 6259 | } |
7c673cae | 6260 | |
494da23a TL |
6261 | jstring jcf_name = |
6262 | JniUtil::toJavaString(env, &(thread_status->cf_name), true); | |
6263 | if (env->ExceptionCheck()) { | |
6264 | // an error occurred | |
6265 | env->DeleteLocalRef(jdb_name); | |
6266 | return nullptr; | |
6267 | } | |
7c673cae | 6268 | |
494da23a TL |
6269 | // long[] |
6270 | const jsize len = static_cast<jsize>(rocksdb::ThreadStatus::kNumOperationProperties); | |
6271 | jlongArray joperation_properties = | |
6272 | env->NewLongArray(len); | |
6273 | if (joperation_properties == nullptr) { | |
6274 | // an exception occurred | |
6275 | env->DeleteLocalRef(jdb_name); | |
6276 | env->DeleteLocalRef(jcf_name); | |
6277 | return nullptr; | |
6278 | } | |
6279 | jlong *body = env->GetLongArrayElements(joperation_properties, nullptr); | |
6280 | if (body == nullptr) { | |
7c673cae | 6281 | // exception thrown: OutOfMemoryError |
494da23a TL |
6282 | env->DeleteLocalRef(jdb_name); |
6283 | env->DeleteLocalRef(jcf_name); | |
6284 | env->DeleteLocalRef(joperation_properties); | |
7c673cae | 6285 | return nullptr; |
494da23a TL |
6286 | } |
6287 | for (size_t i = 0; i < len; ++i) { | |
6288 | body[i] = static_cast<jlong>(thread_status->op_properties[i]); | |
6289 | } | |
6290 | env->ReleaseLongArrayElements(joperation_properties, body, 0); | |
6291 | ||
6292 | jobject jcfd = env->NewObject(jclazz, mid, | |
6293 | static_cast<jlong>(thread_status->thread_id), | |
6294 | ThreadTypeJni::toJavaThreadType(thread_status->thread_type), | |
6295 | jdb_name, | |
6296 | jcf_name, | |
6297 | OperationTypeJni::toJavaOperationType(thread_status->operation_type), | |
6298 | static_cast<jlong>(thread_status->op_elapsed_micros), | |
6299 | OperationStageJni::toJavaOperationStage(thread_status->operation_stage), | |
6300 | joperation_properties, | |
6301 | StateTypeJni::toJavaStateType(thread_status->state_type)); | |
6302 | if (env->ExceptionCheck()) { | |
6303 | // exception occurred | |
6304 | env->DeleteLocalRef(jdb_name); | |
6305 | env->DeleteLocalRef(jcf_name); | |
6306 | env->DeleteLocalRef(joperation_properties); | |
6307 | return nullptr; | |
6308 | } | |
7c673cae | 6309 | |
494da23a TL |
6310 | // cleanup |
6311 | env->DeleteLocalRef(jdb_name); | |
6312 | env->DeleteLocalRef(jcf_name); | |
6313 | env->DeleteLocalRef(joperation_properties); | |
7c673cae | 6314 | |
494da23a TL |
6315 | return jcfd; |
6316 | } | |
6317 | }; | |
6318 | ||
6319 | // The portal class for org.rocksdb.CompactionStyle | |
6320 | class CompactionStyleJni { | |
6321 | public: | |
6322 | // Returns the equivalent org.rocksdb.CompactionStyle for the provided | |
6323 | // C++ rocksdb::CompactionStyle enum | |
6324 | static jbyte toJavaCompactionStyle( | |
6325 | const rocksdb::CompactionStyle& compaction_style) { | |
6326 | switch(compaction_style) { | |
6327 | case rocksdb::CompactionStyle::kCompactionStyleLevel: | |
6328 | return 0x0; | |
6329 | case rocksdb::CompactionStyle::kCompactionStyleUniversal: | |
6330 | return 0x1; | |
6331 | case rocksdb::CompactionStyle::kCompactionStyleFIFO: | |
6332 | return 0x2; | |
6333 | case rocksdb::CompactionStyle::kCompactionStyleNone: | |
6334 | return 0x3; | |
6335 | default: | |
6336 | return 0x7F; // undefined | |
6337 | } | |
6338 | } | |
6339 | ||
6340 | // Returns the equivalent C++ rocksdb::CompactionStyle enum for the | |
6341 | // provided Java org.rocksdb.CompactionStyle | |
6342 | static rocksdb::CompactionStyle toCppCompactionStyle( | |
6343 | jbyte jcompaction_style) { | |
6344 | switch(jcompaction_style) { | |
6345 | case 0x0: | |
6346 | return rocksdb::CompactionStyle::kCompactionStyleLevel; | |
6347 | case 0x1: | |
6348 | return rocksdb::CompactionStyle::kCompactionStyleUniversal; | |
6349 | case 0x2: | |
6350 | return rocksdb::CompactionStyle::kCompactionStyleFIFO; | |
6351 | case 0x3: | |
6352 | return rocksdb::CompactionStyle::kCompactionStyleNone; | |
6353 | default: | |
6354 | // undefined/default | |
6355 | return rocksdb::CompactionStyle::kCompactionStyleLevel; | |
6356 | } | |
6357 | } | |
6358 | }; | |
6359 | ||
6360 | // The portal class for org.rocksdb.CompactionReason | |
6361 | class CompactionReasonJni { | |
6362 | public: | |
6363 | // Returns the equivalent org.rocksdb.CompactionReason for the provided | |
6364 | // C++ rocksdb::CompactionReason enum | |
6365 | static jbyte toJavaCompactionReason( | |
6366 | const rocksdb::CompactionReason& compaction_reason) { | |
6367 | switch(compaction_reason) { | |
6368 | case rocksdb::CompactionReason::kUnknown: | |
6369 | return 0x0; | |
6370 | case rocksdb::CompactionReason::kLevelL0FilesNum: | |
6371 | return 0x1; | |
6372 | case rocksdb::CompactionReason::kLevelMaxLevelSize: | |
6373 | return 0x2; | |
6374 | case rocksdb::CompactionReason::kUniversalSizeAmplification: | |
6375 | return 0x3; | |
6376 | case rocksdb::CompactionReason::kUniversalSizeRatio: | |
6377 | return 0x4; | |
6378 | case rocksdb::CompactionReason::kUniversalSortedRunNum: | |
6379 | return 0x5; | |
6380 | case rocksdb::CompactionReason::kFIFOMaxSize: | |
6381 | return 0x6; | |
6382 | case rocksdb::CompactionReason::kFIFOReduceNumFiles: | |
6383 | return 0x7; | |
6384 | case rocksdb::CompactionReason::kFIFOTtl: | |
6385 | return 0x8; | |
6386 | case rocksdb::CompactionReason::kManualCompaction: | |
6387 | return 0x9; | |
6388 | case rocksdb::CompactionReason::kFilesMarkedForCompaction: | |
6389 | return 0x10; | |
6390 | case rocksdb::CompactionReason::kBottommostFiles: | |
6391 | return 0x0A; | |
6392 | case rocksdb::CompactionReason::kTtl: | |
6393 | return 0x0B; | |
6394 | case rocksdb::CompactionReason::kFlush: | |
6395 | return 0x0C; | |
6396 | case rocksdb::CompactionReason::kExternalSstIngestion: | |
6397 | return 0x0D; | |
6398 | default: | |
6399 | return 0x7F; // undefined | |
6400 | } | |
6401 | } | |
6402 | ||
6403 | // Returns the equivalent C++ rocksdb::CompactionReason enum for the | |
6404 | // provided Java org.rocksdb.CompactionReason | |
6405 | static rocksdb::CompactionReason toCppCompactionReason( | |
6406 | jbyte jcompaction_reason) { | |
6407 | switch(jcompaction_reason) { | |
6408 | case 0x0: | |
6409 | return rocksdb::CompactionReason::kUnknown; | |
6410 | case 0x1: | |
6411 | return rocksdb::CompactionReason::kLevelL0FilesNum; | |
6412 | case 0x2: | |
6413 | return rocksdb::CompactionReason::kLevelMaxLevelSize; | |
6414 | case 0x3: | |
6415 | return rocksdb::CompactionReason::kUniversalSizeAmplification; | |
6416 | case 0x4: | |
6417 | return rocksdb::CompactionReason::kUniversalSizeRatio; | |
6418 | case 0x5: | |
6419 | return rocksdb::CompactionReason::kUniversalSortedRunNum; | |
6420 | case 0x6: | |
6421 | return rocksdb::CompactionReason::kFIFOMaxSize; | |
6422 | case 0x7: | |
6423 | return rocksdb::CompactionReason::kFIFOReduceNumFiles; | |
6424 | case 0x8: | |
6425 | return rocksdb::CompactionReason::kFIFOTtl; | |
6426 | case 0x9: | |
6427 | return rocksdb::CompactionReason::kManualCompaction; | |
6428 | case 0x10: | |
6429 | return rocksdb::CompactionReason::kFilesMarkedForCompaction; | |
6430 | case 0x0A: | |
6431 | return rocksdb::CompactionReason::kBottommostFiles; | |
6432 | case 0x0B: | |
6433 | return rocksdb::CompactionReason::kTtl; | |
6434 | case 0x0C: | |
6435 | return rocksdb::CompactionReason::kFlush; | |
6436 | case 0x0D: | |
6437 | return rocksdb::CompactionReason::kExternalSstIngestion; | |
6438 | default: | |
6439 | // undefined/default | |
6440 | return rocksdb::CompactionReason::kUnknown; | |
6441 | } | |
6442 | } | |
6443 | }; | |
7c673cae | 6444 | |
494da23a TL |
6445 | // The portal class for org.rocksdb.WalFileType |
6446 | class WalFileTypeJni { | |
6447 | public: | |
6448 | // Returns the equivalent org.rocksdb.WalFileType for the provided | |
6449 | // C++ rocksdb::WalFileType enum | |
6450 | static jbyte toJavaWalFileType( | |
6451 | const rocksdb::WalFileType& wal_file_type) { | |
6452 | switch(wal_file_type) { | |
6453 | case rocksdb::WalFileType::kArchivedLogFile: | |
6454 | return 0x0; | |
6455 | case rocksdb::WalFileType::kAliveLogFile: | |
6456 | return 0x1; | |
6457 | default: | |
6458 | return 0x7F; // undefined | |
6459 | } | |
6460 | } | |
7c673cae | 6461 | |
494da23a TL |
6462 | // Returns the equivalent C++ rocksdb::WalFileType enum for the |
6463 | // provided Java org.rocksdb.WalFileType | |
6464 | static rocksdb::WalFileType toCppWalFileType( | |
6465 | jbyte jwal_file_type) { | |
6466 | switch(jwal_file_type) { | |
6467 | case 0x0: | |
6468 | return rocksdb::WalFileType::kArchivedLogFile; | |
6469 | case 0x1: | |
6470 | return rocksdb::WalFileType::kAliveLogFile; | |
6471 | default: | |
6472 | // undefined/default | |
6473 | return rocksdb::WalFileType::kAliveLogFile; | |
6474 | } | |
6475 | } | |
6476 | }; | |
7c673cae | 6477 | |
494da23a TL |
6478 | class LogFileJni : public JavaClass { |
6479 | public: | |
6480 | /** | |
6481 | * Create a new Java org.rocksdb.LogFile object. | |
6482 | * | |
6483 | * @param env A pointer to the Java environment | |
6484 | * @param log_file A Cpp log file object | |
6485 | * | |
6486 | * @return A reference to a Java org.rocksdb.LogFile object, or | |
6487 | * nullptr if an an exception occurs | |
6488 | */ | |
6489 | static jobject fromCppLogFile(JNIEnv* env, rocksdb::LogFile* log_file) { | |
6490 | jclass jclazz = getJClass(env); | |
6491 | if (jclazz == nullptr) { | |
6492 | // exception occurred accessing class | |
6493 | return nullptr; | |
6494 | } | |
7c673cae | 6495 | |
494da23a TL |
6496 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(Ljava/lang/String;JBJJ)V"); |
6497 | if (mid == nullptr) { | |
6498 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
6499 | return nullptr; | |
7c673cae | 6500 | } |
11fdf7f2 | 6501 | |
494da23a TL |
6502 | std::string path_name = log_file->PathName(); |
6503 | jstring jpath_name = rocksdb::JniUtil::toJavaString(env, &path_name, true); | |
6504 | if (env->ExceptionCheck()) { | |
6505 | // exception occurred creating java string | |
6506 | return nullptr; | |
11fdf7f2 TL |
6507 | } |
6508 | ||
494da23a TL |
6509 | jobject jlog_file = env->NewObject(jclazz, mid, |
6510 | jpath_name, | |
6511 | static_cast<jlong>(log_file->LogNumber()), | |
6512 | rocksdb::WalFileTypeJni::toJavaWalFileType(log_file->Type()), | |
6513 | static_cast<jlong>(log_file->StartSequence()), | |
6514 | static_cast<jlong>(log_file->SizeFileBytes()) | |
6515 | ); | |
6516 | ||
6517 | if (env->ExceptionCheck()) { | |
6518 | env->DeleteLocalRef(jpath_name); | |
6519 | return nullptr; | |
11fdf7f2 | 6520 | } |
7c673cae | 6521 | |
494da23a TL |
6522 | // cleanup |
6523 | env->DeleteLocalRef(jpath_name); | |
7c673cae | 6524 | |
494da23a TL |
6525 | return jlog_file; |
6526 | } | |
7c673cae | 6527 | |
494da23a TL |
6528 | static jclass getJClass(JNIEnv* env) { |
6529 | return JavaClass::getJClass(env, "org/rocksdb/LogFile"); | |
6530 | } | |
6531 | }; | |
7c673cae | 6532 | |
494da23a TL |
6533 | class LiveFileMetaDataJni : public JavaClass { |
6534 | public: | |
6535 | /** | |
6536 | * Create a new Java org.rocksdb.LiveFileMetaData object. | |
6537 | * | |
6538 | * @param env A pointer to the Java environment | |
6539 | * @param live_file_meta_data A Cpp live file meta data object | |
6540 | * | |
6541 | * @return A reference to a Java org.rocksdb.LiveFileMetaData object, or | |
6542 | * nullptr if an an exception occurs | |
6543 | */ | |
6544 | static jobject fromCppLiveFileMetaData(JNIEnv* env, | |
6545 | rocksdb::LiveFileMetaData* live_file_meta_data) { | |
6546 | jclass jclazz = getJClass(env); | |
6547 | if (jclazz == nullptr) { | |
6548 | // exception occurred accessing class | |
6549 | return nullptr; | |
6550 | } | |
7c673cae | 6551 | |
494da23a TL |
6552 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "([BILjava/lang/String;Ljava/lang/String;JJJ[B[BJZJJ)V"); |
6553 | if (mid == nullptr) { | |
6554 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
6555 | return nullptr; | |
6556 | } | |
11fdf7f2 | 6557 | |
494da23a TL |
6558 | jbyteArray jcolumn_family_name = rocksdb::JniUtil::copyBytes( |
6559 | env, live_file_meta_data->column_family_name); | |
6560 | if (jcolumn_family_name == nullptr) { | |
6561 | // exception occurred creating java byte array | |
6562 | return nullptr; | |
7c673cae FG |
6563 | } |
6564 | ||
494da23a TL |
6565 | jstring jfile_name = rocksdb::JniUtil::toJavaString( |
6566 | env, &live_file_meta_data->name, true); | |
6567 | if (env->ExceptionCheck()) { | |
6568 | // exception occurred creating java string | |
6569 | env->DeleteLocalRef(jcolumn_family_name); | |
6570 | return nullptr; | |
6571 | } | |
7c673cae | 6572 | |
494da23a TL |
6573 | jstring jpath = rocksdb::JniUtil::toJavaString( |
6574 | env, &live_file_meta_data->db_path, true); | |
6575 | if (env->ExceptionCheck()) { | |
6576 | // exception occurred creating java string | |
6577 | env->DeleteLocalRef(jcolumn_family_name); | |
6578 | env->DeleteLocalRef(jfile_name); | |
6579 | return nullptr; | |
6580 | } | |
7c673cae | 6581 | |
494da23a TL |
6582 | jbyteArray jsmallest_key = rocksdb::JniUtil::copyBytes( |
6583 | env, live_file_meta_data->smallestkey); | |
6584 | if (jsmallest_key == nullptr) { | |
6585 | // exception occurred creating java byte array | |
6586 | env->DeleteLocalRef(jcolumn_family_name); | |
6587 | env->DeleteLocalRef(jfile_name); | |
6588 | env->DeleteLocalRef(jpath); | |
6589 | return nullptr; | |
6590 | } | |
7c673cae | 6591 | |
494da23a TL |
6592 | jbyteArray jlargest_key = rocksdb::JniUtil::copyBytes( |
6593 | env, live_file_meta_data->largestkey); | |
6594 | if (jlargest_key == nullptr) { | |
6595 | // exception occurred creating java byte array | |
6596 | env->DeleteLocalRef(jcolumn_family_name); | |
6597 | env->DeleteLocalRef(jfile_name); | |
6598 | env->DeleteLocalRef(jpath); | |
6599 | env->DeleteLocalRef(jsmallest_key); | |
6600 | return nullptr; | |
6601 | } | |
11fdf7f2 | 6602 | |
494da23a TL |
6603 | jobject jlive_file_meta_data = env->NewObject(jclazz, mid, |
6604 | jcolumn_family_name, | |
6605 | static_cast<jint>(live_file_meta_data->level), | |
6606 | jfile_name, | |
6607 | jpath, | |
6608 | static_cast<jlong>(live_file_meta_data->size), | |
6609 | static_cast<jlong>(live_file_meta_data->smallest_seqno), | |
6610 | static_cast<jlong>(live_file_meta_data->largest_seqno), | |
6611 | jsmallest_key, | |
6612 | jlargest_key, | |
6613 | static_cast<jlong>(live_file_meta_data->num_reads_sampled), | |
6614 | static_cast<jboolean>(live_file_meta_data->being_compacted), | |
6615 | static_cast<jlong>(live_file_meta_data->num_entries), | |
6616 | static_cast<jlong>(live_file_meta_data->num_deletions) | |
6617 | ); | |
6618 | ||
6619 | if (env->ExceptionCheck()) { | |
6620 | env->DeleteLocalRef(jcolumn_family_name); | |
6621 | env->DeleteLocalRef(jfile_name); | |
6622 | env->DeleteLocalRef(jpath); | |
6623 | env->DeleteLocalRef(jsmallest_key); | |
6624 | env->DeleteLocalRef(jlargest_key); | |
6625 | return nullptr; | |
7c673cae FG |
6626 | } |
6627 | ||
494da23a TL |
6628 | // cleanup |
6629 | env->DeleteLocalRef(jcolumn_family_name); | |
6630 | env->DeleteLocalRef(jfile_name); | |
6631 | env->DeleteLocalRef(jpath); | |
6632 | env->DeleteLocalRef(jsmallest_key); | |
6633 | env->DeleteLocalRef(jlargest_key); | |
7c673cae | 6634 | |
494da23a TL |
6635 | return jlive_file_meta_data; |
6636 | } | |
7c673cae | 6637 | |
494da23a TL |
6638 | static jclass getJClass(JNIEnv* env) { |
6639 | return JavaClass::getJClass(env, "org/rocksdb/LiveFileMetaData"); | |
6640 | } | |
6641 | }; | |
7c673cae | 6642 | |
494da23a TL |
6643 | class SstFileMetaDataJni : public JavaClass { |
6644 | public: | |
6645 | /** | |
6646 | * Create a new Java org.rocksdb.SstFileMetaData object. | |
6647 | * | |
6648 | * @param env A pointer to the Java environment | |
6649 | * @param sst_file_meta_data A Cpp sst file meta data object | |
6650 | * | |
6651 | * @return A reference to a Java org.rocksdb.SstFileMetaData object, or | |
6652 | * nullptr if an an exception occurs | |
6653 | */ | |
6654 | static jobject fromCppSstFileMetaData(JNIEnv* env, | |
6655 | const rocksdb::SstFileMetaData* sst_file_meta_data) { | |
6656 | jclass jclazz = getJClass(env); | |
6657 | if (jclazz == nullptr) { | |
6658 | // exception occurred accessing class | |
6659 | return nullptr; | |
6660 | } | |
7c673cae | 6661 | |
494da23a TL |
6662 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;JJJ[B[BJZJJ)V"); |
6663 | if (mid == nullptr) { | |
6664 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
6665 | return nullptr; | |
6666 | } | |
7c673cae | 6667 | |
494da23a TL |
6668 | jstring jfile_name = rocksdb::JniUtil::toJavaString( |
6669 | env, &sst_file_meta_data->name, true); | |
6670 | if (jfile_name == nullptr) { | |
6671 | // exception occurred creating java byte array | |
6672 | return nullptr; | |
6673 | } | |
7c673cae | 6674 | |
494da23a TL |
6675 | jstring jpath = rocksdb::JniUtil::toJavaString( |
6676 | env, &sst_file_meta_data->db_path, true); | |
6677 | if (jpath == nullptr) { | |
6678 | // exception occurred creating java byte array | |
6679 | env->DeleteLocalRef(jfile_name); | |
6680 | return nullptr; | |
6681 | } | |
7c673cae | 6682 | |
494da23a TL |
6683 | jbyteArray jsmallest_key = rocksdb::JniUtil::copyBytes( |
6684 | env, sst_file_meta_data->smallestkey); | |
6685 | if (jsmallest_key == nullptr) { | |
6686 | // exception occurred creating java byte array | |
6687 | env->DeleteLocalRef(jfile_name); | |
6688 | env->DeleteLocalRef(jpath); | |
6689 | return nullptr; | |
6690 | } | |
7c673cae | 6691 | |
494da23a TL |
6692 | jbyteArray jlargest_key = rocksdb::JniUtil::copyBytes( |
6693 | env, sst_file_meta_data->largestkey); | |
6694 | if (jlargest_key == nullptr) { | |
6695 | // exception occurred creating java byte array | |
6696 | env->DeleteLocalRef(jfile_name); | |
6697 | env->DeleteLocalRef(jpath); | |
6698 | env->DeleteLocalRef(jsmallest_key); | |
6699 | return nullptr; | |
6700 | } | |
6701 | ||
6702 | jobject jsst_file_meta_data = env->NewObject(jclazz, mid, | |
6703 | jfile_name, | |
6704 | jpath, | |
6705 | static_cast<jlong>(sst_file_meta_data->size), | |
6706 | static_cast<jint>(sst_file_meta_data->smallest_seqno), | |
6707 | static_cast<jlong>(sst_file_meta_data->largest_seqno), | |
6708 | jsmallest_key, | |
6709 | jlargest_key, | |
6710 | static_cast<jlong>(sst_file_meta_data->num_reads_sampled), | |
6711 | static_cast<jboolean>(sst_file_meta_data->being_compacted), | |
6712 | static_cast<jlong>(sst_file_meta_data->num_entries), | |
6713 | static_cast<jlong>(sst_file_meta_data->num_deletions) | |
6714 | ); | |
6715 | ||
6716 | if (env->ExceptionCheck()) { | |
6717 | env->DeleteLocalRef(jfile_name); | |
6718 | env->DeleteLocalRef(jpath); | |
6719 | env->DeleteLocalRef(jsmallest_key); | |
6720 | env->DeleteLocalRef(jlargest_key); | |
7c673cae FG |
6721 | return nullptr; |
6722 | } | |
494da23a TL |
6723 | |
6724 | // cleanup | |
6725 | env->DeleteLocalRef(jfile_name); | |
6726 | env->DeleteLocalRef(jpath); | |
6727 | env->DeleteLocalRef(jsmallest_key); | |
6728 | env->DeleteLocalRef(jlargest_key); | |
6729 | ||
6730 | return jsst_file_meta_data; | |
6731 | } | |
6732 | ||
6733 | static jclass getJClass(JNIEnv* env) { | |
6734 | return JavaClass::getJClass(env, "org/rocksdb/SstFileMetaData"); | |
6735 | } | |
7c673cae FG |
6736 | }; |
6737 | ||
494da23a | 6738 | class LevelMetaDataJni : public JavaClass { |
11fdf7f2 TL |
6739 | public: |
6740 | /** | |
494da23a | 6741 | * Create a new Java org.rocksdb.LevelMetaData object. |
11fdf7f2 TL |
6742 | * |
6743 | * @param env A pointer to the Java environment | |
494da23a | 6744 | * @param level_meta_data A Cpp level meta data object |
11fdf7f2 | 6745 | * |
494da23a TL |
6746 | * @return A reference to a Java org.rocksdb.LevelMetaData object, or |
6747 | * nullptr if an an exception occurs | |
11fdf7f2 | 6748 | */ |
494da23a TL |
6749 | static jobject fromCppLevelMetaData(JNIEnv* env, |
6750 | const rocksdb::LevelMetaData* level_meta_data) { | |
6751 | jclass jclazz = getJClass(env); | |
6752 | if (jclazz == nullptr) { | |
6753 | // exception occurred accessing class | |
6754 | return nullptr; | |
6755 | } | |
6756 | ||
6757 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(IJ[Lorg/rocksdb/SstFileMetaData;)V"); | |
6758 | if (mid == nullptr) { | |
6759 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
6760 | return nullptr; | |
6761 | } | |
6762 | ||
6763 | const jsize jlen = | |
6764 | static_cast<jsize>(level_meta_data->files.size()); | |
6765 | jobjectArray jfiles = env->NewObjectArray(jlen, SstFileMetaDataJni::getJClass(env), nullptr); | |
6766 | if (jfiles == nullptr) { | |
6767 | // exception thrown: OutOfMemoryError | |
6768 | return nullptr; | |
6769 | } | |
6770 | ||
6771 | jsize i = 0; | |
6772 | for (auto it = level_meta_data->files.begin(); | |
6773 | it != level_meta_data->files.end(); ++it) { | |
6774 | jobject jfile = SstFileMetaDataJni::fromCppSstFileMetaData(env, &(*it)); | |
6775 | if (jfile == nullptr) { | |
6776 | // exception occurred | |
6777 | env->DeleteLocalRef(jfiles); | |
6778 | return nullptr; | |
6779 | } | |
6780 | env->SetObjectArrayElement(jfiles, i++, jfile); | |
6781 | } | |
6782 | ||
6783 | jobject jlevel_meta_data = env->NewObject(jclazz, mid, | |
6784 | static_cast<jint>(level_meta_data->level), | |
6785 | static_cast<jlong>(level_meta_data->size), | |
6786 | jfiles | |
6787 | ); | |
6788 | ||
6789 | if (env->ExceptionCheck()) { | |
6790 | env->DeleteLocalRef(jfiles); | |
6791 | return nullptr; | |
6792 | } | |
6793 | ||
6794 | // cleanup | |
6795 | env->DeleteLocalRef(jfiles); | |
6796 | ||
6797 | return jlevel_meta_data; | |
6798 | } | |
6799 | ||
11fdf7f2 | 6800 | static jclass getJClass(JNIEnv* env) { |
494da23a | 6801 | return JavaClass::getJClass(env, "org/rocksdb/LevelMetaData"); |
11fdf7f2 | 6802 | } |
494da23a | 6803 | }; |
11fdf7f2 | 6804 | |
494da23a TL |
6805 | class ColumnFamilyMetaDataJni : public JavaClass { |
6806 | public: | |
11fdf7f2 | 6807 | /** |
494da23a | 6808 | * Create a new Java org.rocksdb.ColumnFamilyMetaData object. |
11fdf7f2 TL |
6809 | * |
6810 | * @param env A pointer to the Java environment | |
494da23a | 6811 | * @param column_famly_meta_data A Cpp live file meta data object |
11fdf7f2 | 6812 | * |
494da23a | 6813 | * @return A reference to a Java org.rocksdb.ColumnFamilyMetaData object, or |
11fdf7f2 TL |
6814 | * nullptr if an an exception occurs |
6815 | */ | |
494da23a TL |
6816 | static jobject fromCppColumnFamilyMetaData(JNIEnv* env, |
6817 | const rocksdb::ColumnFamilyMetaData* column_famly_meta_data) { | |
11fdf7f2 TL |
6818 | jclass jclazz = getJClass(env); |
6819 | if (jclazz == nullptr) { | |
6820 | // exception occurred accessing class | |
6821 | return nullptr; | |
6822 | } | |
6823 | ||
494da23a | 6824 | jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JJ[B[Lorg/rocksdb/LevelMetaData;)V"); |
11fdf7f2 TL |
6825 | if (mid == nullptr) { |
6826 | // exception thrown: NoSuchMethodException or OutOfMemoryError | |
11fdf7f2 TL |
6827 | return nullptr; |
6828 | } | |
6829 | ||
494da23a TL |
6830 | jbyteArray jname = rocksdb::JniUtil::copyBytes( |
6831 | env, column_famly_meta_data->name); | |
6832 | if (jname == nullptr) { | |
6833 | // exception occurred creating java byte array | |
6834 | return nullptr; | |
6835 | } | |
6836 | ||
6837 | const jsize jlen = | |
6838 | static_cast<jsize>(column_famly_meta_data->levels.size()); | |
6839 | jobjectArray jlevels = env->NewObjectArray(jlen, LevelMetaDataJni::getJClass(env), nullptr); | |
6840 | if(jlevels == nullptr) { | |
6841 | // exception thrown: OutOfMemoryError | |
6842 | env->DeleteLocalRef(jname); | |
6843 | return nullptr; | |
6844 | } | |
6845 | ||
6846 | jsize i = 0; | |
6847 | for (auto it = column_famly_meta_data->levels.begin(); | |
6848 | it != column_famly_meta_data->levels.end(); ++it) { | |
6849 | jobject jlevel = LevelMetaDataJni::fromCppLevelMetaData(env, &(*it)); | |
6850 | if (jlevel == nullptr) { | |
6851 | // exception occurred | |
6852 | env->DeleteLocalRef(jname); | |
6853 | env->DeleteLocalRef(jlevels); | |
6854 | return nullptr; | |
6855 | } | |
6856 | env->SetObjectArrayElement(jlevels, i++, jlevel); | |
6857 | } | |
6858 | ||
6859 | jobject jcolumn_family_meta_data = env->NewObject(jclazz, mid, | |
6860 | static_cast<jlong>(column_famly_meta_data->size), | |
6861 | static_cast<jlong>(column_famly_meta_data->file_count), | |
6862 | jname, | |
6863 | jlevels | |
6864 | ); | |
6865 | ||
11fdf7f2 | 6866 | if (env->ExceptionCheck()) { |
494da23a TL |
6867 | env->DeleteLocalRef(jname); |
6868 | env->DeleteLocalRef(jlevels); | |
11fdf7f2 TL |
6869 | return nullptr; |
6870 | } | |
6871 | ||
494da23a TL |
6872 | // cleanup |
6873 | env->DeleteLocalRef(jname); | |
6874 | env->DeleteLocalRef(jlevels); | |
6875 | ||
6876 | return jcolumn_family_meta_data; | |
6877 | } | |
6878 | ||
6879 | static jclass getJClass(JNIEnv* env) { | |
6880 | return JavaClass::getJClass(env, "org/rocksdb/ColumnFamilyMetaData"); | |
11fdf7f2 | 6881 | } |
494da23a | 6882 | }; |
11fdf7f2 | 6883 | |
494da23a TL |
6884 | // The portal class for org.rocksdb.AbstractTraceWriter |
6885 | class AbstractTraceWriterJni : public RocksDBNativeClass< | |
6886 | const rocksdb::TraceWriterJniCallback*, | |
6887 | AbstractTraceWriterJni> { | |
6888 | public: | |
11fdf7f2 | 6889 | /** |
494da23a TL |
6890 | * Get the Java Class org.rocksdb.AbstractTraceWriter |
6891 | * | |
6892 | * @param env A pointer to the Java environment | |
6893 | * | |
6894 | * @return The Java Class or nullptr if one of the | |
6895 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
6896 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
6897 | */ | |
6898 | static jclass getJClass(JNIEnv* env) { | |
6899 | return RocksDBNativeClass::getJClass(env, | |
6900 | "org/rocksdb/AbstractTraceWriter"); | |
6901 | } | |
6902 | ||
6903 | /** | |
6904 | * Get the Java Method: AbstractTraceWriter#write | |
11fdf7f2 TL |
6905 | * |
6906 | * @param env A pointer to the Java environment | |
6907 | * | |
6908 | * @return The Java Method ID or nullptr if the class or method id could not | |
6909 | * be retieved | |
6910 | */ | |
494da23a | 6911 | static jmethodID getWriteProxyMethodId(JNIEnv* env) { |
11fdf7f2 | 6912 | jclass jclazz = getJClass(env); |
494da23a | 6913 | if(jclazz == nullptr) { |
11fdf7f2 TL |
6914 | // exception occurred accessing class |
6915 | return nullptr; | |
6916 | } | |
6917 | ||
494da23a TL |
6918 | static jmethodID mid = env->GetMethodID( |
6919 | jclazz, "writeProxy", "(J)S"); | |
11fdf7f2 TL |
6920 | assert(mid != nullptr); |
6921 | return mid; | |
6922 | } | |
6923 | ||
6924 | /** | |
494da23a | 6925 | * Get the Java Method: AbstractTraceWriter#closeWriter |
11fdf7f2 TL |
6926 | * |
6927 | * @param env A pointer to the Java environment | |
6928 | * | |
6929 | * @return The Java Method ID or nullptr if the class or method id could not | |
6930 | * be retieved | |
6931 | */ | |
494da23a | 6932 | static jmethodID getCloseWriterProxyMethodId(JNIEnv* env) { |
11fdf7f2 | 6933 | jclass jclazz = getJClass(env); |
494da23a | 6934 | if(jclazz == nullptr) { |
11fdf7f2 TL |
6935 | // exception occurred accessing class |
6936 | return nullptr; | |
6937 | } | |
6938 | ||
6939 | static jmethodID mid = env->GetMethodID( | |
494da23a | 6940 | jclazz, "closeWriterProxy", "()S"); |
11fdf7f2 TL |
6941 | assert(mid != nullptr); |
6942 | return mid; | |
6943 | } | |
11fdf7f2 TL |
6944 | |
6945 | /** | |
494da23a | 6946 | * Get the Java Method: AbstractTraceWriter#getFileSize |
11fdf7f2 TL |
6947 | * |
6948 | * @param env A pointer to the Java environment | |
6949 | * | |
6950 | * @return The Java Method ID or nullptr if the class or method id could not | |
6951 | * be retieved | |
6952 | */ | |
494da23a TL |
6953 | static jmethodID getGetFileSizeMethodId(JNIEnv* env) { |
6954 | jclass jclazz = getJClass(env); | |
6955 | if(jclazz == nullptr) { | |
11fdf7f2 TL |
6956 | // exception occurred accessing class |
6957 | return nullptr; | |
6958 | } | |
6959 | ||
494da23a TL |
6960 | static jmethodID mid = env->GetMethodID( |
6961 | jclazz, "getFileSize", "()J"); | |
11fdf7f2 TL |
6962 | assert(mid != nullptr); |
6963 | return mid; | |
6964 | } | |
6965 | }; | |
6966 | ||
494da23a TL |
6967 | // The portal class for org.rocksdb.AbstractWalFilter |
6968 | class AbstractWalFilterJni : public RocksDBNativeClass< | |
6969 | const rocksdb::WalFilterJniCallback*, | |
6970 | AbstractWalFilterJni> { | |
11fdf7f2 TL |
6971 | public: |
6972 | /** | |
494da23a | 6973 | * Get the Java Class org.rocksdb.AbstractWalFilter |
11fdf7f2 TL |
6974 | * |
6975 | * @param env A pointer to the Java environment | |
6976 | * | |
6977 | * @return The Java Class or nullptr if one of the | |
6978 | * ClassFormatError, ClassCircularityError, NoClassDefFoundError, | |
6979 | * OutOfMemoryError or ExceptionInInitializerError exceptions is thrown | |
6980 | */ | |
6981 | static jclass getJClass(JNIEnv* env) { | |
494da23a TL |
6982 | return RocksDBNativeClass::getJClass(env, |
6983 | "org/rocksdb/AbstractWalFilter"); | |
11fdf7f2 TL |
6984 | } |
6985 | ||
6986 | /** | |
494da23a | 6987 | * Get the Java Method: AbstractWalFilter#columnFamilyLogNumberMap |
11fdf7f2 TL |
6988 | * |
6989 | * @param env A pointer to the Java environment | |
6990 | * | |
494da23a TL |
6991 | * @return The Java Method ID or nullptr if the class or method id could not |
6992 | * be retieved | |
11fdf7f2 | 6993 | */ |
494da23a | 6994 | static jmethodID getColumnFamilyLogNumberMapMethodId(JNIEnv* env) { |
11fdf7f2 | 6995 | jclass jclazz = getJClass(env); |
494da23a | 6996 | if(jclazz == nullptr) { |
11fdf7f2 TL |
6997 | // exception occurred accessing class |
6998 | return nullptr; | |
6999 | } | |
7000 | ||
494da23a TL |
7001 | static jmethodID mid = env->GetMethodID( |
7002 | jclazz, "columnFamilyLogNumberMap", | |
7003 | "(Ljava/util/Map;Ljava/util/Map;)V"); | |
7004 | assert(mid != nullptr); | |
7005 | return mid; | |
11fdf7f2 TL |
7006 | } |
7007 | ||
7008 | /** | |
494da23a | 7009 | * Get the Java Method: AbstractTraceWriter#logRecordFoundProxy |
11fdf7f2 | 7010 | * |
494da23a TL |
7011 | * @param env A pointer to the Java environment |
7012 | * | |
7013 | * @return The Java Method ID or nullptr if the class or method id could not | |
7014 | * be retieved | |
11fdf7f2 | 7015 | */ |
494da23a TL |
7016 | static jmethodID getLogRecordFoundProxyMethodId(JNIEnv* env) { |
7017 | jclass jclazz = getJClass(env); | |
7018 | if(jclazz == nullptr) { | |
7019 | // exception occurred accessing class | |
7020 | return nullptr; | |
11fdf7f2 TL |
7021 | } |
7022 | ||
494da23a TL |
7023 | static jmethodID mid = env->GetMethodID( |
7024 | jclazz, "logRecordFoundProxy", "(JLjava/lang/String;JJ)S"); | |
7025 | assert(mid != nullptr); | |
7026 | return mid; | |
11fdf7f2 | 7027 | } |
11fdf7f2 | 7028 | |
11fdf7f2 | 7029 | /** |
494da23a | 7030 | * Get the Java Method: AbstractTraceWriter#name |
11fdf7f2 TL |
7031 | * |
7032 | * @param env A pointer to the Java environment | |
7033 | * | |
494da23a TL |
7034 | * @return The Java Method ID or nullptr if the class or method id could not |
7035 | * be retieved | |
11fdf7f2 | 7036 | */ |
494da23a | 7037 | static jmethodID getNameMethodId(JNIEnv* env) { |
11fdf7f2 | 7038 | jclass jclazz = getJClass(env); |
494da23a | 7039 | if(jclazz == nullptr) { |
11fdf7f2 TL |
7040 | // exception occurred accessing class |
7041 | return nullptr; | |
7042 | } | |
7043 | ||
494da23a TL |
7044 | static jmethodID mid = env->GetMethodID( |
7045 | jclazz, "name", "()Ljava/lang/String;"); | |
7046 | assert(mid != nullptr); | |
7047 | return mid; | |
7048 | } | |
7049 | }; | |
11fdf7f2 | 7050 | |
494da23a TL |
7051 | // The portal class for org.rocksdb.WalProcessingOption |
7052 | class WalProcessingOptionJni { | |
7053 | public: | |
7054 | // Returns the equivalent org.rocksdb.WalProcessingOption for the provided | |
7055 | // C++ rocksdb::WalFilter::WalProcessingOption enum | |
7056 | static jbyte toJavaWalProcessingOption( | |
7057 | const rocksdb::WalFilter::WalProcessingOption& wal_processing_option) { | |
7058 | switch(wal_processing_option) { | |
7059 | case rocksdb::WalFilter::WalProcessingOption::kContinueProcessing: | |
7060 | return 0x0; | |
7061 | case rocksdb::WalFilter::WalProcessingOption::kIgnoreCurrentRecord: | |
7062 | return 0x1; | |
7063 | case rocksdb::WalFilter::WalProcessingOption::kStopReplay: | |
7064 | return 0x2; | |
7065 | case rocksdb::WalFilter::WalProcessingOption::kCorruptedRecord: | |
7066 | return 0x3; | |
7067 | default: | |
7068 | return 0x7F; // undefined | |
7069 | } | |
7070 | } | |
11fdf7f2 | 7071 | |
494da23a TL |
7072 | // Returns the equivalent C++ rocksdb::WalFilter::WalProcessingOption enum for |
7073 | // the provided Java org.rocksdb.WalProcessingOption | |
7074 | static rocksdb::WalFilter::WalProcessingOption toCppWalProcessingOption( | |
7075 | jbyte jwal_processing_option) { | |
7076 | switch(jwal_processing_option) { | |
7077 | case 0x0: | |
7078 | return rocksdb::WalFilter::WalProcessingOption::kContinueProcessing; | |
7079 | case 0x1: | |
7080 | return rocksdb::WalFilter::WalProcessingOption::kIgnoreCurrentRecord; | |
7081 | case 0x2: | |
7082 | return rocksdb::WalFilter::WalProcessingOption::kStopReplay; | |
7083 | case 0x3: | |
7084 | return rocksdb::WalFilter::WalProcessingOption::kCorruptedRecord; | |
7085 | default: | |
7086 | // undefined/default | |
7087 | return rocksdb::WalFilter::WalProcessingOption::kCorruptedRecord; | |
7088 | } | |
7089 | } | |
11fdf7f2 | 7090 | }; |
7c673cae FG |
7091 | } // namespace rocksdb |
7092 | #endif // JAVA_ROCKSJNI_PORTAL_H_ |