Skip to content

Commit a009736

Browse files
author
Mark
committed
AQL query cache
1 parent df85724 commit a009736

File tree

5 files changed

+222
-43
lines changed

5 files changed

+222
-43
lines changed

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

Lines changed: 113 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.arangodb.entity.GraphEntity;
3838
import com.arangodb.entity.IndexEntity;
3939
import com.arangodb.entity.PathEntity;
40+
import com.arangodb.entity.QueryCachePropertiesEntity;
4041
import com.arangodb.entity.TraversalEntity;
4142
import com.arangodb.internal.ArangoDBConstants;
4243
import com.arangodb.internal.CollectionCache;
@@ -157,11 +158,8 @@ public CompletableFuture<CollectionEntity> createCollectionAsync(
157158
}
158159

159160
private Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
160-
final Request request;
161-
request = new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION);
162-
request.setBody(
161+
return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION).setBody(
163162
serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));
164-
return request;
165163
}
166164

167165
/**
@@ -353,11 +351,9 @@ public CompletableFuture<Void> grantAccessAync(final String user) {
353351
}
354352

355353
private Request grantAccessRequest(final String user) {
356-
final Request request;
357-
request = new Request(ArangoDBConstants.SYSTEM, RequestType.PUT,
358-
createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name));
359-
request.setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.RW)));
360-
return request;
354+
return new Request(ArangoDBConstants.SYSTEM, RequestType.PUT,
355+
createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name))
356+
.setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.RW)));
361357
}
362358

363359
/**
@@ -389,11 +385,9 @@ public CompletableFuture<Void> revokeAccessAsync(final String user) {
389385
}
390386

391387
private Request revokeAccessRequest(final String user) {
392-
final Request request;
393-
request = new Request(ArangoDBConstants.SYSTEM, RequestType.PUT,
394-
createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name));
395-
request.setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.NONE)));
396-
return request;
388+
return new Request(ArangoDBConstants.SYSTEM, RequestType.PUT,
389+
createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name))
390+
.setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.NONE)));
397391
}
398392

399393
/**
@@ -440,8 +434,7 @@ public <T> CompletableFuture<ArangoCursor<T>> queryAsync(
440434
final Map<String, Object> bindVars,
441435
final AqlQueryOptions options,
442436
final Class<T> type) throws ArangoDBException {
443-
final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_CURSOR);
444-
request.setBody(
437+
final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_CURSOR).setBody(
445438
serialize(OptionsBuilder.build(options != null ? options : new AqlQueryOptions(), query, bindVars)));
446439
final CompletableFuture<CursorEntity> execution = executeAsync(request, CursorEntity.class);
447440
return execution.thenApply(result -> {
@@ -494,10 +487,8 @@ private Request explainQueryRequest(
494487
final String query,
495488
final Map<String, Object> bindVars,
496489
final AqlQueryExplainOptions options) {
497-
final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_EXPLAIN);
498-
request.setBody(
490+
return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_EXPLAIN).setBody(
499491
serialize(OptionsBuilder.build(options != null ? options : new AqlQueryExplainOptions(), query, bindVars)));
500-
return request;
501492
}
502493

503494
/**
@@ -530,9 +521,103 @@ public CompletableFuture<AqlParseEntity> parseQueryAsync(final String query) {
530521
}
531522

532523
private Request parseQueryRequest(final String query) {
533-
final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_QUERY);
534-
request.setBody(serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query)));
535-
return request;
524+
return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_QUERY)
525+
.setBody(serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query)));
526+
}
527+
528+
/**
529+
* Clears the AQL query cache
530+
*
531+
* @see <a href=
532+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#clears-any-results-in-the-aql-query-cache">API
533+
* Documentation</a>
534+
* @throws ArangoDBException
535+
*/
536+
public void clearQueryCache() throws ArangoDBException {
537+
executeSync(clearQueryCacheRequest(), Void.class);
538+
}
539+
540+
/**
541+
* Clears the AQL query cache
542+
*
543+
* @see <a href=
544+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#clears-any-results-in-the-aql-query-cache">API
545+
* Documentation</a>
546+
* @return void
547+
*/
548+
public CompletableFuture<Void> clearQueryCacheAsync() {
549+
return executeAsync(clearQueryCacheRequest(), Void.class);
550+
}
551+
552+
private Request clearQueryCacheRequest() {
553+
return new Request(name, RequestType.DELETE, ArangoDBConstants.PATH_API_QUERY_CACHE);
554+
}
555+
556+
/**
557+
* Returns the global configuration for the AQL query cache
558+
*
559+
* @see <a href=
560+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#returns-the-global-properties-for-the-aql-query-cache">API
561+
* Documentation</a>
562+
* @return configuration for the AQL query cache
563+
* @throws ArangoDBException
564+
*/
565+
public QueryCachePropertiesEntity getQueryCacheProperties() throws ArangoDBException {
566+
return executeSync(getQueryCachePropertiesRequest(), QueryCachePropertiesEntity.class);
567+
}
568+
569+
/**
570+
* Returns the global configuration for the AQL query cache
571+
*
572+
* @see <a href=
573+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#returns-the-global-properties-for-the-aql-query-cache">API
574+
* Documentation</a>
575+
* @return configuration for the AQL query cache
576+
*/
577+
public CompletableFuture<QueryCachePropertiesEntity> getQueryCachePropertiesAsync() {
578+
return executeAsync(getQueryCachePropertiesRequest(), QueryCachePropertiesEntity.class);
579+
}
580+
581+
private Request getQueryCachePropertiesRequest() {
582+
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_QUERY_CACHE_PROPERTIES);
583+
}
584+
585+
/**
586+
* Changes the configuration for the AQL query cache. Note: changing the properties may invalidate all results in
587+
* the cache.
588+
*
589+
* @see <a href=
590+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#globally-adjusts-the-aql-query-result-cache-properties">API
591+
* Documentation</a>
592+
* @param properties
593+
* properties to be set
594+
* @return current set of properties
595+
* @throws ArangoDBException
596+
*/
597+
public QueryCachePropertiesEntity setQueryCacheProperties(final QueryCachePropertiesEntity properties)
598+
throws ArangoDBException {
599+
return executeSync(setQueryCachePropertiesRequest(properties), QueryCachePropertiesEntity.class);
600+
}
601+
602+
/**
603+
* Changes the configuration for the AQL query cache. Note: changing the properties may invalidate all results in
604+
* the cache.
605+
*
606+
* @see <a href=
607+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#globally-adjusts-the-aql-query-result-cache-properties">API
608+
* Documentation</a>
609+
* @param properties
610+
* properties to be set
611+
* @return current set of properties
612+
*/
613+
public CompletableFuture<QueryCachePropertiesEntity> setQueryCachePropertiesAsync(
614+
final QueryCachePropertiesEntity properties) {
615+
return executeAsync(setQueryCachePropertiesRequest(properties), QueryCachePropertiesEntity.class);
616+
}
617+
618+
private Request setQueryCachePropertiesRequest(final QueryCachePropertiesEntity properties) {
619+
return new Request(name, RequestType.PUT, ArangoDBConstants.PATH_API_QUERY_CACHE_PROPERTIES)
620+
.setBody(serialize(properties));
536621
}
537622

538623
/**
@@ -578,10 +663,8 @@ private Request createAqlFunctionRequest(
578663
final String name,
579664
final String code,
580665
final AqlFunctionCreateOptions options) {
581-
final Request request = new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_AQLFUNCTION);
582-
request.setBody(
666+
return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_AQLFUNCTION).setBody(
583667
serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code)));
584-
return request;
585668
}
586669

587670
/**
@@ -751,11 +834,8 @@ private Request createGraphRequest(
751834
final String name,
752835
final Collection<EdgeDefinition> edgeDefinitions,
753836
final GraphCreateOptions options) {
754-
final Request request;
755-
request = new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_GHARIAL);
756-
request.setBody(serialize(
837+
return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_GHARIAL).setBody(serialize(
757838
OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions)));
758-
return request;
759839
}
760840

761841
private ResponseDeserializer<GraphEntity> createGraphResponseDeserializer() {
@@ -835,10 +915,8 @@ public <T> CompletableFuture<T> transactionAsync(
835915
}
836916

837917
private Request transactionRequest(final String action, final TransactionOptions options) {
838-
final Request request;
839-
request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRANSACTION);
840-
request.setBody(serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action)));
841-
return request;
918+
return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRANSACTION)
919+
.setBody(serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action)));
842920
}
843921

844922
private <T> ResponseDeserializer<T> transactionResponseDeserializer(final Class<T> type) {
@@ -932,9 +1010,8 @@ public <V, E> CompletableFuture<TraversalEntity<V, E>> executeTraversalAsync(
9321010
}
9331011

9341012
private Request executeTraversalRequest(final TraversalOptions options) {
935-
final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRAVERSAL);
936-
request.setBody(serialize(options != null ? options : new TransactionOptions()));
937-
return request;
1013+
return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRAVERSAL)
1014+
.setBody(serialize(options != null ? options : new TransactionOptions()));
9381015
}
9391016

9401017
private <E, V> ResponseDeserializer<TraversalEntity<V, E>> executeTraversalResponseDeserializer(
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Mark - mark at arangodb.com
25+
*
26+
* @see <a href=
27+
* "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#http-interface-for-the-aql-query-cache">API
28+
* Documentation</a>
29+
*/
30+
public class QueryCachePropertiesEntity {
31+
32+
public enum CacheMode {
33+
off, on, demand;
34+
}
35+
36+
private CacheMode mode;
37+
private Long maxResults;
38+
39+
public QueryCachePropertiesEntity() {
40+
super();
41+
}
42+
43+
public CacheMode getMode() {
44+
return mode;
45+
}
46+
47+
/**
48+
* @param mode
49+
* the mode the AQL query cache operates in. The mode is one of the following values: off, on or demand
50+
*/
51+
public void setMode(final CacheMode mode) {
52+
this.mode = mode;
53+
}
54+
55+
public Long getMaxResults() {
56+
return maxResults;
57+
}
58+
59+
/**
60+
* @param maxResults
61+
* the maximum number of query results that will be stored per database-specific cache
62+
*/
63+
public void setMaxResults(final Long maxResults) {
64+
this.maxResults = maxResults;
65+
}
66+
67+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class ArangoDBConstants {
4747
public static final String PATH_API_AQLFUNCTION = "/_api/aqlfunction";
4848
public static final String PATH_API_EXPLAIN = "/_api/explain";
4949
public static final String PATH_API_QUERY = "/_api/query";
50+
public static final String PATH_API_QUERY_CACHE = "/_api/query-cache";
51+
public static final String PATH_API_QUERY_CACHE_PROPERTIES = "/_api/query-cache/properties";
5052
public static final String PATH_API_TRAVERSAL = "/_api/traversal";
5153

5254
public static final String ENCRYPTION_PLAIN = "plain";

src/main/java/com/arangodb/velocystream/Request.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,18 @@ public int getVersion() {
5757
return version;
5858
}
5959

60-
public void setVersion(final int version) {
60+
public Request setVersion(final int version) {
6161
this.version = version;
62+
return this;
6263
}
6364

6465
public int getType() {
6566
return type;
6667
}
6768

68-
public void setType(final int type) {
69+
public Request setType(final int type) {
6970
this.type = type;
71+
return this;
7072
}
7173

7274
public String getDatabase() {
@@ -88,10 +90,11 @@ public Map<String, String> getQueryParam() {
8890
return queryParam;
8991
}
9092

91-
public void putQueryParam(final String key, final Object value) {
93+
public Request putQueryParam(final String key, final Object value) {
9294
if (value != null) {
9395
getQueryParam().put(key, value.toString());
9496
}
97+
return this;
9598
}
9699

97100
public Map<String, String> getHeaderParam() {
@@ -101,18 +104,20 @@ public Map<String, String> getHeaderParam() {
101104
return headerParam;
102105
}
103106

104-
public void putHeaderParam(final String key, final String value) {
107+
public Request putHeaderParam(final String key, final String value) {
105108
if (value != null) {
106109
getHeaderParam().put(key, value);
107110
}
111+
return this;
108112
}
109113

110114
public Optional<VPackSlice> getBody() {
111115
return body;
112116
}
113117

114-
public void setBody(final VPackSlice body) {
118+
public Request setBody(final VPackSlice body) {
115119
this.body = Optional.ofNullable(body);
120+
return this;
116121
}
117122

118123
}

0 commit comments

Comments
 (0)