Skip to content

Commit e3adc90

Browse files
committed
typed ArangoCollection#deleteDocument
1 parent cf1da0e commit e3adc90

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

src/main/java/com/arangodb/ArangoCollection.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,19 @@ <T, U> MultiDocumentEntity<DocumentUpdateEntity<U>> updateDocuments(
418418
*/
419419
DocumentDeleteEntity<Void> deleteDocument(String key) throws ArangoDBException;
420420

421+
/**
422+
* Deletes the document with the given {@code key} from the collection.
423+
*
424+
* @param key The key of the document
425+
* @param options Additional options, can be null
426+
* @return information about the document
427+
* @throws ArangoDBException
428+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#removes-a-document">API
429+
* Documentation</a>
430+
*/
431+
<T> DocumentDeleteEntity<T> deleteDocument(String key, DocumentDeleteOptions options)
432+
throws ArangoDBException;
433+
421434
/**
422435
* Deletes the document with the given {@code key} from the collection.
423436
*
@@ -430,7 +443,7 @@ <T, U> MultiDocumentEntity<DocumentUpdateEntity<U>> updateDocuments(
430443
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#removes-a-document">API
431444
* Documentation</a>
432445
*/
433-
<T> DocumentDeleteEntity<T> deleteDocument(String key, Class<T> type, DocumentDeleteOptions options)
446+
<T> DocumentDeleteEntity<T> deleteDocument(String key, DocumentDeleteOptions options, Class<T> type)
434447
throws ArangoDBException;
435448

436449
/**

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,19 @@ <T, U> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<U>>> updateDoc
388388
*/
389389
CompletableFuture<DocumentDeleteEntity<Void>> deleteDocument(final String key);
390390

391+
/**
392+
* Removes a document
393+
*
394+
* @param key The key of the document
395+
* @param options Additional options, can be null
396+
* @return information about the document
397+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#removes-a-document">API
398+
* Documentation</a>
399+
*/
400+
<T> CompletableFuture<DocumentDeleteEntity<T>> deleteDocument(
401+
final String key,
402+
final DocumentDeleteOptions options);
403+
391404
/**
392405
* Removes a document
393406
*
@@ -401,8 +414,8 @@ <T, U> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<U>>> updateDoc
401414
*/
402415
<T> CompletableFuture<DocumentDeleteEntity<T>> deleteDocument(
403416
final String key,
404-
final Class<T> type,
405-
final DocumentDeleteOptions options);
417+
final DocumentDeleteOptions options,
418+
final Class<T> type);
406419

407420
/**
408421
* Removes multiple document

src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,20 @@ public <T, U> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<U>>> up
231231

232232
@Override
233233
public CompletableFuture<DocumentDeleteEntity<Void>> deleteDocument(final String key) {
234-
return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()),
235-
constructParametricType(DocumentDeleteEntity.class, Void.class));
234+
return deleteDocument(key, new DocumentDeleteOptions());
235+
}
236+
237+
@Override
238+
@SuppressWarnings("unchecked")
239+
public <T> CompletableFuture<DocumentDeleteEntity<T>> deleteDocument(String key, DocumentDeleteOptions options) {
240+
return deleteDocument(key, options, (Class<T>) Void.class);
236241
}
237242

238243
@Override
239244
public <T> CompletableFuture<DocumentDeleteEntity<T>> deleteDocument(
240245
final String key,
241-
final Class<T> type,
242-
final DocumentDeleteOptions options) {
246+
final DocumentDeleteOptions options,
247+
final Class<T> type) {
243248
return executor.execute(deleteDocumentRequest(key, options),
244249
constructParametricType(DocumentDeleteEntity.class, type));
245250
}

src/main/java/com/arangodb/internal/ArangoCollectionImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,18 @@ public <T, U> MultiDocumentEntity<DocumentUpdateEntity<U>> updateDocuments(
223223

224224
@Override
225225
public DocumentDeleteEntity<Void> deleteDocument(final String key) throws ArangoDBException {
226-
return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()),
227-
constructParametricType(DocumentDeleteEntity.class, Void.class));
226+
return deleteDocument(key, new DocumentDeleteOptions());
227+
}
228+
229+
@Override
230+
@SuppressWarnings("unchecked")
231+
public <T> DocumentDeleteEntity<T> deleteDocument(String key, DocumentDeleteOptions options) throws ArangoDBException {
232+
return deleteDocument(key, options, (Class<T>) Void.class);
228233
}
229234

230235
@Override
231236
public <T> DocumentDeleteEntity<T> deleteDocument(
232-
final String key, final Class<T> type, final DocumentDeleteOptions options) throws ArangoDBException {
237+
final String key, final DocumentDeleteOptions options, final Class<T> type) throws ArangoDBException {
233238
return executor.execute(deleteDocumentRequest(key, options),
234239
constructParametricType(DocumentDeleteEntity.class, type));
235240
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ void replaceDocumentsSilent(ArangoCollection collection) {
11511151
void deleteDocument(ArangoCollection collection) {
11521152
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
11531153
final DocumentCreateEntity<BaseDocument> createResult = collection.insertDocument(doc, null);
1154-
collection.deleteDocument(createResult.getKey(), null, null);
1154+
collection.deleteDocument(createResult.getKey());
11551155
final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, null);
11561156
assertThat(document).isNull();
11571157
}
@@ -1163,7 +1163,7 @@ void deleteDocumentReturnOld(ArangoCollection collection) {
11631163
doc.addAttribute("a", "test");
11641164
final DocumentCreateEntity<BaseDocument> createResult = collection.insertDocument(doc, null);
11651165
final DocumentDeleteOptions options = new DocumentDeleteOptions().returnOld(true);
1166-
final DocumentDeleteEntity<BaseDocument> deleteResult = collection.deleteDocument(createResult.getKey(), BaseDocument.class, options);
1166+
final DocumentDeleteEntity<BaseDocument> deleteResult = collection.deleteDocument(createResult.getKey(), options, BaseDocument.class);
11671167
assertThat(deleteResult.getOld()).isNotNull();
11681168
assertThat(deleteResult.getOld()).isInstanceOf(BaseDocument.class);
11691169
assertThat(deleteResult.getOld().getAttribute("a")).isNotNull();
@@ -1176,7 +1176,7 @@ void deleteDocumentIfMatch(ArangoCollection collection) {
11761176
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
11771177
final DocumentCreateEntity<BaseDocument> createResult = collection.insertDocument(doc, null);
11781178
final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch(createResult.getRev());
1179-
collection.deleteDocument(createResult.getKey(), null, options);
1179+
collection.deleteDocument(createResult.getKey(), options);
11801180
final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, null);
11811181
assertThat(document).isNull();
11821182
}
@@ -1185,9 +1185,9 @@ void deleteDocumentIfMatch(ArangoCollection collection) {
11851185
@MethodSource("cols")
11861186
void deleteDocumentIfMatchFail(ArangoCollection collection) {
11871187
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
1188-
final DocumentCreateEntity<BaseDocument> createResult = collection.insertDocument(doc, null);
1188+
final DocumentCreateEntity<?> createResult = collection.insertDocument(doc);
11891189
final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch("no");
1190-
Throwable thrown = catchThrowable(() -> collection.deleteDocument(createResult.getKey(), null, options));
1190+
Throwable thrown = catchThrowable(() -> collection.deleteDocument(createResult.getKey(), options));
11911191
assertThat(thrown).isInstanceOf(ArangoDBException.class);
11921192
}
11931193

@@ -1196,7 +1196,7 @@ void deleteDocumentIfMatchFail(ArangoCollection collection) {
11961196
void deleteDocumentSilent(ArangoCollection collection) {
11971197
assumeTrue(isSingleServer());
11981198
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
1199-
final DocumentDeleteEntity<BaseDocument> meta = collection.deleteDocument(createResult.getKey(), BaseDocument.class, new DocumentDeleteOptions().silent(true));
1199+
final DocumentDeleteEntity<BaseDocument> meta = collection.deleteDocument(createResult.getKey(), new DocumentDeleteOptions().silent(true), BaseDocument.class);
12001200
assertThat(meta).isNotNull();
12011201
assertThat(meta.getId()).isNull();
12021202
assertThat(meta.getKey()).isNull();

src/test/java/com/arangodb/StreamTransactionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void deleteDocument(ArangoDatabase db) {
552552

553553
// delete document from within the tx
554554
collection
555-
.deleteDocument(createdDoc.getKey(), null, new DocumentDeleteOptions().streamTransactionId(tx.getId()));
555+
.deleteDocument(createdDoc.getKey(), new DocumentDeleteOptions().streamTransactionId(tx.getId()));
556556

557557
// assert that the document has not been deleted from outside the tx
558558
assertThat(collection.getDocument(createdDoc.getKey(), BaseDocument.class, null)).isNotNull();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void deleteDocument() throws InterruptedException, ExecutionException {
791791
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
792792
final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null)
793793
.get();
794-
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), null, null).get();
794+
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey()).get();
795795
db.collection(COLLECTION_NAME).getDocument(createResult.getKey(), BaseDocument.class, null)
796796
.whenComplete((document, ex) -> assertThat(document).isNull())
797797
.get();
@@ -804,7 +804,7 @@ void deleteDocumentReturnOld() throws InterruptedException, ExecutionException {
804804
final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null)
805805
.get();
806806
final DocumentDeleteOptions options = new DocumentDeleteOptions().returnOld(true);
807-
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), BaseDocument.class, options)
807+
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), options, BaseDocument.class)
808808
.whenComplete((deleteResult, ex) -> {
809809
assertThat(deleteResult.getOld()).isNotNull();
810810
assertThat(deleteResult.getOld()).isInstanceOf(BaseDocument.class);
@@ -820,7 +820,7 @@ void deleteDocumentIfMatch() throws InterruptedException, ExecutionException {
820820
final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null)
821821
.get();
822822
final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch(createResult.getRev());
823-
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), null, options).get();
823+
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), options).get();
824824
db.collection(COLLECTION_NAME).getDocument(createResult.getKey(), BaseDocument.class, null)
825825
.whenComplete((document, ex) -> assertThat(document).isNull())
826826
.get();
@@ -833,7 +833,7 @@ void deleteDocumentIfMatchFail() throws InterruptedException, ExecutionException
833833
.get();
834834
final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch("no");
835835
try {
836-
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), null, options).get();
836+
db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), options).get();
837837
fail();
838838
} catch (final ExecutionException e) {
839839
assertThat(e.getCause()).isInstanceOf(ArangoDBException.class);

0 commit comments

Comments
 (0)