diff --git a/java/org/rocksdb/RocksDB.java b/java/org/rocksdb/RocksDB.java index 289638d657..649433b8cc 100644 --- a/java/org/rocksdb/RocksDB.java +++ b/java/org/rocksdb/RocksDB.java @@ -154,58 +154,58 @@ public class RocksDB { public byte[] get(ReadOptions opt, byte[] key) throws RocksDBException { return get(nativeHandle_, opt.nativeHandle_, key, key.length); } - + /** * Returns a map of keys for which values were found in DB. - * + * * @param keys List of keys for which values need to be retrieved. - * @return Map where key of map is the key passed by user and value for map + * @return Map where key of map is the key passed by user and value for map * entry is the corresponding value in DB. - * - * @see RocksDBException + * + * @see RocksDBException */ public Map multiGet(List keys) throws RocksDBException { List values = multiGet( nativeHandle_, keys, keys.size()); - - Map keyValueMap = new HashMap(); + + Map keyValueMap = new HashMap(); for(int i = 0; i < values.size(); i++) { if(values.get(i) == null) { continue; } - + keyValueMap.put(keys.get(i), values.get(i)); } - + return keyValueMap; } - - + + /** * Returns a map of keys for which values were found in DB. - * + * * @param List of keys for which values need to be retrieved. * @param opt Read options. - * @return Map where key of map is the key passed by user and value for map + * @return Map where key of map is the key passed by user and value for map * entry is the corresponding value in DB. - * - * @see RocksDBException + * + * @see RocksDBException */ public Map multiGet(ReadOptions opt, List keys) throws RocksDBException { List values = multiGet( nativeHandle_, opt.nativeHandle_, keys, keys.size()); - - Map keyValueMap = new HashMap(); + + Map keyValueMap = new HashMap(); for(int i = 0; i < values.size(); i++) { if(values.get(i) == null) { continue; } - + keyValueMap.put(keys.get(i), values.get(i)); } - + return keyValueMap; } diff --git a/java/rocksjni/portal.h b/java/rocksjni/portal.h index 11764eee89..7d70eecae2 100644 --- a/java/rocksjni/portal.h +++ b/java/rocksjni/portal.h @@ -324,7 +324,7 @@ class ListJni { assert(jclazz != nullptr); return jclazz; } - + // Get the java class id of java.util.ArrayList. static jclass getArrayListClass(JNIEnv* env) { static jclass jclazz = env->FindClass("java/util/ArrayList"); @@ -338,7 +338,7 @@ class ListJni { assert(jclazz != nullptr); return jclazz; } - + // Get the java method id of java.util.List.iterator(). static jmethodID getIteratorMethod(JNIEnv* env) { static jmethodID mid = env->GetMethodID( @@ -346,7 +346,7 @@ class ListJni { assert(mid != nullptr); return mid; } - + // Get the java method id of java.util.Iterator.hasNext(). static jmethodID getHasNextMethod(JNIEnv* env) { static jmethodID mid = env->GetMethodID( @@ -354,7 +354,7 @@ class ListJni { assert(mid != nullptr); return mid; } - + // Get the java method id of java.util.Iterator.next(). static jmethodID getNextMethod(JNIEnv* env) { static jmethodID mid = env->GetMethodID( @@ -362,7 +362,7 @@ class ListJni { assert(mid != nullptr); return mid; } - + // Get the java method id of arrayList constructor. static jmethodID getArrayListConstructorMethodId(JNIEnv* env, jclass jclazz) { static jmethodID mid = env->GetMethodID( @@ -370,7 +370,7 @@ class ListJni { assert(mid != nullptr); return mid; } - + // Get the java method id of java.util.List.add(). static jmethodID getListAddMethodId(JNIEnv* env) { static jmethodID mid = env->GetMethodID( diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc index a8e6dfbb0a..639c54adea 100644 --- a/java/rocksjni/rocksjni.cc +++ b/java/rocksjni/rocksjni.cc @@ -249,37 +249,37 @@ jobject multi_get_helper(JNIEnv* env, jobject jdb, rocksdb::DB* db, const rocksdb::ReadOptions& rOpt, jobject jkey_list, jint jkeys_count) { std::vector keys; std::vector keys_to_free; - + // get iterator jobject iteratorObj = env->CallObjectMethod( jkey_list, rocksdb::ListJni::getIteratorMethod(env)); - + // iterate over keys and convert java byte array to slice while(env->CallBooleanMethod( iteratorObj, rocksdb::ListJni::getHasNextMethod(env)) == JNI_TRUE) { jbyteArray jkey = (jbyteArray) env->CallObjectMethod( iteratorObj, rocksdb::ListJni::getNextMethod(env)); jint key_length = env->GetArrayLength(jkey); - + jbyte* key = new jbyte[key_length]; env->GetByteArrayRegion(jkey, 0, key_length, key); // store allocated jbyte to free it after multiGet call - keys_to_free.push_back(key); - + keys_to_free.push_back(key); + rocksdb::Slice key_slice( reinterpret_cast(key), key_length); keys.push_back(key_slice); } - + std::vector values; std::vector s = db->MultiGet(rOpt, keys, &values); - + // Don't reuse class pointer - jclass jclazz = env->FindClass("java/util/ArrayList"); + jclass jclazz = env->FindClass("java/util/ArrayList"); jmethodID mid = rocksdb::ListJni::getArrayListConstructorMethodId( - env, jclazz); + env, jclazz); jobject jvalue_list = env->NewObject(jclazz, mid, jkeys_count); - + // insert in java list for(std::vector::size_type i = 0; i != s.size(); i++) { if(s[i].ok()) { @@ -295,13 +295,13 @@ jobject multi_get_helper(JNIEnv* env, jobject jdb, rocksdb::DB* db, jvalue_list, rocksdb::ListJni::getListAddMethodId(env), nullptr); } } - + // free up allocated byte arrays for(std::vector::size_type i = 0; i != keys_to_free.size(); i++) { delete[] keys_to_free[i]; } keys_to_free.clear(); - + return jvalue_list; }