Skip to content

Commit 97a36ed

Browse files
author
a-brandt
committed
added query functions
1 parent d73f91f commit 97a36ed

File tree

3 files changed

+133
-2
lines changed

3 files changed

+133
-2
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
import com.arangodb.entity.JobsEntity;
5252
import com.arangodb.entity.PlainEdgeEntity;
5353
import com.arangodb.entity.Policy;
54+
import com.arangodb.entity.QueriesResultEntity;
5455
import com.arangodb.entity.QueryCachePropertiesEntity;
56+
import com.arangodb.entity.QueryTrackingPropertiesEntity;
5557
import com.arangodb.entity.ReplicationApplierConfigEntity;
5658
import com.arangodb.entity.ReplicationApplierStateEntity;
5759
import com.arangodb.entity.ReplicationInventoryEntity;
@@ -5522,4 +5524,70 @@ public QueryCachePropertiesEntity setQueryCacheProperties(QueryCachePropertiesEn
55225524
throws ArangoException {
55235525
return queryCacheDriver.setQueryCacheProperties(properties);
55245526
}
5527+
5528+
/**
5529+
* Returns the configuration for the AQL query tracking
5530+
*
5531+
* @return the configuration
5532+
* @throws ArangoException
5533+
*/
5534+
public QueryTrackingPropertiesEntity getQueryTrackingProperties() throws ArangoException {
5535+
return this.cursorDriver.getQueryTrackingProperties(getDefaultDatabase());
5536+
}
5537+
5538+
/**
5539+
* Changes the configuration for the AQL query tracking
5540+
*
5541+
* @param properties
5542+
* the configuration
5543+
* @return the configuration
5544+
* @throws ArangoException
5545+
*/
5546+
public QueryTrackingPropertiesEntity setQueryTrackingProperties(QueryTrackingPropertiesEntity properties)
5547+
throws ArangoException {
5548+
return this.cursorDriver.setQueryTrackingProperties(getDefaultDatabase(), properties);
5549+
}
5550+
5551+
/**
5552+
* Returns a list of currently running AQL queries
5553+
*
5554+
* @return a list of currently running AQL queries
5555+
* @throws ArangoException
5556+
*/
5557+
public QueriesResultEntity getCurrentlyRunningQueries() throws ArangoException {
5558+
return this.cursorDriver.getCurrentlyRunningQueries(getDefaultDatabase());
5559+
}
5560+
5561+
/**
5562+
* Returns a list of slow running AQL queries
5563+
*
5564+
* @return a list of slow running AQL queries
5565+
* @throws ArangoException
5566+
*/
5567+
public QueriesResultEntity getSlowQueries() throws ArangoException {
5568+
return this.cursorDriver.getSlowQueries(getDefaultDatabase());
5569+
}
5570+
5571+
/**
5572+
* Clears the list of slow AQL queries
5573+
*
5574+
* @return
5575+
* @throws ArangoException
5576+
*/
5577+
public DefaultEntity deleteSlowQueries() throws ArangoException {
5578+
return this.cursorDriver.deleteSlowQueries(getDefaultDatabase());
5579+
}
5580+
5581+
/**
5582+
* Kills an AQL query
5583+
*
5584+
* @param id
5585+
* the identifier of a query
5586+
* @return
5587+
* @throws ArangoException
5588+
*/
5589+
public DefaultEntity killQuery(String id) throws ArangoException {
5590+
return this.cursorDriver.killQuery(getDefaultDatabase(), id);
5591+
}
5592+
55255593
}

src/main/java/com/arangodb/InternalCursorDriver.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.arangodb.entity.CursorEntity;
66
import com.arangodb.entity.DefaultEntity;
77
import com.arangodb.entity.DocumentEntity;
8+
import com.arangodb.entity.QueriesResultEntity;
9+
import com.arangodb.entity.QueryTrackingPropertiesEntity;
810
import com.arangodb.entity.ShortestPathEntity;
911
import com.arangodb.impl.BaseDriverInterface;
1012
import com.arangodb.util.AqlQueryOptions;
@@ -107,4 +109,17 @@ <T> CursorResultSet<T> executeQueryWithResultSet(
107109
Class<T> clazz,
108110
Boolean calcCount,
109111
Integer batchSize) throws ArangoException;
112+
113+
QueryTrackingPropertiesEntity getQueryTrackingProperties(String database) throws ArangoException;
114+
115+
QueryTrackingPropertiesEntity setQueryTrackingProperties(String database, QueryTrackingPropertiesEntity properties)
116+
throws ArangoException;
117+
118+
QueriesResultEntity getCurrentlyRunningQueries(String database) throws ArangoException;
119+
120+
QueriesResultEntity getSlowQueries(String database) throws ArangoException;
121+
122+
DefaultEntity deleteSlowQueries(String database) throws ArangoException;
123+
124+
DefaultEntity killQuery(String database, String id) throws ArangoException;
110125
}

src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.arangodb.entity.DefaultEntity;
2929
import com.arangodb.entity.DocumentEntity;
3030
import com.arangodb.entity.EntityFactory;
31+
import com.arangodb.entity.QueriesResultEntity;
32+
import com.arangodb.entity.QueryTrackingPropertiesEntity;
3133
import com.arangodb.entity.ShortestPathEntity;
3234
import com.arangodb.http.HttpManager;
3335
import com.arangodb.http.HttpResponseEntity;
@@ -150,8 +152,8 @@ public <V, E> ShortestPathEntity<V, E> getShortesPath(
150152

151153
String query = "for i in graph_shortest_path(@graphName, @startVertexExample, @endVertexExample, @options) return i";
152154

153-
Map<String, Object> options = shortestPathOptions == null ? new MapBuilder().get() : shortestPathOptions
154-
.toMap();
155+
Map<String, Object> options = shortestPathOptions == null ? new MapBuilder().get()
156+
: shortestPathOptions.toMap();
155157

156158
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
157159
.put("startVertexExample", startVertexExample).put("endVertexExample", endVertexExample)
@@ -214,4 +216,50 @@ public <T> CursorResultSet<T> executeQueryWithResultSet(
214216

215217
}
216218

219+
@Override
220+
public QueryTrackingPropertiesEntity getQueryTrackingProperties(String database) throws ArangoException {
221+
222+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/properties"), null, null);
223+
224+
return createEntity(res, QueryTrackingPropertiesEntity.class);
225+
}
226+
227+
@Override
228+
public QueryTrackingPropertiesEntity setQueryTrackingProperties(
229+
String database,
230+
QueryTrackingPropertiesEntity properties) throws ArangoException {
231+
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/query/properties"), null,
232+
EntityFactory.toJsonString(properties));
233+
234+
return createEntity(res, QueryTrackingPropertiesEntity.class);
235+
}
236+
237+
@Override
238+
public QueriesResultEntity getCurrentlyRunningQueries(String database) throws ArangoException {
239+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/current"), null, null);
240+
241+
return createEntity(res, QueriesResultEntity.class);
242+
}
243+
244+
@Override
245+
public QueriesResultEntity getSlowQueries(String database) throws ArangoException {
246+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/slow"), null, null);
247+
248+
return createEntity(res, QueriesResultEntity.class);
249+
}
250+
251+
@Override
252+
public DefaultEntity deleteSlowQueries(String database) throws ArangoException {
253+
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/query/slow"), null, null);
254+
255+
return createEntity(res, DefaultEntity.class);
256+
}
257+
258+
@Override
259+
public DefaultEntity killQuery(String database, String id) throws ArangoException {
260+
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/query", id), null, null);
261+
262+
return createEntity(res, DefaultEntity.class);
263+
}
264+
217265
}

0 commit comments

Comments
 (0)