]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/rocksjni/write_batch_with_index.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / java / rocksjni / write_batch_with_index.cc
CommitLineData
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 implements the "bridge" between Java and C++ and enables
f67539c2 7// calling c++ ROCKSDB_NAMESPACE::WriteBatchWithIndex methods from Java side.
7c673cae 8
11fdf7f2 9#include "rocksdb/utilities/write_batch_with_index.h"
7c673cae
FG
10#include "include/org_rocksdb_WBWIRocksIterator.h"
11#include "include/org_rocksdb_WriteBatchWithIndex.h"
12#include "rocksdb/comparator.h"
7c673cae
FG
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__(
11fdf7f2 21 JNIEnv* /*env*/, jclass /*jcls*/) {
f67539c2 22 auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex();
7c673cae
FG
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(
11fdf7f2 32 JNIEnv* /*env*/, jclass /*jcls*/, jboolean joverwrite_key) {
f67539c2
TL
33 auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex(
34 ROCKSDB_NAMESPACE::BytewiseComparator(), 0,
35 static_cast<bool>(joverwrite_key));
7c673cae
FG
36 return reinterpret_cast<jlong>(wbwi);
37}
38
39/*
40 * Class: org_rocksdb_WriteBatchWithIndex
41 * Method: newWriteBatchWithIndex
11fdf7f2
TL
42 * Signature: (JBIZ)J
43 */
44jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__JBIZ(
45 JNIEnv* /*env*/, jclass /*jcls*/, jlong jfallback_index_comparator_handle,
46 jbyte jcomparator_type, jint jreserved_bytes, jboolean joverwrite_key) {
f67539c2 47 ROCKSDB_NAMESPACE::Comparator* fallback_comparator = nullptr;
11fdf7f2
TL
48 switch (jcomparator_type) {
49 // JAVA_COMPARATOR
50 case 0x0:
11fdf7f2 51 fallback_comparator =
f67539c2 52 reinterpret_cast<ROCKSDB_NAMESPACE::ComparatorJniCallback*>(
11fdf7f2
TL
53 jfallback_index_comparator_handle);
54 break;
55
56 // JAVA_NATIVE_COMPARATOR_WRAPPER
f67539c2
TL
57 case 0x1:
58 fallback_comparator = reinterpret_cast<ROCKSDB_NAMESPACE::Comparator*>(
11fdf7f2
TL
59 jfallback_index_comparator_handle);
60 break;
61 }
f67539c2 62 auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex(
11fdf7f2
TL
63 fallback_comparator, static_cast<size_t>(jreserved_bytes),
64 static_cast<bool>(joverwrite_key));
7c673cae
FG
65 return reinterpret_cast<jlong>(wbwi);
66}
67
68/*
69 * Class: org_rocksdb_WriteBatchWithIndex
70 * Method: count0
71 * Signature: (J)I
72 */
11fdf7f2
TL
73jint Java_org_rocksdb_WriteBatchWithIndex_count0(JNIEnv* /*env*/,
74 jobject /*jobj*/,
75 jlong jwbwi_handle) {
f67539c2
TL
76 auto* wbwi =
77 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae
FG
78 assert(wbwi != nullptr);
79
80 return static_cast<jint>(wbwi->GetWriteBatch()->Count());
81}
82
83/*
84 * Class: org_rocksdb_WriteBatchWithIndex
85 * Method: put
86 * Signature: (J[BI[BI)V
87 */
88void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BI(
89 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
90 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
f67539c2
TL
91 auto* wbwi =
92 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 93 assert(wbwi != nullptr);
f67539c2
TL
94 auto put = [&wbwi](ROCKSDB_NAMESPACE::Slice key,
95 ROCKSDB_NAMESPACE::Slice value) {
11fdf7f2 96 return wbwi->Put(key, value);
7c673cae 97 };
f67539c2
TL
98 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
99 ROCKSDB_NAMESPACE::JniUtil::kv_op(put, env, jobj, jkey, jkey_len,
100 jentry_value, jentry_value_len);
11fdf7f2 101 if (status != nullptr && !status->ok()) {
f67539c2 102 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 103 }
7c673cae
FG
104}
105
106/*
107 * Class: org_rocksdb_WriteBatchWithIndex
108 * Method: put
109 * Signature: (J[BI[BIJ)V
110 */
111void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BIJ(
112 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
113 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
114 jlong jcf_handle) {
f67539c2
TL
115 auto* wbwi =
116 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 117 assert(wbwi != nullptr);
f67539c2
TL
118 auto* cf_handle =
119 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
7c673cae 120 assert(cf_handle != nullptr);
f67539c2
TL
121 auto put = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key,
122 ROCKSDB_NAMESPACE::Slice value) {
11fdf7f2 123 return wbwi->Put(cf_handle, key, value);
7c673cae 124 };
f67539c2
TL
125 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
126 ROCKSDB_NAMESPACE::JniUtil::kv_op(put, env, jobj, jkey, jkey_len,
127 jentry_value, jentry_value_len);
11fdf7f2 128 if (status != nullptr && !status->ok()) {
f67539c2 129 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 130 }
7c673cae
FG
131}
132
f67539c2
TL
133/*
134 * Class: org_rocksdb_WriteBatchWithIndex
135 * Method: putDirect
136 * Signature: (JLjava/nio/ByteBuffer;IILjava/nio/ByteBuffer;IIJ)V
137 */
138void Java_org_rocksdb_WriteBatchWithIndex_putDirect(
139 JNIEnv* env, jobject /*jobj*/, jlong jwb_handle, jobject jkey,
140 jint jkey_offset, jint jkey_len, jobject jval, jint jval_offset,
141 jint jval_len, jlong jcf_handle) {
142 auto* wb = reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatch*>(jwb_handle);
143 assert(wb != nullptr);
144 auto* cf_handle =
145 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
146 auto put = [&wb, &cf_handle](ROCKSDB_NAMESPACE::Slice& key,
147 ROCKSDB_NAMESPACE::Slice& value) {
148 if (cf_handle == nullptr) {
149 wb->Put(key, value);
150 } else {
151 wb->Put(cf_handle, key, value);
152 }
153 };
154 ROCKSDB_NAMESPACE::JniUtil::kv_op_direct(
155 put, env, jkey, jkey_offset, jkey_len, jval, jval_offset, jval_len);
156}
157
7c673cae
FG
158/*
159 * Class: org_rocksdb_WriteBatchWithIndex
160 * Method: merge
161 * Signature: (J[BI[BI)V
162 */
163void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BI(
164 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
165 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
f67539c2
TL
166 auto* wbwi =
167 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 168 assert(wbwi != nullptr);
f67539c2
TL
169 auto merge = [&wbwi](ROCKSDB_NAMESPACE::Slice key,
170 ROCKSDB_NAMESPACE::Slice value) {
11fdf7f2 171 return wbwi->Merge(key, value);
7c673cae 172 };
f67539c2
TL
173 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
174 ROCKSDB_NAMESPACE::JniUtil::kv_op(merge, env, jobj, jkey, jkey_len,
175 jentry_value, jentry_value_len);
11fdf7f2 176 if (status != nullptr && !status->ok()) {
f67539c2 177 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 178 }
7c673cae
FG
179}
180
181/*
182 * Class: org_rocksdb_WriteBatchWithIndex
183 * Method: merge
184 * Signature: (J[BI[BIJ)V
185 */
186void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BIJ(
187 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
188 jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
189 jlong jcf_handle) {
f67539c2
TL
190 auto* wbwi =
191 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 192 assert(wbwi != nullptr);
f67539c2
TL
193 auto* cf_handle =
194 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
7c673cae 195 assert(cf_handle != nullptr);
f67539c2
TL
196 auto merge = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key,
197 ROCKSDB_NAMESPACE::Slice value) {
11fdf7f2
TL
198 return wbwi->Merge(cf_handle, key, value);
199 };
f67539c2
TL
200 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
201 ROCKSDB_NAMESPACE::JniUtil::kv_op(merge, env, jobj, jkey, jkey_len,
202 jentry_value, jentry_value_len);
11fdf7f2 203 if (status != nullptr && !status->ok()) {
f67539c2 204 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2
TL
205 }
206}
207
208/*
209 * Class: org_rocksdb_WriteBatchWithIndex
210 * Method: delete
211 * Signature: (J[BI)V
212 */
213void Java_org_rocksdb_WriteBatchWithIndex_delete__J_3BI(JNIEnv* env,
214 jobject jobj,
215 jlong jwbwi_handle,
216 jbyteArray jkey,
217 jint jkey_len) {
f67539c2
TL
218 auto* wbwi =
219 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
11fdf7f2 220 assert(wbwi != nullptr);
f67539c2
TL
221 auto remove = [&wbwi](ROCKSDB_NAMESPACE::Slice key) {
222 return wbwi->Delete(key);
223 };
224 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
225 ROCKSDB_NAMESPACE::JniUtil::k_op(remove, env, jobj, jkey, jkey_len);
11fdf7f2 226 if (status != nullptr && !status->ok()) {
f67539c2 227 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2
TL
228 }
229}
230
231/*
232 * Class: org_rocksdb_WriteBatchWithIndex
233 * Method: delete
234 * Signature: (J[BIJ)V
235 */
236void Java_org_rocksdb_WriteBatchWithIndex_delete__J_3BIJ(
237 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
238 jint jkey_len, jlong jcf_handle) {
f67539c2
TL
239 auto* wbwi =
240 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
11fdf7f2 241 assert(wbwi != nullptr);
f67539c2
TL
242 auto* cf_handle =
243 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
11fdf7f2 244 assert(cf_handle != nullptr);
f67539c2 245 auto remove = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key) {
11fdf7f2 246 return wbwi->Delete(cf_handle, key);
7c673cae 247 };
f67539c2
TL
248 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
249 ROCKSDB_NAMESPACE::JniUtil::k_op(remove, env, jobj, jkey, jkey_len);
11fdf7f2 250 if (status != nullptr && !status->ok()) {
f67539c2 251 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 252 }
7c673cae
FG
253}
254
255/*
256 * Class: org_rocksdb_WriteBatchWithIndex
11fdf7f2 257 * Method: singleDelete
7c673cae
FG
258 * Signature: (J[BI)V
259 */
11fdf7f2 260void Java_org_rocksdb_WriteBatchWithIndex_singleDelete__J_3BI(
7c673cae
FG
261 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
262 jint jkey_len) {
f67539c2
TL
263 auto* wbwi =
264 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 265 assert(wbwi != nullptr);
f67539c2 266 auto single_delete = [&wbwi](ROCKSDB_NAMESPACE::Slice key) {
11fdf7f2 267 return wbwi->SingleDelete(key);
7c673cae 268 };
f67539c2
TL
269 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
270 ROCKSDB_NAMESPACE::JniUtil::k_op(single_delete, env, jobj, jkey,
271 jkey_len);
11fdf7f2 272 if (status != nullptr && !status->ok()) {
f67539c2 273 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 274 }
7c673cae
FG
275}
276
277/*
278 * Class: org_rocksdb_WriteBatchWithIndex
11fdf7f2 279 * Method: singleDelete
7c673cae
FG
280 * Signature: (J[BIJ)V
281 */
11fdf7f2 282void Java_org_rocksdb_WriteBatchWithIndex_singleDelete__J_3BIJ(
7c673cae
FG
283 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
284 jint jkey_len, jlong jcf_handle) {
f67539c2
TL
285 auto* wbwi =
286 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 287 assert(wbwi != nullptr);
f67539c2
TL
288 auto* cf_handle =
289 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
7c673cae 290 assert(cf_handle != nullptr);
f67539c2 291 auto single_delete = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key) {
11fdf7f2 292 return wbwi->SingleDelete(cf_handle, key);
7c673cae 293 };
f67539c2
TL
294 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
295 ROCKSDB_NAMESPACE::JniUtil::k_op(single_delete, env, jobj, jkey,
296 jkey_len);
11fdf7f2 297 if (status != nullptr && !status->ok()) {
f67539c2 298 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 299 }
7c673cae
FG
300}
301
f67539c2
TL
302/*
303 * Class: org_rocksdb_WriteBatchWithIndex
304 * Method: removeDirect
305 * Signature: (JLjava/nio/ByteBuffer;IIJ)V
306 */
307void Java_org_rocksdb_WriteBatchWithIndex_removeDirect(
308 JNIEnv* env, jobject /*jobj*/, jlong jwb_handle, jobject jkey,
309 jint jkey_offset, jint jkey_len, jlong jcf_handle) {
310 auto* wb = reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatch*>(jwb_handle);
311 assert(wb != nullptr);
312 auto* cf_handle =
313 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
314 auto remove = [&wb, &cf_handle](ROCKSDB_NAMESPACE::Slice& key) {
315 if (cf_handle == nullptr) {
316 wb->Delete(key);
317 } else {
318 wb->Delete(cf_handle, key);
319 }
320 };
321 ROCKSDB_NAMESPACE::JniUtil::k_op_direct(remove, env, jkey, jkey_offset,
322 jkey_len);
323}
324
7c673cae
FG
325/*
326 * Class: org_rocksdb_WriteBatchWithIndex
327 * Method: deleteRange
328 * Signature: (J[BI[BI)V
329 */
330void Java_org_rocksdb_WriteBatchWithIndex_deleteRange__J_3BI_3BI(
331 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jbegin_key,
332 jint jbegin_key_len, jbyteArray jend_key, jint jend_key_len) {
f67539c2
TL
333 auto* wbwi =
334 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 335 assert(wbwi != nullptr);
f67539c2
TL
336 auto deleteRange = [&wbwi](ROCKSDB_NAMESPACE::Slice beginKey,
337 ROCKSDB_NAMESPACE::Slice endKey) {
11fdf7f2 338 return wbwi->DeleteRange(beginKey, endKey);
7c673cae 339 };
f67539c2
TL
340 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
341 ROCKSDB_NAMESPACE::JniUtil::kv_op(deleteRange, env, jobj, jbegin_key,
342 jbegin_key_len, jend_key, jend_key_len);
11fdf7f2 343 if (status != nullptr && !status->ok()) {
f67539c2 344 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 345 }
7c673cae
FG
346}
347
348/*
349 * Class: org_rocksdb_WriteBatchWithIndex
350 * Method: deleteRange
351 * Signature: (J[BI[BIJ)V
352 */
353void Java_org_rocksdb_WriteBatchWithIndex_deleteRange__J_3BI_3BIJ(
354 JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jbegin_key,
355 jint jbegin_key_len, jbyteArray jend_key, jint jend_key_len,
356 jlong jcf_handle) {
f67539c2
TL
357 auto* wbwi =
358 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 359 assert(wbwi != nullptr);
f67539c2
TL
360 auto* cf_handle =
361 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
7c673cae 362 assert(cf_handle != nullptr);
f67539c2
TL
363 auto deleteRange = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice beginKey,
364 ROCKSDB_NAMESPACE::Slice endKey) {
11fdf7f2 365 return wbwi->DeleteRange(cf_handle, beginKey, endKey);
7c673cae 366 };
f67539c2
TL
367 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
368 ROCKSDB_NAMESPACE::JniUtil::kv_op(deleteRange, env, jobj, jbegin_key,
369 jbegin_key_len, jend_key, jend_key_len);
11fdf7f2 370 if (status != nullptr && !status->ok()) {
f67539c2 371 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 372 }
7c673cae
FG
373}
374
375/*
376 * Class: org_rocksdb_WriteBatchWithIndex
377 * Method: putLogData
378 * Signature: (J[BI)V
379 */
11fdf7f2
TL
380void Java_org_rocksdb_WriteBatchWithIndex_putLogData(JNIEnv* env, jobject jobj,
381 jlong jwbwi_handle,
382 jbyteArray jblob,
383 jint jblob_len) {
f67539c2
TL
384 auto* wbwi =
385 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae 386 assert(wbwi != nullptr);
f67539c2 387 auto putLogData = [&wbwi](ROCKSDB_NAMESPACE::Slice blob) {
11fdf7f2 388 return wbwi->PutLogData(blob);
7c673cae 389 };
f67539c2
TL
390 std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
391 ROCKSDB_NAMESPACE::JniUtil::k_op(putLogData, env, jobj, jblob, jblob_len);
11fdf7f2 392 if (status != nullptr && !status->ok()) {
f67539c2 393 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
11fdf7f2 394 }
7c673cae
FG
395}
396
397/*
398 * Class: org_rocksdb_WriteBatchWithIndex
399 * Method: clear
400 * Signature: (J)V
401 */
11fdf7f2
TL
402void Java_org_rocksdb_WriteBatchWithIndex_clear0(JNIEnv* /*env*/,
403 jobject /*jobj*/,
404 jlong jwbwi_handle) {
f67539c2
TL
405 auto* wbwi =
406 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae
FG
407 assert(wbwi != nullptr);
408
409 wbwi->Clear();
410}
411
412/*
413 * Class: org_rocksdb_WriteBatchWithIndex
414 * Method: setSavePoint0
415 * Signature: (J)V
416 */
11fdf7f2
TL
417void Java_org_rocksdb_WriteBatchWithIndex_setSavePoint0(JNIEnv* /*env*/,
418 jobject /*jobj*/,
419 jlong jwbwi_handle) {
f67539c2
TL
420 auto* wbwi =
421 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae
FG
422 assert(wbwi != nullptr);
423
424 wbwi->SetSavePoint();
425}
426
427/*
428 * Class: org_rocksdb_WriteBatchWithIndex
429 * Method: rollbackToSavePoint0
430 * Signature: (J)V
431 */
432void Java_org_rocksdb_WriteBatchWithIndex_rollbackToSavePoint0(
11fdf7f2 433 JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle) {
f67539c2
TL
434 auto* wbwi =
435 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae
FG
436 assert(wbwi != nullptr);
437
438 auto s = wbwi->RollbackToSavePoint();
439
440 if (s.ok()) {
441 return;
442 }
443
f67539c2 444 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
7c673cae
FG
445}
446
11fdf7f2
TL
447/*
448 * Class: org_rocksdb_WriteBatchWithIndex
449 * Method: popSavePoint
450 * Signature: (J)V
451 */
452void Java_org_rocksdb_WriteBatchWithIndex_popSavePoint(JNIEnv* env,
453 jobject /*jobj*/,
454 jlong jwbwi_handle) {
f67539c2
TL
455 auto* wbwi =
456 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
11fdf7f2
TL
457 assert(wbwi != nullptr);
458
459 auto s = wbwi->PopSavePoint();
460
461 if (s.ok()) {
462 return;
463 }
464
f67539c2 465 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
11fdf7f2
TL
466}
467
468/*
469 * Class: org_rocksdb_WriteBatchWithIndex
470 * Method: setMaxBytes
471 * Signature: (JJ)V
472 */
473void Java_org_rocksdb_WriteBatchWithIndex_setMaxBytes(JNIEnv* /*env*/,
474 jobject /*jobj*/,
475 jlong jwbwi_handle,
476 jlong jmax_bytes) {
f67539c2
TL
477 auto* wbwi =
478 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
11fdf7f2
TL
479 assert(wbwi != nullptr);
480
481 wbwi->SetMaxBytes(static_cast<size_t>(jmax_bytes));
482}
483
484/*
485 * Class: org_rocksdb_WriteBatchWithIndex
486 * Method: getWriteBatch
487 * Signature: (J)Lorg/rocksdb/WriteBatch;
488 */
489jobject Java_org_rocksdb_WriteBatchWithIndex_getWriteBatch(JNIEnv* env,
490 jobject /*jobj*/,
491 jlong jwbwi_handle) {
f67539c2
TL
492 auto* wbwi =
493 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
11fdf7f2
TL
494 assert(wbwi != nullptr);
495
496 auto* wb = wbwi->GetWriteBatch();
497
498 // TODO(AR) is the `wb` object owned by us?
f67539c2 499 return ROCKSDB_NAMESPACE::WriteBatchJni::construct(env, wb);
11fdf7f2
TL
500}
501
7c673cae
FG
502/*
503 * Class: org_rocksdb_WriteBatchWithIndex
504 * Method: iterator0
505 * Signature: (J)J
506 */
11fdf7f2
TL
507jlong Java_org_rocksdb_WriteBatchWithIndex_iterator0(JNIEnv* /*env*/,
508 jobject /*jobj*/,
509 jlong jwbwi_handle) {
f67539c2
TL
510 auto* wbwi =
511 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
7c673cae
FG
512 auto* wbwi_iterator = wbwi->NewIterator();
513 return reinterpret_cast<jlong>(wbwi_iterator);
514}
515
516/*
517 * Class: org_rocksdb_WriteBatchWithIndex
518 * Method: iterator1
519 * Signature: (JJ)J
520 */
11fdf7f2
TL
521jlong Java_org_rocksdb_WriteBatchWithIndex_iterator1(JNIEnv* /*env*/,
522 jobject /*jobj*/,
523 jlong jwbwi_handle,
524 jlong jcf_handle) {
f67539c2
TL
525 auto* wbwi =
526 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
527 auto* cf_handle =
528 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
7c673cae
FG
529 auto* wbwi_iterator = wbwi->NewIterator(cf_handle);
530 return reinterpret_cast<jlong>(wbwi_iterator);
531}
532
533/*
534 * Class: org_rocksdb_WriteBatchWithIndex
535 * Method: iteratorWithBase
20effc67 536 * Signature: (JJJJ)J
7c673cae 537 */
20effc67
TL
538jlong Java_org_rocksdb_WriteBatchWithIndex_iteratorWithBase(
539 JNIEnv*, jobject, jlong jwbwi_handle, jlong jcf_handle,
540 jlong jbase_iterator_handle, jlong jread_opts_handle) {
f67539c2
TL
541 auto* wbwi =
542 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
543 auto* cf_handle =
544 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
545 auto* base_iterator =
20effc67
TL
546 reinterpret_cast<ROCKSDB_NAMESPACE::Iterator*>(jbase_iterator_handle);
547 ROCKSDB_NAMESPACE::ReadOptions* read_opts =
548 jread_opts_handle == 0
549 ? nullptr
550 : reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(
551 jread_opts_handle);
552 auto* iterator =
553 wbwi->NewIteratorWithBase(cf_handle, base_iterator, read_opts);
7c673cae
FG
554 return reinterpret_cast<jlong>(iterator);
555}
556
557/*
558 * Class: org_rocksdb_WriteBatchWithIndex
559 * Method: getFromBatch
560 * Signature: (JJ[BI)[B
561 */
562jbyteArray JNICALL Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BI(
11fdf7f2 563 JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdbopt_handle,
7c673cae 564 jbyteArray jkey, jint jkey_len) {
f67539c2
TL
565 auto* wbwi =
566 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
567 auto* dbopt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jdbopt_handle);
7c673cae 568
f67539c2
TL
569 auto getter = [&wbwi, &dbopt](const ROCKSDB_NAMESPACE::Slice& key,
570 std::string* value) {
7c673cae
FG
571 return wbwi->GetFromBatch(*dbopt, key, value);
572 };
573
f67539c2 574 return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
7c673cae
FG
575}
576
577/*
578 * Class: org_rocksdb_WriteBatchWithIndex
579 * Method: getFromBatch
580 * Signature: (JJ[BIJ)[B
581 */
582jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BIJ(
11fdf7f2 583 JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdbopt_handle,
7c673cae 584 jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
f67539c2
TL
585 auto* wbwi =
586 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
587 auto* dbopt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jdbopt_handle);
588 auto* cf_handle =
589 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
7c673cae 590
f67539c2 591 auto getter = [&wbwi, &cf_handle, &dbopt](const ROCKSDB_NAMESPACE::Slice& key,
11fdf7f2
TL
592 std::string* value) {
593 return wbwi->GetFromBatch(cf_handle, *dbopt, key, value);
594 };
7c673cae 595
f67539c2 596 return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
7c673cae
FG
597}
598
599/*
600 * Class: org_rocksdb_WriteBatchWithIndex
601 * Method: getFromBatchAndDB
602 * Signature: (JJJ[BI)[B
603 */
604jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BI(
11fdf7f2 605 JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdb_handle,
7c673cae 606 jlong jreadopt_handle, jbyteArray jkey, jint jkey_len) {
f67539c2
TL
607 auto* wbwi =
608 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
609 auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
610 auto* readopt =
611 reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jreadopt_handle);
7c673cae 612
f67539c2 613 auto getter = [&wbwi, &db, &readopt](const ROCKSDB_NAMESPACE::Slice& key,
11fdf7f2
TL
614 std::string* value) {
615 return wbwi->GetFromBatchAndDB(db, *readopt, key, value);
616 };
7c673cae 617
f67539c2 618 return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
7c673cae
FG
619}
620
621/*
622 * Class: org_rocksdb_WriteBatchWithIndex
623 * Method: getFromBatchAndDB
624 * Signature: (JJJ[BIJ)[B
625 */
626jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BIJ(
11fdf7f2 627 JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdb_handle,
7c673cae 628 jlong jreadopt_handle, jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
f67539c2
TL
629 auto* wbwi =
630 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
631 auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
632 auto* readopt =
633 reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jreadopt_handle);
634 auto* cf_handle =
635 reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
636
637 auto getter = [&wbwi, &db, &cf_handle, &readopt](
638 const ROCKSDB_NAMESPACE::Slice& key, std::string* value) {
11fdf7f2
TL
639 return wbwi->GetFromBatchAndDB(db, *readopt, cf_handle, key, value);
640 };
7c673cae 641
f67539c2 642 return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
7c673cae
FG
643}
644
645/*
646 * Class: org_rocksdb_WriteBatchWithIndex
647 * Method: disposeInternal
648 * Signature: (J)V
649 */
11fdf7f2
TL
650void Java_org_rocksdb_WriteBatchWithIndex_disposeInternal(JNIEnv* /*env*/,
651 jobject /*jobj*/,
652 jlong handle) {
f67539c2
TL
653 auto* wbwi =
654 reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(handle);
7c673cae
FG
655 assert(wbwi != nullptr);
656 delete wbwi;
657}
658
659/* WBWIRocksIterator below */
660
661/*
662 * Class: org_rocksdb_WBWIRocksIterator
663 * Method: disposeInternal
664 * Signature: (J)V
665 */
11fdf7f2
TL
666void Java_org_rocksdb_WBWIRocksIterator_disposeInternal(JNIEnv* /*env*/,
667 jobject /*jobj*/,
668 jlong handle) {
f67539c2 669 auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
7c673cae
FG
670 assert(it != nullptr);
671 delete it;
672}
673
674/*
675 * Class: org_rocksdb_WBWIRocksIterator
676 * Method: isValid0
677 * Signature: (J)Z
678 */
11fdf7f2
TL
679jboolean Java_org_rocksdb_WBWIRocksIterator_isValid0(JNIEnv* /*env*/,
680 jobject /*jobj*/,
681 jlong handle) {
f67539c2 682 return reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Valid();
7c673cae
FG
683}
684
685/*
686 * Class: org_rocksdb_WBWIRocksIterator
687 * Method: seekToFirst0
688 * Signature: (J)V
689 */
11fdf7f2
TL
690void Java_org_rocksdb_WBWIRocksIterator_seekToFirst0(JNIEnv* /*env*/,
691 jobject /*jobj*/,
692 jlong handle) {
f67539c2 693 reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->SeekToFirst();
7c673cae
FG
694}
695
696/*
697 * Class: org_rocksdb_WBWIRocksIterator
698 * Method: seekToLast0
699 * Signature: (J)V
700 */
11fdf7f2
TL
701void Java_org_rocksdb_WBWIRocksIterator_seekToLast0(JNIEnv* /*env*/,
702 jobject /*jobj*/,
703 jlong handle) {
f67539c2 704 reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->SeekToLast();
7c673cae
FG
705}
706
707/*
708 * Class: org_rocksdb_WBWIRocksIterator
709 * Method: next0
710 * Signature: (J)V
711 */
11fdf7f2
TL
712void Java_org_rocksdb_WBWIRocksIterator_next0(JNIEnv* /*env*/, jobject /*jobj*/,
713 jlong handle) {
f67539c2 714 reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Next();
7c673cae
FG
715}
716
717/*
718 * Class: org_rocksdb_WBWIRocksIterator
719 * Method: prev0
720 * Signature: (J)V
721 */
11fdf7f2
TL
722void Java_org_rocksdb_WBWIRocksIterator_prev0(JNIEnv* /*env*/, jobject /*jobj*/,
723 jlong handle) {
f67539c2 724 reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Prev();
7c673cae
FG
725}
726
727/*
728 * Class: org_rocksdb_WBWIRocksIterator
729 * Method: seek0
730 * Signature: (J[BI)V
731 */
11fdf7f2
TL
732void Java_org_rocksdb_WBWIRocksIterator_seek0(JNIEnv* env, jobject /*jobj*/,
733 jlong handle, jbyteArray jtarget,
734 jint jtarget_len) {
f67539c2 735 auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
7c673cae 736 jbyte* target = env->GetByteArrayElements(jtarget, nullptr);
11fdf7f2 737 if (target == nullptr) {
7c673cae
FG
738 // exception thrown: OutOfMemoryError
739 return;
740 }
741
f67539c2
TL
742 ROCKSDB_NAMESPACE::Slice target_slice(reinterpret_cast<char*>(target),
743 jtarget_len);
7c673cae
FG
744
745 it->Seek(target_slice);
746
747 env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT);
748}
749
f67539c2
TL
750/*
751 * Class: org_rocksdb_WBWIRocksIterator
752 * Method: seekDirect0
753 * Signature: (JLjava/nio/ByteBuffer;II)V
754 */
755void Java_org_rocksdb_WBWIRocksIterator_seekDirect0(
756 JNIEnv* env, jobject /*jobj*/, jlong handle, jobject jtarget,
757 jint jtarget_off, jint jtarget_len) {
758 auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
759 auto seek = [&it](ROCKSDB_NAMESPACE::Slice& target_slice) {
760 it->Seek(target_slice);
761 };
762 ROCKSDB_NAMESPACE::JniUtil::k_op_direct(seek, env, jtarget, jtarget_off,
763 jtarget_len);
764}
765
11fdf7f2
TL
766/*
767 * Class: org_rocksdb_WBWIRocksIterator
768 * Method: seekForPrev0
769 * Signature: (J[BI)V
770 */
771void Java_org_rocksdb_WBWIRocksIterator_seekForPrev0(JNIEnv* env,
772 jobject /*jobj*/,
773 jlong handle,
774 jbyteArray jtarget,
775 jint jtarget_len) {
f67539c2 776 auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
11fdf7f2
TL
777 jbyte* target = env->GetByteArrayElements(jtarget, nullptr);
778 if (target == nullptr) {
779 // exception thrown: OutOfMemoryError
780 return;
781 }
782
f67539c2
TL
783 ROCKSDB_NAMESPACE::Slice target_slice(reinterpret_cast<char*>(target),
784 jtarget_len);
11fdf7f2
TL
785
786 it->SeekForPrev(target_slice);
787
788 env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT);
789}
790
7c673cae
FG
791/*
792 * Class: org_rocksdb_WBWIRocksIterator
793 * Method: status0
794 * Signature: (J)V
795 */
11fdf7f2
TL
796void Java_org_rocksdb_WBWIRocksIterator_status0(JNIEnv* env, jobject /*jobj*/,
797 jlong handle) {
f67539c2
TL
798 auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
799 ROCKSDB_NAMESPACE::Status s = it->status();
7c673cae
FG
800
801 if (s.ok()) {
802 return;
803 }
804
f67539c2 805 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
7c673cae
FG
806}
807
808/*
809 * Class: org_rocksdb_WBWIRocksIterator
810 * Method: entry1
811 * Signature: (J)[J
812 */
11fdf7f2
TL
813jlongArray Java_org_rocksdb_WBWIRocksIterator_entry1(JNIEnv* env,
814 jobject /*jobj*/,
815 jlong handle) {
f67539c2
TL
816 auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
817 const ROCKSDB_NAMESPACE::WriteEntry& we = it->Entry();
7c673cae
FG
818
819 jlong results[3];
820
11fdf7f2 821 // set the type of the write entry
f67539c2 822 results[0] = ROCKSDB_NAMESPACE::WriteTypeJni::toJavaWriteType(we.type);
7c673cae 823
11fdf7f2
TL
824 // NOTE: key_slice and value_slice will be freed by
825 // org.rocksdb.DirectSlice#close
7c673cae 826
f67539c2 827 auto* key_slice = new ROCKSDB_NAMESPACE::Slice(we.key.data(), we.key.size());
7c673cae 828 results[1] = reinterpret_cast<jlong>(key_slice);
f67539c2
TL
829 if (we.type == ROCKSDB_NAMESPACE::kDeleteRecord ||
830 we.type == ROCKSDB_NAMESPACE::kSingleDeleteRecord ||
831 we.type == ROCKSDB_NAMESPACE::kLogDataRecord) {
7c673cae
FG
832 // set native handle of value slice to null if no value available
833 results[2] = 0;
834 } else {
f67539c2
TL
835 auto* value_slice =
836 new ROCKSDB_NAMESPACE::Slice(we.value.data(), we.value.size());
7c673cae
FG
837 results[2] = reinterpret_cast<jlong>(value_slice);
838 }
839
840 jlongArray jresults = env->NewLongArray(3);
11fdf7f2 841 if (jresults == nullptr) {
7c673cae 842 // exception thrown: OutOfMemoryError
11fdf7f2 843 if (results[2] != 0) {
f67539c2
TL
844 auto* value_slice =
845 reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(results[2]);
7c673cae
FG
846 delete value_slice;
847 }
848 delete key_slice;
849 return nullptr;
850 }
851
852 env->SetLongArrayRegion(jresults, 0, 3, results);
11fdf7f2 853 if (env->ExceptionCheck()) {
7c673cae
FG
854 // exception thrown: ArrayIndexOutOfBoundsException
855 env->DeleteLocalRef(jresults);
11fdf7f2 856 if (results[2] != 0) {
f67539c2
TL
857 auto* value_slice =
858 reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(results[2]);
7c673cae
FG
859 delete value_slice;
860 }
861 delete key_slice;
862 return nullptr;
863 }
864
865 return jresults;
866}
20effc67
TL
867
868/*
869 * Class: org_rocksdb_WBWIRocksIterator
870 * Method: refresh0
871 * Signature: (J)V
872 */
873void Java_org_rocksdb_WBWIRocksIterator_refresh0(JNIEnv* env) {
874 ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::Status::NotSupported("Refresh() is not supported");
875 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
876}