diff --git a/pom.xml b/pom.xml index 3b3ad6f779380bebee17a039bc0f50def356b0d0..a3b01de4cfea098fa8498cff9aa503ae9ca17605 100644 --- a/pom.xml +++ b/pom.xml @@ -122,5 +122,10 @@ <artifactId>gremlin-java</artifactId> <version>2.6.0</version> </dependency> + <dependency> + <groupId>com.tinkerpop</groupId> + <artifactId>frames</artifactId> + <version>2.6.0</version> + </dependency> </dependencies> </project> diff --git a/src/main/java/com/syncleus/titangraph/example/TitanGods.java b/src/main/java/com/syncleus/titangraph/example/TitanGods.java index 76f15890ad3db692564e6e1eb93fb1a639add3c2..8c131ab6fea1c3092b7c1cc3307177ad5e003ecb 100644 --- a/src/main/java/com/syncleus/titangraph/example/TitanGods.java +++ b/src/main/java/com/syncleus/titangraph/example/TitanGods.java @@ -118,7 +118,7 @@ public class TitanGods { neptune.addEdge("brother", pluto); hercules.addEdge("father", jupiter); - hercules.addEdge("mother", alcmene); + hercules.addEdge("lives", sky).setProperty("reason", "loves heights"); ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1, "place", Geoshape.point(38.1f, 23.7f)); ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2, "place", Geoshape.point(37.7f, 23.9f)); ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12, "place", Geoshape.point(39f, 22f)); @@ -130,6 +130,7 @@ public class TitanGods { pluto.addEdge("pet", cerberus); cerberus.addEdge("lives", tartarus); + ElementHelper.setProperties(cerberus.addEdge("battled", alcmene), "time", 5, "place", Geoshape.point(68.1f, 13.3f)); // commit the transaction to disk graph.commit(); diff --git a/src/main/java/com/syncleus/titangraph/example/frames/God.java b/src/main/java/com/syncleus/titangraph/example/frames/God.java new file mode 100644 index 0000000000000000000000000000000000000000..67cef59acf515c79b192833f8b82e18e1132dbe6 --- /dev/null +++ b/src/main/java/com/syncleus/titangraph/example/frames/God.java @@ -0,0 +1,24 @@ +package com.syncleus.titangraph.example.frames; + +import com.tinkerpop.frames.*; +import com.tinkerpop.frames.annotations.gremlin.GremlinGroovy; + +public interface God { + @Property("name") + public String getName(); + + @Property("age") + public String getAge(); + + @Property("type") + public String getType(); + + @Adjacency(label="father") + public God getFather(); + + @GremlinGroovy("it.in('father')") + public God getSon(); + + @Adjacency(label="lives") + public Location getHome(); +} diff --git a/src/main/java/com/syncleus/titangraph/example/frames/Location.java b/src/main/java/com/syncleus/titangraph/example/frames/Location.java new file mode 100644 index 0000000000000000000000000000000000000000..5d18258736d6330db4a36bd7ae5d954508732670 --- /dev/null +++ b/src/main/java/com/syncleus/titangraph/example/frames/Location.java @@ -0,0 +1,15 @@ +package com.syncleus.titangraph.example.frames; + +import com.tinkerpop.frames.*; +import com.tinkerpop.frames.annotations.gremlin.GremlinGroovy; + +public interface Location { + @Property("name") + public String getName(); + + @Property("type") + public String getType(); + + @GremlinGroovy("it.in('lives')") + public Iterable<God> getResidents(); +} diff --git a/src/test/java/com/syncleus/titangraph/example/FramesTest.java b/src/test/java/com/syncleus/titangraph/example/FramesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..423c1745badf75cf0f0dda9409b92dd624a66f51 --- /dev/null +++ b/src/test/java/com/syncleus/titangraph/example/FramesTest.java @@ -0,0 +1,20 @@ +package com.syncleus.titangraph.example; + +import com.syncleus.titangraph.example.frames.God; +import com.thinkaurelius.titan.core.TitanGraph; +import com.tinkerpop.frames.*; +import com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule; +import org.junit.*; + +public class FramesTest { + @Test + public void testFrames() { + final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); + FramedGraphFactory factory = new FramedGraphFactory(new GremlinGroovyModule()); + + FramedGraph framedGraph = factory.create(godGraph); + + Iterable<God> gods = (Iterable<God>) framedGraph.getVertices("name", "saturn", God.class); + Assert.assertEquals(gods.iterator().next().getName(), "saturn"); + } +}