|
| 1 | +# Graphs |
| 2 | + |
| 3 | +The driver supports the [graph api](https://docs.arangodb.com/HTTP/Gharial/index.html). |
| 4 | + |
| 5 | +Some of the basic graph operations are described in the following: |
| 6 | + |
| 7 | +## add graph |
| 8 | + |
| 9 | +A graph consists of vertices and edges (stored in collections). Which collections are used within a graph is defined via edge definitions. A graph can contain more than one edge definition, at least one is needed. |
| 10 | + |
| 11 | +```Java |
| 12 | + Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>(); |
| 13 | + EdgeDefinition edgeDefinition = new EdgeDefinition(); |
| 14 | + // define the edgeCollection to store the edges |
| 15 | + edgeDefinition.collection("myEdgeCollection"); |
| 16 | + // define a set of collections where an edge is going out... |
| 17 | + edgeDefinition.from("myCollection1", "myCollection2"); |
| 18 | + |
| 19 | + // repeat this for the collections where an edge is going into |
| 20 | + edgeDefinition.to("myCollection1", "myCollection3"); |
| 21 | + |
| 22 | + edgeDefinitions.add(edgeDefinition); |
| 23 | + |
| 24 | + // A graph can contain additional vertex collections, defined in the set of orphan collections |
| 25 | + GraphCreateOptions options = new GraphCreateOptions(); |
| 26 | + options.orphanCollections("myCollection4", "myCollection5"); |
| 27 | + |
| 28 | + // now it's possible to create a graph |
| 29 | + arangoDB.db("myDatabase").createGraph("myGraph", edgeDefinitions, options); |
| 30 | +``` |
| 31 | + |
| 32 | +## delete graph |
| 33 | + |
| 34 | +A graph can be deleted by its name |
| 35 | + |
| 36 | +```Java |
| 37 | + arangoDB.db("myDatabase").graph("myGraph").drop(); |
| 38 | +``` |
| 39 | + |
| 40 | +## add vertex |
| 41 | + |
| 42 | +Vertices are stored in the vertex collections defined above. |
| 43 | + |
| 44 | +```Java |
| 45 | + MyObject myObject1 = new MyObject("Homer", 38); |
| 46 | + MyObject myObject2 = new MyObject("Marge", 36); |
| 47 | + arangoDB.db("myDatabase").graph("myGraph").vertexCollection("collection1").insertVertex(myObject1, null); |
| 48 | + arangoDB.db("myDatabase").graph("myGraph").vertexCollection("collection3").insertVertex(myObject2, null); |
| 49 | +``` |
| 50 | + |
| 51 | +## add edge |
| 52 | + |
| 53 | +Now an edge can be created to set a relation between vertices |
| 54 | + |
| 55 | +```Java |
| 56 | + arangoDB.db("myDatabase").graph("myGraph").edgeCollection("myEdgeCollection").insertEdge(myEdgeObject, null); |
| 57 | +``` |
0 commit comments