-
-
Notifications
You must be signed in to change notification settings - Fork 16
Home
arangodb-tinkerpop-provider is an implementation of the Apache TinkerPop OLTP Provider API for ArangoDB.
To add the provider to your project with maven, you must add the following dependency and let maven know about the Sonatype repository.
<dependencies>
<dependency>
<groupId>org.arangodb</groupId>
<artifactId>arangodb-tinkerpop-provider</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
....
</dependencies>
The same coordinates can be used with Gradle. The current version of the provider works with ArangoDB 3 and the ArangoDB Java driver 4.6.0.
The easiest way is to add a repository entry to your pom:
<repositories>
<repository>
<id>oss-sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
....
</repositories>
For other use cases it might be better to add it to your general maven settings.
Before using the provider via Java or the Gremlin Console your ArangoDB instance must have been started. Also, make sure you create the appropriate databases and users you will use for the connection. Your machine must have network access to the machine in which the ArangoDB is running.
This example is based on the TinkerPop documentation (Creating a graph):
ArangoDBConfigurationBuilder builder = new ArangoDBConfigurationBuilder();
builder.graph("modern")
.withVertexCollection("software")
.withVertexCollection("person")
.withEdgeCollection("knows")
.withEdgeCollection("created")
.configureEdge("knows", "person", "person")
.configureEdge("created", "person", "software");
// use the default database (and user:password) or configure a different database
// builder.arangoHosts("172.168.1.10:4456")
// .arangoUser("stripe")
// .arangoPassword("gizmo")
// create a ArangoDB graph
Graph graph = GraphFactory.open(conf);
GraphTraversalSource gts = new GraphTraversalSource(graph);
// Clone to avoid setup time
GraphTraversalSource g = gts.clone();
// Add vertices
Vertex v1 = g.addV("person").property(T.id, 1).property("name", "marko")
.property("age", 29).next();
g = gts.clone();
Vertex v2 = g.addV("software").property(T.id, 3).property("name", "lop")
.property("lang", "java").next();
// Add edges
g = gts.clone();
Edge e1 = g.addEd("created").from(v1).to(v2).property(T.id, 9)
.property("weight", 0.4).next();
// Graph traversal
// Find "marko" in the graph
g = gts.clone();
Vertex rv = g.V().has("name","marko").next();
assert v1 == rv;
// Walk along the "created" edges to "software" vertices
g = gts.clone();
Edge re = g.V().has("name","marko").outE("created").next();
assert re == e1;
g = gts.clone();
rv = g.V().has("name","marko").outE("created").inV().next();
// If the edge is irrelevant
// rv = g.V().has("name","marko").out("created").next();
assert rv == v2;
// Select the "name" property of the "software" vertices
g = gts.clone();
String name = g.V().has("name","marko").out("created").values("name").next();
assert name.equals("lop");
// close the graph
graph.close();