[JNI] Add java api and java tests for WriteBatch and WriteOptions, add put() and remove() to RocksDB.

Summary:
* Add java api for rocksdb::WriteBatch and rocksdb::WriteOptions, which are necessary components
  for running benchmark.
* Add java test for org.rocksdb.WriteBatch and org.rocksdb.WriteOptions.
* Add remove() to org.rocksdb.RocksDB, and add put() and remove() to RocksDB which take
  org.rocksdb.WriteOptions.

Test Plan: make jtest

Reviewers: haobo, sdong, dhruba

Reviewed By: sdong

CC: leveldb

Differential Revision: https://reviews.facebook.net/D17373
This commit is contained in:
Yueh-Hsuan Chiang
2014-04-02 13:14:55 -07:00
parent 8c4a3bfa5b
commit da0887a3dc
11 changed files with 906 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
@@ -64,6 +64,17 @@ public class RocksDB {
put(key, key.length, value, value.length);
}
/**
* Set the database entry for "key" to "value".
*
* @param key the specified key to be inserted.
* @param value the value associated with the specified key.
*/
public void put(WriteOptions writeOpts, byte[] key, byte[] value)
throws RocksDBException {
put(writeOpts.nativeHandle_, key, key.length, value, value.length);
}
/**
* Get the value associated with the specified key.
*
@@ -95,6 +106,25 @@ public class RocksDB {
return get(key, key.length);
}
/**
* Remove the database entry (if any) for "key". Returns OK on
* success, and a non-OK status on error. It is not an error if "key"
* did not exist in the database.
*/
public void remove(byte[] key) throws RocksDBException {
remove(key, key.length);
}
/**
* Remove the database entry (if any) for "key". Returns OK on
* success, and a non-OK status on error. It is not an error if "key"
* did not exist in the database.
*/
public void remove(WriteOptions writeOpt, byte[] key)
throws RocksDBException {
remove(writeOpt.nativeHandle_, key, key.length);
}
@Override protected void finalize() {
close();
}
@@ -108,15 +138,23 @@ public class RocksDB {
// native methods
private native void open0(String path) throws RocksDBException;
private native void open(long optionsHandle, String path) throws RocksDBException;
private native void open(
long optionsHandle, String path) throws RocksDBException;
private native void put(
byte[] key, int keyLen,
byte[] value, int valueLen) throws RocksDBException;
private native void put(
long writeOptHandle, byte[] key, int keyLen,
byte[] value, int valueLen) throws RocksDBException;
private native int get(
byte[] key, int keyLen,
byte[] value, int valueLen) throws RocksDBException;
private native byte[] get(
byte[] key, int keyLen) throws RocksDBException;
private native void remove(
byte[] key, int keyLen) throws RocksDBException;
private native void remove(
long writeOptHandle, byte[] key, int keyLen) throws RocksDBException;
private native void close0();
private long nativeHandle_;