Skip to content

Commit 0fbc89b

Browse files
maxkernbachmpv1989
authored andcommitted
restructure documentation (#198)
* restructure documentation * restructure * fix typo * fix typo
1 parent 2ce59d3 commit 0fbc89b

File tree

10 files changed

+693
-692
lines changed

10 files changed

+693
-692
lines changed

docs/Drivers/Java/Reference/AQL.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AQL
2+
3+
## Executing an AQL statement
4+
5+
Every AQL operations works with POJOs (e.g. MyObject), VelocyPack (VPackSlice) and Json (String).
6+
7+
E.g. get all Simpsons aged 3 or older in ascending order:
8+
9+
```Java
10+
arangoDB.createDatabase("myDatabase");
11+
ArangoDatabase db = arangoDB.db("myDatabase");
12+
13+
db.createCollection("myCollection");
14+
ArangoCollection collection = db.collection("myCollection");
15+
16+
collection.insertDocument(new MyObject("Homer", 38));
17+
collection.insertDocument(new MyObject("Marge", 36));
18+
collection.insertDocument(new MyObject("Bart", 10));
19+
collection.insertDocument(new MyObject("Lisa", 8));
20+
collection.insertDocument(new MyObject("Maggie", 2));
21+
22+
Map<String, Object> bindVars = new HashMap<>();
23+
bindVars.put("age", 3);
24+
25+
ArangoCursor<MyObject> cursor = db.query(query, bindVars, null, MyObject.class);
26+
27+
for(; cursor.hasNext;) {
28+
MyObject obj = cursor.next();
29+
System.out.println(obj.getName());
30+
}
31+
```
32+
33+
or return the AQL result as VelocyPack:
34+
35+
```Java
36+
ArangoCursor<VPackSlice> cursor = db.query(query, bindVars, null, VPackSlice.class);
37+
38+
for(; cursor.hasNext;) {
39+
VPackSlice obj = cursor.next();
40+
System.out.println(obj.get("name").getAsString());
41+
}
42+
```
43+
44+
**Note**: The parameter `type` in `query()` has to match the result of the query, otherwise you get an VPackParserException. E.g. you set `type` to `BaseDocument` or a POJO and the query result is an array or simple type, you get an VPackParserException caused by VPackValueTypeException: Expecting type OBJECT.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Manipulating databases
2+
3+
## create database
4+
5+
```Java
6+
// create database
7+
arangoDB.createDatabase("myDatabase");
8+
```
9+
10+
## drop database
11+
12+
```Java
13+
// drop database
14+
arangoDB.db("myDatabase").drop();
15+
```
16+
17+
# Manipulating collections
18+
19+
## create collection
20+
21+
```Java
22+
// create collection
23+
arangoDB.db("myDatabase").createCollection("myCollection", null);
24+
```
25+
26+
## drop collection
27+
28+
```Java
29+
// delete collection
30+
arangoDB.db("myDatabase").collection("myCollection").drop();
31+
```
32+
33+
## truncate collection
34+
35+
```Java
36+
arangoDB.db("myDatabase").collection("myCollection").truncate();
37+
```
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Basic Document operations
2+
3+
Every document operations works with POJOs (e.g. MyObject), VelocyPack (VPackSlice) and Json (String).
4+
5+
For the next examples we use a small object:
6+
7+
```Java
8+
public class MyObject {
9+
10+
private String key;
11+
private String name;
12+
private int age;
13+
14+
public MyObject(String name, int age) {
15+
this();
16+
this.name = name;
17+
this.age = age;
18+
}
19+
20+
public MyObject() {
21+
super();
22+
}
23+
24+
/*
25+
* + getter and setter
26+
*/
27+
28+
}
29+
```
30+
31+
## insert document
32+
33+
```Java
34+
MyObject myObject = new MyObject("Homer", 38);
35+
arangoDB.db("myDatabase").collection("myCollection").insertDocument(myObject);
36+
```
37+
38+
When creating a document, the attributes of the object will be stored as key-value pair
39+
E.g. in the previous example the object was stored as follows:
40+
41+
```properties
42+
"name" : "Homer"
43+
"age" : "38"
44+
```
45+
46+
## delete document
47+
48+
```Java
49+
arangoDB.db("myDatabase").collection("myCollection").deleteDocument(myObject.getKey());
50+
```
51+
52+
## update document
53+
54+
```Java
55+
arangoDB.db("myDatabase").collection("myCollection").updateDocument(myObject.getKey(), myUpdatedObject);
56+
```
57+
58+
## replace document
59+
60+
```Java
61+
arangoDB.db("myDatabase").collection("myCollection").replaceDocument(myObject.getKey(), myObject2);
62+
```
63+
64+
## read document as JavaBean
65+
66+
```Java
67+
MyObject document = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey(), MyObject.class);
68+
document.getName();
69+
document.getAge();
70+
```
71+
72+
## read document as VelocyPack
73+
74+
```Java
75+
VPackSlice document = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey(), VPackSlice.class);
76+
document.get("name").getAsString();
77+
document.get("age").getAsInt();
78+
```
79+
80+
## read document as Json
81+
82+
```Java
83+
String json = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey(), String.class);
84+
```
85+
86+
## read document by key
87+
88+
```Java
89+
arangoDB.db("myDatabase").collection("myCollection").getDocument("myKey", MyObject.class);
90+
```
91+
92+
## read document by id
93+
94+
```Java
95+
arangoDB.db("myDatabase").getDocument("myCollection/myKey", MyObject.class);
96+
```

docs/Drivers/Java/Reference/Foxx.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Foxx
2+
3+
## call a service
4+
5+
```Java
6+
Request request = new Request("mydb", RequestType.GET, "/my/foxx/service")
7+
Response response = arangoDB.execute(request);
8+
```

docs/Drivers/Java/Reference/Graph.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Multi Document operations
2+
3+
## insert documents
4+
5+
```Java
6+
Collection<MyObject> documents = new ArrayList<>;
7+
documents.add(myObject1);
8+
documents.add(myObject2);
9+
documents.add(myObject3);
10+
arangoDB.db("myDatabase").collection("myCollection").insertDocuments(documents);
11+
```
12+
13+
## delete documents
14+
15+
```Java
16+
Collection<String> keys = new ArrayList<>;
17+
keys.add(myObject1.getKey());
18+
keys.add(myObject2.getKey());
19+
keys.add(myObject3.getKey());
20+
arangoDB.db("myDatabase").collection("myCollection").deleteDocuments(keys);
21+
```
22+
23+
## update documents
24+
25+
```Java
26+
Collection<MyObject> documents = new ArrayList<>;
27+
documents.add(myObject1);
28+
documents.add(myObject2);
29+
documents.add(myObject3);
30+
arangoDB.db("myDatabase").collection("myCollection").updateDocuments(documents);
31+
```
32+
33+
## replace documents
34+
35+
```Java
36+
Collection<MyObject> documents = new ArrayList<>;
37+
documents.add(myObject1);
38+
documents.add(myObject2);
39+
documents.add(myObject3);
40+
arangoDB.db("myDatabase").collection("myCollection").replaceDocuments(documents);
41+
```

0 commit comments

Comments
 (0)