ArangoCursor instances provide an abstraction over the HTTP API's limitations. Unless a method explicitly exhausts the cursor, the driver will only fetch as many batches from the server as necessary. Like the server-side cursors, ArangoCursor instances are incrementally depleted as they are read from.
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class);
// query result list: [1, 2, 3, 4, 5]
Integer value = cursor.next();
assertThat(value, is(1));
// remaining result list: [2, 3, 4, 5]
ArangoCursor.hasNext() : boolean
Returns true if the cursor has more elements in its current batch of results or the cursor on the server has more batches.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
boolean hasNext = cursor.hasNext();
ArangoCursor.next() : T
Returns the next element of the query result. If the current element is the last element of the batch and the cursor on the server provides more batches, the next batch is fetched from the server.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
Integer value = cursor.next();
assertThat(value, is(1));
ArangoCursor.first() : T
Returns the first element or {@code null} if no element exists.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("RETURN 1", Integer.class)
Integer value = cursor.first();
assertThat(value, is(1));
ArangoCursor.foreach(Consumer<? super T> action) : void
Performs the given action for each element of the ArangoIterable
Arguments
-
action:
Consumer<? super T>
A action to perform on the elements
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
cursor.foreach(e -> {
// remaining results: [1, 2, 3, 4, 5]
});
ArangoCursor.map(Function<? super T, ? extends R> mapper) : ArangoIterable<R>
Returns a ArangoIterable consisting of the results of applying the given function to the elements of this ArangoIterable.
Arguments
-
mapper:
Function<? super T, ? extends R>
A function to apply to each element
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
cursor.map(e -> e * 10).foreach(e -> {
// remaining results: [10, 20, 30, 40, 50]
});
ArangoCursor.filter(Predicate<? super T> predicate) : ArangoIterable<T>
Arguments
-
predicate:
Predicate<? super T>
A predicate to apply to each element to determine if it should be included
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
cursor.filter(e -> e < 4).foreach(e -> {
// remaining results: [1, 2, 3]
});
ArangoCursor.anyMatch(Predicate<? super T> predicate) : boolean
Returns whether any elements of this ArangoIterable match the provided predicate.
Arguments
-
predicate:
Predicate<? super T>
A predicate to apply to elements of this {@code ArangoIterable}
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
boolean match = cursor.anyMatch(e -> e == 3);
assertThat(match, is(true));
ArangoCursor.anyMatch(Predicate<? super T> predicate) : boolean
Returns whether all elements of this ArangoIterable match the provided predicate.
Arguments
-
predicate:
Predicate<? super T>
A predicate to apply to elements of this {@code ArangoIterable}
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
boolean match = cursor.allMatch(e -> e <= 5);
assertThat(match, is(true));
ArangoCursor.noneMatch(Predicate<? super T> predicate) : boolean
Returns whether no elements of this ArangoIterable match the provided predicate.
Arguments
-
predicate:
Predicate<? super T>
A predicate to apply to elements of this {@code ArangoIterable}
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
boolean match = cursor.noneMatch(e -> e > 5);
assertThat(match, is(true));
ArangoCursor.collectInto(R target) : R
Arguments
Iterates over all elements of this {@code ArangoIterable} and adds each to the given target.
-
target:
R <R extends Collection<? super T>>
The collection to insert into
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
Collection<Integer> list = cursor.collectInto(new ArrayList());
// -- or --
Collection<Integer> set = cursor.collectInto(new HashSet());
ArangoCursor.iterator() : Iterator<T>
Returns an iterator over elements of the query result.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
Iterator<Integer> iterator = cursor.iterator();
ArangoCursor.asListRemaining() : List<T>
Returns the remaining results as a List.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
Collection<Integer> list = cursor.asListRemaining();
ArangoCursor.getCount() : Integer
Returns the total number of result documents available (only available if the query was executed with the count attribute set)
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", new AqlQueryOptions().count(true), Integer.class)
Integer count = cursor.getCount();
assertThat(count, is(5));
ArangoCursor.count() : long
Returns the count of elements of this ArangoIterable.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
long count = cursor.filter(e -> e < 4).count();
// remaining results: [1, 2, 3]
asserThat(count, is(3L));
ArangoCursor.getStats() : Stats
Returns extra information about the query result. For data-modification queries, the stats will contain the number of modified documents and the number of documents that could not be modified due to an error (if ignoreErrors query option is specified);
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
Stats stats = cursor.getStats();
ArangoCursor.getWarnings() : Collection<Warning>
Returns warnings which the query could have been produced.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
Collection<Warning> warnings = cursor.getWarnings();
ArangoCursor.isCached() : boolean
Iindicating whether the query result was served from the query cache or not.
Examples
ArangoDB arango = new ArangoDB.Builder().build();
ArangoDatabase db = arango.db("myDB");
ArangoCursor<Integer> cursor = db.query("FOR x IN 1..5 RETURN x", Integer.class)
boolean cached = cursor.isCached();