Skip to content

Commit e032eaa

Browse files
committed
added allowRetry AQL query option (DE-589)
1 parent d911a0f commit e032eaa

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/main/java/com/arangodb/springframework/annotation/QueryOptions.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
package com.arangodb.springframework.annotation;
2222

23+
import com.arangodb.model.AqlQueryOptions;
24+
2325
import java.lang.annotation.ElementType;
2426
import java.lang.annotation.Retention;
2527
import java.lang.annotation.RetentionPolicy;
@@ -140,4 +142,22 @@
140142
*/
141143
boolean allowDirtyRead() default false;
142144

145+
/**
146+
* Set this option to true to make it possible to retry fetching the latest batch from a cursor.
147+
* <p/>
148+
* This makes possible to safely retry invoking {@link com.arangodb.ArangoCursor#next()} in
149+
* case of I/O exceptions (which are actually thrown as {@link com.arangodb.ArangoDBException}
150+
* with cause {@link java.io.IOException})
151+
* <p/>
152+
* If set to false (default), then it is not safe to retry invoking
153+
* {@link com.arangodb.ArangoCursor#next()} in case of I/O exceptions, since the request to
154+
* fetch the next batch is not idempotent (i.e. the cursor may advance multiple times on the
155+
* server).
156+
* <p/>
157+
* Note: once you successfully received the last batch, you should call
158+
* {@link com.arangodb.ArangoCursor#close()} so that the server does not unnecessary keep the
159+
* batch until the cursor times out ({@link AqlQueryOptions#ttl(Integer)}).
160+
*/
161+
boolean allowRetry() default false;
162+
143163
}

src/main/java/com/arangodb/springframework/repository/query/ArangoQueryMethod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public AqlQueryOptions getAnnotatedQueryOptions() {
127127
if (allowDirtyRead) {
128128
options.allowDirtyRead(allowDirtyRead);
129129
}
130+
if (queryOptions.allowRetry()) {
131+
options.allowRetry(true);
132+
}
130133
return options;
131134
}
132135

src/test/java/com/arangodb/springframework/repository/CustomerRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface CustomerRepository extends ArangoRepository<Customer, String>,
5151
@Query("FOR c IN #collection FILTER c._key == @id AND c.`customer-name` == @name RETURN c")
5252
ArangoCursor<Customer> findOneByBindVarsAql(AqlQueryOptions options, @BindVars Map<String, Object> bindVars);
5353

54-
@QueryOptions(count = true)
54+
@QueryOptions(count = true, allowRetry = true)
5555
@Query("for i in @n..10000 return 1/i")
5656
ArangoCursor<Double> sequenceTo10K(@Param("n") Integer n, AqlQueryOptions options);
5757

0 commit comments

Comments
 (0)