Created
July 29, 2012 09:47
-
-
Save darekmydlarz/3197122 to your computer and use it in GitHub Desktop.
Java + Neo4j + Blueprints
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
import java.util.Iterator; | |
import com.tinkerpop.blueprints.Direction; | |
import com.tinkerpop.blueprints.Edge; | |
import com.tinkerpop.blueprints.Graph; | |
import com.tinkerpop.blueprints.Vertex; | |
import com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph; | |
public class EmbeddeNeo4j { | |
public static void main(final String[] args) { | |
Graph graph = new Neo4jGraph("tmp/graph"); | |
Vertex a = graph.addVertex(null); | |
Vertex b = graph.addVertex(null); | |
a.setProperty("name", "marko"); | |
b.setProperty("name", "polo"); | |
Edge e = graph.addEdge(null, a, b, "knows"); | |
e.setProperty("since", "2006"); | |
Iterator<Edge> it = a.getEdges(Direction.BOTH).iterator(); | |
while(it.hasNext()) { | |
Edge edge = it.next(); | |
Vertex v1 = edge.getVertex(Direction.IN); | |
Vertex v2 = edge.getVertex(Direction.OUT); | |
System.out.println(v1.getProperty("name") + " knows " + v2.getProperty("name") + " since " + edge.getProperty("since")); | |
} | |
graph.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment