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