diff --git a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 18c596314..862425e31 100644 --- a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -51,6 +51,7 @@ public abstract class InternalArangoCollection, D private static final String PATH_API_USER = "/_api/user"; private static final String MERGE_OBJECTS = "mergeObjects"; private static final String KEEP_NULL = "keepNull"; + private static final String REFILL_INDEX_CACHES = "refillIndexCaches"; private static final String IGNORE_REVS = "ignoreRevs"; private static final String RETURN_NEW = "returnNew"; private static final String RETURN_OLD = "returnOld"; @@ -106,6 +107,7 @@ private InternalRequest createInsertDocumentRequest(final DocumentCreateOptions params.getOverwriteMode().getValue() : null); request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putQueryParam(KEEP_NULL, params.getKeepNull()); + request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); return request; } @@ -243,6 +245,7 @@ private InternalRequest createReplaceDocumentRequest(final DocumentReplaceOption request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); + request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches()); return request; } @@ -304,6 +307,7 @@ private InternalRequest createUpdateDocumentRequest(final DocumentUpdateOptions request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); + request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches()); return request; } @@ -359,6 +363,7 @@ private InternalRequest createDeleteDocumentRequest(final DocumentDeleteOptions request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); + request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches()); return request; } diff --git a/core/src/main/java/com/arangodb/model/DocumentCreateOptions.java b/core/src/main/java/com/arangodb/model/DocumentCreateOptions.java index f90845950..55a9fb9ca 100644 --- a/core/src/main/java/com/arangodb/model/DocumentCreateOptions.java +++ b/core/src/main/java/com/arangodb/model/DocumentCreateOptions.java @@ -36,6 +36,7 @@ public final class DocumentCreateOptions { private String streamTransactionId; private Boolean mergeObjects; private Boolean keepNull; + private Boolean refillIndexCaches; public DocumentCreateOptions() { super(); @@ -163,4 +164,17 @@ public DocumentCreateOptions keepNull(Boolean keepNull) { return this; } + public Boolean getRefillIndexCaches() { + return refillIndexCaches; + } + + /** + * @param refillIndexCaches Whether to add a new entry to the in-memory edge cache if an edge document is inserted. + * @return options + * @since ArangoDB 3.11 + */ + public DocumentCreateOptions refillIndexCaches(Boolean refillIndexCaches) { + this.refillIndexCaches = refillIndexCaches; + return this; + } } diff --git a/core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java b/core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java index d2de3aa43..dde285c13 100644 --- a/core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java +++ b/core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java @@ -33,6 +33,7 @@ public final class DocumentDeleteOptions { private Boolean returnOld; private Boolean silent; private String streamTransactionId; + private Boolean refillIndexCaches; public DocumentDeleteOptions() { super(); @@ -107,4 +108,18 @@ public DocumentDeleteOptions streamTransactionId(final String streamTransactionI return this; } + public Boolean getRefillIndexCaches() { + return refillIndexCaches; + } + + /** + * @param refillIndexCaches Whether to delete an existing entry from the in-memory edge cache and refill it with + * another edge if an edge document is removed. + * @return options + * @since ArangoDB 3.11 + */ + public DocumentDeleteOptions refillIndexCaches(Boolean refillIndexCaches) { + this.refillIndexCaches = refillIndexCaches; + return this; + } } diff --git a/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java b/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java index 8dae60508..b8f9fa9a7 100644 --- a/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java +++ b/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java @@ -35,6 +35,7 @@ public final class DocumentReplaceOptions { private Boolean returnOld; private Boolean silent; private String streamTransactionId; + private Boolean refillIndexCaches; public DocumentReplaceOptions() { super(); @@ -139,4 +140,18 @@ public DocumentReplaceOptions streamTransactionId(final String streamTransaction return this; } + public Boolean getRefillIndexCaches() { + return refillIndexCaches; + } + + /** + * @param refillIndexCaches Whether to update an existing entry in the in-memory edge cache if an edge document is + * replaced. + * @return options + * @since ArangoDB 3.11 + */ + public DocumentReplaceOptions refillIndexCaches(Boolean refillIndexCaches) { + this.refillIndexCaches = refillIndexCaches; + return this; + } } diff --git a/core/src/main/java/com/arangodb/model/DocumentUpdateOptions.java b/core/src/main/java/com/arangodb/model/DocumentUpdateOptions.java index e405582c1..0b7d73126 100644 --- a/core/src/main/java/com/arangodb/model/DocumentUpdateOptions.java +++ b/core/src/main/java/com/arangodb/model/DocumentUpdateOptions.java @@ -37,6 +37,7 @@ public final class DocumentUpdateOptions { private Boolean returnOld; private Boolean silent; private String streamTransactionId; + private Boolean refillIndexCaches; public DocumentUpdateOptions() { super(); @@ -174,4 +175,19 @@ public DocumentUpdateOptions streamTransactionId(final String streamTransactionI return this; } + public Boolean getRefillIndexCaches() { + return refillIndexCaches; + } + + /** + * @param refillIndexCaches Whether to update an existing entry in the in-memory edge cache if an edge document is + * updated. + * @return options + * @since ArangoDB 3.11 + */ + public DocumentUpdateOptions refillIndexCaches(Boolean refillIndexCaches) { + this.refillIndexCaches = refillIndexCaches; + return this; + } + } diff --git a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java index 2e82cb9f0..d7e452a9d 100644 --- a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -324,6 +324,18 @@ void insertDocumentWaitForSync(ArangoCollection collection) { assertThat(doc.getNew()).isNull(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void insertDocumentRefillIndexCaches(ArangoCollection collection) { + final DocumentCreateOptions options = new DocumentCreateOptions().refillIndexCaches(true); + final DocumentCreateEntity doc = collection.insertDocument(new BaseDocument(), options); + assertThat(doc).isNotNull(); + assertThat(doc.getId()).isNotNull(); + assertThat(doc.getKey()).isNotNull(); + assertThat(doc.getRev()).isNotNull(); + assertThat(doc.getNew()).isNull(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentAsJson(ArangoCollection collection) { @@ -396,6 +408,15 @@ void insertDocumentsSilent(ArangoCollection collection) { assertThat(info.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void insertDocumentsRefillIndexCaches(ArangoCollection collection) { + final MultiDocumentEntity> info = + collection.insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument()), + new DocumentCreateOptions().refillIndexCaches(true), BaseDocument.class); + assertThat(info.getErrors()).isEmpty(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocument(ArangoCollection collection) { @@ -941,6 +962,29 @@ void updateDocumentPreconditionFailed(ArangoCollection collection) { assertThat(readDocument.getAttribute("foo")).isEqualTo("b"); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void updateDocumentRefillIndexCaches(ArangoCollection collection) { + BaseDocument doc = new BaseDocument(); + DocumentCreateEntity createResult = collection.insertDocument(doc); + doc.addAttribute("foo", "bar"); + DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), + doc , new DocumentUpdateOptions().refillIndexCaches(true)); + assertThat(updateResult.getRev()) + .isNotNull() + .isNotEqualTo(createResult.getRev()); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void updateDocumentsRefillIndexCaches(ArangoCollection collection) { + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = + collection.updateDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), + new DocumentUpdateOptions().refillIndexCaches(true), BaseDocument.class); + assertThat(info.getErrors()).isEmpty(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void replaceDocument(ArangoCollection collection) { @@ -1098,7 +1142,7 @@ void replaceDocumentSilentDontTouchInstance(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); final DocumentCreateEntity createResult = collection.insertDocument(doc); final DocumentUpdateEntity meta = collection.replaceDocument(createResult.getKey(), doc, - new DocumentReplaceOptions().silent(true)); + new DocumentReplaceOptions().silent(true)); assertThat(meta.getRev()).isNull(); assertThat(doc.getRevision()).isNull(); assertThat(createResult.getRev()).isNotNull(); @@ -1110,14 +1154,36 @@ void replaceDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); final MultiDocumentEntity> info = - collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), - new DocumentReplaceOptions().silent(true), BaseDocument.class); + collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), + new DocumentReplaceOptions().silent(true), BaseDocument.class); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); assertThat(info.getDocumentsAndErrors()).isEmpty(); assertThat(info.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void replaceDocumentRefillIndexCaches(ArangoCollection collection) { + final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); + final DocumentCreateEntity createResult = collection.insertDocument(doc); + final DocumentUpdateEntity replaceResult = collection.replaceDocument(createResult.getKey(), doc, + new DocumentReplaceOptions().refillIndexCaches(true)); + assertThat(replaceResult.getRev()) + .isNotNull() + .isNotEqualTo(createResult.getRev()); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void replaceDocumentsRefillIndexCaches(ArangoCollection collection) { + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = + collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), + new DocumentReplaceOptions().refillIndexCaches(true), BaseDocument.class); + assertThat(info.getErrors()).isEmpty(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void deleteDocument(ArangoCollection collection) { @@ -1192,6 +1258,29 @@ void deleteDocumentsSilent(ArangoCollection collection) { assertThat(info.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void deleteDocumentRefillIndexCaches(ArangoCollection collection) { + DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + DocumentDeleteEntity deleteResult = collection.deleteDocument(createResult.getKey(), + new DocumentDeleteOptions().refillIndexCaches(true)); + assertThat(deleteResult.getRev()) + .isNotNull() + .isEqualTo(createResult.getRev()); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void deleteDocumentsRefillIndexCaches(ArangoCollection collection) { + assumeTrue(isSingleServer()); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = collection.deleteDocuments( + Collections.singletonList(createResult.getKey()), + new DocumentDeleteOptions().refillIndexCaches(true), + BaseDocument.class); + assertThat(info.getErrors()).isEmpty(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void getIndex(ArangoCollection collection) {