-
Notifications
You must be signed in to change notification settings - Fork 252
/
JanusCassandra.java
85 lines (70 loc) · 3.05 KB
/
JanusCassandra.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// JanusCassandra.java
//
// Simple example of using JanusGraph with Java (outside the Gremlin console)
//
// This example does the following:
// 1. Connects to an existing JanusGraph/Cassandra instance
// 2. Runs a few queries against graph
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.*;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.*;
import org.janusgraph.core.*;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
public class JanusCassandra
{
public static void main(String[] args)
{
System.out.println(" --------------------------");
System.out.println(" Connecting to Graph ");
System.out.println(" --------------------------");
//JanusGraph jg = JanusGraphFactory.open("janusgraph-cassandra.properties") ;
JanusGraph jg = JanusGraphFactory.open("janusgraph-cql.properties") ;
GraphTraversalSource g = jg.traversal();
System.out.println(" --------------------------");
System.out.println(" Sending queries ");
System.out.println(" --------------------------");
Map<String,?> aus = g.V().has("code","AUS").valueMap().next();
System.out.println(aus);
List city = (List)(aus.get("city"));
System.out.println("The AUS airport is in " + city.get(0));
aus.forEach( (k,v) -> System.out.println(k + ": "+ v));
Long n = g.V().has("code","DFW").out().count().next();
System.out.println("There are " + n + " routes from Dallas");
List fromAus = (g.V().has("code","AUS").out().values("code").toList());
System.out.println(fromAus);
List <Path> lhrToUsa = g.V().has("code","LHR").outE().inV().
has("country","US").limit(5).
path().by("code").by("dist").toList();
lhrToUsa.forEach((k) -> System.out.println(k));
ArrayList <Path> routes = new ArrayList<>();
g.V().has("code","SAT").out().path().by("icao").fill(routes);
System.out.println(routes);
System.out.println("*******************");
Vertex v = g.V().has("code","FRA").next();
System.out.println(v.keys());
Set <String> s = v.keys();
for (String k : s)
{
System.out.println( k + "\t: " + v.property(k).value());
}
System.out.println("*******************");
List eng = g.V().has("code","AUS").repeat(__.out()).times(2).
has("region","GB-ENG").dedup().values("code").toList();
System.out.println(eng);
System.out.println(" --------------------------");
System.out.println(" Shutting down ");
System.out.println(" --------------------------");
jg.tx().commit();
jg.close();
System.exit(0);
}
}