JLevelDB is a project mainly written in JAVA and C++, it's free.
Java access to LevelDB Google Project Database
LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. That project provides tiny access to library making transparent access to C++ classes through Java facade.
Checkout the project and run in command line : 'make' - checkout leveldb project from svn, compile it and build ready to use jar.
Build is only tested under Linux. Possible problems :
// Loads library to corresponding OS if it is not loaded exception is thrown
// Before library is loaded you can not create any object!
// Library can be loaded in class initializator : `static { boolean loaded = LevelDBAccess.load(); }`
DBAccessor dbAccessor = LevelDBAccess.getDBAcessor();
Options options = new Options();
options.setCreateIfMissing(true);
Status status = dbAccessor.open(options, "filepath");
if (status.ok()) {
WriteOptions opts = new WriteOptions();
ReadOptions ro = new ReadOptions();
dbAccessor.put(opts, "key", "value");
assert "value".equals(dbAccessor.get(ro, "key"));
}
There are some operations not linked with C++ API :
Is it really needed ?
Please feel free to make forks and provide your pull requests :)
That project provides very fast ArraySerializer that allows to store array of strings into string. The stream parser processes String in place and not allocate new memory.
With that helper you can serialize/deserialize every data structure like as array of arrays or map (as doubled array).
The format of serialization is pretty simple : [Value, Value2, [ Value3 ]]
. It also supports quotation of important for deserialization characters.
int next;
EntityValueTokenizer tokenizer = new EntityValueTokenizer();
tokenizer.tokenize(value);
while ((next = tokenizer.next()) != END) {
if (next == ELEMENT) {
// TODO process element
String value = tokenizer.value();
} else if (next == START_ARRAY) {
// TODO process start of inner array
} else if (next == END_ARRAY) {
// TODO process end of array
}
}