Skip to content

Commit 2bdde54

Browse files
author
mpv1989
committed
added ArangoDatabase.getVersion,ArangoDatabase.getAccessibleDatabases
1 parent 969cc4b commit 2bdde54

File tree

6 files changed

+60
-11
lines changed

6 files changed

+60
-11
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
* fixed NPE in ArangoCursor (issue #112)
99
* added support for replacing build-in VelocyPack serializer/deserializer
10+
* added ArangoDatabase.getVersion(), ArangoDatabase.getAccessibleDatabases()
1011

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

src/main/java/com/arangodb/ArangoDB.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public Collection<String> getDatabases() throws ArangoDBException {
390390
* @throws ArangoDBException
391391
*/
392392
public Collection<String> getAccessibleDatabases() throws ArangoDBException {
393-
return executor.execute(getAccessibleDatabasesRequest(db().name()), getDatabaseResponseDeserializer());
393+
return db().getAccessibleDatabases();
394394
}
395395

396396
/**
@@ -418,7 +418,7 @@ public Collection<String> getAccessibleDatabasesFor(final String user) throws Ar
418418
* @throws ArangoDBException
419419
*/
420420
public ArangoDBVersion getVersion() throws ArangoDBException {
421-
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
421+
return db().getVersion();
422422
}
423423

424424
/**

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.arangodb.entity.AqlExecutionExplainEntity;
2727
import com.arangodb.entity.AqlFunctionEntity;
2828
import com.arangodb.entity.AqlParseEntity;
29+
import com.arangodb.entity.ArangoDBVersion;
2930
import com.arangodb.entity.CollectionEntity;
3031
import com.arangodb.entity.CursorEntity;
3132
import com.arangodb.entity.DatabaseEntity;
@@ -74,6 +75,31 @@ protected ArangoDatabase(final Communication<Response, ConnectionSync> communica
7475
super(null, new ArangoExecutorSync(communication, util, documentCache, collectionCache), name);
7576
}
7677

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

src/main/java/com/arangodb/internal/InternalArangoDB.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,6 @@ public Collection<String> deserialize(final Response response) throws VPackExcep
162162
};
163163
}
164164

165-
protected Request getAccessibleDatabasesRequest(final String database) {
166-
return new Request(database, RequestType.GET,
167-
executor.createPath(ArangoDBConstants.PATH_API_DATABASE, ArangoDBConstants.USER));
168-
}
169-
170165
protected Request getAccessibleDatabasesForRequest(final String database, final String user) {
171166
return new Request(database, RequestType.GET,
172167
executor.createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE));
@@ -187,10 +182,6 @@ public Collection<String> deserialize(final Response response) throws VPackExcep
187182
};
188183
}
189184

190-
protected Request getVersionRequest() {
191-
return new Request(ArangoDBConstants.SYSTEM, RequestType.GET, ArangoDBConstants.PATH_API_VERSION);
192-
}
193-
194185
protected Request createUserRequest(
195186
final String database,
196187
final String user,

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ public String name() {
7979
return name;
8080
}
8181

82+
protected ResponseDeserializer<Collection<String>> getDatabaseResponseDeserializer() {
83+
return arango.getDatabaseResponseDeserializer();
84+
}
85+
86+
protected Request getAccessibleDatabasesRequest() {
87+
return new Request(name, RequestType.GET,
88+
executor.createPath(ArangoDBConstants.PATH_API_DATABASE, ArangoDBConstants.USER));
89+
}
90+
91+
protected Request getVersionRequest() {
92+
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_VERSION);
93+
}
94+
8295
protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
8396
return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION).setBody(
8497
executor.serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));

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

Lines changed: 18 additions & 0 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;
@@ -47,6 +48,7 @@
4748
import com.arangodb.entity.AqlFunctionEntity;
4849
import com.arangodb.entity.AqlParseEntity;
4950
import com.arangodb.entity.AqlParseEntity.AstNode;
51+
import com.arangodb.entity.ArangoDBVersion;
5052
import com.arangodb.entity.BaseDocument;
5153
import com.arangodb.entity.BaseEdgeDocument;
5254
import com.arangodb.entity.CollectionEntity;
@@ -82,6 +84,22 @@ public class ArangoDatabaseTest extends BaseTest {
8284
private static final String COLLECTION_NAME = "db_test";
8385
private static final String GRAPH_NAME = "graph_test";
8486

87+
@Test
88+
public void getVersion() {
89+
final ArangoDBVersion version = db.getVersion();
90+
assertThat(version, is(notNullValue()));
91+
assertThat(version.getServer(), is(notNullValue()));
92+
assertThat(version.getVersion(), is(notNullValue()));
93+
}
94+
95+
@Test
96+
public void getAccessibleDatabases() {
97+
final Collection<String> dbs = db.getAccessibleDatabases();
98+
assertThat(dbs, is(notNullValue()));
99+
assertThat(dbs.size(), greaterThan(0));
100+
assertThat(dbs, hasItem("_system"));
101+
}
102+
85103
@Test
86104
public void createCollection() {
87105
try {

0 commit comments

Comments
 (0)