From 904d78d2e238ef1e8023f7dfba416bbba7b936ab Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 25 Apr 2023 10:48:47 +0200 Subject: [PATCH 1/5] DocumentCreateOptions.refillIndexCaches --- .../internal/InternalArangoCollection.java | 2 ++ .../com/arangodb/model/DocumentCreateOptions.java | 14 ++++++++++++++ .../java/com/arangodb/ArangoCollectionTest.java | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 18c596314..18df7ea86 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; } 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/driver/src/test/java/com/arangodb/ArangoCollectionTest.java b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java index 2e82cb9f0..be748019d 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) { From 13212b0609078f0d672760eaa6ea5bbbd66a32a3 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 25 Apr 2023 11:03:09 +0200 Subject: [PATCH 2/5] DocumentReplaceOptions.refillIndexCaches --- .../internal/InternalArangoCollection.java | 1 + .../arangodb/model/DocumentReplaceOptions.java | 14 ++++++++++++++ .../com/arangodb/ArangoCollectionTest.java | 18 +++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 18df7ea86..1022a2b79 100644 --- a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -245,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; } diff --git a/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java b/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java index 8dae60508..2fa202e52 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,17 @@ public DocumentReplaceOptions streamTransactionId(final String streamTransaction 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 DocumentReplaceOptions 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 be748019d..8146d6c88 100644 --- a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -1110,7 +1110,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(); @@ -1122,14 +1122,26 @@ 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 deleteDocument(ArangoCollection collection) { From b4e47197f0b5d0882fe9fd8df02cb97956de5df5 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 25 Apr 2023 11:09:44 +0200 Subject: [PATCH 3/5] DocumentUpdateOptions.refillIndexCaches --- .../internal/InternalArangoCollection.java | 1 + .../arangodb/model/DocumentReplaceOptions.java | 3 ++- .../arangodb/model/DocumentUpdateOptions.java | 16 ++++++++++++++++ .../java/com/arangodb/ArangoCollectionTest.java | 13 +++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 1022a2b79..d68dc9f52 100644 --- a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -307,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; } diff --git a/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java b/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java index 2fa202e52..b8f9fa9a7 100644 --- a/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java +++ b/core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java @@ -145,7 +145,8 @@ public Boolean getRefillIndexCaches() { } /** - * @param refillIndexCaches Whether to add a new entry to the in-memory edge cache if an edge document is inserted. + * @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 */ 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 8146d6c88..77945e393 100644 --- a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -953,6 +953,19 @@ 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 replaceDocument(ArangoCollection collection) { From e7154652ce331c7ab3b75b2770d4b4094b11ae38 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 25 Apr 2023 11:18:04 +0200 Subject: [PATCH 4/5] DocumentDeleteOptions.refillIndexCaches --- .../internal/InternalArangoCollection.java | 1 + .../com/arangodb/model/DocumentDeleteOptions.java | 15 +++++++++++++++ .../java/com/arangodb/ArangoCollectionTest.java | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java index d68dc9f52..862425e31 100644 --- a/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/core/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -363,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/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/driver/src/test/java/com/arangodb/ArangoCollectionTest.java b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java index 77945e393..c435dd0c7 100644 --- a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -1229,6 +1229,17 @@ 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 getIndex(ArangoCollection collection) { From daf30489c807b10a35e44af631887aa92591e431 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 25 Apr 2023 11:24:44 +0200 Subject: [PATCH 5/5] test CRUD methods on multiple documents --- .../com/arangodb/ArangoCollectionTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java index c435dd0c7..d7e452a9d 100644 --- a/driver/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/driver/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -408,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) { @@ -966,6 +975,16 @@ void updateDocumentRefillIndexCaches(ArangoCollection collection) { .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) { @@ -1155,6 +1174,16 @@ void replaceDocumentRefillIndexCaches(ArangoCollection collection) { .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) { @@ -1240,6 +1269,18 @@ void deleteDocumentRefillIndexCaches(ArangoCollection collection) { .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) {