Skip to content

dmontag/neo4j-versioning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neo4j Versioning

Implements time machine style versioning. Every change to the graph bumps the version number used. The graph can then be viewed at any given version number. With fairly little effort, this library can be modified to provide timestamp-based versioning instead.

Implementation-wise, it stores a validity range on relationships, and also keeps versioned copies of node properties. Indices and relationship properties are currently not versioned.

To set up

Add a VersioningTransactionEventHandler as a transaction event handler to the GraphDatabaseService used:

GraphDatabaseService graphDb = ...;
VersioningTransactionEventHandler eventHandler = new VersioningTransactionEventHandler(graphDb.getReferenceNode());
graphDb.registerTransactionEventHandler(eventHandler);

The event handler takes a constructor argument which is a node to store the config on, so that the latest version
number can be stored in-graph.

To read

Use a VersionContext to browse the graph as it looked at a given version.

import static org.neo4j.support.versioning.date.VersionContext.vc;

// Obtain node from somewhere, e.g. index lookups
Node someNode = ...;

// Versioned node, seeing the graph as it looked at time 1234
Node versionedNode = vc(1234).node(someNode);

long snapshot = eventHandler.getLatestVersion();
Node head = vc(snapshot).node(someNode);

To write

Most things are taken care of by the event handler seamlessly. Every transaction will bump the version number.

Transaction tx = graphDb.beginTx();
try {
    Node bob = graphDb.createNode();
    Node jim = graphDb.createNode();
    bob.createRelationshipTo(jim, KNOWS);
    tx.success();
} finally {
    tx.finish();
}

Deletion of nodes and relationships must be done specially.

Transaction tx = graphDb.beginTx();
try {
    vc(1234).deleteNode(someNode);
    vc(1234).deleteRelationship(someRelationship);
    tx.success();
} finally {
    tx.finish();
}

Indexing

This versioning component does currently not cover indexing.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages