Skip to content

Commit f8767dd

Browse files
author
mpv1989
committed
added ArangoDatabase.getVersion(), ArangoDatabase.getAccessibleDatabases
1 parent 77f66c3 commit f8767dd

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ v4.1.11 (2017-03-xx)
77
* extracted VelocyPack implementation to https://github.com/arangodb/java-velocypack
88
* added dependency java-velocypack-module-jdk8
99
* added support for replacing build-in VelocyPack serializer/deserializer
10+
* added ArangoDatabaseAsync.getVersion(), ArangoDatabaseAsync.getAccessibleDatabases()
1011

1112
v4.1.10 (2017-02-22)
1213
---------------------------

src/main/java/com/arangodb/ArangoDBAsync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public CompletableFuture<Collection<String>> getDatabases() {
399399
* @return a list of all databases the current user can access
400400
*/
401401
public CompletableFuture<Collection<String>> getAccessibleDatabases() {
402-
return executor.execute(getAccessibleDatabasesRequest(db().name()), getDatabaseResponseDeserializer());
402+
return db().getAccessibleDatabases();
403403
}
404404

405405
/**
@@ -426,7 +426,7 @@ public CompletableFuture<Collection<String>> getAccessibleDatabasesFor(final Str
426426
* @return the server version, number
427427
*/
428428
public CompletableFuture<ArangoDBVersion> getVersion() {
429-
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
429+
return db().getVersion();
430430
}
431431

432432
/**

src/main/java/com/arangodb/ArangoDatabaseAsync.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.arangodb.entity.AqlExecutionExplainEntity;
2929
import com.arangodb.entity.AqlFunctionEntity;
3030
import com.arangodb.entity.AqlParseEntity;
31+
import com.arangodb.entity.ArangoDBVersion;
3132
import com.arangodb.entity.CollectionEntity;
3233
import com.arangodb.entity.CursorEntity;
3334
import com.arangodb.entity.DatabaseEntity;
@@ -77,6 +78,29 @@ protected ArangoDatabaseAsync(final CommunicationAsync communication, final Aran
7778
super(null, new ArangoExecutorAsync(communication, util, documentCache, collectionCache), name);
7879
}
7980

81+
/**
82+
* Returns the server name and version number.
83+
*
84+
* @see <a href="https://docs.arangodb.com/current/HTTP/MiscellaneousFunctions/index.html#return-server-version">API
85+
* Documentation</a>
86+
* @return the server version, number
87+
*/
88+
public CompletableFuture<ArangoDBVersion> getVersion() {
89+
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
90+
}
91+
92+
/**
93+
* Retrieves a list of all databases the current user can access
94+
*
95+
* @see <a href=
96+
* "https://docs.arangodb.com/current/HTTP/Database/DatabaseManagement.html#list-of-accessible-databases">API
97+
* Documentation</a>
98+
* @return a list of all databases the current user can access
99+
*/
100+
public CompletableFuture<Collection<String>> getAccessibleDatabases() {
101+
return executor.execute(getAccessibleDatabasesRequest(), getDatabaseResponseDeserializer());
102+
}
103+
80104
/**
81105
* Returns a handler of the collection by the given name
82106
*

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.hamcrest.CoreMatchers.nullValue;
2525
import static org.hamcrest.Matchers.empty;
2626
import static org.hamcrest.Matchers.greaterThan;
27+
import static org.hamcrest.Matchers.hasItem;
2728
import static org.hamcrest.Matchers.is;
2829
import static org.hamcrest.Matchers.not;
2930
import static org.junit.Assert.assertThat;
@@ -48,6 +49,7 @@
4849
import com.arangodb.entity.AqlFunctionEntity;
4950
import com.arangodb.entity.AqlParseEntity;
5051
import com.arangodb.entity.AqlParseEntity.AstNode;
52+
import com.arangodb.entity.ArangoDBVersion;
5153
import com.arangodb.entity.BaseDocument;
5254
import com.arangodb.entity.BaseEdgeDocument;
5355
import com.arangodb.entity.CollectionEntity;
@@ -81,6 +83,30 @@ public class ArangoDatabaseTest extends BaseTest {
8183
private static final String COLLECTION_NAME = "db_test";
8284
private static final String GRAPH_NAME = "graph_test";
8385

86+
@Test
87+
public void getVersion() throws InterruptedException, ExecutionException {
88+
final CompletableFuture<ArangoDBVersion> f = db.getVersion();
89+
assertThat(f, is(notNullValue()));
90+
f.whenComplete((version, ex) -> {
91+
assertThat(version, is(notNullValue()));
92+
assertThat(version.getServer(), is(notNullValue()));
93+
assertThat(version.getVersion(), is(notNullValue()));
94+
});
95+
f.get();
96+
}
97+
98+
@Test
99+
public void getAccessibleDatabases() throws InterruptedException, ExecutionException {
100+
final CompletableFuture<Collection<String>> f = db.getAccessibleDatabases();
101+
assertThat(f, is(notNullValue()));
102+
f.whenComplete((dbs, ex) -> {
103+
assertThat(dbs, is(notNullValue()));
104+
assertThat(dbs.size(), greaterThan(0));
105+
assertThat(dbs, hasItem("_system"));
106+
});
107+
f.get();
108+
}
109+
84110
@Test
85111
public void createCollection() throws InterruptedException, ExecutionException {
86112
try {
@@ -203,8 +229,8 @@ public void getCollectionsExcludeSystem() throws InterruptedException, Execution
203229
final CollectionsReadOptions options = new CollectionsReadOptions().excludeSystem(true);
204230
final Collection<CollectionEntity> systemCollections = db.getCollections(options).get();
205231
assertThat(systemCollections.size(), is(0));
206-
db.createCollection(COLLECTION_NAME + "1", null);
207-
db.createCollection(COLLECTION_NAME + "2", null);
232+
db.createCollection(COLLECTION_NAME + "1", null).get();
233+
db.createCollection(COLLECTION_NAME + "2", null).get();
208234
final CompletableFuture<Collection<CollectionEntity>> f = db.getCollections(options);
209235
assertThat(f, is(notNullValue()));
210236
f.whenComplete((collections, ex) -> {

src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ private static DocumentCreateEntity<BaseEdgeDocument> saveActsIn(
395395
}
396396

397397
private static void createData() throws InterruptedException, ExecutionException {
398-
db.createCollection("actors");
398+
db.createCollection("actors").get();
399399
final ArangoCollectionAsync actors = db.collection("actors");
400-
db.createCollection("movies");
400+
db.createCollection("movies").get();
401401
final ArangoCollectionAsync movies = db.collection("movies");
402-
db.createCollection("actsIn", new CollectionCreateOptions().type(CollectionType.EDGES));
402+
db.createCollection("actsIn", new CollectionCreateOptions().type(CollectionType.EDGES)).get();
403403
final ArangoCollectionAsync actsIn = db.collection("actsIn");
404404

405405
final String theMatrix = saveMovie(movies, "TheMatrix", "The Matrix", 1999, "Welcome to the Real World")

0 commit comments

Comments
 (0)