Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Shcherb committed Aug 5, 2011
1 parent 341639d commit dae6ea5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,62 @@ Possible problems :
How to use
-----------

To do put example.
// 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"));
}


What is not supported
--------------------
There are some things not supported from C++ [API](http://code.google.com/p/leveldb/source/browse/#svn%2Ftrunk%2Finclude%2Fleveldb) :
There are some operations not linked with C++ [API](http://code.google.com/p/leveldb/source/browse/#svn%2Ftrunk%2Finclude%2Fleveldb) :

* [TableBuilder](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/table_builder.h) and [Table](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/table.h) - important enough to be implemented.
* [Comparator](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/comparator.h) - important enough (callback)

Is it really needed ?

* [Cache](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/cache.h) - own implementation of cache
* [Environment](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/env.h) - own implementation of RandomAccessFile, SequentialFile,...
* [Cleanup Function of Iterator](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/iterator.h)
* [Options +](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/options.h) - requires additional entity to be implemented such as Snapshot, Environment, Logger.
* [Cleanup Function of Iterator](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/iterator.h)
* [WriteBatch Iterator](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/write_batch.h) - iterate over entities to be writen

Something missed?

Contribution
--------------------
Please feel free to make for and provide your pull requests :)
Please feel free to make forks and provide your pull requests :)


Additional
--------------------

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
}
}

3 changes: 1 addition & 2 deletions src/com/anvisics/jleveldb/TestDBAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void main(String[] args) {
DBAccessor dbAccessor = LevelDBAccess.getDBAcessor();
Options options = new Options();
options.setCreateIfMissing(true);
Status status = dbAccessor.open(options, "/home/victor/projects/OsmAnd/navigation_ws/JavaLevelDB/db");
Status status = dbAccessor.open(options, "tmp/JavaLevelDB/db");

if (!status.ok()) {
System.out.println(status.ToString());
Expand All @@ -29,7 +29,6 @@ public static void main(String[] args) {
for (int i = 5; i < 1000; i++) {
updates.Put(i+"", (i * i) + "");
}

dbAccessor.write(opts, updates);
updates.delete();
ro.setVerifyChecksums(true);
Expand Down

0 comments on commit dae6ea5

Please sign in to comment.