Adds support for db->DefaultColumnFamily() to the Java API
This commit is contained in:
parent
516a04267e
commit
45e43b81df
@ -1180,6 +1180,15 @@ public class RocksDB extends RocksObject {
|
||||
return iterators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the handle for the default column family
|
||||
*
|
||||
* @return The handle of the default column family
|
||||
*/
|
||||
public ColumnFamilyHandle getDefaultColumnFamily() {
|
||||
return new ColumnFamilyHandle(this, getDefaultColumnFamily(nativeHandle_));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new column family with the name columnFamilyName and
|
||||
* allocates a ColumnFamilyHandle within an internal structure.
|
||||
@ -1620,6 +1629,7 @@ public class RocksDB extends RocksObject {
|
||||
protected native void releaseSnapshot(
|
||||
long nativeHandle, long snapshotHandle);
|
||||
private native void disposeInternal(long handle);
|
||||
private native long getDefaultColumnFamily(long handle);
|
||||
private native long createColumnFamily(long handle,
|
||||
ColumnFamilyDescriptor columnFamilyDescriptor) throws RocksDBException;
|
||||
private native void dropColumnFamily(long handle, long cfHandle) throws RocksDBException;
|
||||
|
@ -56,6 +56,40 @@ public class ColumnFamilyTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultColumnFamily() throws RocksDBException {
|
||||
RocksDB db = null;
|
||||
Options options = null;
|
||||
try {
|
||||
options = new Options();
|
||||
options.setCreateIfMissing(true);
|
||||
|
||||
DBOptions dbOptions = new DBOptions();
|
||||
dbOptions.setCreateIfMissing(true);
|
||||
|
||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
||||
ColumnFamilyHandle cfh = db.getDefaultColumnFamily();
|
||||
assertThat(cfh).isNotNull();
|
||||
|
||||
final byte[] key = "key".getBytes();
|
||||
final byte[] value = "value".getBytes();
|
||||
|
||||
db.put(cfh, key, value);
|
||||
|
||||
final byte[] actualValue = db.get(cfh, key);
|
||||
|
||||
assertThat(cfh).isNotNull();
|
||||
assertThat(actualValue).isEqualTo(value);
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
if (options != null) {
|
||||
options.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createColumnFamily() throws RocksDBException {
|
||||
RocksDB db = null;
|
||||
|
@ -1174,6 +1174,18 @@ jlongArray Java_org_rocksdb_RocksDB_iterators(
|
||||
return env->NewLongArray(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: getDefaultColumnFamily
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_RocksDB_getDefaultColumnFamily(
|
||||
JNIEnv* env, jobject jobj, jlong jdb_handle) {
|
||||
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||
auto* cf_handle = db_handle->DefaultColumnFamily();
|
||||
return reinterpret_cast<jlong>(cf_handle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RocksDB
|
||||
* Method: createColumnFamily
|
||||
|
Loading…
Reference in New Issue
Block a user