Skip to content

Instantly share code, notes, and snippets.

@szarnyasg
Created May 8, 2012 21:59
Show Gist options
  • Save szarnyasg/2639711 to your computer and use it in GitHub Desktop.
Save szarnyasg/2639711 to your computer and use it in GitHub Desktop.
GraphDatabaseService graphDb = new EmbeddedGraphDatabase("tempdb");
Transaction tx = graphDb.beginTx();
try {
// graph: (0)---"A"--->(1)---"B"--->(2) (3)
List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < 4; i++) {
Node node = graphDb.createNode();
node.setProperty("label", "(" + i + ")");
nodes.add(node);
}
Relationship relationshipA = nodes.get(0).createRelationshipTo(nodes.get(1), MyTypes.POINTS_TO);
relationshipA.setProperty("edgelabel", "A");
Relationship relationshipB = nodes.get(1).createRelationshipTo(nodes.get(2), MyTypes.POINTS_TO);
relationshipB.setProperty("edgelabel", "B");
tx.success();
} finally {
tx.finish();
}
graphDb.shutdown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment