Skip to content

[DE-844] added ignoreRevs to DocumentDeleteOptions #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ private InternalRequest createDeleteDocumentRequest(final DocumentDeleteOptions
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.putQueryParam(IGNORE_REVS, params.getIgnoreRevs());
return request;
}

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class DocumentDeleteOptions extends TransactionalOptions<DocumentDe
private Boolean returnOld;
private Boolean silent;
private Boolean refillIndexCaches;
private Boolean ignoreRevs;

@Override
DocumentDeleteOptions getThis() {
Expand Down Expand Up @@ -106,4 +107,18 @@ public DocumentDeleteOptions refillIndexCaches(Boolean refillIndexCaches) {
this.refillIndexCaches = refillIndexCaches;
return this;
}

public Boolean getIgnoreRevs() {
return ignoreRevs;
}

/**
* @param ignoreRevs If set to true, ignore any _rev attribute in the selectors. No revision check is performed.
* If set to false then revisions are checked. The default is true.
* @return options
*/
public DocumentDeleteOptions ignoreRevs(final Boolean ignoreRevs) {
this.ignoreRevs = ignoreRevs;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.arangodb;

import com.arangodb.entity.*;
import com.arangodb.internal.RequestContextHolder;
import com.arangodb.internal.serde.SerdeUtils;
import com.arangodb.model.*;
import com.arangodb.model.DocumentImportOptions.OnDuplicate;
Expand All @@ -35,6 +34,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -557,8 +557,7 @@ void insertDocumentAsBytes(ArangoCollectionAsync collection) throws ExecutionExc
assertThat(createEntity.getKey()).isEqualTo(key);
assertThat(createEntity.getRev()).isNotNull();
assertThat(createEntity.getNew()).isNotNull().isInstanceOf(RawBytes.class);
Map<String, Object> newDoc = RequestContextHolder.INSTANCE.runWithCtx(RequestContext.EMPTY, () ->
collection.getSerde().deserializeUserData(createEntity.getNew().get(), Map.class));
Map<String, Object> newDoc = collection.getSerde().getUserSerde().deserialize(createEntity.getNew().get(), Map.class);
assertThat(newDoc).containsAllEntriesOf(doc);
}

Expand Down Expand Up @@ -1597,6 +1596,38 @@ void deleteDocumentIfMatchFail(ArangoCollectionAsync collection) throws Executio
assertThat(thrown).isInstanceOf(ArangoDBException.class);
}

@ParameterizedTest
@MethodSource("asyncCols")
void deleteDocuments(ArangoCollectionAsync collection) throws ExecutionException, InterruptedException {
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument()).get();
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument()).get();
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
Arrays.asList(a.getKey(), b.getKey())).get();
assertThat(info).isNotNull();
assertThat(info.getDocuments()).hasSize(2);
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest
@MethodSource("asyncCols")
void deleteDocumentsWithRevs(ArangoCollectionAsync collection) throws ExecutionException, InterruptedException {
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument()).get();
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument()).get();
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
Arrays.asList(
JsonNodeFactory.instance.objectNode()
.put("_key", a.getKey())
.put("_rev", a.getRev()),
JsonNodeFactory.instance.objectNode()
.put("_key", b.getKey())
.put("_rev", "wrong")
), new DocumentDeleteOptions().ignoreRevs(false)).get();
assertThat(info).isNotNull();
assertThat(info.getDocuments()).hasSize(1);
assertThat(info.getDocuments().get(0).getKey()).isEqualTo(a.getKey());
assertThat(info.getErrors()).hasSize(1);
}

@ParameterizedTest
@MethodSource("asyncCols")
void deleteDocumentSilent(ArangoCollectionAsync collection) throws ExecutionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.arangodb;

import com.arangodb.entity.*;
import com.arangodb.internal.RequestContextHolder;
import com.arangodb.internal.serde.SerdeUtils;
import com.arangodb.model.*;
import com.arangodb.model.DocumentImportOptions.OnDuplicate;
Expand All @@ -35,6 +34,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -560,8 +560,7 @@ void insertDocumentAsBytes(ArangoCollection collection) {
assertThat(createEntity.getKey()).isEqualTo(key);
assertThat(createEntity.getRev()).isNotNull();
assertThat(createEntity.getNew()).isNotNull().isInstanceOf(RawBytes.class);
Map<String, Object> newDoc = RequestContextHolder.INSTANCE.runWithCtx(RequestContext.EMPTY, () ->
collection.getSerde().deserializeUserData(createEntity.getNew().get(), Map.class));
Map<String, Object> newDoc = collection.getSerde().getUserSerde().deserialize(createEntity.getNew().get(), Map.class);
assertThat(newDoc).containsAllEntriesOf(doc);
}

Expand Down Expand Up @@ -1622,6 +1621,38 @@ void deleteDocumentIfMatchFail(ArangoCollection collection) {
assertThat(thrown).isInstanceOf(ArangoDBException.class);
}

@ParameterizedTest
@MethodSource("cols")
void deleteDocuments(ArangoCollection collection) {
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument());
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument());
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
Arrays.asList(a.getKey(), b.getKey()));
assertThat(info).isNotNull();
assertThat(info.getDocuments()).hasSize(2);
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest
@MethodSource("cols")
void deleteDocumentsWithRevs(ArangoCollection collection) {
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument());
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument());
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
Arrays.asList(
JsonNodeFactory.instance.objectNode()
.put("_key", a.getKey())
.put("_rev", a.getRev()),
JsonNodeFactory.instance.objectNode()
.put("_key", b.getKey())
.put("_rev", "wrong")
), new DocumentDeleteOptions().ignoreRevs(false));
assertThat(info).isNotNull();
assertThat(info.getDocuments()).hasSize(1);
assertThat(info.getDocuments().get(0).getKey()).isEqualTo(a.getKey());
assertThat(info.getErrors()).hasSize(1);
}

@ParameterizedTest
@MethodSource("cols")
void deleteDocumentSilent(ArangoCollection collection) {
Expand Down