Skip to content

Instantly share code, notes, and snippets.

@datablend
Created July 16, 2011 10:27
Show Gist options
  • Save datablend/1086243 to your computer and use it in GitHub Desktop.
Save datablend/1086243 to your computer and use it in GitHub Desktop.
public class MyNeo4jGraph extends Neo4jGraph {
private long numberOfItems = 0;
private long maxNumberOfItems = 1;
public MyNeo4jGraph(final String directory, long maxNumberOfItems) {
super(directory, null);
this.maxNumberOfItems = maxNumberOfItems;
}
public MyNeo4jGraph(final String directory, final Map<String, String> configuration, long maxNumberOfItems) {
super(directory, configuration);
this.maxNumberOfItems = maxNumberOfItems;
}
public Vertex addVertex(final Object id) {
Vertex vertex = super.addVertex(id);
commitIfRequired();
return vertex;
}
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
Edge edge = super.addEdge(id, outVertex, inVertex, label);
commitIfRequired();
return edge;
}
private void commitIfRequired() {
// Check whether commit should be executed
if (++numberOfItems % maxNumberOfItems == 0) {
// Stop the transaction
stopTransaction(Conclusion.SUCCESS);
// Immediately start a new one
startTransaction();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment