Skip to content

Feature ArangoGraph.drop(boolean dropCollections) #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]


### Added

- added `ArangoGraph#drop(boolean dropCollections)`

### Changed

- changed `ArangoDB#timeout` to also set the request timeout when using VelocyStream (issue #230)
Expand Down
8 changes: 7 additions & 1 deletion docs/Drivers/Java/Reference/Graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,17 @@ GraphEntity info = graph.getInfo();
## ArangoGraph.drop

```
ArangoGraph.drop() : void
ArangoGraph.drop(boolean dropCollections) : void
```

Deletes the graph from the database.

**Arguments**

- **dropCollections**: `boolean`

Drop collections of this graph as well. Collections will only be dropped if they are not used in other graphs.

**Examples**

```Java
Expand Down
45 changes: 29 additions & 16 deletions src/main/java/com/arangodb/ArangoGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@

/**
* Interface for operations on ArangoDB graph level.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/">API Documentation</a>
* @author Mark Vollmary
*/
public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* The the handler of the database the named graph is within
*
*
* @return database handler
*/
public ArangoDatabase db();

/**
* The name of the collection
*
*
* @return collection name
*/
public String name();

/**
* Checks whether the graph exists
*
*
* @return true if the graph exists, otherwise false
*/
boolean exists() throws ArangoDBException;

/**
* Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
* its edges.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#create-a-graph">API
* Documentation</a>
* @param edgeDefinitions
Expand All @@ -71,7 +71,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
/**
* Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
* its edges.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#create-a-graph">API
* Documentation</a>
* @param edgeDefinitions
Expand All @@ -85,15 +85,28 @@ public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* Deletes the graph from the database.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#drop-a-graph">API Documentation</a>
* @throws ArangoDBException
*/
void drop() throws ArangoDBException;

/**
* Deletes the graph from the database.
*
* @see <a href=
* "https://docs.arangodb.com/current/HTTP/Gharial/Management.html#drop-a-graph">API
* Documentation</a>
* @param dropCollections
* Drop collections of this graph as well. Collections will only be
* dropped if they are not used in other graphs.
* @throws ArangoDBException
*/
void drop(boolean dropCollections) throws ArangoDBException;

/**
* Retrieves general information about the graph.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#get-a-graph">API Documentation</a>
* @return the definition content of this graph
* @throws ArangoDBException
Expand All @@ -102,7 +115,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* Fetches all vertex collections from the graph and returns a list of collection names.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#list-vertex-collections">API
* Documentation</a>
* @return all vertex collections within this graph
Expand All @@ -113,7 +126,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
/**
* Adds a vertex collection to the set of collections of the graph. If the collection does not exist, it will be
* created.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#add-vertex-collection">API
* Documentation</a>
* @param name
Expand All @@ -125,7 +138,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* Returns a {@code ArangoVertexCollection} instance for the given vertex collection name.
*
*
* @param name
* Name of the vertex collection
* @return collection handler
Expand All @@ -134,7 +147,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* Returns a {@code ArangoEdgeCollection} instance for the given edge collection name.
*
*
* @param name
* Name of the edge collection
* @return collection handler
Expand All @@ -143,7 +156,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* Fetches all edge collections from the graph and returns a list of collection names.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#list-edge-definitions">API
* Documentation</a>
* @return all edge collections within this graph
Expand All @@ -153,7 +166,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {

/**
* Adds the given edge definition to the graph.
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#add-edge-definition">API
* Documentation</a>
* @param definition
Expand All @@ -166,7 +179,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
/**
* Change one specific edge definition. This will modify all occurrences of this definition in all graphs known to
* your database
*
*
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#replace-an-edge-definition">API
* Documentation</a>
* @param definition
Expand All @@ -179,7 +192,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
/**
* Remove one edge definition from the graph. This will only remove the edge collection, the vertex collections
* remain untouched and can still be used in your queries
*
*
* @see <a href=
* "https://docs.arangodb.com/current/HTTP/Gharial/Management.html#remove-an-edge-definition-from-the-graph">API
* Documentation</a>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/arangodb/internal/ArangoGraphImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public void drop() throws ArangoDBException {
executor.execute(dropRequest(), Void.class);
}

@Override
public void drop(final boolean dropCollections) throws ArangoDBException {
executor.execute(dropRequest(dropCollections), Void.class);
}

@Override
public GraphEntity getInfo() throws ArangoDBException {
return executor.execute(getInfoRequest(), getInfoResponseDeserializer());
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/arangodb/internal/InternalArangoGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ public String name() {
}

protected Request dropRequest() {
return request(db.name(), RequestType.DELETE, PATH_API_GHARIAL, name);
return dropRequest(false);
}

protected Request dropRequest(final boolean dropCollections) {
final Request request = request(db.name(), RequestType.DELETE, PATH_API_GHARIAL, name);
if (dropCollections) {
request.putQueryParam("dropCollections", dropCollections);
}
return request;
}

protected Request getInfoRequest() {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/arangodb/ArangoGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.junit.After;
Expand Down Expand Up @@ -255,4 +256,31 @@ public void smartGraph() {
assertThat(graph.getNumberOfShards(), is(2));
}
}

@Test
public void drop() {
final String edgeCollection = "edge_drop";
final String vertexCollection = "vertex_drop";
final String graph = GRAPH_NAME + "_drop";
final GraphEntity result = db.graph(graph).create(Collections
.singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)));
assertThat(result, is(notNullValue()));
db.graph(graph).drop();
assertThat(db.collection(edgeCollection).exists(), is(true));
assertThat(db.collection(vertexCollection).exists(), is(true));
}

@Test
public void dropPlusDropCollections() {
final String edgeCollection = "edge_dropC";
final String vertexCollection = "vertex_dropC";
final String graph = GRAPH_NAME + "_dropC";
final GraphEntity result = db.graph(graph).create(Collections
.singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)));
assertThat(result, is(notNullValue()));
db.graph(graph).drop(true);
assertThat(db.collection(edgeCollection).exists(), is(false));
assertThat(db.collection(vertexCollection).exists(), is(false));
}

}