]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/rocksjni/write_batch_with_index.cc
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / rocksdb / java / rocksjni / write_batch_with_index.cc
CommitLineData
7c673cae
FG
1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2// This source code is licensed under the BSD-style license found in the
3// LICENSE file in the root directory of this source tree. An additional grant
4// of patent rights can be found in the PATENTS file in the same directory.
5//
6// This file implements the "bridge" between Java and C++ and enables
7// calling c++ rocksdb::WriteBatchWithIndex methods from Java side.
8
9#include "include/org_rocksdb_WBWIRocksIterator.h"
10#include "include/org_rocksdb_WriteBatchWithIndex.h"
11#include "rocksdb/comparator.h"
12#include "rocksdb/utilities/write_batch_with_index.h"
13#include "rocksjni/portal.h"
14
15/*
16 * Class: org_rocksdb_WriteBatchWithIndex
17 * Method: newWriteBatchWithIndex
18 * Signature: ()J
19 */
20jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__(
21 JNIEnv* env, jclass jcls) {
22 auto* wbwi = new rocksdb::WriteBatchWithIndex();
23 return reinterpret_cast<jlong>(wbwi);
24}
25
26/*
27 * Class: org_rocksdb_WriteBatchWithIndex
28 * Method: newWriteBatchWithIndex
29 * Signature: (Z)J
30 */
31jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__Z(
32 JNIEnv* env, jclass jcls, jboolean joverwrite_key) {
33 auto* wbwi =
34 new rocksdb::WriteBatchWithIndex(rocksdb::BytewiseComparator(), 0,
35 static_cast<bool>(joverwrite_key));
36 return reinterpret_cast<jlong>(wbwi);
37}
38
39/*
40 * Class: org_rocksdb_WriteBatchWithIndex
41 * Method: newWriteBatchWithIndex
42 * Signature: (JIZ)J
43 */
44jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__JIZ(
45 JNIEnv* env, jclass jcls, jlong jfallback_index_comparator_handle,
46 jint jreserved_bytes, jboolean joverwrite_key) {
47 auto* wbwi =
48 new rocksdb::WriteBatchWithIndex(
49 reinterpret_cast<rocksdb::Comparator*>(jfallback_index_comparator_handle),
50 static_cast<size_t>(jreserved_bytes), static_cast<bool>(joverwrite_key));
51 return reinterpret_cast<jlong>(wbwi);
52}
53
54/*
55 * Class: org_rocksdb_WriteBatchWithIndex
56 * Method: count0
57 * Signature: (J)I
58 */
59jint Java_org_rocksdb_WriteBatchWithIndex_count0(
60 JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
61 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
62 assert(wbwi != nullptr);
63
64 return static_cast<jint>(wbwi->GetWriteBatch()->Count());
65}
66
67/*
68 * Class: org_rocksdb_WriteBatchWithIndex
69 * Method: put
70 * Signature: (J[BI[BI)V
71 */
72void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BI(
73 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
74 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
75 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
76 assert(wbwi != nullptr);
77 auto put = [&wbwi] (rocksdb::Slice key, rocksdb::Slice value) {
78 wbwi->Put(key, value);
79 };
80 rocksdb::JniUtil::kv_op(put, env, jobj, jkey, jkey_len, jentry_value,
81 jentry_value_len);
82}
83
84/*
85 * Class: org_rocksdb_WriteBatchWithIndex
86 * Method: put
87 * Signature: (J[BI[BIJ)V
88 */
89void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BIJ(
90 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
91 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
92 jlong jcf_handle) {
93 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
94 assert(wbwi != nullptr);
95 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
96 assert(cf_handle != nullptr);
97 auto put = [&wbwi, &cf_handle] (rocksdb::Slice key, rocksdb::Slice value) {
98 wbwi->Put(cf_handle, key, value);
99 };
100 rocksdb::JniUtil::kv_op(put, env, jobj, jkey, jkey_len, jentry_value,
101 jentry_value_len);
102}
103
104/*
105 * Class: org_rocksdb_WriteBatchWithIndex
106 * Method: merge
107 * Signature: (J[BI[BI)V
108 */
109void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BI(
110 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
111 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
112 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
113 assert(wbwi != nullptr);
114 auto merge = [&wbwi] (rocksdb::Slice key, rocksdb::Slice value) {
115 wbwi->Merge(key, value);
116 };
117 rocksdb::JniUtil::kv_op(merge, env, jobj, jkey, jkey_len, jentry_value,
118 jentry_value_len);
119}
120
121/*
122 * Class: org_rocksdb_WriteBatchWithIndex
123 * Method: merge
124 * Signature: (J[BI[BIJ)V
125 */
126void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BIJ(
127 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
128 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
129 jlong jcf_handle) {
130 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
131 assert(wbwi != nullptr);
132 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
133 assert(cf_handle != nullptr);
134 auto merge = [&wbwi, &cf_handle] (rocksdb::Slice key, rocksdb::Slice value) {
135 wbwi->Merge(cf_handle, key, value);
136 };
137 rocksdb::JniUtil::kv_op(merge, env, jobj, jkey, jkey_len, jentry_value,
138 jentry_value_len);
139}
140
141/*
142 * Class: org_rocksdb_WriteBatchWithIndex
143 * Method: remove
144 * Signature: (J[BI)V
145 */
146void Java_org_rocksdb_WriteBatchWithIndex_remove__J_3BI(
147 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
148 jint jkey_len) {
149 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
150 assert(wbwi != nullptr);
151 auto remove = [&wbwi] (rocksdb::Slice key) {
152 wbwi->Delete(key);
153 };
154 rocksdb::JniUtil::k_op(remove, env, jobj, jkey, jkey_len);
155}
156
157/*
158 * Class: org_rocksdb_WriteBatchWithIndex
159 * Method: remove
160 * Signature: (J[BIJ)V
161 */
162void Java_org_rocksdb_WriteBatchWithIndex_remove__J_3BIJ(
163 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
164 jint jkey_len, jlong jcf_handle) {
165 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
166 assert(wbwi != nullptr);
167 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
168 assert(cf_handle != nullptr);
169 auto remove = [&wbwi, &cf_handle] (rocksdb::Slice key) {
170 wbwi->Delete(cf_handle, key);
171 };
172 rocksdb::JniUtil::k_op(remove, env, jobj, jkey, jkey_len);
173}
174
175/*
176 * Class: org_rocksdb_WriteBatchWithIndex
177 * Method: deleteRange
178 * Signature: (J[BI[BI)V
179 */
180void Java_org_rocksdb_WriteBatchWithIndex_deleteRange__J_3BI_3BI(
181 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jbegin_key,
182 jint jbegin_key_len, jbyteArray jend_key, jint jend_key_len) {
183 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
184 assert(wbwi != nullptr);
185 auto deleteRange = [&wbwi](rocksdb::Slice beginKey, rocksdb::Slice endKey) {
186 wbwi->DeleteRange(beginKey, endKey);
187 };
188 rocksdb::JniUtil::kv_op(deleteRange, env, jobj, jbegin_key, jbegin_key_len,
189 jend_key, jend_key_len);
190}
191
192/*
193 * Class: org_rocksdb_WriteBatchWithIndex
194 * Method: deleteRange
195 * Signature: (J[BI[BIJ)V
196 */
197void Java_org_rocksdb_WriteBatchWithIndex_deleteRange__J_3BI_3BIJ(
198 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jbegin_key,
199 jint jbegin_key_len, jbyteArray jend_key, jint jend_key_len,
200 jlong jcf_handle) {
201 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
202 assert(wbwi != nullptr);
203 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
204 assert(cf_handle != nullptr);
205 auto deleteRange = [&wbwi, &cf_handle](rocksdb::Slice beginKey,
206 rocksdb::Slice endKey) {
207 wbwi->DeleteRange(cf_handle, beginKey, endKey);
208 };
209 rocksdb::JniUtil::kv_op(deleteRange, env, jobj, jbegin_key, jbegin_key_len,
210 jend_key, jend_key_len);
211}
212
213/*
214 * Class: org_rocksdb_WriteBatchWithIndex
215 * Method: putLogData
216 * Signature: (J[BI)V
217 */
218void Java_org_rocksdb_WriteBatchWithIndex_putLogData(
219 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jblob,
220 jint jblob_len) {
221 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
222 assert(wbwi != nullptr);
223 auto putLogData = [&wbwi] (rocksdb::Slice blob) {
224 wbwi->PutLogData(blob);
225 };
226 rocksdb::JniUtil::k_op(putLogData, env, jobj, jblob, jblob_len);
227}
228
229/*
230 * Class: org_rocksdb_WriteBatchWithIndex
231 * Method: clear
232 * Signature: (J)V
233 */
234void Java_org_rocksdb_WriteBatchWithIndex_clear0(
235 JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
236 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
237 assert(wbwi != nullptr);
238
239 wbwi->Clear();
240}
241
242/*
243 * Class: org_rocksdb_WriteBatchWithIndex
244 * Method: setSavePoint0
245 * Signature: (J)V
246 */
247void Java_org_rocksdb_WriteBatchWithIndex_setSavePoint0(
248 JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
249 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
250 assert(wbwi != nullptr);
251
252 wbwi->SetSavePoint();
253}
254
255/*
256 * Class: org_rocksdb_WriteBatchWithIndex
257 * Method: rollbackToSavePoint0
258 * Signature: (J)V
259 */
260void Java_org_rocksdb_WriteBatchWithIndex_rollbackToSavePoint0(
261 JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
262 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
263 assert(wbwi != nullptr);
264
265 auto s = wbwi->RollbackToSavePoint();
266
267 if (s.ok()) {
268 return;
269 }
270
271 rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
272}
273
274/*
275 * Class: org_rocksdb_WriteBatchWithIndex
276 * Method: iterator0
277 * Signature: (J)J
278 */
279jlong Java_org_rocksdb_WriteBatchWithIndex_iterator0(
280 JNIEnv* env, jobject jobj, jlong jwbwi_handle) {
281 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
282 auto* wbwi_iterator = wbwi->NewIterator();
283 return reinterpret_cast<jlong>(wbwi_iterator);
284}
285
286/*
287 * Class: org_rocksdb_WriteBatchWithIndex
288 * Method: iterator1
289 * Signature: (JJ)J
290 */
291jlong Java_org_rocksdb_WriteBatchWithIndex_iterator1(
292 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jcf_handle) {
293 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
294 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
295 auto* wbwi_iterator = wbwi->NewIterator(cf_handle);
296 return reinterpret_cast<jlong>(wbwi_iterator);
297}
298
299/*
300 * Class: org_rocksdb_WriteBatchWithIndex
301 * Method: iteratorWithBase
302 * Signature: (JJJ)J
303 */
304jlong Java_org_rocksdb_WriteBatchWithIndex_iteratorWithBase(
305 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jcf_handle,
306 jlong jbi_handle) {
307 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
308 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
309 auto* base_iterator = reinterpret_cast<rocksdb::Iterator*>(jbi_handle);
310 auto* iterator = wbwi->NewIteratorWithBase(cf_handle, base_iterator);
311 return reinterpret_cast<jlong>(iterator);
312}
313
314/*
315 * Class: org_rocksdb_WriteBatchWithIndex
316 * Method: getFromBatch
317 * Signature: (JJ[BI)[B
318 */
319jbyteArray JNICALL Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BI(
320 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jdbopt_handle,
321 jbyteArray jkey, jint jkey_len) {
322 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
323 auto* dbopt = reinterpret_cast<rocksdb::DBOptions*>(jdbopt_handle);
324
325 auto getter = [&wbwi, &dbopt](const rocksdb::Slice& key, std::string* value) {
326 return wbwi->GetFromBatch(*dbopt, key, value);
327 };
328
329 return rocksdb::JniUtil::v_op(getter, env, jkey, jkey_len);
330}
331
332/*
333 * Class: org_rocksdb_WriteBatchWithIndex
334 * Method: getFromBatch
335 * Signature: (JJ[BIJ)[B
336 */
337jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BIJ(
338 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jdbopt_handle,
339 jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
340 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
341 auto* dbopt = reinterpret_cast<rocksdb::DBOptions*>(jdbopt_handle);
342 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
343
344 auto getter =
345 [&wbwi, &cf_handle, &dbopt](const rocksdb::Slice& key,
346 std::string* value) {
347 return wbwi->GetFromBatch(cf_handle, *dbopt, key, value);
348 };
349
350 return rocksdb::JniUtil::v_op(getter, env, jkey, jkey_len);
351}
352
353/*
354 * Class: org_rocksdb_WriteBatchWithIndex
355 * Method: getFromBatchAndDB
356 * Signature: (JJJ[BI)[B
357 */
358jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BI(
359 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jdb_handle,
360 jlong jreadopt_handle, jbyteArray jkey, jint jkey_len) {
361 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
362 auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
363 auto* readopt = reinterpret_cast<rocksdb::ReadOptions*>(jreadopt_handle);
364
365 auto getter =
366 [&wbwi, &db, &readopt](const rocksdb::Slice& key, std::string* value) {
367 return wbwi->GetFromBatchAndDB(db, *readopt, key, value);
368 };
369
370 return rocksdb::JniUtil::v_op(getter, env, jkey, jkey_len);
371}
372
373/*
374 * Class: org_rocksdb_WriteBatchWithIndex
375 * Method: getFromBatchAndDB
376 * Signature: (JJJ[BIJ)[B
377 */
378jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BIJ(
379 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jlong jdb_handle,
380 jlong jreadopt_handle, jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
381 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
382 auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
383 auto* readopt = reinterpret_cast<rocksdb::ReadOptions*>(jreadopt_handle);
384 auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
385
386 auto getter =
387 [&wbwi, &db, &cf_handle, &readopt](const rocksdb::Slice& key,
388 std::string* value) {
389 return wbwi->GetFromBatchAndDB(db, *readopt, cf_handle, key, value);
390 };
391
392 return rocksdb::JniUtil::v_op(getter, env, jkey, jkey_len);
393}
394
395/*
396 * Class: org_rocksdb_WriteBatchWithIndex
397 * Method: disposeInternal
398 * Signature: (J)V
399 */
400void Java_org_rocksdb_WriteBatchWithIndex_disposeInternal(
401 JNIEnv* env, jobject jobj, jlong handle) {
402 auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(handle);
403 assert(wbwi != nullptr);
404 delete wbwi;
405}
406
407/* WBWIRocksIterator below */
408
409/*
410 * Class: org_rocksdb_WBWIRocksIterator
411 * Method: disposeInternal
412 * Signature: (J)V
413 */
414void Java_org_rocksdb_WBWIRocksIterator_disposeInternal(
415 JNIEnv* env, jobject jobj, jlong handle) {
416 auto* it = reinterpret_cast<rocksdb::WBWIIterator*>(handle);
417 assert(it != nullptr);
418 delete it;
419}
420
421/*
422 * Class: org_rocksdb_WBWIRocksIterator
423 * Method: isValid0
424 * Signature: (J)Z
425 */
426jboolean Java_org_rocksdb_WBWIRocksIterator_isValid0(
427 JNIEnv* env, jobject jobj, jlong handle) {
428 return reinterpret_cast<rocksdb::WBWIIterator*>(handle)->Valid();
429}
430
431/*
432 * Class: org_rocksdb_WBWIRocksIterator
433 * Method: seekToFirst0
434 * Signature: (J)V
435 */
436void Java_org_rocksdb_WBWIRocksIterator_seekToFirst0(
437 JNIEnv* env, jobject jobj, jlong handle) {
438 reinterpret_cast<rocksdb::WBWIIterator*>(handle)->SeekToFirst();
439}
440
441/*
442 * Class: org_rocksdb_WBWIRocksIterator
443 * Method: seekToLast0
444 * Signature: (J)V
445 */
446void Java_org_rocksdb_WBWIRocksIterator_seekToLast0(
447 JNIEnv* env, jobject jobj, jlong handle) {
448 reinterpret_cast<rocksdb::WBWIIterator*>(handle)->SeekToLast();
449}
450
451/*
452 * Class: org_rocksdb_WBWIRocksIterator
453 * Method: next0
454 * Signature: (J)V
455 */
456void Java_org_rocksdb_WBWIRocksIterator_next0(
457 JNIEnv* env, jobject jobj, jlong handle) {
458 reinterpret_cast<rocksdb::WBWIIterator*>(handle)->Next();
459}
460
461/*
462 * Class: org_rocksdb_WBWIRocksIterator
463 * Method: prev0
464 * Signature: (J)V
465 */
466void Java_org_rocksdb_WBWIRocksIterator_prev0(
467 JNIEnv* env, jobject jobj, jlong handle) {
468 reinterpret_cast<rocksdb::WBWIIterator*>(handle)->Prev();
469}
470
471/*
472 * Class: org_rocksdb_WBWIRocksIterator
473 * Method: seek0
474 * Signature: (J[BI)V
475 */
476void Java_org_rocksdb_WBWIRocksIterator_seek0(
477 JNIEnv* env, jobject jobj, jlong handle, jbyteArray jtarget,
478 jint jtarget_len) {
479 auto* it = reinterpret_cast<rocksdb::WBWIIterator*>(handle);
480 jbyte* target = env->GetByteArrayElements(jtarget, nullptr);
481 if(target == nullptr) {
482 // exception thrown: OutOfMemoryError
483 return;
484 }
485
486 rocksdb::Slice target_slice(
487 reinterpret_cast<char*>(target), jtarget_len);
488
489 it->Seek(target_slice);
490
491 env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT);
492}
493
494/*
495 * Class: org_rocksdb_WBWIRocksIterator
496 * Method: status0
497 * Signature: (J)V
498 */
499void Java_org_rocksdb_WBWIRocksIterator_status0(
500 JNIEnv* env, jobject jobj, jlong handle) {
501 auto* it = reinterpret_cast<rocksdb::WBWIIterator*>(handle);
502 rocksdb::Status s = it->status();
503
504 if (s.ok()) {
505 return;
506 }
507
508 rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
509}
510
511/*
512 * Class: org_rocksdb_WBWIRocksIterator
513 * Method: entry1
514 * Signature: (J)[J
515 */
516jlongArray Java_org_rocksdb_WBWIRocksIterator_entry1(
517 JNIEnv* env, jobject jobj, jlong handle) {
518 auto* it = reinterpret_cast<rocksdb::WBWIIterator*>(handle);
519 const rocksdb::WriteEntry& we = it->Entry();
520
521 jlong results[3];
522
523 //set the type of the write entry
524 switch (we.type) {
525 case rocksdb::kPutRecord:
526 results[0] = 0x1;
527 break;
528
529 case rocksdb::kMergeRecord:
530 results[0] = 0x2;
531 break;
532
533 case rocksdb::kDeleteRecord:
534 results[0] = 0x4;
535 break;
536
537 case rocksdb::kLogDataRecord:
538 results[0] = 0x8;
539 break;
540
541 default:
542 results[0] = 0x0;
543 }
544
545 // key_slice and value_slice will be freed by org.rocksdb.DirectSlice#close
546
547 auto* key_slice = new rocksdb::Slice(we.key.data(), we.key.size());
548 results[1] = reinterpret_cast<jlong>(key_slice);
549 if (we.type == rocksdb::kDeleteRecord
550 || we.type == rocksdb::kLogDataRecord) {
551 // set native handle of value slice to null if no value available
552 results[2] = 0;
553 } else {
554 auto* value_slice = new rocksdb::Slice(we.value.data(), we.value.size());
555 results[2] = reinterpret_cast<jlong>(value_slice);
556 }
557
558 jlongArray jresults = env->NewLongArray(3);
559 if(jresults == nullptr) {
560 // exception thrown: OutOfMemoryError
561 if(results[2] != 0) {
562 auto* value_slice = reinterpret_cast<rocksdb::Slice*>(results[2]);
563 delete value_slice;
564 }
565 delete key_slice;
566 return nullptr;
567 }
568
569 env->SetLongArrayRegion(jresults, 0, 3, results);
570 if(env->ExceptionCheck()) {
571 // exception thrown: ArrayIndexOutOfBoundsException
572 env->DeleteLocalRef(jresults);
573 if(results[2] != 0) {
574 auto* value_slice = reinterpret_cast<rocksdb::Slice*>(results[2]);
575 delete value_slice;
576 }
577 delete key_slice;
578 return nullptr;
579 }
580
581 return jresults;
582}