项目作者: ArangoDB-Community

项目描述 :
ArangoDB的Tinkerpop OLTP Provider的实现
高级语言: Java
项目地址: git://github.com/ArangoDB-Community/arangodb-tinkerpop-provider.git
创建时间: 2013-02-04T08:07:58Z
项目社区:https://github.com/ArangoDB-Community/arangodb-tinkerpop-provider

开源协议:Apache License 2.0

下载


ArangoDB-Logo

arangodb-tinkerpop-provider

An implementation of the Apache TinkerPop OLTP Provider API for ArangoDB

Compatibility

This Provider supports:

  • Apache TinkerPop 3.3
  • ArangoDB 3.11+ (via ArangoDB Java Driver 7.17.0).

ArangoDB

Please check the
ArangoDB Installation Manual for guides on how to install ArangoDB.

Maven

To add the provider to your project via maven you need to add the following dependency (shown is the latest version - you can replace the version with the one you need)

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.arangodb</groupId>
  4. <artifactId>arangodb-tinkerpop-provider</artifactId>
  5. <version>2.0.3</version>
  6. </dependency>
  7. ....
  8. </dependencies>

The same coordinates can be used with Gradle and any other build system that uses maven repositories.

Using ArangoDBGraph via the TinkerPop API

This example is based on the TinkerPop documentation (Creating a graph):

  1. ArangoDBConfigurationBuilder builder = new ArangoDBConfigurationBuilder();
  2. builder.graph("modern")
  3. .withVertexCollection("software")
  4. .withVertexCollection("person")
  5. .withEdgeCollection("knows")
  6. .withEdgeCollection("created")
  7. .configureEdge("knows", "person", "person")
  8. .configureEdge("created", "person", "software");
  9. // use the default database (and user:password) or configure a different database
  10. // builder.arangoHosts("172.168.1.10:4456")
  11. // .arangoUser("stripe")
  12. // .arangoPassword("gizmo")
  13. // create a ArangoDB graph
  14. BaseConfiguration conf = builder.build();
  15. Graph graph = GraphFactory.open(conf);
  16. GraphTraversalSource gts = new GraphTraversalSource(graph);
  17. // Clone to avoid setup time
  18. GraphTraversalSource g = gts.clone();
  19. // Add vertices
  20. Vertex v1 = g.addV("person").property(T.id, "1").property("name", "marko")
  21. .property("age", 29).next();
  22. g = gts.clone();
  23. Vertex v2 = g.addV("software").property(T.id, "3").property("name", "lop")
  24. .property("lang", "java").next();
  25. // Add edges
  26. g = gts.clone();
  27. Edge e1 = g.addE("created").from(v1).to(v2).property(T.id, "9")
  28. .property("weight", 0.4).next();
  29. // Graph traversal
  30. // Find "marko" in the graph
  31. g = gts.clone();
  32. Vertex rv = g.V().has("name","marko").next();
  33. assert v1 == rv;
  34. // Walk along the "created" edges to "software" vertices
  35. g = gts.clone();
  36. Edge re = g.V().has("name","marko").outE("created").next();
  37. assert re == e1;
  38. g = gts.clone();
  39. rv = g.V().has("name","marko").outE("created").inV().next();
  40. // If the edge is irrelevant
  41. // rv = g.V().has("name","marko").out("created").next();
  42. assert rv == v2;
  43. // Select the "name" property of the "software" vertices
  44. g = gts.clone();
  45. String name = (String) g.V().has("name","marko").out("created").values("name").next();
  46. assert name.equals("lop");
  47. // close the graph and the traversal source
  48. gts.close();
  49. graph.close();

A note on element IDs

The provider implementation supports user supplied IDs, i.e. provide an id property for graph
elements, but currently we only support String ids, that is:

  1. Vertex v1 = g.addV("person").property(T.id, "1");

will create a vertex with id “1”. However, implementation wise, in ArangoDB we are only allowed to manipulate the documents name, not its id. For this reason, providing a TinkerPop vertex id (T.id) actually sets the vertex’s ArangoDB name. As a result, retrieving the vertex by the given id will fail:

  1. Vertex v2 = g.V("1");
  2. assert v2 == null;

Since we know that documents IDs are created by concatenating (with a slash) the document’s collection and its name, then we can find the vertex like so:

  1. Vertex v2 = g.V("person/1");
  2. assert v2 == v1;

Contributing

We welcome bug reports (bugs, feature requests, etc.) as well as patches. When reporting a bug try to include as much information as possible (expected behaviour, seen behaviour, steps to reproduce, etc.).

More

Please visit our Wiki for additional information on how to use the latest version, build locally, run tests, etc.