Skip to content

Commit 4d0d4a7

Browse files
author
Mark
committed
Replace graph_edge function with aql
1 parent 8ae09b9 commit 4d0d4a7

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/main/java/com/arangodb/util/GraphQueryUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public static String createEdgeQuery(
5757
appendEdgeCollectionsOrGraph(graphName, bindVars, sb, edgeCollectionRestriction);
5858
appendFilter("e", graphEdgesOptions.getEdgeExamples(), sb);
5959
appendFilter("v", graphEdgesOptions.getNeighborExamples(), sb);
60+
{
61+
final List<String> endVertexCollectionRestriction = graphEdgesOptions.getEndVertexCollectionRestriction();
62+
if (endVertexCollectionRestriction != null && endVertexCollectionRestriction.size() > 0) {
63+
sb.append(" FILTER ");
64+
for (String endVertexCollection : endVertexCollectionRestriction) {
65+
sb.append("IS_SAME_COLLECTION(`");
66+
sb.append(endVertexCollection);
67+
sb.append("`,v)");
68+
sb.append(OR);
69+
}
70+
sb.delete(sb.length() - OR.length(), sb.length() - 1);
71+
}
72+
}
6073
final Integer limit = graphEdgesOptions.getLimit();
6174
if (limit != null) {
6275
sb.append(" LIMIT ");

src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,40 @@ public void graphGetEdgeCursorByExampleStartVertexRestriction() throws ArangoExc
410410
assertThat(cursor.getCount(), is(2));
411411
}
412412

413+
@Test
414+
public void graphGetEdgeCursorByExampleEndVertexRestriction() throws ArangoException {
415+
final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38);
416+
final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36);
417+
final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10);
418+
final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38);
419+
420+
final VertexEntity<TestComplexEntity01> vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true);
421+
422+
final VertexEntity<TestComplexEntity01> vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true);
423+
424+
final VertexEntity<TestComplexEntity01> vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true);
425+
426+
final VertexEntity<TestComplexEntity01> vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true);
427+
428+
driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(),
429+
new TestComplexEntity02(1, 2, 3), null);
430+
431+
driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(),
432+
new TestComplexEntity02(4, 5, 6), null);
433+
434+
driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(),
435+
new TestComplexEntity02(7, 8, 9), null);
436+
437+
GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions();
438+
List<String> endVertexCollectionRestriction = new ArrayList<String>();
439+
endVertexCollectionRestriction.add("to1-1");
440+
graphEdgesOptions.setEndVertexCollectionRestriction(endVertexCollectionRestriction);
441+
442+
EdgeCursor<TestComplexEntity02> cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class,
443+
new TestComplexEntity01(null, "A Simpson", null), graphEdgesOptions, getAqlQueryOptions(true, 10, true));
444+
assertThat(cursor.getCount(), is(2));
445+
}
446+
413447
@Test
414448
public void shortestPathTest() throws ArangoException {
415449

0 commit comments

Comments
 (0)