[JNI] Each set function of Options / WriteOptions now returns its option instance.

Summary:
Make each set function of Options / WriteOptions return its option instance.
Java developers can now easier specify each option like the following:

    options.setCreateIfMissing(true)
        .setWriteBufferSize(8 * 1024)
        .setMaxWriteBufferNumber(3)
        .setDisableSeekCompaction(true)
        .setBlockSize(64 * 1024)
        .setMaxBackgroundCompactions(10);

Test Plan:
make rocksdbjava
make jtest

Reviewers: haobo, ankgup87, sdong, dhruba

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D17661
This commit is contained in:
Yueh-Hsuan Chiang 2014-04-14 12:48:50 -07:00
parent be016613c2
commit 2885ad9b77
3 changed files with 55 additions and 31 deletions

View File

@ -32,12 +32,12 @@ public class RocksDBSample {
assert(db == null);
}
options.setCreateIfMissing(true);
options.setWriteBufferSize(8*1024);
options.setMaxWriteBufferNumber(3);
options.setDisableSeekCompaction(true);
options.setBlockSize(64*1024);
options.setMaxBackgroundCompactions(10);
options.setCreateIfMissing(true)
.setWriteBufferSize(8 * 1024)
.setMaxWriteBufferNumber(3)
.setDisableSeekCompaction(true)
.setBlockSize(64 * 1024)
.setMaxBackgroundCompactions(10);
assert(options.createIfMissing() == true);
assert(options.writeBufferSize() == 8192);

View File

@ -7,7 +7,7 @@ package org.rocksdb;
/**
* Options to control the behavior of a database. It will be used
* during the creation of a RocksDB (i.e., RocksDB::Open()).
* during the creation of a RocksDB (i.e., RocksDB.open()).
*
* Note that dispose() must be called before an Options instance
* become out-of-scope to release the allocated memory in c++.
@ -26,23 +26,25 @@ public class Options {
/**
* If this value is set to true, then the database will be created
* if it is missing during RocksDB::Open().
* if it is missing during RocksDB.open().
* Default: false
*
* @param flag a flag indicating whether to create a database the
* specified database in RocksDB::Open() operation is missing.
* @see RocksDB::Open()
* specified database in RocksDB.open() operation is missing.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public void setCreateIfMissing(boolean flag) {
public Options setCreateIfMissing(boolean flag) {
assert(isInitialized());
setCreateIfMissing(nativeHandle_, flag);
return this;
}
/**
* Return true if the create_if_missing flag is set to true.
* If true, the database will be created if it is missing.
*
* @return return true if the create_if_missing flag is set to true.
* @return true if the createIfMissing option is set to true.
* @see setCreateIfMissing()
*/
public boolean createIfMissing() {
@ -63,12 +65,14 @@ public class Options {
* the next time the database is opened.
*
* Default: 4MB
* @param size of write buffer.
* @see RocksDB::Open()
* @param writeBufferSize the size of write buffer.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public void setWriteBufferSize(int writeBufferSize) {
public Options setWriteBufferSize(int writeBufferSize) {
assert(isInitialized());
setWriteBufferSize(nativeHandle_, writeBufferSize);
return this;
}
/**
@ -88,12 +92,14 @@ public class Options {
* storage, new writes can continue to the other write buffer.
* Default: 2
*
* @param maximum number of write buffers.
* @see RocksDB::Open()
* @param maxWriteBufferNumber maximum number of write buffers.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public void setMaxWriteBufferNumber(int maxWriteBufferNumber) {
public Options setMaxWriteBufferNumber(int maxWriteBufferNumber) {
assert(isInitialized());
setMaxWriteBufferNumber(nativeHandle_, maxWriteBufferNumber);
return this;
}
/**
@ -115,16 +121,18 @@ public class Options {
*
* Default: 4K
*
* @param block size.
* @see RocksDB::Open()
* @param blockSize the size of each block in bytes.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public void setBlockSize(int blockSize) {
public Options setBlockSize(int blockSize) {
assert(isInitialized());
setBlockSize(nativeHandle_, blockSize);
return this;
}
/*
* Returns block size.
* Returns the size of a block in bytes.
*
* @return block size.
* @see setBlockSize()
@ -141,12 +149,15 @@ public class Options {
* (which is true if max_open_files is large).
* Default: true
*
* @param disable seek compaction.
* @see RocksDB::Open()
* @param disableSeekCompaction a boolean value to specify whether
* to disable seek compaction.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public void setDisableSeekCompaction(boolean disableSeekCompaction) {
public Options setDisableSeekCompaction(boolean disableSeekCompaction) {
assert(isInitialized());
setDisableSeekCompaction(nativeHandle_, disableSeekCompaction);
return this;
}
/*
@ -165,12 +176,15 @@ public class Options {
* the default LOW priority thread pool.
* Default: 1
*
* @param maximum number of concurrent background jobs.
* @see RocksDB::Open()
* @param maxBackgroundCompactions the maximum number of concurrent
* background jobs.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public void setMaxBackgroundCompactions(int maxBackgroundCompactions) {
public Options setMaxBackgroundCompactions(int maxBackgroundCompactions) {
assert(isInitialized());
setMaxBackgroundCompactions(nativeHandle_, maxBackgroundCompactions);
return this;
}
/*

View File

@ -40,9 +40,14 @@ public class WriteOptions {
* system call followed by "fdatasync()".
*
* Default: false
*
* @param flag a boolean flag to indicate whether a write
* should be synchronized.
* @return the instance of the current WriteOptions.
*/
public void setSync(boolean flag) {
public WriteOptions setSync(boolean flag) {
setSync(nativeHandle_, flag);
return this;
}
/**
@ -68,9 +73,14 @@ public class WriteOptions {
/**
* If true, writes will not first go to the write ahead log,
* and the write may got lost after a crash.
*
* @param flag a boolean flag to specify whether to disable
* write-ahead-log on writes.
* @return the instance of the current WriteOptions.
*/
public void setDisableWAL(boolean flag) {
public WriteOptions setDisableWAL(boolean flag) {
setDisableWAL(nativeHandle_, flag);
return this;
}
/**
@ -92,5 +102,5 @@ public class WriteOptions {
private native boolean disableWAL(long handle);
private native void dispose0(long handle);
protected long nativeHandle_;
protected long nativeHandle_;
}