Database Reference
In-Depth Information
2.
Let's create another vertex for tweets and define an edge between the
user and tweet vertex:
Vertex tweet = graph.addVertex(null);
tweet.setProperty("body", "Working on
Cassandra book for apress");
tweet.setProperty("tweeted_at", "2014-09-21");
graph.addEdge(null, vivs, tweet,
"has_tweeted"); // User vivs has tweets
3.
We can also add another vertex and establish a relation of "follow-
ing" :
Vertex apress = graph.addVertex(null);
apress.setProperty("fname", "apress");
apress.setProperty("twitter_tag",
"apress_team");
graph.addEdge(null, vivs, apress,
"following"); // Vivs is following apress team
4.
And then finally commit the transaction:
graph.commit();
Reading from the Graph
Let's explore a bit around reading vertices and properties from a Titan graph:
1.
Reading from a graph is also fairly easy, and we can retrieve all ver-
tices for a particular graph or even a specific vertex:
Iterable<Vertex> vertices =
graph.getVertices();
Iterator<Vertex> iter = vertices.iterator();
2.
We can iterate over each vertex and retrieve incident edges like this:
Search WWH ::




Custom Search