jankotek/MapDB — pull request #169 by ncolomer (2013-08-15 18:35:15+00:00)
Title: MapDBGraph: Blueprints implementation for MapDB

## Commit description

1. addd9dc `Rework Maven project structure to allow new modules`
A Maven structure refactoring was necessary to add a new `graph` module into the project. Actual MapDB sources was moved to the `core` module. Its build lifecycle is not affected. The `graph` module depends to the `core` module.

2. d9b6467 `Add MapDB blueprints implementation in a dedicated module`
The MapDBGraph implementation

## Implementation notes

This implementation was inspired from [TinkerGraph](https://github.com/tinkerpop/blueprints/wiki/TinkerGraph) at the begin (the closest implementation, that uses in-heap native Java collections) but diverged much to take advantage of MapDB API and features.

This implementation uses several MapDB collections, regrouped in the `GraphStore` class:

* `IdStore` **vertexIdStore**: stores vertex id/uid index
* `Set` **vertexStore**: stores vertex uids. Allows fast vertex uid lookup
* `IdStore` **edgeIdStore**: stores edge id/uid index
* `Map` **edgeStore**: stores edges data, indexed by edge uid. Values are a `Tuple3` where:
* `Tuple3.a` = out vertex uid
* `Tuple3.b` = in vertex uid
* `Tuple3.c` = edge label
* `` **inRelationStore**: stores relations indexed by in vertex uid. Allows to retrieve all vertex inbound edges and vertices. Value contains the related edge uid. Keys are a `Tuple3` where:
* `Tuple3.a` = in vertex uid
* `Tuple3.b` = out vertex uid
* `Tuple3.c` = edge label
* `` **outRelationStore**: stores relations indexed by out vertex uid. Allows to retrieve all vertex outbound edges and vertices. Value contains the related edge uid. Keys are a `Tuple3` where:
* `Tuple3.a` = out vertex uid
* `Tuple3.b` = in vertex uid
* `Tuple3.c` = edge label
* `` **propertyStore**: stores element properties, indexed by element uid and property key. Keys are a `Tuple2` where:
* `Tuple2.a` = edge/vertex uid (the uid generator is common to both elements)
* `Tuple2.b` = the property key

The `IdStore` class uses a shared `Atomic.Long` (the common uid generator) and 2 `HashMap`s each:
* `Map` that stores uids as key and ids as value
* `Map` that stores ids as key and uids as value

Other things to note:
* The `IdStore` class allows decoupling ids provided by users and internal ids (named uids)
* This implementation follows the recommandations described in the [Implementations](https://github.com/tinkerpop/blueprints/wiki/Implementations) page of the Blueprints wiki.
* Operation requiring multiple stores are not atomic yet (however, MapDB is capable to handle transactions among multiple stores)
* This implementation is not thread-safe. Due to the previous (temporary) limitation, concurrent operations might lead to inconsistent results
* This is a beta version! Work is in progress and there is probably lot of things to arrange/improve to make it more efficient.

## Test coverage

This implementation is enforced by the Blueprints [Property Graph Model Test Suite](https://github.com/tinkerpop/blueprints/wiki/Property-Graph-Model-Test-Suite) from Tinkerpop.

The following table describes its current state:

| # | TestSuite | Description | State |
|:---:|:--- |:--- |:---:|
| 1 | GraphTestSuite | ensure that vertices and edges work together properly. | ✓ |
| 2 | VertexTestSuite | ensure that vertices and their properties are added and removed properly. | ✓ |
| 3 | EdgeTestSuite | ensure that edges and their properties are added and removed properly. | ✓ |
| 4 | GraphMLReaderTestSuite | ensure that GraphML files are read properly from disk and represented properly. | work in progress |
| 5 | GMLReaderTestSuite | ensure that GML files are read properly from disk and represented properly. | work in progress |
| 6 | GraphSONReaderTestSuite | ensure that GraphSON files are read properly from disk and represented properly. | work in progress |
| 7 | KeyIndexableGraphTestSuite | ensures that graphs that support automatic key indices work properly. | to be done |
| 8 | IndexableGraphTestSuite | ensures that graphs that support indices behave properly. | to be done |
| 9 | IndexTestSuite | ensure that the index system works properly. | to be done |
| 10 | TransactionalGraphTestSuite | ensures that graphs that support transactions behave properly. | to be done |

## What this piece of code needs now

* Code review
* Some benchs
* Be merged into master if satisfying :)