]>
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 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 | */ | |
20 | jlong 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 | */ | |
31 | jlong 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 | */ | |
44 | jlong 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 |
73 | jint 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 | */ | |
88 | void 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 | */ | |
111 | void 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 | */ | |
138 | void 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 | */ | |
163 | void 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 | */ | |
186 | void 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 | */ | |
213 | void 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 | */ | |
236 | void 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 | 260 | void 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 | 282 | void 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 | */ | |
307 | void 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 | */ | |
330 | void 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 | */ | |
353 | void 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 |
380 | void 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 |
402 | void 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 |
417 | void 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 | */ | |
432 | void 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 | */ | |
452 | void 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 | */ | |
473 | void 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 | */ | |
489 | jobject 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 |
507 | jlong 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 |
521 | jlong 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 | |
536 | * Signature: (JJJ)J | |
537 | */ | |
11fdf7f2 TL |
538 | jlong Java_org_rocksdb_WriteBatchWithIndex_iteratorWithBase(JNIEnv* /*env*/, |
539 | jobject /*jobj*/, | |
540 | jlong jwbwi_handle, | |
541 | jlong jcf_handle, | |
542 | jlong jbi_handle) { | |
f67539c2 TL |
543 | auto* wbwi = |
544 | reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle); | |
545 | auto* cf_handle = | |
546 | reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle); | |
547 | auto* base_iterator = | |
548 | reinterpret_cast<ROCKSDB_NAMESPACE::Iterator*>(jbi_handle); | |
7c673cae FG |
549 | auto* iterator = wbwi->NewIteratorWithBase(cf_handle, base_iterator); |
550 | return reinterpret_cast<jlong>(iterator); | |
551 | } | |
552 | ||
553 | /* | |
554 | * Class: org_rocksdb_WriteBatchWithIndex | |
555 | * Method: getFromBatch | |
556 | * Signature: (JJ[BI)[B | |
557 | */ | |
558 | jbyteArray JNICALL Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BI( | |
11fdf7f2 | 559 | JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdbopt_handle, |
7c673cae | 560 | jbyteArray jkey, jint jkey_len) { |
f67539c2 TL |
561 | auto* wbwi = |
562 | reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle); | |
563 | auto* dbopt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jdbopt_handle); | |
7c673cae | 564 | |
f67539c2 TL |
565 | auto getter = [&wbwi, &dbopt](const ROCKSDB_NAMESPACE::Slice& key, |
566 | std::string* value) { | |
7c673cae FG |
567 | return wbwi->GetFromBatch(*dbopt, key, value); |
568 | }; | |
569 | ||
f67539c2 | 570 | return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len); |
7c673cae FG |
571 | } |
572 | ||
573 | /* | |
574 | * Class: org_rocksdb_WriteBatchWithIndex | |
575 | * Method: getFromBatch | |
576 | * Signature: (JJ[BIJ)[B | |
577 | */ | |
578 | jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BIJ( | |
11fdf7f2 | 579 | JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdbopt_handle, |
7c673cae | 580 | jbyteArray jkey, jint jkey_len, jlong jcf_handle) { |
f67539c2 TL |
581 | auto* wbwi = |
582 | reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle); | |
583 | auto* dbopt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jdbopt_handle); | |
584 | auto* cf_handle = | |
585 | reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle); | |
7c673cae | 586 | |
f67539c2 | 587 | auto getter = [&wbwi, &cf_handle, &dbopt](const ROCKSDB_NAMESPACE::Slice& key, |
11fdf7f2 TL |
588 | std::string* value) { |
589 | return wbwi->GetFromBatch(cf_handle, *dbopt, key, value); | |
590 | }; | |
7c673cae | 591 | |
f67539c2 | 592 | return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len); |
7c673cae FG |
593 | } |
594 | ||
595 | /* | |
596 | * Class: org_rocksdb_WriteBatchWithIndex | |
597 | * Method: getFromBatchAndDB | |
598 | * Signature: (JJJ[BI)[B | |
599 | */ | |
600 | jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BI( | |
11fdf7f2 | 601 | JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdb_handle, |
7c673cae | 602 | jlong jreadopt_handle, jbyteArray jkey, jint jkey_len) { |
f67539c2 TL |
603 | auto* wbwi = |
604 | reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle); | |
605 | auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle); | |
606 | auto* readopt = | |
607 | reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jreadopt_handle); | |
7c673cae | 608 | |
f67539c2 | 609 | auto getter = [&wbwi, &db, &readopt](const ROCKSDB_NAMESPACE::Slice& key, |
11fdf7f2 TL |
610 | std::string* value) { |
611 | return wbwi->GetFromBatchAndDB(db, *readopt, key, value); | |
612 | }; | |
7c673cae | 613 | |
f67539c2 | 614 | return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len); |
7c673cae FG |
615 | } |
616 | ||
617 | /* | |
618 | * Class: org_rocksdb_WriteBatchWithIndex | |
619 | * Method: getFromBatchAndDB | |
620 | * Signature: (JJJ[BIJ)[B | |
621 | */ | |
622 | jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BIJ( | |
11fdf7f2 | 623 | JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdb_handle, |
7c673cae | 624 | jlong jreadopt_handle, jbyteArray jkey, jint jkey_len, jlong jcf_handle) { |
f67539c2 TL |
625 | auto* wbwi = |
626 | reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle); | |
627 | auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle); | |
628 | auto* readopt = | |
629 | reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jreadopt_handle); | |
630 | auto* cf_handle = | |
631 | reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle); | |
632 | ||
633 | auto getter = [&wbwi, &db, &cf_handle, &readopt]( | |
634 | const ROCKSDB_NAMESPACE::Slice& key, std::string* value) { | |
11fdf7f2 TL |
635 | return wbwi->GetFromBatchAndDB(db, *readopt, cf_handle, key, value); |
636 | }; | |
7c673cae | 637 | |
f67539c2 | 638 | return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len); |
7c673cae FG |
639 | } |
640 | ||
641 | /* | |
642 | * Class: org_rocksdb_WriteBatchWithIndex | |
643 | * Method: disposeInternal | |
644 | * Signature: (J)V | |
645 | */ | |
11fdf7f2 TL |
646 | void Java_org_rocksdb_WriteBatchWithIndex_disposeInternal(JNIEnv* /*env*/, |
647 | jobject /*jobj*/, | |
648 | jlong handle) { | |
f67539c2 TL |
649 | auto* wbwi = |
650 | reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(handle); | |
7c673cae FG |
651 | assert(wbwi != nullptr); |
652 | delete wbwi; | |
653 | } | |
654 | ||
655 | /* WBWIRocksIterator below */ | |
656 | ||
657 | /* | |
658 | * Class: org_rocksdb_WBWIRocksIterator | |
659 | * Method: disposeInternal | |
660 | * Signature: (J)V | |
661 | */ | |
11fdf7f2 TL |
662 | void Java_org_rocksdb_WBWIRocksIterator_disposeInternal(JNIEnv* /*env*/, |
663 | jobject /*jobj*/, | |
664 | jlong handle) { | |
f67539c2 | 665 | auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle); |
7c673cae FG |
666 | assert(it != nullptr); |
667 | delete it; | |
668 | } | |
669 | ||
670 | /* | |
671 | * Class: org_rocksdb_WBWIRocksIterator | |
672 | * Method: isValid0 | |
673 | * Signature: (J)Z | |
674 | */ | |
11fdf7f2 TL |
675 | jboolean Java_org_rocksdb_WBWIRocksIterator_isValid0(JNIEnv* /*env*/, |
676 | jobject /*jobj*/, | |
677 | jlong handle) { | |
f67539c2 | 678 | return reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Valid(); |
7c673cae FG |
679 | } |
680 | ||
681 | /* | |
682 | * Class: org_rocksdb_WBWIRocksIterator | |
683 | * Method: seekToFirst0 | |
684 | * Signature: (J)V | |
685 | */ | |
11fdf7f2 TL |
686 | void Java_org_rocksdb_WBWIRocksIterator_seekToFirst0(JNIEnv* /*env*/, |
687 | jobject /*jobj*/, | |
688 | jlong handle) { | |
f67539c2 | 689 | reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->SeekToFirst(); |
7c673cae FG |
690 | } |
691 | ||
692 | /* | |
693 | * Class: org_rocksdb_WBWIRocksIterator | |
694 | * Method: seekToLast0 | |
695 | * Signature: (J)V | |
696 | */ | |
11fdf7f2 TL |
697 | void Java_org_rocksdb_WBWIRocksIterator_seekToLast0(JNIEnv* /*env*/, |
698 | jobject /*jobj*/, | |
699 | jlong handle) { | |
f67539c2 | 700 | reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->SeekToLast(); |
7c673cae FG |
701 | } |
702 | ||
703 | /* | |
704 | * Class: org_rocksdb_WBWIRocksIterator | |
705 | * Method: next0 | |
706 | * Signature: (J)V | |
707 | */ | |
11fdf7f2 TL |
708 | void Java_org_rocksdb_WBWIRocksIterator_next0(JNIEnv* /*env*/, jobject /*jobj*/, |
709 | jlong handle) { | |
f67539c2 | 710 | reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Next(); |
7c673cae FG |
711 | } |
712 | ||
713 | /* | |
714 | * Class: org_rocksdb_WBWIRocksIterator | |
715 | * Method: prev0 | |
716 | * Signature: (J)V | |
717 | */ | |
11fdf7f2 TL |
718 | void Java_org_rocksdb_WBWIRocksIterator_prev0(JNIEnv* /*env*/, jobject /*jobj*/, |
719 | jlong handle) { | |
f67539c2 | 720 | reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Prev(); |
7c673cae FG |
721 | } |
722 | ||
723 | /* | |
724 | * Class: org_rocksdb_WBWIRocksIterator | |
725 | * Method: seek0 | |
726 | * Signature: (J[BI)V | |
727 | */ | |
11fdf7f2 TL |
728 | void Java_org_rocksdb_WBWIRocksIterator_seek0(JNIEnv* env, jobject /*jobj*/, |
729 | jlong handle, jbyteArray jtarget, | |
730 | jint jtarget_len) { | |
f67539c2 | 731 | auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle); |
7c673cae | 732 | jbyte* target = env->GetByteArrayElements(jtarget, nullptr); |
11fdf7f2 | 733 | if (target == nullptr) { |
7c673cae FG |
734 | // exception thrown: OutOfMemoryError |
735 | return; | |
736 | } | |
737 | ||
f67539c2 TL |
738 | ROCKSDB_NAMESPACE::Slice target_slice(reinterpret_cast<char*>(target), |
739 | jtarget_len); | |
7c673cae FG |
740 | |
741 | it->Seek(target_slice); | |
742 | ||
743 | env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT); | |
744 | } | |
745 | ||
f67539c2 TL |
746 | /* |
747 | * Class: org_rocksdb_WBWIRocksIterator | |
748 | * Method: seekDirect0 | |
749 | * Signature: (JLjava/nio/ByteBuffer;II)V | |
750 | */ | |
751 | void Java_org_rocksdb_WBWIRocksIterator_seekDirect0( | |
752 | JNIEnv* env, jobject /*jobj*/, jlong handle, jobject jtarget, | |
753 | jint jtarget_off, jint jtarget_len) { | |
754 | auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle); | |
755 | auto seek = [&it](ROCKSDB_NAMESPACE::Slice& target_slice) { | |
756 | it->Seek(target_slice); | |
757 | }; | |
758 | ROCKSDB_NAMESPACE::JniUtil::k_op_direct(seek, env, jtarget, jtarget_off, | |
759 | jtarget_len); | |
760 | } | |
761 | ||
11fdf7f2 TL |
762 | /* |
763 | * Class: org_rocksdb_WBWIRocksIterator | |
764 | * Method: seekForPrev0 | |
765 | * Signature: (J[BI)V | |
766 | */ | |
767 | void Java_org_rocksdb_WBWIRocksIterator_seekForPrev0(JNIEnv* env, | |
768 | jobject /*jobj*/, | |
769 | jlong handle, | |
770 | jbyteArray jtarget, | |
771 | jint jtarget_len) { | |
f67539c2 | 772 | auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle); |
11fdf7f2 TL |
773 | jbyte* target = env->GetByteArrayElements(jtarget, nullptr); |
774 | if (target == nullptr) { | |
775 | // exception thrown: OutOfMemoryError | |
776 | return; | |
777 | } | |
778 | ||
f67539c2 TL |
779 | ROCKSDB_NAMESPACE::Slice target_slice(reinterpret_cast<char*>(target), |
780 | jtarget_len); | |
11fdf7f2 TL |
781 | |
782 | it->SeekForPrev(target_slice); | |
783 | ||
784 | env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT); | |
785 | } | |
786 | ||
7c673cae FG |
787 | /* |
788 | * Class: org_rocksdb_WBWIRocksIterator | |
789 | * Method: status0 | |
790 | * Signature: (J)V | |
791 | */ | |
11fdf7f2 TL |
792 | void Java_org_rocksdb_WBWIRocksIterator_status0(JNIEnv* env, jobject /*jobj*/, |
793 | jlong handle) { | |
f67539c2 TL |
794 | auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle); |
795 | ROCKSDB_NAMESPACE::Status s = it->status(); | |
7c673cae FG |
796 | |
797 | if (s.ok()) { | |
798 | return; | |
799 | } | |
800 | ||
f67539c2 | 801 | ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); |
7c673cae FG |
802 | } |
803 | ||
804 | /* | |
805 | * Class: org_rocksdb_WBWIRocksIterator | |
806 | * Method: entry1 | |
807 | * Signature: (J)[J | |
808 | */ | |
11fdf7f2 TL |
809 | jlongArray Java_org_rocksdb_WBWIRocksIterator_entry1(JNIEnv* env, |
810 | jobject /*jobj*/, | |
811 | jlong handle) { | |
f67539c2 TL |
812 | auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle); |
813 | const ROCKSDB_NAMESPACE::WriteEntry& we = it->Entry(); | |
7c673cae FG |
814 | |
815 | jlong results[3]; | |
816 | ||
11fdf7f2 | 817 | // set the type of the write entry |
f67539c2 | 818 | results[0] = ROCKSDB_NAMESPACE::WriteTypeJni::toJavaWriteType(we.type); |
7c673cae | 819 | |
11fdf7f2 TL |
820 | // NOTE: key_slice and value_slice will be freed by |
821 | // org.rocksdb.DirectSlice#close | |
7c673cae | 822 | |
f67539c2 | 823 | auto* key_slice = new ROCKSDB_NAMESPACE::Slice(we.key.data(), we.key.size()); |
7c673cae | 824 | results[1] = reinterpret_cast<jlong>(key_slice); |
f67539c2 TL |
825 | if (we.type == ROCKSDB_NAMESPACE::kDeleteRecord || |
826 | we.type == ROCKSDB_NAMESPACE::kSingleDeleteRecord || | |
827 | we.type == ROCKSDB_NAMESPACE::kLogDataRecord) { | |
7c673cae FG |
828 | // set native handle of value slice to null if no value available |
829 | results[2] = 0; | |
830 | } else { | |
f67539c2 TL |
831 | auto* value_slice = |
832 | new ROCKSDB_NAMESPACE::Slice(we.value.data(), we.value.size()); | |
7c673cae FG |
833 | results[2] = reinterpret_cast<jlong>(value_slice); |
834 | } | |
835 | ||
836 | jlongArray jresults = env->NewLongArray(3); | |
11fdf7f2 | 837 | if (jresults == nullptr) { |
7c673cae | 838 | // exception thrown: OutOfMemoryError |
11fdf7f2 | 839 | if (results[2] != 0) { |
f67539c2 TL |
840 | auto* value_slice = |
841 | reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(results[2]); | |
7c673cae FG |
842 | delete value_slice; |
843 | } | |
844 | delete key_slice; | |
845 | return nullptr; | |
846 | } | |
847 | ||
848 | env->SetLongArrayRegion(jresults, 0, 3, results); | |
11fdf7f2 | 849 | if (env->ExceptionCheck()) { |
7c673cae FG |
850 | // exception thrown: ArrayIndexOutOfBoundsException |
851 | env->DeleteLocalRef(jresults); | |
11fdf7f2 | 852 | if (results[2] != 0) { |
f67539c2 TL |
853 | auto* value_slice = |
854 | reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(results[2]); | |
7c673cae FG |
855 | delete value_slice; |
856 | } | |
857 | delete key_slice; | |
858 | return nullptr; | |
859 | } | |
860 | ||
861 | return jresults; | |
862 | } |