Created
July 16, 2011 10:27
-
-
Save datablend/1086243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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