Skip to content
Snippets Groups Projects
Commit 41727153 authored by Aidan's avatar Aidan
Browse files

Fix bug where we need to use HashMap[] instead of Map<HashMap> for batch operations

parent c067b785
No related branches found
No related tags found
No related merge requests found
......@@ -101,14 +101,14 @@ public class LevelDBWrapperTest {
String batchValue2_b64 = Base64.getEncoder().encodeToString(batchValue2.getBytes());
// Perform batch put operations
Map<String, String>[] operations = new Map[2];
Map<String, String> operation1 = new HashMap<>();
HashMap<String, String>[] operations = new HashMap[2];
HashMap<String, String> operation1 = new HashMap<>();
operation1.put("type", "put");
operation1.put("key", batchKey1_b64);
operation1.put("value", batchValue1_b64);
operations[0] = operation1;
Map<String, String> operation2 = new HashMap<>();
HashMap<String, String> operation2 = new HashMap<>();
operation2.put("type", "put");
operation2.put("key", batchKey2_b64);
operation2.put("value", batchValue2_b64);
......
......@@ -241,7 +241,7 @@ JNIEXPORT void JNICALL Java_org_futo_polycentric_leveldbcapacitor_MobileLevelImp
batch.Put(decoded_key, decoded_value);
env->ReleaseStringUTFChars(value, value_cstr);
} else if (strcmp(type_cstr, "delete") == 0) {
} else if (strcmp(type_cstr, "del") == 0) {
batch.Delete(decoded_key);
} else {
throwJavaException(env, "Invalid operation type");
......
......@@ -17,7 +17,7 @@ public class MobileLevelImpl {
public native void db_delete(String dbName, String key);
public native void db_clear(String dbName) throws Exception;
public native void db_close(String dbName);
public native void db_batch(String dbName, Map<String, String>[] operations);
public native void db_batch(String dbName, HashMap<String, String>[] operations);
public native ArrayList<ArrayList<String>> db_iterator(String dbName, HashMap<String, Object> options);
static {
......
......@@ -140,17 +140,19 @@ public class MobileLevelPlugin extends Plugin {
}
try {
Map<String, String>[] java_operations = new Map[operations.length()];
HashMap<String, String>[] javaOperations = new HashMap[operations.length()];
for (int i = 0; i < operations.length(); i++) {
JSONObject operation = operations.getJSONObject(0);
Map<String, String> java_operation = new HashMap<>();
java_operation.put("type", operation.getString("type"));
java_operation.put("key", operation.getString("key"));
java_operation.put("value", operation.getString("value"));
java_operations[i] = java_operation;
JSONObject operation = operations.getJSONObject(i); // corrected to getJSONObject(i)
HashMap<String, String> javaOperation = new HashMap<>();
javaOperation.put("type", operation.getString("type"));
javaOperation.put("key", operation.getString("key"));
if (operation.has("value")) {
javaOperation.put("value", operation.getString("value"));
}
javaOperations[i] = javaOperation;
}
mobileLevel.db_batch(dbName, java_operations);
mobileLevel.db_batch(dbName, javaOperations);
call.resolve();
} catch (Exception e) {
call.reject(e.getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment