Skip to content

Commit 09e8557

Browse files
authored
added ignoreRevs to DocumentDeleteOptions (#567)
1 parent 505e3bf commit 09e8557

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

Diff for: core/src/main/java/com/arangodb/internal/InternalArangoCollection.java

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ private InternalRequest createDeleteDocumentRequest(final DocumentDeleteOptions
363363
request.putQueryParam(RETURN_OLD, params.getReturnOld());
364364
request.putQueryParam(SILENT, params.getSilent());
365365
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
366+
request.putQueryParam(IGNORE_REVS, params.getIgnoreRevs());
366367
return request;
367368
}
368369

Diff for: core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public final class DocumentDeleteOptions extends TransactionalOptions<DocumentDe
3131
private Boolean returnOld;
3232
private Boolean silent;
3333
private Boolean refillIndexCaches;
34+
private Boolean ignoreRevs;
3435

3536
@Override
3637
DocumentDeleteOptions getThis() {
@@ -106,4 +107,18 @@ public DocumentDeleteOptions refillIndexCaches(Boolean refillIndexCaches) {
106107
this.refillIndexCaches = refillIndexCaches;
107108
return this;
108109
}
110+
111+
public Boolean getIgnoreRevs() {
112+
return ignoreRevs;
113+
}
114+
115+
/**
116+
* @param ignoreRevs If set to true, ignore any _rev attribute in the selectors. No revision check is performed.
117+
* If set to false then revisions are checked. The default is true.
118+
* @return options
119+
*/
120+
public DocumentDeleteOptions ignoreRevs(final Boolean ignoreRevs) {
121+
this.ignoreRevs = ignoreRevs;
122+
return this;
123+
}
109124
}

Diff for: test-functional/src/test/java/com/arangodb/ArangoCollectionAsyncTest.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.arangodb;
2222

2323
import com.arangodb.entity.*;
24-
import com.arangodb.internal.RequestContextHolder;
2524
import com.arangodb.internal.serde.SerdeUtils;
2625
import com.arangodb.model.*;
2726
import com.arangodb.model.DocumentImportOptions.OnDuplicate;
@@ -35,6 +34,7 @@
3534
import com.fasterxml.jackson.core.JsonProcessingException;
3635
import com.fasterxml.jackson.databind.JsonNode;
3736
import com.fasterxml.jackson.databind.ObjectMapper;
37+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
3838
import org.junit.jupiter.api.BeforeAll;
3939
import org.junit.jupiter.params.ParameterizedTest;
4040
import org.junit.jupiter.params.provider.Arguments;
@@ -557,8 +557,7 @@ void insertDocumentAsBytes(ArangoCollectionAsync collection) throws ExecutionExc
557557
assertThat(createEntity.getKey()).isEqualTo(key);
558558
assertThat(createEntity.getRev()).isNotNull();
559559
assertThat(createEntity.getNew()).isNotNull().isInstanceOf(RawBytes.class);
560-
Map<String, Object> newDoc = RequestContextHolder.INSTANCE.runWithCtx(RequestContext.EMPTY, () ->
561-
collection.getSerde().deserializeUserData(createEntity.getNew().get(), Map.class));
560+
Map<String, Object> newDoc = collection.getSerde().getUserSerde().deserialize(createEntity.getNew().get(), Map.class);
562561
assertThat(newDoc).containsAllEntriesOf(doc);
563562
}
564563

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

1599+
@ParameterizedTest
1600+
@MethodSource("asyncCols")
1601+
void deleteDocuments(ArangoCollectionAsync collection) throws ExecutionException, InterruptedException {
1602+
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument()).get();
1603+
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument()).get();
1604+
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
1605+
Arrays.asList(a.getKey(), b.getKey())).get();
1606+
assertThat(info).isNotNull();
1607+
assertThat(info.getDocuments()).hasSize(2);
1608+
assertThat(info.getErrors()).isEmpty();
1609+
}
1610+
1611+
@ParameterizedTest
1612+
@MethodSource("asyncCols")
1613+
void deleteDocumentsWithRevs(ArangoCollectionAsync collection) throws ExecutionException, InterruptedException {
1614+
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument()).get();
1615+
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument()).get();
1616+
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
1617+
Arrays.asList(
1618+
JsonNodeFactory.instance.objectNode()
1619+
.put("_key", a.getKey())
1620+
.put("_rev", a.getRev()),
1621+
JsonNodeFactory.instance.objectNode()
1622+
.put("_key", b.getKey())
1623+
.put("_rev", "wrong")
1624+
), new DocumentDeleteOptions().ignoreRevs(false)).get();
1625+
assertThat(info).isNotNull();
1626+
assertThat(info.getDocuments()).hasSize(1);
1627+
assertThat(info.getDocuments().get(0).getKey()).isEqualTo(a.getKey());
1628+
assertThat(info.getErrors()).hasSize(1);
1629+
}
1630+
16001631
@ParameterizedTest
16011632
@MethodSource("asyncCols")
16021633
void deleteDocumentSilent(ArangoCollectionAsync collection) throws ExecutionException, InterruptedException {

Diff for: test-functional/src/test/java/com/arangodb/ArangoCollectionTest.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.arangodb;
2222

2323
import com.arangodb.entity.*;
24-
import com.arangodb.internal.RequestContextHolder;
2524
import com.arangodb.internal.serde.SerdeUtils;
2625
import com.arangodb.model.*;
2726
import com.arangodb.model.DocumentImportOptions.OnDuplicate;
@@ -35,6 +34,7 @@
3534
import com.fasterxml.jackson.core.JsonProcessingException;
3635
import com.fasterxml.jackson.databind.JsonNode;
3736
import com.fasterxml.jackson.databind.ObjectMapper;
37+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
3838
import org.junit.jupiter.api.BeforeAll;
3939
import org.junit.jupiter.params.ParameterizedTest;
4040
import org.junit.jupiter.params.provider.Arguments;
@@ -560,8 +560,7 @@ void insertDocumentAsBytes(ArangoCollection collection) {
560560
assertThat(createEntity.getKey()).isEqualTo(key);
561561
assertThat(createEntity.getRev()).isNotNull();
562562
assertThat(createEntity.getNew()).isNotNull().isInstanceOf(RawBytes.class);
563-
Map<String, Object> newDoc = RequestContextHolder.INSTANCE.runWithCtx(RequestContext.EMPTY, () ->
564-
collection.getSerde().deserializeUserData(createEntity.getNew().get(), Map.class));
563+
Map<String, Object> newDoc = collection.getSerde().getUserSerde().deserialize(createEntity.getNew().get(), Map.class);
565564
assertThat(newDoc).containsAllEntriesOf(doc);
566565
}
567566

@@ -1622,6 +1621,38 @@ void deleteDocumentIfMatchFail(ArangoCollection collection) {
16221621
assertThat(thrown).isInstanceOf(ArangoDBException.class);
16231622
}
16241623

1624+
@ParameterizedTest
1625+
@MethodSource("cols")
1626+
void deleteDocuments(ArangoCollection collection) {
1627+
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument());
1628+
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument());
1629+
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
1630+
Arrays.asList(a.getKey(), b.getKey()));
1631+
assertThat(info).isNotNull();
1632+
assertThat(info.getDocuments()).hasSize(2);
1633+
assertThat(info.getErrors()).isEmpty();
1634+
}
1635+
1636+
@ParameterizedTest
1637+
@MethodSource("cols")
1638+
void deleteDocumentsWithRevs(ArangoCollection collection) {
1639+
DocumentCreateEntity<?> a = collection.insertDocument(new BaseDocument());
1640+
DocumentCreateEntity<?> b = collection.insertDocument(new BaseDocument());
1641+
MultiDocumentEntity<DocumentDeleteEntity<Void>> info = collection.deleteDocuments(
1642+
Arrays.asList(
1643+
JsonNodeFactory.instance.objectNode()
1644+
.put("_key", a.getKey())
1645+
.put("_rev", a.getRev()),
1646+
JsonNodeFactory.instance.objectNode()
1647+
.put("_key", b.getKey())
1648+
.put("_rev", "wrong")
1649+
), new DocumentDeleteOptions().ignoreRevs(false));
1650+
assertThat(info).isNotNull();
1651+
assertThat(info.getDocuments()).hasSize(1);
1652+
assertThat(info.getDocuments().get(0).getKey()).isEqualTo(a.getKey());
1653+
assertThat(info.getErrors()).hasSize(1);
1654+
}
1655+
16251656
@ParameterizedTest
16261657
@MethodSource("cols")
16271658
void deleteDocumentSilent(ArangoCollection collection) {

0 commit comments

Comments
 (0)