Skip to content

Commit 6547160

Browse files
author
mpv1989
committed
issue #146: Add ArangoCollection.exists()
1 parent 2075f86 commit 6547160

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v4.2.5 (2017-xx-xx)
2+
---------------------------
3+
* issue #146: added ArangoCollection.exists()
4+
15
v4.2.4 (2017-09-04)
26
---------------------------
37
* fixed ArangoDatabase.transaction(): ignore null result

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,23 @@ public Collection<IndexEntity> getIndexes() throws ArangoDBException {
776776
return executor.execute(getIndexesRequest(), getIndexesResponseDeserializer());
777777
}
778778

779+
/**
780+
* Checks whether the collection exists
781+
*
782+
* @return true if the collection exists, otherwise false
783+
*/
784+
public boolean exists() {
785+
boolean exists = false;
786+
final Collection<CollectionEntity> collections = db().getCollections();
787+
for (final CollectionEntity collection : collections) {
788+
if (collection.getName().equals(name())) {
789+
exists = true;
790+
break;
791+
}
792+
}
793+
return exists;
794+
}
795+
779796
/**
780797
* Removes all documents from the collection, but leaves the indexes intact
781798
*

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,12 @@ public void getEdgeIndex() {
954954
}
955955
}
956956

957+
@Test
958+
public void exists() {
959+
assertThat(db.collection(COLLECTION_NAME).exists(), is(true));
960+
assertThat(db.collection(COLLECTION_NAME + "no").exists(), is(false));
961+
}
962+
957963
@Test
958964
public void truncate() {
959965
final BaseDocument doc = new BaseDocument();

0 commit comments

Comments
 (0)