@@ -250,6 +250,7 @@ public CompletableFuture<Void> revokeAccess(final String user) {
250250 * @param type
251251 * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map)
252252 * @return cursor of the results
253+ * @throws ArangoDBException
253254 */
254255 public <T > CompletableFuture <ArangoCursorAsync <T >> query (
255256 final String query ,
@@ -259,30 +260,56 @@ public <T> CompletableFuture<ArangoCursorAsync<T>> query(
259260 final Request request = queryRequest (query , bindVars , options );
260261 final CompletableFuture <CursorEntity > execution = executor .execute (request , CursorEntity .class );
261262 return execution .thenApply (result -> {
262- return new ArangoCursorAsync <>(this , new ArangoCursorExecute () {
263- @ Override
264- public CursorEntity next (final String id ) {
265- final CompletableFuture <CursorEntity > result = executor .execute (queryNextRequest (id ),
266- CursorEntity .class );
267- try {
268- return result .get ();
269- } catch (InterruptedException | ExecutionException e ) {
270- throw new ArangoDBException (e );
271- }
272- }
263+ return createCursor (result , type );
264+ });
265+ }
273266
274- @ Override
275- public void close (final String id ) {
276- try {
277- executor .execute (queryCloseRequest (id ), Void .class ).get ();
278- } catch (InterruptedException | ExecutionException e ) {
279- throw new ArangoDBException (e );
280- }
281- }
282- }, type , result );
267+ /**
268+ * Return an cursor from the given cursor-ID if still existing
269+ *
270+ * @see <a href=
271+ * "https://docs.arangodb.com/current/HTTP/AqlQueryCursor/AccessingCursors.html#read-next-batch-from-cursor">API
272+ * Documentation</a>
273+ * @param cursorId
274+ * The ID of the cursor
275+ * @param type
276+ * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map)
277+ * @return cursor of the results
278+ * @throws ArangoDBException
279+ */
280+ public <T > CompletableFuture <ArangoCursorAsync <T >> cursor (final String cursorId , final Class <T > type )
281+ throws ArangoDBException {
282+ final CompletableFuture <CursorEntity > execution = executor .execute (queryNextRequest (cursorId ),
283+ CursorEntity .class );
284+ return execution .thenApply (result -> {
285+ return createCursor (result , type );
283286 });
284287 }
285288
289+ private <T > ArangoCursorAsync <T > createCursor (final CursorEntity result , final Class <T > type ) {
290+ return new ArangoCursorAsync <>(this , new ArangoCursorExecute () {
291+ @ Override
292+ public CursorEntity next (final String id ) {
293+ final CompletableFuture <CursorEntity > result = executor .execute (queryNextRequest (id ),
294+ CursorEntity .class );
295+ try {
296+ return result .get ();
297+ } catch (InterruptedException | ExecutionException e ) {
298+ throw new ArangoDBException (e );
299+ }
300+ }
301+
302+ @ Override
303+ public void close (final String id ) {
304+ try {
305+ executor .execute (queryCloseRequest (id ), Void .class ).get ();
306+ } catch (InterruptedException | ExecutionException e ) {
307+ throw new ArangoDBException (e );
308+ }
309+ }
310+ }, type , result );
311+ }
312+
286313 /**
287314 * Explain an AQL query and return information about it
288315 *
0 commit comments