8000 Merge branch 'devel' of https://github.com/triAGENS/arangodb-java-dri… · anderick/arangodb-java-driver@92f9667 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92f9667

Browse files
committed
Merge branch 'devel' of https://github.com/triAGENS/arangodb-java-driver into devel
2 parents 9e4258d + 4452938 commit 92f9667

File tree

7 files changed

+421
-72
lines changed

7 files changed

+421
-72
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 115 additions & 2 deletions
2531
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.arangodb.entity.IndexType;
4848
import com.arangodb.entity.IndexesEntity;
4949
import com.arangodb.entity.JobsEntity;
50+
import com.arangodb.entity.PlainEdgeEntity;
5051
import com.arangodb.entity.Policy;
5152
import com.arangodb.entity.ReplicationApplierConfigEntity;
5253
import com.arangodb.entity.ReplicationApplierStateEntity;
@@ -2459,18 +2460,130 @@ public <T> EdgeEntity<T> graphUpdateEdge(
24592460

24602461
// Some methods not using the graph api
24612462

2462-
public <T> CursorEntity<T> graphGetEdges(String graphName, Class<T> clazz) throws ArangoException {
2463+
/**
2464+
* Returns all Edges of a graph, each edge as a PlainEdgeEntity.
2465+
*
2466+
* @param graphName
2467+
* @return CursorEntity<PlainEdgeEntity>
2468+
* @throws ArangoException
2469+
*/
2470+
public CursorEntity<PlainEdgeEntity> graphGetEdges(String graphName) throws ArangoException {
24632471

24642472
validateCollectionName(graphName);
2465-
String query = "return graph_edges(@graphName, null)";
2473+
String query = "for i in graph_edges(@graphName, null) return i";
24662474
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).get();
24672475

2476+
CursorEntity<PlainEdgeEntity> result = this.executeQuery(query, bindVars, PlainEdgeEntity.class, true, 20);
2477+
2478+
return result;
2479+
2480+
}
2481+
2482+
/**
2483+
* Returns all Edges of a given vertex.
2484+
*
2485+
* @param graphName
2486+
* @param clazz
2487+
* @param vertexDocumentHandle
2488+
* @return <T> CursorEntity<T>
2489+
* @throws ArangoException
2490+
*/
2491+
public <T> CursorEntity<T> graphGetEdges(String graphName, Class<T> clazz, String vertexDocumentHandle)
2492+
throws ArangoException {
2493+
2494+
validateCollectionName(graphName);
2495+
String query = "for i in graph_edges(@graphName, @vertexDocumentHandle) return i";
2496+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
2497+
.put("vertexDocumentHandle", vertexDocumentHandle).get();
2498+
24682499
CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true, 20);
24692500

24702501
return result;
24712502

24722503
}
24732504

2505+
/**
2506+
* Returns all Edges of vertices matching the example object (non-primitive
2507+
* set to null will not be used for comparing).
2508+
*
2509+
* @param graphName
2510+
* @param clazzT
2511+
* @param vertexExample
2512+
* @return <T> CursorEntity<T>
2513+
* @throws ArangoException
2514+
*/
2515+
public <T, S> CursorEntity<T> graphGetEdgesByExampleObject(String graphName, Class<T> clazzT, S vertexExample)
2516+
throws ArangoException {
2517+
validateCollectionName(graphName);
2518+
String query = "for i in graph_edges(@graphName, @vertexExample) return i";
2519+
2520+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
2521+
.get();
2522+
2523+
CursorEntity<T> result = this.executeQuery(query, bindVars, clazzT, true, 20);
2524+
2525+
return result;
2526+
}
2527+
2528+
/**
2529+
* Returns all Edges of vertices matching the map.
2530+
*
+
* @param graphName
2532+
* @param clazzT
2533+
* @param vertexExample
2534+
* @return <T> CursorEntity<T>
2535+
* @throws ArangoException
2536+
*/
2537+
public <T> CursorEntity<T> graphGetEdgesByExampleMap(
2538+
String graphName,
2539+
Class<T> clazzT,
2540+
Map<String, Object> vertexExample) throws ArangoException {
2541+
validateCollectionName(graphName);
2542+
String query = "for i in graph_edges(@graphName, @vertexExample) return i";
2543+
2544+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
2545+
.get();
2546+
2547+
CursorEntity<T> result = this.executeQuery(query, bindVars, clazzT, true, 20);
2548+
2549+
return result;
2550+
}
2551+
2552+
public <T, S> CursorEntity<EdgeEntity<T>> graphGetEdgesByExampleObject1(
2553+
String graphName,
2554+
Class<T> clazzT,
2555+
S vertexExample) throws ArangoException {
2556+
validateCollectionName(graphName);
2557+
String query = "for i in graph_edges(@graphName, @vertexExample) return i";
2558+
2559+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
2560+
.get();
2561+
2562+
// CursorEntity<EdgeEntity<T>> result = this.executeQuery(query, bindVars,
2563+
// clazzT, true, 20);
2564+
2565+
return null;
2566+
}
2567+
2568+
// public <T> CursorEntity<EdgeEntity<T>> graphGetEdgesWithData(
2569+
// String graphName,
2570+
// Class<T> clazz,
2571+
// String vertexDocumentHandle,
2572+
// int i) throws ArangoException {
2573+
//
2574+
// validateCollectionName(graphName);
2575+
// String query =
2576+
// "for i in graph_edges(@graphName, @vertexDocumentHandle) return i";
2577+
// Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
2578+
// .put("vertexDocumentHandle", vertexDocumentHandle).get();
2579+
//
2580+
// CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true,
2581+
// 20);
2582+
//
2583+
// return (CursorEntity<EdgeEntity<T>>) result;
2584+
//
2585+
// }
2586+
24742587
// ***************************************
24752588
// *** end of graph **********************
24762589
// ***************************************

src/main/java/com/arangodb/InternalCursorDriver.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@
99
/**
1010
* Created by fbartels on 10/27/14.
1111
*/
12-
public interface InternalCursorDriver extends BaseDriverInterface {
12+
public interface InternalCursorDriver extends BaseDriverInterface {
1313
CursorEntity<?> validateQuery(String database, String query) throws ArangoException;
1414

1515
<T> CursorEntity<T> executeQuery(
1616
String database,
17-
String query, Map<String, Object> bindVars,
17+
String query,
18+
Map<String, Object> bindVars,
1819
Class<T> clazz,
19-
Boolean calcCount, Integer batchSize) throws ArangoException;
20+
Boolean calcCount,
21+
Integer batchSize) throws ArangoException;
2022

2123
<T> CursorEntity<T> continueQuery(String database, long cursorId, Class<?>... clazz) throws ArangoException;
2224

2325
DefaultEntity finishQuery(String database, long cursorId) throws ArangoException;
2426

2527
<T> CursorResultSet<T> executeQueryWithResultSet(
2628
String database,
27-
String query, Map<String, Object> bindVars,
29+
String query,
30+
Map<String, Object> bindVars,
2831
Class<T> clazz,
29-
Boolean calcCount, Integer batchSize) throws ArangoException;
32+
Boolean calcCount,
33+
Integer batchSize) throws ArangoException;
3034
}

src/main/java/com/arangodb/entity/EdgeEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616

1717
package com.arangodb.entity;
1818

19+
import com.google.gson.annotations.SerializedName;
20+
1921
/**
2022
* @author tamtam180 - kirscheless at gmail.com
23+
* @author gschwab
2124
*
2225
*/
2326
public class EdgeEntity<T> extends DocumentEntity<T> {
2427

28+
@SerializedName("_from")
2529
String fromVertexHandle;
30+
@SerializedName("_to")
2631
String toVertexHandle;
2732

2833
public String getFromVertexHandle() {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.arangodb.entity;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public class PlainEdgeEntity extends BaseEntity {
6+
7+
@SerializedName("_rev")
8+
long documentRevision;
9+
@SerializedName("_id")
10+
String documentHandle;
11+
@SerializedName("_key")
12+
String documentKey;
13+
@SerializedName("_from")
14+
String fromCollection;
15+
@SerializedName("_to")
16+
String toCollection;
17+
18+
public long getDocumentRevision() {
19+
return documentRevision;
20+
}
21+
22+
public void setDocumentRevision(long documentRevision) {
23+
this.documentRevision = documentRevision;
24+
}
25+
26+
public String getDocumentHandle() {
27+
return documentHandle;
28+
}
29+
30+
public void setDocumentHandle(String documentHandle) {
31+
this.documentHandle = documentHandle;
32+
}
33+
34+
public String getDocumentKey() {
35+
return documentKey;
36+
}
37+
38+
public void setDocumentKey(String documentKey) {
39+
this.documentKey = documentKey;
40+
}
41+
42+
public String getFromCollection() {
43+
return fromCollection;
44+
}
45+
46+
public void setFromCollection(String fromCollection) {
47+
this.fromCollection = fromCollection;
48+
}
49+
50+
public String getToCollection() {
51+
return toCollection;
52+
}
53+
54+
public void setToCollection(String toCollection) {
55+
this.toCollection = toCollection;
56+
}
57+
58+
}

src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,85 +36,78 @@
3636
public class InternalCursorDriverImpl extends BaseArangoDriverImpl implements com.arangodb.InternalCursorDriver {
3737

3838
InternalCursorDriverImpl(ArangoConfigure configure, HttpManager httpManager) {
39-
super(configure , httpManager);
39+
super(configure, httpManager);
4040
}
41-
41+
4242
@Override
4343
public CursorEntity<?> validateQuery(String database, String query) throws ArangoException {
44-
44+
4545
HttpResponseEntity res = httpManager.doPost(
46-
createEndpointUrl(baseUrl, database, "/_api/query"),
47-
null,
48-
EntityFactory.toJsonString(new MapBuilder("query", query).get())
49-
);
46+
createEndpointUrl(baseUrl, database, "/_api/query"),
47+
null,
48+
EntityFactory.toJsonString(new MapBuilder("query", query).get()));
5049
try {
5150
CursorEntity<?> entity = createEntity(res, CursorEntity.class);
5251
return entity;
5352
} catch (ArangoException e) {
5453
return (CursorEntity<?>) e.getEntity();
5554
}
56-
55+
5756
}
5857

5958
// ※Iteratorで綺麗に何回もRoundtripもしてくれる処理はClientのレイヤーで行う。
6059
// ※ここでは単純にコールするだけ
61-
60+
6261
@Override
6362
public <T> CursorEntity<T> executeQuery(
6463
String database,
65-
String query, Map<String, Object> bindVars,
64+
String query,
65+
Map<String, Object> bindVars,
6666
Class<T> clazz,
67-
Boolean calcCount, Integer batchSize) throws ArangoException {
68-
67+
Boolean calcCount,
68+
Integer batchSize) throws ArangoException {
69+
6970
HttpResponseEntity res = httpManager.doPost(
70-
createEndpointUrl(baseUrl, database, "/_api/cursor"),
71-
null,
72-
EntityFactory.toJsonString(
73-
new MapBuilder()
74-
.put("query", query)
75-
.put("bindVars", bindVars == null ? Collections.emptyMap() : bindVars)
76-
.put("count", calcCount)
77-
.put("batchSize", batchSize)
78-
.get())
79-
);
71+
createEndpointUrl(baseUrl, database, "/_api/cursor"),
72+
null,
73+
EntityFactory.toJsonString(new MapBuilder().put("query", query)
74+
.put("bindVars", bindVars == null ? Collections.emptyMap() : bindVars).put("count", calcCount)
75+
.put("batchSize", batchSize).get()));
8076
try {
8177
CursorEntity<T> entity = createEntity(res, CursorEntity.class, clazz);
8278
// resultを処理する
83-
//EntityFactory.createResult(entity, clazz);
79+
// EntityFactory.createResult(entity, clazz);
8480
return entity;
8581
} catch (ArangoException e) {
8682
throw e;
8783
}
88-
84+
8985
}
90-
86+
9187
@Override
9288
public <T> CursorEntity<T> continueQuery(String database, long cursorId, Class<?>... clazz) throws ArangoException {
93-
89+
9490
HttpResponseEntity res = httpManager.doPut(
95-
createEndpointUrl(baseUrl, database, "/_api/cursor", cursorId),
96-
null,
97-
null
98-
);
99-
91+
createEndpointUrl(baseUrl, database, "/_api/cursor", cursorId),
92+
null,
93+
null);
94+
10095
try {
10196
CursorEntity<T> entity = createEntity(res, CursorEntity.class, clazz);
10297
// resultを処理する
103-
//EntityFactory.createResult(entity, clazz);
98+
// EntityFactory.createResult(entity, clazz);
10499
return entity;
105100
} catch (ArangoException e) {
106101
throw e;
107102
}
108-
103+
109104
}
110-
105+
111106
@Override
112107
public DefaultEntity finishQuery(String database, long cursorId) throws ArangoException {
113-
HttpResponseEntity res = httpManager.doDelete(
114-
createEndpointUrl(baseUrl, database, "/_api/cursor/", cursorId),
115-
null
116-
);
117-
108+
HttpResponseEntity res = httpManager
109+
.doDelete(createEndpointUrl(baseUrl, database, "/_api/cursor/", cursorId), null);
110+
118111
try {
119112
DefaultEntity entity = createEntity(res, DefaultEntity.class);
120113
return entity;
@@ -127,18 +120,20 @@ public DefaultEntity finishQuery(String database, long cursorId) throws ArangoEx
127120
throw e;
128121
}
129122
}
130-
123+
131124
@Override
132125
public <T> CursorResultSet<T> executeQueryWithResultSet(
133126
String database,
134-
String query, Map<String, Object> bindVars,
127+
String query,
128+
Map<String, Object> bindVars,
135129
Class<T> clazz,
136-
Boolean calcCount, Integer batchSize) throws ArangoException {
137-
130+
Boolean calcCount,
131+
Integer batchSize) throws ArangoException {
132+
138133
CursorEntity<T> entity = executeQuery(database, query, bindVars, clazz, calcCount, batchSize);
139134
CursorResultSet<T> rs = new CursorResultSet<T>(database, this, entity, clazz);
140135
return rs;
141-
136+
142137
}
143-
138+
144139
}

0 commit comments

Comments
 (0)
0