Skip to content

Commit 083ef58

Browse files
author
mpv1989
committed
Add ArangoDatabase.exists()
1 parent 6547160 commit 083ef58

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
v4.2.5 (2017-xx-xx)
22
---------------------------
33
* issue #146: added ArangoCollection.exists()
4+
* added ArangoDatabase.exists()
45

56
v4.2.4 (2017-09-04)
67
---------------------------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public Collection<IndexEntity> getIndexes() throws ArangoDBException {
781781
*
782782
* @return true if the collection exists, otherwise false
783783
*/
784-
public boolean exists() {
784+
public boolean exists() throws ArangoDBException {
785785
boolean exists = false;
786786
final Collection<CollectionEntity> collections = db().getCollections();
787787
for (final CollectionEntity collection : collections) {

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ public ArangoDBVersion getVersion() throws ArangoDBException {
9090
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
9191
}
9292

93+
/**
94+
* Checks whether the database exists
95+
*
96+
* @return true if the database exists, otherwise false
97+
*/
98+
public boolean exists() throws ArangoDBException {
99+
return arango().getDatabases().contains(name());
100+
}
101+
93102
/**
94103
* Retrieves a list of all databases the current user can access
95104
*

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public void getVersion() {
104104
assertThat(version.getVersion(), is(notNullValue()));
105105
}
106106

107+
@Test
108+
public void exists() {
109+
assertThat(db.exists(), is(true));
110+
assertThat(arangoDB.db("no").exists(), is(false));
111+
}
112+
107113
@Test
108114
public void getAccessibleDatabases() {
109115
final Collection<String> dbs = db.getAccessibleDatabases();

0 commit comments

Comments
 (0)