Java Code Examples for com.arangodb.ArangoCursor#next()
The following examples show how to use
com.arangodb.ArangoCursor#next() .
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: 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 3
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 4
Source File: AbstractArangoQuery.java From spring-data with Apache License 2.0 | 5 votes |
private Object convertResult(final ArangoCursor<?> result, final ArangoParameterAccessor accessor) { if (isExistsQuery()) { if (!result.hasNext()) { return false; } return (Integer) result.next() > 0; } final ArangoResultConverter resultConverter = new ArangoResultConverter(accessor, result, operations, domainClass); return resultConverter.convertResult(method.getReturnType().getType()); }
Example 5
Source File: SimpleArangoRepository.java From spring-data with Apache License 2.0 | 5 votes |
/** * Counts the number of documents in the collection which match with the given example * * @param example * example object to construct query with * @param <S> * @return number of matching documents found */ @Override public <S extends T> long count(final Example<S> example) { final Map<String, Object> bindVars = new HashMap<>(); final String predicate = exampleConverter.convertExampleToPredicate(example, bindVars); final String filter = predicate.length() == 0 ? "" : " FILTER " + predicate; final String query = String.format("FOR e IN %s%s COLLECT WITH COUNT INTO length RETURN length", getCollectionName(), filter); final ArangoCursor<Long> cursor = arangoOperations.query(query, bindVars, null, Long.class); return cursor.next(); }
Example 6
Source File: AqlQueryWithSpecialReturnTypesExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void aqlWithLimitQueryAsVPackObject() { 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<VPackSlice> cursor = db.query(query, bindVars, null, VPackSlice.class); assertThat(cursor, is(notNullValue())); for (; cursor.hasNext(); ) { final VPackSlice vpack = cursor.next(); assertThat(vpack.get("name").getAsString(), isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19")); assertThat(vpack.get("gender").getAsString(), is(Gender.FEMALE.name())); assertThat(vpack.get("age").getAsInt(), isOneOf(21, 23, 25, 27, 29)); } }
Example 7
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)); } }
Example 8
Source File: ShortestPathInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
private Collection<String> toVertexCollection(final ArangoCursor<Pair> cursor) { final List<String> result = new ArrayList<>(); for (; cursor.hasNext(); ) { final Pair pair = cursor.next(); result.add(pair.getVertex()); } return result; }
Example 9
Source File: ArangoResultConverter.java From spring-data with Apache License 2.0 | 4 votes |
private Object getNext(final ArangoCursor<?> cursor) { return cursor.hasNext() ? cursor.next() : null; }