Skip to content

Commit af98ae6

Browse files
author
Mark
committed
changed ArangoCollection.deleteDocuments() to work with keys+docs
1 parent 01c7a85 commit af98ae6

File tree

3 files changed

+87
-11
lines changed

3 files changed

+87
-11
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ v4.1.8 (2017-02-xx)
99
* added byte[] de-/serialization from/to VPack.string (Base64)
1010
* added ArangoCollection.drop(isSystem)
1111
* improved ArangoDBException with responseCode, errorNum, errorMessage
12+
* changed ArangoCollection.deleteDocuments() to work with keys and documents
1213

1314
v4.1.7 (2017-01-26)
1415
---------------------------

src/main/java/com/arangodb/ArangoCollectionAsync.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,16 +440,16 @@ public <T> CompletableFuture<DocumentDeleteEntity<T>> deleteDocument(
440440
* @see <a href=
441441
* "https://docs.arangodb.com/current/HTTP/Document/WorkingWithDocuments.html#removes-multiple-documents">API
442442
* Documentation</a>
443-
* @param keys
444-
* The keys of the documents
443+
* @param values
444+
* The keys of the documents or the documents themselves
445445
* @param type
446446
* The type of the documents (POJO class, VPackSlice or String for Json). Only necessary if
447447
* options.returnOld is set to true, otherwise can be null.
448448
* @return information about the documents
449449
*/
450450
public CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<Void>>> deleteDocuments(
451-
final Collection<String> keys) {
452-
return executor.execute(deleteDocumentsRequest(keys, new DocumentDeleteOptions()),
451+
final Collection<?> values) {
452+
return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()),
453453
deleteDocumentsResponseDeserializer(Void.class));
454454
}
455455

@@ -459,8 +459,8 @@ public CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<Void>>> delete
459459
* @see <a href=
460460
* "https://docs.arangodb.com/current/HTTP/Document/WorkingWithDocuments.html#removes-multiple-documents">API
461461
* Documentation</a>
462-
* @param keys
463-
* The keys of the documents
462+
* @param values
463+
* The keys of the documents or the documents themselves
464464
* @param type
465465
* The type of the documents (POJO class, VPackSlice or String for Json). Only necessary if
466466
* options.returnOld is set to true, otherwise can be null.
@@ -469,10 +469,10 @@ public CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<Void>>> delete
469469
* @return information about the documents
470470
*/
471471
public <T> CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<T>>> deleteDocuments(
472-
final Collection<String> keys,
472+
final Collection<?> values,
473473
final Class<T> type,
474474
final DocumentDeleteOptions options) {
475-
return executor.execute(deleteDocumentsRequest(keys, options), deleteDocumentsResponseDeserializer(type));
475+
return executor.execute(deleteDocumentsRequest(values, options), deleteDocumentsResponseDeserializer(type));
476476
}
477477

478478
/**

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ public void importDocumentsJsonFromToPrefix() throws InterruptedException, Execu
15081508
}
15091509

15101510
@Test
1511-
public void deleteDocuments() throws InterruptedException, ExecutionException {
1511+
public void deleteDocumentsByKey() throws InterruptedException, ExecutionException {
15121512
final Collection<BaseDocument> values = new ArrayList<>();
15131513
{
15141514
final BaseDocument e = new BaseDocument();
@@ -1539,7 +1539,35 @@ public void deleteDocuments() throws InterruptedException, ExecutionException {
15391539
}
15401540

15411541
@Test
1542-
public void deleteDocumentsOne() throws InterruptedException, ExecutionException {
1542+
public void deleteDocumentsByDocuments() throws InterruptedException, ExecutionException {
1543+
final Collection<BaseDocument> values = new ArrayList<>();
1544+
{
1545+
final BaseDocument e = new BaseDocument();
1546+
e.setKey("1");
1547+
values.add(e);
1548+
}
1549+
{
1550+
final BaseDocument e = new BaseDocument();
1551+
e.setKey("2");
1552+
values.add(e);
1553+
}
1554+
db.collection(COLLECTION_NAME).insertDocuments(values, null);
1555+
final CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<Object>>> f = db.collection(COLLECTION_NAME)
1556+
.deleteDocuments(values, null, null);
1557+
assertThat(f, is(notNullValue()));
1558+
f.whenComplete((deleteResult, ex) -> {
1559+
assertThat(deleteResult, is(notNullValue()));
1560+
assertThat(deleteResult.getDocuments().size(), is(2));
1561+
for (final DocumentDeleteEntity<Object> i : deleteResult.getDocuments()) {
1562+
assertThat(i.getKey(), anyOf(is("1"), is("2")));
1563+
}
1564+
assertThat(deleteResult.getErrors().size(), is(0));
1565+
});
1566+
f.get();
1567+
}
1568+
1569+
@Test
1570+
public void deleteDocumentsByKeyOne() throws InterruptedException, ExecutionException {
15431571
final Collection<BaseDocument> values = new ArrayList<>();
15441572
{
15451573
final BaseDocument e = new BaseDocument();
@@ -1563,6 +1591,29 @@ public void deleteDocumentsOne() throws InterruptedException, ExecutionException
15631591
f.get();
15641592
}
15651593

1594+
@Test
1595+
public void deleteDocumentsByDocumentOne() throws InterruptedException, ExecutionException {
1596+
final Collection<BaseDocument> values = new ArrayList<>();
1597+
{
1598+
final BaseDocument e = new BaseDocument();
1599+
e.setKey("1");
1600+
values.add(e);
1601+
}
1602+
db.collection(COLLECTION_NAME).insertDocuments(values, null);
1603+
final CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<Object>>> f = db.collection(COLLECTION_NAME)
1604+
.deleteDocuments(values, null, null);
1605+
assertThat(f, is(notNullValue()));
1606+
f.whenComplete((deleteResult, ex) -> {
1607+
assertThat(deleteResult, is(notNullValue()));
1608+
assertThat(deleteResult.getDocuments().size(), is(1));
1609+
for (final DocumentDeleteEntity<Object> i : deleteResult.getDocuments()) {
1610+
assertThat(i.getKey(), is("1"));
1611+
}
1612+
assertThat(deleteResult.getErrors().size(), is(0));
1613+
});
1614+
f.get();
1615+
}
1616+
15661617
@Test
15671618
public void deleteDocumentsEmpty() throws InterruptedException, ExecutionException {
15681619
final Collection<BaseDocument> values = new ArrayList<>();
@@ -1580,7 +1631,7 @@ public void deleteDocumentsEmpty() throws InterruptedException, ExecutionExcepti
15801631
}
15811632

15821633
@Test
1583-
public void deleteDocumentsNotExisting() throws InterruptedException, ExecutionException {
1634+
public void deleteDocumentsByKeyNotExisting() throws InterruptedException, ExecutionException {
15841635
final Collection<BaseDocument> values = new ArrayList<>();
15851636
db.collection(COLLECTION_NAME).insertDocuments(values, null);
15861637
final Collection<String> keys = new ArrayList<>();
@@ -1597,6 +1648,30 @@ public void deleteDocumentsNotExisting() throws InterruptedException, ExecutionE
15971648
f.get();
15981649
}
15991650

1651+
@Test
1652+
public void deleteDocumentsByDocumentsNotExisting() throws InterruptedException, ExecutionException {
1653+
final Collection<BaseDocument> values = new ArrayList<>();
1654+
{
1655+
final BaseDocument e = new BaseDocument();
1656+
e.setKey("1");
1657+
values.add(e);
1658+
}
1659+
{
1660+
final BaseDocument e = new BaseDocument();
1661+
e.setKey("2");
1662+
values.add(e);
1663+
}
1664+
final CompletableFuture<MultiDocumentEntity<DocumentDeleteEntity<Object>>> f = db.collection(COLLECTION_NAME)
1665+
.deleteDocuments(values, null, null);
1666+
assertThat(f, is(notNullValue()));
1667+
f.whenComplete((deleteResult, ex) -> {
1668+
assertThat(deleteResult, is(notNullValue()));
1669+
assertThat(deleteResult.getDocuments().size(), is(0));
1670+
assertThat(deleteResult.getErrors().size(), is(2));
1671+
});
1672+
f.get();
1673+
}
1674+
16001675
@Test
16011676
public void updateDocuments() throws InterruptedException, ExecutionException {
16021677
final Collection<BaseDocument> values = new ArrayList<>();

0 commit comments

Comments
 (0)