Skip to content

Commit c524880

Browse files
author
a-brandt
committed
added new cursor API for vertices and edges
1 parent 917e647 commit c524880

30 files changed

+3644
-2744
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ E.g. get all Simpsons aged 3 or older in ascending order:
247247
}
248248
```
249249

250-
instead of using a for statement you can also use an DocumentEntitiy or an entity iterator:
250+
instead of using a ```for``` statement you can also use an DocumentEntitiy or an entity iterator:
251251
``` Java
252252
Iterator<DocumentEntity<Person>> iterator = documentCursor.iterator();
253253
while (iterator.hasNext()) {

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

Lines changed: 231 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.List;
2424
import java.util.Map;
2525

26-
import com.arangodb.InternalTraversalDriver.Direction;
2726
import com.arangodb.InternalTraversalDriver.ItemOrder;
2827
import com.arangodb.InternalTraversalDriver.Order;
2928
import com.arangodb.InternalTraversalDriver.Strategy;
@@ -81,7 +80,11 @@
8180
import com.arangodb.impl.ImplFactory;
8281
import com.arangodb.impl.InternalBatchDriverImpl;
8382
import com.arangodb.util.DumpHandler;
83+
import com.arangodb.util.GraphEdgesOptions;
84+
import com.arangodb.util.GraphVerticesOptions;
85+
import com.arangodb.util.JsonUtils;
8486
import com.arangodb.util.MapBuilder;
87+
import com.arangodb.util.ShortestPathOptions;
8588

8689
/**
8790
* ArangoDB driver. All of the functionality to use ArangoDB is provided via
@@ -2322,7 +2325,7 @@ public <T, S extends DocumentEntity<T>> BaseCursorEntity<T, S> executeCursorDocu
23222325
Boolean fullCount) throws ArangoException {
23232326

23242327
return cursorDocumentDriver.executeBaseCursorEntityQuery(getDefaultDatabase(), query, bindVars,
2325-
classDocumentEntity, clazz, calcCount, batchSize, fullCount);
2328+
classDocumentEntity, clazz, calcCount, batchSize, fullCount, null);
23262329
}
23272330

23282331
/**
@@ -2373,6 +2376,8 @@ public DefaultEntity finishCursorDocumentEntityQuery(long cursorId) throws Arang
23732376
* @param fullCount
23742377
* if set to true, then all results before the final LIMIT will
23752378
* be counted
2379+
* @param ttl
2380+
* an optional time-to-live for the cursor (in seconds)
23762381
* @return DocumentCursor<T>
23772382
* @throws ArangoException
23782383
*/
@@ -2382,10 +2387,12 @@ public <T> DocumentCursor<T> executeDocumentQuery(
23822387
Class<T> clazz,
23832388
Boolean calcCount,
23842389
Integer batchSize,
2385-
Boolean fullCount) throws ArangoException {
2390+
Boolean fullCount,
2391+
Integer ttl) throws ArangoException {
23862392

2393+
@SuppressWarnings("unchecked")
23872394
BaseCursor<T, DocumentEntity<T>> baseCursor = cursorDocumentDriver.executeBaseCursorQuery(query, query,
2388-
bindVars, DocumentEntity.class, clazz, calcCount, batchSize, fullCount);
2395+
bindVars, DocumentEntity.class, clazz, calcCount, batchSize, fullCount, ttl);
23892396
return new DocumentCursor<T>(baseCursor);
23902397
}
23912398

@@ -2413,8 +2420,9 @@ public <T> DocumentCursor<T> executeDocumentQuery(
24132420
Boolean calcCount,
24142421
Integer batchSize) throws ArangoException {
24152422

2423+
@SuppressWarnings("unchecked")
24162424
BaseCursor<T, DocumentEntity<T>> baseCursor = cursorDocumentDriver.executeBaseCursorQuery(getDefaultDatabase(),
2417-
query, bindVars, DocumentEntity.class, clazz, calcCount, batchSize, false);
2425+
query, bindVars, DocumentEntity.class, clazz, calcCount, batchSize, false, null);
24182426
return new DocumentCursor<T>(baseCursor);
24192427
}
24202428

@@ -2444,7 +2452,7 @@ public <T, S extends DocumentEntity<T>> BaseCursor<T, S> executeBaseCursorQuery(
24442452
Integer batchSize) throws ArangoException {
24452453

24462454
return cursorDocumentDriver.executeBaseCursorQuery(getDefaultDatabase(), query, bindVars, classDocumentEntity,
2447-
clazz, calcCount, batchSize, false);
2455+
clazz, calcCount, batchSize, false, null);
24482456
}
24492457

24502458
/**
@@ -4719,7 +4727,7 @@ public <T> VertexEntity<T> graphReplaceVertex(
47194727
* @return DocumentEntity<T>
47204728
* @throws ArangoException
47214729
*/
4722-
public <T> DocumentEntity<T> graphUpdateVertex(
4730+
public <T> VertexEntity<T> graphUpdateVertex(
47234731
String graphName,
47244732
String collectionName,
47254733
String key,
@@ -4754,7 +4762,7 @@ public <T> DocumentEntity<T> graphUpdateVertex(
47544762
* @return DocumentEntity<T>
47554763
* @throws ArangoException
47564764
*/
4757-
public <T> DocumentEntity<T> graphUpdateVertex(
4765+
public <T> VertexEntity<T> graphUpdateVertex(
47584766
String graphName,
47594767
String collectionName,
47604768
String key,
@@ -5105,7 +5113,10 @@ public <T> EdgeEntity<T> graphUpdateEdge(
51055113
* The name of the graph.
51065114
* @return CursorEntity<PlainEdgeEntity>
51075115
* @throws ArangoException
5116+
* @Deprecated As of release 2.5.4, replaced by
5117+
* {@link #graphGetEdgeCursor()}
51085118
*/
5119+
@Deprecated
51095120
public CursorEntity<PlainEdgeEntity> graphGetEdges(String graphName) throws ArangoException {
51105121

51115122
validateCollectionName(graphName);
@@ -5115,7 +5126,153 @@ public CursorEntity<PlainEdgeEntity> graphGetEdges(String graphName) throws Aran
51155126
CursorEntity<PlainEdgeEntity> result = this.executeQuery(query, bindVars, PlainEdgeEntity.class, true, 20);
51165127

51175128
return result;
5129+
}
5130+
5131+
/**
5132+
* Returns edges as an EdgeCursor by a given query
5133+
*
5134+
* @param graphName
5135+
* the graph name
5136+
* @param query
5137+
* the query
5138+
* @param bindVars
5139+
* the variables
5140+
* @param clazz
5141+
* the result class
5142+
* @param calcCount
5143+
* count results
5144+
* @param batchSize
5145+
* result batch size of the cursor
5146+
* @param fullCount
5147+
* do a full count
5148+
* @param ttl
5149+
* an optional time-to-live for the cursor (in seconds)
5150+
* @return EdgeCursor<T>
5151+
* @throws ArangoException
5152+
*/
5153+
public <T> EdgeCursor<T> executeEdgeQuery(
5154+
String query,
5155+
Map<String, Object> bindVars,
5156+
Class<T> clazz,
5157+
Boolean calcCount,
5158+
Integer batchSize,
5159+
Boolean fullCount,
5160+
Integer ttl) throws ArangoException {
5161+
5162+
@SuppressWarnings("unchecked")
5163+
BaseCursor<T, EdgeEntity<T>> baseCursor = cursorDocumentDriver.executeBaseCursorQuery(getDefaultDatabase(),
5164+
query, bindVars, EdgeEntity.class, clazz, calcCount, batchSize, fullCount, ttl);
5165+
return new EdgeCursor<T>(baseCursor);
5166+
}
5167+
5168+
/**
5169+
* Returns vertices as a VertexCursor by a given query
5170+
*
5171+
* @param graphName
5172+
* the graph name
5173+
* @param query
5174+
* the query
5175+
* @param bindVars
5176+
* the variables
5177+
* @param clazz
5178+
* the result class
5179+
* @param calcCount
5180+
* count results
5181+
* @param batchSize
5182+
* result batch size of the cursor
5183+
* @param fullCount
5184+
* do a full count
5185+
* @param ttl
5186+
* an optional time-to-live for the cursor (in seconds)
5187+
* @return EdgeCursor<T>
5188+
* @throws ArangoException
5189+
*/
5190+
public <T> VertexCursor<T> executeVertexQuery(
5191+
String query,
5192+
Map<String, Object> bindVars,
5193+
Class<T> clazz,
5194+
Boolean calcCount,
5195+
Integer batchSize,
5196+
Boolean fullCount,
5197+
Integer ttl) throws ArangoException {
5198+
5199+
@SuppressWarnings("unchecked")
5200+
BaseCursor<T, VertexEntity<T>> baseCursor = cursorDocumentDriver.executeBaseCursorQuery(getDefaultDatabase(),
5201+
query, bindVars, VertexEntity.class, clazz, calcCount, batchSize, fullCount, ttl);
5202+
return new VertexCursor<T>(baseCursor);
5203+
}
5204+
5205+
/**
5206+
* Returns an EdgeCursor by a given vertex example and some options
5207+
*
5208+
* @param graphName
5209+
* The name of the graph.
5210+
* @param clazz
5211+
* @param vertexExample
5212+
* An example for the desired vertices
5213+
* @param graphEdgesOptions
5214+
* An object containing the options
5215+
* @return EdgeCursor<T>
5216+
* @throws ArangoException
5217+
*/
5218+
public <T> EdgeCursor<T> graphGetEdgeCursor(
5219+
String graphName,
5220+
Class<T> clazz,
5221+
Object vertexExample,
5222+
GraphEdgesOptions graphEdgesOptions) throws ArangoException {
5223+
5224+
validateCollectionName(graphName);
5225+
5226+
String query = "for i in graph_edges(@graphName, @vertexExample, @options) return i";
5227+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
5228+
.put("vertexExample", JsonUtils.convertNullToMap(vertexExample))
5229+
.put("options", JsonUtils.convertNullToMap(graphEdgesOptions)).get();
5230+
5231+
return executeEdgeQuery(query, bindVars, clazz, true, 20, false, null);
5232+
}
5233+
5234+
/**
5235+
* Returns a VertexCursor by a given vertex example and some options
5236+
*
5237+
* @param graphName
5238+
* The name of the graph.
5239+
* @param clazz
5240+
* @param vertexExample
5241+
* An example for the desired vertices
5242+
* @param graphEdgesOptions
5243+
* An object containing the options
5244+
* @return EdgeCursor<T>
5245+
* @throws ArangoException
5246+
*/
5247+
public <T> VertexCursor<T> graphGetVertexCursor(
5248+
String graphName,
5249+
Class<T> clazz,
5250+
Object vertexExample,
5251+
GraphVerticesOptions graphVerticesOptions) throws ArangoException {
5252+
5253+
validateCollectionName(graphName);
51185254

5255+
String query = "for i in graph_vertices(@graphName , @vertexExample, @options) return i";
5256+
5257+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
5258+
.put("vertexExample", JsonUtils.convertNullToMap(vertexExample))
5259+
.put("options", JsonUtils.convertNullToMap(graphVerticesOptions)).get();
5260+
5261+
return executeVertexQuery(query, bindVars, clazz, true, 20, false, null);
5262+
}
5263+
5264+
/**
5265+
* Returns all Edges of a graph, each edge as a PlainEdgeEntity.
5266+
*
5267+
* @param graphName
5268+
* The name of the graph.
5269+
* @return EdgeCursor<PlainEdgeEntity>
5270+
* @throws ArangoException
5271+
*/
5272+
public EdgeCursor<PlainEdgeEntity> graphGetEdgeCursor(String graphName) throws ArangoException {
5273+
validateCollectionName(graphName);
5274+
5275+
return graphGetEdgeCursor(graphName, PlainEdgeEntity.class, null, null);
51195276
}
51205277

51215278
/**
@@ -5124,9 +5281,12 @@ public CursorEntity<PlainEdgeEntity> graphGetEdges(String graphName) throws Aran
51245281
* @param graphName
51255282
* @param clazz
51265283
* @param vertexDocumentHandle
5127-
* @return <T> CursorEntity<T>
5284+
* @return CursorEntity<T>
51285285
* @throws ArangoException
5286+
* @Deprecated As of release 2.5.4, replaced by
5287+
* {@link #graphGetEdgeCursor()}
51295288
*/
5289+
@Deprecated
51305290
public <T> CursorEntity<T> graphGetEdges(String graphName, Class<T> clazz, String vertexDocumentHandle)
51315291
throws ArangoException {
51325292

@@ -5141,25 +5301,44 @@ public <T> CursorEntity<T> graphGetEdges(String graphName, Class<T> clazz, Strin
51415301

51425302
}
51435303

5304+
/**
5305+
* Returns all Edges of a given vertex.
5306+
*
5307+
* @param graphName
5308+
* @param clazz
5309+
* @param vertexExample
5310+
* a vertex example or a document handle
5311+
* @return EdgeCursor<T>
5312+
* @throws ArangoException
5313+
*/
5314+
public <T> EdgeCursor<T> graphGetEdgeCursorByExample(String graphName, Class<T> clazz, Object vertexExample)
5315+
throws ArangoException {
5316+
5317+
return graphGetEdgeCursor(graphName, clazz, vertexExample, null);
5318+
}
5319+
51445320
/**
51455321
* Returns all Edges of vertices matching the example object (non-primitive
51465322
* set to null will not be used for comparing).
51475323
*
51485324
* @param graphName
5149-
* @param clazzT
5325+
* @param clazz
51505326
* @param vertexExample
5151-
* @return <T> CursorEntity<T>
5327+
* @return CursorEntity<T>
51525328
* @throws ArangoException
5329+
* @Deprecated As of release 2.5.4, replaced by
5330+
* {@link #graphGetEdgeCursorByExampleObject()}
51535331
*/
5154-
public <T, S> CursorEntity<T> graphGetEdgesByExampleObject(String graphName, Class<T> clazzT, S vertexExample)
5332+
@Deprecated
5333+
public <T, S> CursorEntity<T> graphGetEdgesByExampleObject(String graphName, Class<T> clazz, S vertexExample)
51555334
throws ArangoException {
51565335
validateCollectionName(graphName);
51575336
String query = "for i in graph_edges(@graphName, @vertexExample) return i";
51585337

51595338
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
51605339
.get();
51615340

5162-
CursorEntity<T> result = this.executeQuery(query, bindVars, clazzT, true, 20);
5341+
CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true, 20);
51635342

51645343
return result;
51655344
}
@@ -5169,28 +5348,63 @@ public <T, S> CursorEntity<T> graphGetEdgesByExampleObject(String graphName, Cla
51695348
*
51705349
* @param graphName
51715350
* The name of the graph.
5172-
* @param clazzT
5351+
* @param clazz
51735352
* Class of returned edge documents.
51745353
* @param vertexExample
51755354
* Map with example of vertex, where edges start or end.
5176-
* @return <T> CursorEntity<T>
5355+
* @return CursorEntity<T>
51775356
* @throws ArangoException
5357+
* @Deprecated As of release 2.5.4, replaced by
5358+
* {@link #graphGetEdgeCursorByExampleMap()}
51785359
*/
5360+
@Deprecated
51795361
public <T> CursorEntity<T> graphGetEdgesByExampleMap(
51805362
String graphName,
5181-
Class<T> clazzT,
5363+
Class<T> clazz,
51825364
Map<String, Object> vertexExample) throws ArangoException {
51835365
validateCollectionName(graphName);
51845366
String query = "for i in graph_edges(@graphName, @vertexExample) return i";
51855367

51865368
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
51875369
.get();
51885370

5189-
CursorEntity<T> result = this.executeQuery(query, bindVars, clazzT, true, 20);
5371+
CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true, 20, null);
51905372

51915373
return result;
51925374
}
51935375

5376+
/**
5377+
* Returns all Edges of vertices matching the map.
5378+
*
5379+
* @param graphName
5380+
* The name of the graph.
5381+
* @param clazz
5382+
* Class of returned edge documents.
5383+
* @param vertexExample
5384+
* Map with example of vertex, where edges start or end.
5385+
* @return EdgeCursor<T>
5386+
* @throws ArangoException
5387+
*/
5388+
public <T> EdgeCursor<T> graphGetShortesPath(
5389+
String graphName,
5390+
Class<T> clazz,
5391+
Object startVertexExample,
5392+
Object endVertexExample,
5393+
ShortestPathOptions shortestPathOptions) throws ArangoException {
5394+
5395+
validateCollectionName(graphName);
5396+
5397+
String query = "for i in graph_shortest_path(@graphName, @startVertexExample, @endVertexExample, @options) return i";
5398+
5399+
Map<String, Object> options = shortestPathOptions == null ? null : shortestPathOptions.toMap();
5400+
5401+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
5402+
.put("startVertexExample", startVertexExample).put("endVertexExample", endVertexExample)
5403+
.put("options", options).get();
5404+
5405+
return executeEdgeQuery(query, bindVars, clazz, true, 20, false, null);
5406+
}
5407+
51945408
// public <T, S> CursorEntity<EdgeEntity<T>> graphGetEdgesByExampleObject1(
51955409
// String graphName,
51965410
// Class<T> clazzT,

0 commit comments

Comments
 (0)