Skip to content

Commit 173980d

Browse files
author
mpv1989
committed
Revert "Revert "Fix issue #133""
This reverts commit d1dc038.
1 parent d1dc038 commit 173980d

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ public <T> T getDocument(final String key, final Class<T> type, final DocumentRe
242242
if (LOGGER.isDebugEnabled()) {
243243
LOGGER.debug(e.getMessage(), e);
244244
}
245-
return null;
245+
if (options == null || options.isCatchException()) {
246+
return null;
247+
}
248+
throw e;
246249
}
247250
}
248251

@@ -521,13 +524,18 @@ public Boolean documentExists(final String key) {
521524
* @param options
522525
* Additional options, can be null
523526
* @return true if the document was found, otherwise false
527+
* @throws ArangoDBException
528+
* only thrown when {@link DocumentExistsOptions#isCatchException()} == false
524529
*/
525-
public Boolean documentExists(final String key, final DocumentExistsOptions options) {
530+
public Boolean documentExists(final String key, final DocumentExistsOptions options) throws ArangoDBException {
526531
try {
527532
executor.execute(documentExistsRequest(key, options), VPackSlice.class);
528533
return true;
529534
} catch (final ArangoDBException e) {
530-
return false;
535+
if (options == null || options.isCatchException()) {
536+
return false;
537+
}
538+
throw e;
531539
}
532540
}
533541

src/main/java/com/arangodb/model/DocumentExistsOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ public class DocumentExistsOptions {
3030

3131
private String ifNoneMatch;
3232
private String ifMatch;
33+
private boolean catchException;
3334

3435
public DocumentExistsOptions() {
3536
super();
37+
catchException = true;
3638
}
3739

3840
public String getIfNoneMatch() {
@@ -63,4 +65,18 @@ public DocumentExistsOptions ifMatch(final String ifMatch) {
6365
return this;
6466
}
6567

68+
public boolean isCatchException() {
69+
return catchException;
70+
}
71+
72+
/**
73+
* @param catchException
74+
* whether or not catch possible thrown exceptions
75+
* @return options
76+
*/
77+
public DocumentExistsOptions catchException(final boolean catchException) {
78+
this.catchException = catchException;
79+
return this;
80+
}
81+
6682
}

src/main/java/com/arangodb/model/DocumentReadOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ public class DocumentReadOptions {
3030

3131
private String ifNoneMatch;
3232
private String ifMatch;
33+
private boolean catchException;
3334

3435
public DocumentReadOptions() {
3536
super();
37+
catchException = true;
3638
}
3739

3840
public String getIfNoneMatch() {
@@ -63,4 +65,18 @@ public DocumentReadOptions ifMatch(final String ifMatch) {
6365
return this;
6466
}
6567

68+
public boolean isCatchException() {
69+
return catchException;
70+
}
71+
72+
/**
73+
* @param catchException
74+
* whether or not catch possible thrown exceptions
75+
* @return options
76+
*/
77+
public DocumentReadOptions catchException(final boolean catchException) {
78+
this.catchException = catchException;
79+
return this;
80+
}
81+
6682
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ public void getDocumentNotFound() {
213213
assertThat(document, is(nullValue()));
214214
}
215215

216+
@Test(expected = ArangoDBException.class)
217+
public void getDocumentNotFoundThrowException() {
218+
db.collection(COLLECTION_NAME).getDocument("no", BaseDocument.class,
219+
new DocumentReadOptions().catchException(false));
220+
}
221+
216222
@Test(expected = ArangoDBException.class)
217223
public void getDocumentWrongKey() {
218224
db.collection(COLLECTION_NAME).getDocument("no/no", BaseDocument.class);
@@ -914,6 +920,11 @@ public void documentExists() {
914920
assertThat(exists, is(true));
915921
}
916922

923+
@Test(expected = ArangoDBException.class)
924+
public void documentExistsThrowExcpetion() {
925+
db.collection(COLLECTION_NAME).documentExists("no", new DocumentExistsOptions().catchException(false));
926+
}
927+
917928
@Test
918929
public void documentExistsIfMatch() {
919930
final DocumentCreateEntity<String> createResult = db.collection(COLLECTION_NAME)

0 commit comments

Comments
 (0)