Skip to content

Commit 06d2b59

Browse files
mpv1989hkernbach
authored andcommitted
Feature ArangoGraph.drop(boolean dropCollections) (arangodb#238)
* Change `ArangoDB#timeout` to also set the request timeout when using VelocyStream (issue arangodb#230) * Add ArangoGraph#drop(boolean dropCollections)
1 parent 9f371d1 commit 06d2b59

File tree

6 files changed

+83
-18
lines changed

6 files changed

+83
-18
lines changed

ChangeLog.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
10+
### Added
11+
12+
- added `ArangoGraph#drop(boolean dropCollections)`
13+
914
### Changed
1015

1116
- changed `ArangoDB#timeout` to also set the request timeout when using VelocyStream (issue #230)

docs/Drivers/Java/Reference/Graph/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@ GraphEntity info = graph.getInfo();
149149
## ArangoGraph.drop
150150

151151
```
152-
ArangoGraph.drop() : void
152+
ArangoGraph.drop(boolean dropCollections) : void
153153
```
154154

155155
Deletes the graph from the database.
156156

157+
**Arguments**
158+
159+
- **dropCollections**: `boolean`
160+
161+
Drop collections of this graph as well. Collections will only be dropped if they are not used in other graphs.
162+
157163
**Examples**
158164

159165
```Java

src/main/java/com/arangodb/ArangoGraph.java

+29-16
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,37 @@
2828

2929
/**
3030
* Interface for operations on ArangoDB graph level.
31-
*
31+
*
3232
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/">API Documentation</a>
3333
* @author Mark Vollmary
3434
*/
3535
public interface ArangoGraph extends ArangoSerializationAccessor {
3636

3737
/**
3838
* The the handler of the database the named graph is within
39-
*
39+
*
4040
* @return database handler
4141
*/
4242
public ArangoDatabase db();
4343

4444
/**
4545
* The name of the collection
46-
*
46+
*
4747
* @return collection name
4848
*/
4949
public String name();
5050

5151
/**
5252
* Checks whether the graph exists
53-
*
53+
*
5454
* @return true if the graph exists, otherwise false
5555
*/
5656
boolean exists() throws ArangoDBException;
5757

5858
/**
5959
* Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
6060
* its edges.
61-
*
61+
*
6262
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#create-a-graph">API
6363
* Documentation</a>
6464
* @param edgeDefinitions
@@ -71,7 +71,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
7171
/**
7272
* Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
7373
* its edges.
74-
*
74+
*
7575
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#create-a-graph">API
7676
* Documentation</a>
7777
* @param edgeDefinitions
@@ -85,15 +85,28 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
8585

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

94+
/**
95+
* Deletes the graph from the database.
96+
*
97+
* @see <a href=
98+
* "https://docs.arangodb.com/current/HTTP/Gharial/Management.html#drop-a-graph">API
99+
* Documentation</a>
100+
* @param dropCollections
101+
* Drop collections of this graph as well. Collections will only be
102+
* dropped if they are not used in other graphs.
103+
* @throws ArangoDBException
104+
*/
105+
void drop(boolean dropCollections) throws ArangoDBException;
106+
94107
/**
95108
* Retrieves general information about the graph.
96-
*
109+
*
97110
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#get-a-graph">API Documentation</a>
98111
* @return the definition content of this graph
99112
* @throws ArangoDBException
@@ -102,7 +115,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
102115

103116
/**
104117
* Fetches all vertex collections from the graph and returns a list of collection names.
105-
*
118+
*
106119
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#list-vertex-collections">API
107120
* Documentation</a>
108121
* @return all vertex collections within this graph
@@ -113,7 +126,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
113126
/**
114127
* Adds a vertex collection to the set of collections of the graph. If the collection does not exist, it will be
115128
* created.
116-
*
129+
*
117130
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#add-vertex-collection">API
118131
* Documentation</a>
119132
* @param name
@@ -125,7 +138,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
125138

126139
/**
127140
* Returns a {@code ArangoVertexCollection} instance for the given vertex collection name.
128-
*
141+
*
129142
* @param name
130143
* Name of the vertex collection
131144
* @return collection handler
@@ -134,7 +147,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
134147

135148
/**
136149
* Returns a {@code ArangoEdgeCollection} instance for the given edge collection name.
137-
*
150+
*
138151
* @param name
139152
* Name of the edge collection
140153
* @return collection handler
@@ -143,7 +156,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
143156

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

154167
/**
155168
* Adds the given edge definition to the graph.
156-
*
169+
*
157170
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#add-edge-definition">API
158171
* Documentation</a>
159172
* @param definition
@@ -166,7 +179,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
166179
/**
167180
* Change one specific edge definition. This will modify all occurrences of this definition in all graphs known to
168181
* your database
169-
*
182+
*
170183
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#replace-an-edge-definition">API
171184
* Documentation</a>
172185
* @param definition
@@ -179,7 +192,7 @@ public interface ArangoGraph extends ArangoSerializationAccessor {
179192
/**
180193
* Remove one edge definition from the graph. This will only remove the edge collection, the vertex collections
181194
* remain untouched and can still be used in your queries
182-
*
195+
*
183196
* @see <a href=
184197
* "https://docs.arangodb.com/current/HTTP/Gharial/Management.html#remove-an-edge-definition-from-the-graph">API
185198
* Documentation</a>

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

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public void drop() throws ArangoDBException {
7070
executor.execute(dropRequest(), Void.class);
7171
}
7272

73+
@Override
74+
public void drop(final boolean dropCollections) throws ArangoDBException {
75+
executor.execute(dropRequest(dropCollections), Void.class);
76+
}
77+
7378
@Override
7479
public GraphEntity getInfo() throws ArangoDBException {
7580
return executor.execute(getInfoRequest(), getInfoResponseDeserializer());

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ public String name() {
6363
}
6464

6565
protected Request dropRequest() {
66-
return request(db.name(), RequestType.DELETE, PATH_API_GHARIAL, name);
66+
return dropRequest(false);
67+
}
68+
69+
protected Request dropRequest(final boolean dropCollections) {
70+
final Request request = request(db.name(), RequestType.DELETE, PATH_API_GHARIAL, name);
71+
if (dropCollections) {
72+
request.putQueryParam("dropCollections", dropCollections);
73+
}
74+
return request;
6775
}
6876

6977
protected Request getInfoRequest() {

src/test/java/com/arangodb/ArangoGraphTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.ArrayList;
3131
import java.util.Collection;
32+
import java.util.Collections;
3233
import java.util.Iterator;
3334

3435
import org.junit.After;
@@ -255,4 +256,31 @@ public void smartGraph() {
255256
assertThat(graph.getNumberOfShards(), is(2));
256257
}
257258
}
259+
260+
@Test
261+
public void drop() {
262+
final String edgeCollection = "edge_drop";
263+
final String vertexCollection = "vertex_drop";
264+
final String graph = GRAPH_NAME + "_drop";
265+
final GraphEntity result = db.graph(graph).create(Collections
266+
.singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)));
267+
assertThat(result, is(notNullValue()));
268+
db.graph(graph).drop();
269+
assertThat(db.collection(edgeCollection).exists(), is(true));
270+
assertThat(db.collection(vertexCollection).exists(), is(true));
271+
}
272+
273+
@Test
274+
public void dropPlusDropCollections() {
275+
final String edgeCollection = "edge_dropC";
276+
final String vertexCollection = "vertex_dropC";
277+
final String graph = GRAPH_NAME + "_dropC";
278+
final GraphEntity result = db.graph(graph).create(Collections
279+
.singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)));
280+
assertThat(result, is(notNullValue()));
281+
db.graph(graph).drop(true);
282+
assertThat(db.collection(edgeCollection).exists(), is(false));
283+
assertThat(db.collection(vertexCollection).exists(), is(false));
284+
}
285+
258286
}

0 commit comments

Comments
 (0)