com.arangodb.ArangoCursor Java Examples
The following examples show how to use
com.arangodb.ArangoCursor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AqlQueryWithSpecialReturnTypesExample.java From arangodb-java-driver with Apache License 2.0 | 7 votes |
@Test @SuppressWarnings("rawtypes") public void aqlWithLimitQueryAsMap() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; final Map<String, Object> bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); final ArangoCursor<Map> cursor = db.query(query, bindVars, null, Map.class); assertThat(cursor, is(notNullValue())); for (; cursor.hasNext(); ) { final Map map = cursor.next(); assertThat(map.get("name"), is(notNullValue())); assertThat(String.valueOf(map.get("name")), isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19")); assertThat(map.get("gender"), is(notNullValue())); assertThat(String.valueOf(map.get("gender")), is(Gender.FEMALE.name())); assertThat(map.get("age"), is(notNullValue())); assertThat(Long.valueOf(map.get("age").toString()), isOneOf(21L, 23L, 25L, 27L, 29L)); } }
Example #2
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#the-number-of-actors-by-movie-">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void theNumberOfActorsByMovie() { final ArangoCursor<Movie> cursor = db.query( "FOR x IN actsIn COLLECT movie = x._to WITH COUNT INTO counter RETURN {movie: movie, actors: counter}", null, null, Movie.class); assertThat(cursor.asListRemaining(), hasItems(new Movie("movies/AFewGoodMen", 11), new Movie("movies/AsGoodAsItGets", 4), new Movie("movies/JerryMaguire", 9), new Movie("movies/JoeVersustheVolcano", 3), new Movie("movies/SleeplessInSeattle", 6), new Movie("movies/SnowFallingonCedars", 4), new Movie("movies/StandByMe", 7), new Movie("movies/TheDevilsAdvocate", 3), new Movie("movies/TheMatrix", 5), new Movie("movies/TheMatrixReloaded", 4), new Movie("movies/TheMatrixRevolutions", 4), new Movie("movies/TopGun", 6), new Movie("movies/WhatDreamsMayCome", 5), new Movie("movies/WhenHarryMetSally", 4), new Movie("movies/YouveGotMail", 6))); }
Example #3
Source File: ArangoResultConverter.java From spring-data with Apache License 2.0 | 6 votes |
/** * Build a GeoResult from the given ArangoCursor * * @param cursor * query result from driver * @return GeoResult object */ private GeoResult<?> buildGeoResult(final ArangoCursor<?> cursor) { GeoResult<?> geoResult = null; while (cursor.hasNext() && geoResult == null) { final Object object = cursor.next(); if (!(object instanceof VPackSlice)) { continue; } final VPackSlice slice = (VPackSlice) object; final VPackSlice distSlice = slice.get("_distance"); final Double distanceInMeters = distSlice.isDouble() ? distSlice.getAsDouble() : null; if (distanceInMeters == null) { continue; } final Object entity = operations.getConverter().read(domainClass, slice); final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS); geoResult = new GeoResult<>(entity, distance); } return geoResult; }
Example #4
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Gets the element properties. * * @param <T> the generic type * @param document the document * @param edgeLabelsFilter a list of edge types to follow * @param propertyFilter Filter the neighbours on the given property:value values * @param propertyType the property type * @return ArangoDBBaseQuery the query object */ public <T> ArangoCursor<T> getElementProperties( ArangoDBBaseDocument document, List<String> edgeLabelsFilter, ArangoDBPropertyFilter propertyFilter, Class<T> propertyType) { logger.debug("Get Vertex's {}:{} Neighbors, in {}, from collections {}", document, graph.name(), edgeLabelsFilter); Map<String, Object> bindVars = new HashMap<>(); ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder(); logger.debug("Creating query"); queryBuilder.iterateGraph(graph.name(), "v", Optional.of("e"), Optional.empty(), Optional.empty(), Optional.empty(), ArangoDBQueryBuilder.Direction.OUT, document._id(), bindVars) .graphOptions(Optional.of(UniqueVertices.GLOBAL), Optional.empty(), true) .filterSameCollections("e", edgeLabelsFilter, bindVars) .filterProperties(propertyFilter, "v", bindVars) .ret("v"); String query = queryBuilder.toString(); logger.debug("AQL {}", query); return executeAqlQuery(query, bindVars, null, propertyType); }
Example #5
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Get all neighbours of a document. * * @param <T> the document type * @param document the document * @param edgeLabelsFilter a list of edge types to follow * @param direction a direction * @param propertyFilter filter the neighbours on the given property:value values * @param resultType the result type * @return ArangoDBBaseQuery the query object */ public <T> ArangoCursor<T> getDocumentNeighbors( ArangoDBBaseDocument document, List<String> edgeLabelsFilter, Direction direction, ArangoDBPropertyFilter propertyFilter, Class<T> resultType) { logger.debug("Get Document's {}:{} Neighbors, in {}, from collections {}", document, direction, graph.name(), edgeLabelsFilter); Map<String, Object> bindVars = new HashMap<>(); ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder(); ArangoDBQueryBuilder.Direction arangoDirection = ArangoDBUtil.getArangoDirectionFromGremlinDirection(direction); logger.debug("Creating query"); queryBuilder.iterateGraph(graph.name(), "v", Optional.of("e"), Optional.empty(), Optional.empty(), Optional.empty(), arangoDirection, document._id(), bindVars) .graphOptions(Optional.of(UniqueVertices.GLOBAL), Optional.empty(), true) .filterSameCollections("e", edgeLabelsFilter, bindVars) .filterProperties(propertyFilter, "v", bindVars) .ret("v"); String query = queryBuilder.toString(); return executeAqlQuery(query, bindVars, null, resultType); }
Example #6
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Create a query to get all the edges of a vertex. * * @param vertex the vertex * @param edgeLabels a list of edge labels to follow, empty if all type of edges * @param direction the direction of the edges * @return ArangoDBBaseQuery the query object * @throws ArangoDBException if there is an error executing the query */ public ArangoCursor<ArangoDBEdge> getVertexEdges( ArangoDBVertex vertex, List<String> edgeLabels, Direction direction) throws ArangoDBException { logger.debug("Get Vertex's {}:{} Edges, in {}, from collections {}", vertex, direction, graph.name(), edgeLabels); Map<String, Object> bindVars = new HashMap<>(); ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder(); ArangoDBQueryBuilder.Direction arangoDirection = ArangoDBUtil.getArangoDirectionFromGremlinDirection(direction); logger.debug("Creating query"); queryBuilder.iterateGraph(graph.name(), "v", Optional.of("e"), Optional.empty(), Optional.empty(), Optional.empty(), arangoDirection, vertex._id(), bindVars) .graphOptions(Optional.of(UniqueVertices.NONE), Optional.empty(), true) .filterSameCollections("e", edgeLabels, bindVars) .ret("e"); String query = queryBuilder.toString(); return executeAqlQuery(query, bindVars, null, ArangoDBEdge.class); }
Example #7
Source File: AqlQueryWithSpecialReturnTypesExample.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("rawtypes") public void aqlWithLimitQueryAsList() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]"; final Map<String, Object> bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); final ArangoCursor<List> cursor = db.query(query, bindVars, null, List.class); assertThat(cursor, is(notNullValue())); for (; cursor.hasNext(); ) { final List list = cursor.next(); assertThat(list.get(0), is(notNullValue())); assertThat(String.valueOf(list.get(0)), isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19")); assertThat(list.get(1), is(notNullValue())); assertThat(Gender.valueOf(String.valueOf(list.get(1))), is(Gender.FEMALE)); assertThat(list.get(2), is(notNullValue())); assertThat(Long.valueOf(String.valueOf(list.get(2))), isOneOf(21L, 23L, 25L, 27L, 29L)); } }
Example #8
Source File: RelationsResolver.java From spring-data with Apache License 2.0 | 6 votes |
private ArangoCursor<?> _resolve( final String id, final Class<?> type, final Relations annotation, final boolean limit) { final String edges = Arrays.stream(annotation.edges()).map(e -> template.collection(e).name()) .collect(Collectors.joining(",")); final String query = String.format( "WITH @@vertex FOR v IN %d .. %d %s @start %s OPTIONS {bfs: true, uniqueVertices: \"global\"} %s RETURN v", // Math.max(1, annotation.minDepth()), // Math.max(1, annotation.maxDepth()), // annotation.direction(), // edges, // limit ? "LIMIT 1" : ""); final Map<String, Object> bindVars = new MapBuilder()// .put("start", id) // .put("@vertex", type) // .get(); return template.query(query, bindVars, type); }
Example #9
Source File: GraphTraversalsInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void queryOutboundInbound() throws ArangoDBException { String queryString = "FOR v IN 1..3 OUTBOUND 'circles/E' GRAPH 'traversalGraph' return v._key"; ArangoCursor<String> cursor = db.query(queryString, null, null, String.class); Collection<String> result = cursor.asListRemaining(); assertThat(result.size(), is(1)); assertThat(result, hasItems("F")); queryString = "FOR v IN 1..3 INBOUND 'circles/E' GRAPH 'traversalGraph' return v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(2)); assertThat(result, hasItems("B", "A")); queryString = "FOR v IN 1..3 ANY 'circles/E' GRAPH 'traversalGraph' return v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(6)); assertThat(result, hasItems("F", "B", "C", "D", "A", "G")); }
Example #10
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Execute AQL query. * * @param <T> the generic type of the returned values * @param query the query string * @param bindVars the value of the bind parameters * @param aqlQueryOptions the aql query options * @param type the type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return the cursor result * @throws ArangoDBGraphException if executing the query raised an exception */ public <T> ArangoCursor<T> executeAqlQuery( String query, Map<String, Object> bindVars, AqlQueryOptions aqlQueryOptions, final Class<T> type) throws ArangoDBGraphException { logger.debug("Executing AQL query ({}) against db, with bind vars: {}", query, bindVars); try { return db.query(query, bindVars, aqlQueryOptions, type); } catch (ArangoDBException e) { logger.error("Error executing query", e); throw ArangoDBExceptions.getArangoDBException(e); } }
Example #11
Source File: PolymorphicTemplate.java From spring-data with Apache License 2.0 | 6 votes |
@Test public void query() { Dog dog = new Dog(); dog.setId("1"); dog.setName("dog"); dog.setTeeths(11); Eagle eagle = new Eagle(); dog.setId("2"); eagle.setName("eagle"); eagle.setWingspan(2.5); template.insert(dog); template.insert(eagle); final ArangoCursor<Animal> cursor = template.query("FOR a IN animals RETURN a", Animal.class); Assert.assertThat(cursor, is(notNullValue())); final List<Animal> animals = cursor.asListRemaining(); Assert.assertThat(animals.size(), is(2)); Assert.assertThat(animals.stream().anyMatch(it -> it.equals(eagle)), is(true)); Assert.assertThat(animals.stream().anyMatch(it -> it.equals(dog)), is(true)); }
Example #12
Source File: ArangoDBPropertyProperty.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public Element element() { ArangoCursor<ArangoDBVertexProperty> q = graph.getClient() .getDocumentNeighbors(this, Collections.emptyList(), Direction.IN, ArangoDBPropertyFilter.empty(), ArangoDBVertexProperty.class); ArangoDBIterator<ArangoDBVertexProperty> iterator = new ArangoDBIterator<ArangoDBVertexProperty>(graph, q); return iterator.hasNext() ? iterator.next() : null; }
Example #13
Source File: ArangoDBVertexProperty.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@Override public Vertex element() { ArangoCursor<ArangoDBVertex> q = graph.getClient() .getDocumentNeighbors(this, Collections.emptyList(), Direction.IN, ArangoDBPropertyFilter.empty(), ArangoDBVertex.class); ArangoDBIterator<ArangoDBVertex> iterator = new ArangoDBIterator<ArangoDBVertex>(graph, q); return iterator.hasNext() ? iterator.next() : null; }
Example #14
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
/** * Get edges of a graph. If no ids are provided, get all edges. * * @param ids the ids to match * @param collections the collections to search within * @return ArangoDBBaseQuery the query object */ public ArangoCursor<ArangoDBEdge> getGraphEdges( List<String> ids, List<String> collections) { logger.debug("Get all {} graph edges, filtered by ids: {}", graph.name(), ids); Map<String, Object> bindVars = new HashMap<>(); ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder(); List<String> prefixedColNames = graph.edgeCollections().stream().map(graph::getPrefixedCollectioName).collect(Collectors.toList()); if (ids.isEmpty()) { if (prefixedColNames.size() > 1) { queryBuilder.union(prefixedColNames, "e", bindVars); } else { queryBuilder.iterateCollection("e", prefixedColNames.get(0), bindVars); } } else { if (!collections.isEmpty()) { prefixedColNames = collections.stream().map(graph::getPrefixedCollectioName).collect(Collectors.toList()); } queryBuilder.with(prefixedColNames, bindVars) .documentsById(ids, "e", bindVars); } queryBuilder.ret("e"); String query = queryBuilder.toString(); logger.debug("AQL {}", query); return executeAqlQuery(query, bindVars, null, ArangoDBEdge.class); }
Example #15
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
/** * Get vertices of a graph. If no ids are provided, get all vertices. * * @param ids the ids to match * @param collections the collections to search within * @return ArangoDBBaseQuery the query object */ public ArangoCursor<ArangoDBVertex> getGraphVertices( final List<String> ids, final List<String> collections) { logger.debug("Get all {} graph vertices, filtered by ids: {}", graph.name(), ids); Map<String, Object> bindVars = new HashMap<>(); ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder(); List<String> prefixedColNames = graph.vertexCollections().stream().map(graph::getPrefixedCollectioName).collect(Collectors.toList()); if (ids.isEmpty()) { if (prefixedColNames.size() > 1) { queryBuilder.union(prefixedColNames, "v", bindVars); } else { queryBuilder.iterateCollection("v", prefixedColNames.get(0), bindVars); } } else { if (!collections.isEmpty()) { prefixedColNames = collections.stream().map(graph::getPrefixedCollectioName).collect(Collectors.toList()); } queryBuilder.with(prefixedColNames, bindVars) .documentsById(ids, "v", bindVars); } queryBuilder.ret("v"); String query = queryBuilder.toString(); logger.debug("AQL {}", query); return executeAqlQuery(query, bindVars, null, ArangoDBVertex.class); }
Example #16
Source File: ArangoDBVertex.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <V> Iterator<VertexProperty<V>> properties(String... propertyKeys) { logger.debug("Get properties {}", (Object[])propertyKeys); List<String> labels = new ArrayList<>(); labels.add(graph.getPrefixedCollectioName(ArangoDBGraph.ELEMENT_PROPERTIES_EDGE_COLLECTION)); ArangoDBPropertyFilter filter = new ArangoDBPropertyFilter(); for (String pk : propertyKeys) { filter.has("name", pk, ArangoDBPropertyFilter.Compare.EQUAL); } ArangoCursor<?> query = graph.getClient().getElementProperties(this, labels, filter, ArangoDBVertexProperty.class); return new ArangoDBPropertyIterator<>(graph, (ArangoCursor<ArangoDBVertexProperty<V>>) query); }
Example #17
Source File: ArangoDBVertex.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(Direction direction, String... edgeLabels) { List<String> edgeCollections = getQueryEdgeCollections(edgeLabels); // If edgeLabels was not empty but all were discarded, this means that we should // return an empty iterator, i.e. no edges for that edgeLabels exist. if (edgeCollections.isEmpty()) { return Collections.emptyIterator(); } ArangoCursor<ArangoDBVertex> documentNeighbors = graph.getClient().getDocumentNeighbors(this, edgeCollections, direction, ArangoDBPropertyFilter.empty(), ArangoDBVertex.class); return new ArangoDBIterator<>(graph, documentNeighbors); }
Example #18
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#all-actors-who-acted-in-both-movie1-and-movie2-">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void allActorsActsInMovie1and2() { final ArangoCursor<String> cursor = db.query( "WITH actors FOR x IN INTERSECTION ((FOR y IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'movies/TheDevilsAdvocate' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x", null, null, String.class); assertThat(cursor.asListRemaining(), hasItems("actors/Keanu")); }
Example #19
Source File: ArangoDBVertexProperty.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <U> Iterator<Property<U>> properties(String... propertyKeys) { List<String> labels = new ArrayList<>(); labels.add(graph.getPrefixedCollectioName(ArangoDBGraph.ELEMENT_PROPERTIES_EDGE_COLLECTION)); ArangoDBPropertyFilter filter = new ArangoDBPropertyFilter(); for (String pk : propertyKeys) { filter.has("name", pk, ArangoDBPropertyFilter.Compare.EQUAL); } ArangoCursor<?> query = graph.getClient().getElementProperties(this, labels, filter, ArangoDBPropertyProperty.class); return new ArangoDBPropertyIterator<>(graph, (ArangoCursor<ArangoDBPropertyProperty<U>>) query); }
Example #20
Source File: ArangoCursorIterator.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected ArangoCursorIterator(final ArangoCursor<T> cursor, final ArangoCursorExecute execute, final InternalArangoDatabase<?, ?> db, final CursorEntity result) { super(); this.cursor = cursor; this.execute = execute; this.db = db; this.result = result; pos = 0; }
Example #21
Source File: ShortestPathInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void queryShortestPathFromAToD() throws ArangoDBException { String queryString = "FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' GRAPH 'traversalGraph' RETURN {'vertex': v._key, 'edge': e._key}"; ArangoCursor<Pair> cursor = db.query(queryString, null, null, Pair.class); final Collection<String> collection = toVertexCollection(cursor); assertThat(collection.size(), is(4)); assertThat(collection, hasItems("A", "B", "C", "D")); queryString = "WITH circles FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' edges RETURN {'vertex': v._key, 'edge': e._key}"; db.query(queryString, null, null, Pair.class); assertThat(collection.size(), is(4)); assertThat(collection, hasItems("A", "B", "C", "D")); }
Example #22
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#all-actors-who-acted-in-3-or-more-movies-">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void allActorsWhoActedIn3orMoreMovies() { final ArangoCursor<Actor> cursor = db.query( "FOR x IN actsIn COLLECT actor = x._from WITH COUNT INTO counter FILTER counter >= 3 RETURN {actor: actor, movies: counter}", null, null, Actor.class); assertThat(cursor.asListRemaining(), hasItems(new Actor("actors/Carrie", 3), new Actor("actors/CubaG", 4), new Actor("actors/Hugo", 3), new Actor("actors/Keanu", 4), new Actor("actors/Laurence", 3), new Actor("actors/MegR", 5), new Actor("actors/TomC", 3), new Actor("actors/TomH", 3))); }
Example #23
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#all-common-movies-between-actor1-and-actor2-">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void allMoviesBetweenActor1andActor2() { final ArangoCursor<String> cursor = db.query( "WITH movies FOR x IN INTERSECTION ((FOR y IN ANY 'actors/Hugo' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'actors/Keanu' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x", null, null, String.class); assertThat(cursor.asListRemaining(), hasItems("movies/TheMatrixRevolutions", "movies/TheMatrixReloaded", "movies/TheMatrix")); }
Example #24
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#the-number-of-movies-acted-in-between-2005-and-2010-by-actor-">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void theNumberOfMoviesActedInBetween2005and2010byActor() { final ArangoCursor<Actor> cursor = db.query( "FOR x IN actsIn FILTER x.year >= 1990 && x.year <= 1995 COLLECT actor = x._from WITH COUNT INTO counter RETURN {actor: actor, movies: counter}", null, null, Actor.class); assertThat(cursor.asListRemaining(), hasItems(new Actor("actors/BillPull", 1), new Actor("actors/ChristopherG", 1), new Actor("actors/CubaG", 1), new Actor("actors/DemiM", 1), new Actor("actors/JackN", 1), new Actor("actors/JamesM", 1), new Actor("actors/JTW", 1), new Actor("actors/KevinB", 1), new Actor("actors/KieferS", 1), new Actor("actors/MegR", 2), new Actor("actors/Nathan", 1), new Actor("actors/NoahW", 1), new Actor("actors/RitaW", 1), new Actor("actors/RosieO", 1), new Actor("actors/TomC", 1), new Actor("actors/TomH", 2), new Actor("actors/VictorG", 1))); }
Example #25
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#all-actors-who-acted-in-movie1-or-movie2">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void allActorsActsInMovie1or2UnionDistinct() { final ArangoCursor<String> cursor = db.query( "WITH actors FOR x IN UNION_DISTINCT ((FOR y IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'movies/TheDevilsAdvocate' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x", null, null, String.class); assertThat(cursor.asListRemaining(), hasItems("actors/Emil", "actors/Hugo", "actors/Carrie", "actors/Laurence", "actors/Keanu", "actors/Al", "actors/Charlize")); }
Example #26
Source File: AQLActorsAndMoviesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
/** * @see <a href= * "https://www.arangodb.com/docs/stable/cookbook/graph-example-actors-and-movies.html#all-actors-who-acted-in-movie1-or-movie2">AQL * Example Queries on an Actors and Movies Database</a> */ @Test public void allActorsActsInMovie1or2() { final ArangoCursor<String> cursor = db.query( "WITH actors FOR x IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN x._id", null, null, String.class); assertThat(cursor.asListRemaining(), hasItems("actors/Keanu", "actors/Hugo", "actors/Emil", "actors/Carrie", "actors/Laurence")); }
Example #27
Source File: GraphTraversalsInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void queryWithFilter() throws ArangoDBException { String queryString = "FOR v, e, p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' RETURN v._key"; ArangoCursor<String> cursor = db.query(queryString, null, null, String.class); Collection<String> result = cursor.asListRemaining(); assertThat(result.size(), is(5)); assertThat(result, hasItems("B", "C", "D", "E", "F")); queryString = "FOR v, e, p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.edges[0].label != 'right_foo' RETURN v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(5)); assertThat(result, hasItems("B", "C", "D", "E", "F")); queryString = "FOR v,e,p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' FILTER p.edges[1].label != 'left_blub' return v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(3)); assertThat(result, hasItems("B", "C", "D")); queryString = "FOR v,e,p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' AND p.edges[1].label != 'left_blub' return v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(3)); assertThat(result, hasItems("B", "C", "D")); }
Example #28
Source File: GraphTraversalsInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void queryDepthTwo() throws ArangoDBException { String queryString = "FOR v IN 2..2 OUTBOUND 'circles/A' GRAPH 'traversalGraph' return v._key"; ArangoCursor<String> cursor = db.query(queryString, null, null, String.class); Collection<String> result = cursor.asListRemaining(); assertThat(result.size(), is(4)); assertThat(result, hasItems("C", "E", "H", "J")); queryString = "FOR v IN 2 OUTBOUND 'circles/A' GRAPH 'traversalGraph' return v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(4)); assertThat(result, hasItems("C", "E", "H", "J")); }
Example #29
Source File: GraphTraversalsInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void queryAllVertices() throws ArangoDBException { String queryString = "FOR v IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' RETURN v._key"; ArangoCursor<String> cursor = db.query(queryString, null, null, String.class); Collection<String> result = cursor.asListRemaining(); assertThat(result.size(), is(10)); queryString = "WITH circles FOR v IN 1..3 OUTBOUND 'circles/A' edges RETURN v._key"; cursor = db.query(queryString, null, null, String.class); result = cursor.asListRemaining(); assertThat(result.size(), is(10)); }
Example #30
Source File: AqlQueryWithSpecialReturnTypesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void aqlWithLimitQueryAsVPackArray() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]"; final Map<String, Object> bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); final ArangoCursor<VPackSlice> cursor = db.query(query, bindVars, null, VPackSlice.class); assertThat(cursor, is(notNullValue())); for (; cursor.hasNext(); ) { final VPackSlice vpack = cursor.next(); assertThat(vpack.get(0).getAsString(), isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19")); assertThat(vpack.get(1).getAsString(), is(Gender.FEMALE.name())); assertThat(vpack.get(2).getAsInt(), isOneOf(21, 23, 25, 27, 29)); } }