Skip to content

Commit b72a80e

Browse files
author
mpv1989
committed
issue #146: ArangoCollection/ArangoDatabase.exists()
1 parent 083ef58 commit b72a80e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,15 +782,12 @@ public Collection<IndexEntity> getIndexes() throws ArangoDBException {
782782
* @return true if the collection exists, otherwise false
783783
*/
784784
public boolean exists() throws ArangoDBException {
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-
}
785+
try {
786+
getInfo();
787+
return true;
788+
} catch (final ArangoDBException e) {
789+
return false;
792790
}
793-
return exists;
794791
}
795792

796793
/**

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ public ArangoDBVersion getVersion() throws ArangoDBException {
9696
* @return true if the database exists, otherwise false
9797
*/
9898
public boolean exists() throws ArangoDBException {
99-
return arango().getDatabases().contains(name());
99+
try {
100+
getInfo();
101+
return true;
102+
} catch (final ArangoDBException e) {
103+
return false;
104+
}
100105
}
101106

102107
/**

0 commit comments

Comments
 (0)