Skip to content

Commit

Permalink
added ArangoDatabase.getVersion,ArangoDatabase.getAccessibleDatabases
Browse files Browse the repository at this point in the history
  • Loading branch information
mpv1989 committed Mar 20, 2017
1 parent 969cc4b commit 2bdde54
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ v4.1.11 (2017-03-xx)
* extracted VelocyPack implementation to https://github.com/arangodb/java-velocypack
* fixed NPE in ArangoCursor (issue #112)
* added support for replacing build-in VelocyPack serializer/deserializer
* added ArangoDatabase.getVersion(), ArangoDatabase.getAccessibleDatabases()

v4.1.10 (2017-02-22)
---------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public Collection<String> getDatabases() throws ArangoDBException {
* @throws ArangoDBException
*/
public Collection<String> getAccessibleDatabases() throws ArangoDBException {
return executor.execute(getAccessibleDatabasesRequest(db().name()), getDatabaseResponseDeserializer());
return db().getAccessibleDatabases();
}

/**
Expand Down Expand Up @@ -418,7 +418,7 @@ public Collection<String> getAccessibleDatabasesFor(final String user) throws Ar
* @throws ArangoDBException
*/
public ArangoDBVersion getVersion() throws ArangoDBException {
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
return db().getVersion();
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/arangodb/ArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.arangodb.entity.AqlExecutionExplainEntity;
import com.arangodb.entity.AqlFunctionEntity;
import com.arangodb.entity.AqlParseEntity;
import com.arangodb.entity.ArangoDBVersion;
import com.arangodb.entity.CollectionEntity;
import com.arangodb.entity.CursorEntity;
import com.arangodb.entity.DatabaseEntity;
Expand Down Expand Up @@ -74,6 +75,31 @@ protected ArangoDatabase(final Communication<Response, ConnectionSync> communica
super(null, new ArangoExecutorSync(communication, util, documentCache, collectionCache), name);
}

/**
* Returns the server name and version number.
*
* @see <a href="https://docs.arangodb.com/current/HTTP/MiscellaneousFunctions/index.html#return-server-version">API
* Documentation</a>
* @return the server version, number
* @throws ArangoDBException
*/
public ArangoDBVersion getVersion() throws ArangoDBException {
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
}

/**
* Retrieves a list of all databases the current user can access
*
* @see <a href=
* "https://docs.arangodb.com/current/HTTP/Database/DatabaseManagement.html#list-of-accessible-databases">API
* Documentation</a>
* @return a list of all databases the current user can access
* @throws ArangoDBException
*/
public Collection<String> getAccessibleDatabases() throws ArangoDBException {
return executor.execute(getAccessibleDatabasesRequest(), getDatabaseResponseDeserializer());
}

/**
* Returns a handler of the collection by the given name
*
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/com/arangodb/internal/InternalArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ public Collection<String> deserialize(final Response response) throws VPackExcep
};
}

protected Request getAccessibleDatabasesRequest(final String database) {
return new Request(database, RequestType.GET,
executor.createPath(ArangoDBConstants.PATH_API_DATABASE, ArangoDBConstants.USER));
}

protected Request getAccessibleDatabasesForRequest(final String database, final String user) {
return new Request(database, RequestType.GET,
executor.createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE));
Expand All @@ -187,10 +182,6 @@ public Collection<String> deserialize(final Response response) throws VPackExcep
};
}

protected Request getVersionRequest() {
return new Request(ArangoDBConstants.SYSTEM, RequestType.GET, ArangoDBConstants.PATH_API_VERSION);
}

protected Request createUserRequest(
final String database,
final String user,
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/arangodb/internal/InternalArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public String name() {
return name;
}

protected ResponseDeserializer<Collection<String>> getDatabaseResponseDeserializer() {
return arango.getDatabaseResponseDeserializer();
}

protected Request getAccessibleDatabasesRequest() {
return new Request(name, RequestType.GET,
executor.createPath(ArangoDBConstants.PATH_API_DATABASE, ArangoDBConstants.USER));
}

protected Request getVersionRequest() {
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_VERSION);
}

protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION).setBody(
executor.serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/arangodb/ArangoDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
Expand All @@ -47,6 +48,7 @@
import com.arangodb.entity.AqlFunctionEntity;
import com.arangodb.entity.AqlParseEntity;
import com.arangodb.entity.AqlParseEntity.AstNode;
import com.arangodb.entity.ArangoDBVersion;
import com.arangodb.entity.BaseDocument;
import com.arangodb.entity.BaseEdgeDocument;
import com.arangodb.entity.CollectionEntity;
Expand Down Expand Up @@ -82,6 +84,22 @@ public class ArangoDatabaseTest extends BaseTest {
private static final String COLLECTION_NAME = "db_test";
private static final String GRAPH_NAME = "graph_test";

@Test
public void getVersion() {
final ArangoDBVersion version = db.getVersion();
assertThat(version, is(notNullValue()));
assertThat(version.getServer(), is(notNullValue()));
assertThat(version.getVersion(), is(notNullValue()));
}

@Test
public void getAccessibleDatabases() {
final Collection<String> dbs = db.getAccessibleDatabases();
assertThat(dbs, is(notNullValue()));
assertThat(dbs.size(), greaterThan(0));
assertThat(dbs, hasItem("_system"));
}

@Test
public void createCollection() {
try {
Expand Down

0 comments on commit 2bdde54

Please sign in to comment.