Skip to content

Commit d73f91f

Browse files
author
a-brandt
committed
added AQL query cache for ArangoDB 2.7
1 parent 3a9da7b commit d73f91f

10 files changed

+434
-14
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.arangodb.entity.JobsEntity;
5252
import com.arangodb.entity.PlainEdgeEntity;
5353
import com.arangodb.entity.Policy;
54+
import com.arangodb.entity.QueryCachePropertiesEntity;
5455
import com.arangodb.entity.ReplicationApplierConfigEntity;
5556
import com.arangodb.entity.ReplicationApplierStateEntity;
5657
import com.arangodb.entity.ReplicationInventoryEntity;
@@ -121,6 +122,7 @@ public class ArangoDriver extends BaseArangoDriver {
121122
private InternalEdgeDriver edgeDriver;
122123
private InternalTransactionDriver transactionDriver;
123124
private InternalTraversalDriver traversalDriver;
125+
private InternalQueryCacheDriver queryCacheDriver;
124126

125127
private String database;
126128

@@ -176,6 +178,7 @@ private void createModuleDrivers(boolean createProxys) {
176178
this.jobsDriver = ImplFactory.createJobsDriver(configure, this.httpManager);
177179
this.transactionDriver = ImplFactory.createTransactionDriver(configure, this.httpManager);
178180
this.traversalDriver = ImplFactory.createTraversalDriver(configure, httpManager);
181+
this.queryCacheDriver = ImplFactory.createQueryCacheDriver(configure, httpManager);
179182
} else {
180183
this.transactionDriver = (InternalTransactionDriver) Proxy.newProxyInstance(
181184
InternalTransactionDriver.class.getClassLoader(), new Class<?>[] { InternalTransactionDriver.class },
@@ -222,6 +225,9 @@ private void createModuleDrivers(boolean createProxys) {
222225
this.traversalDriver = (InternalTraversalDriver) Proxy.newProxyInstance(
223226
InternalTraversalDriver.class.getClassLoader(), new Class<?>[] { InternalTraversalDriver.class },
224227
new InvocationHandlerImpl(this.traversalDriver));
228+
this.queryCacheDriver = (InternalQueryCacheDriver) Proxy.newProxyInstance(
229+
InternalQueryCacheDriver.class.getClassLoader(), new Class<?>[] { InternalQueryCacheDriver.class },
230+
new InvocationHandlerImpl(this.queryCacheDriver));
225231
}
226232
}
227233

@@ -5484,4 +5490,36 @@ public <V, E> TraversalEntity<V, E> getTraversal(
54845490

54855491
return this.traversalDriver.getTraversal(getDefaultDatabase(), traversalQueryOptions, vertexClazz, edgeClazz);
54865492
}
5493+
5494+
/**
5495+
* Clears the AQL query cache (since ArangoDB 2.7)
5496+
*
5497+
* @return DefaultEntity
5498+
* @throws ArangoException
5499+
*/
5500+
public DefaultEntity deleteQueryCache() throws ArangoException {
5501+
return queryCacheDriver.deleteQueryCache();
5502+
}
5503+
5504+
/**
5505+
* Returns the global configuration for the AQL query cache (since ArangoDB
5506+
* 2.7)
5507+
*
5508+
* @return QueryCachePropertiesEntity
5509+
* @throws ArangoException
5510+
*/
5511+
public QueryCachePropertiesEntity getQueryCacheProperties() throws ArangoException {
5512+
return queryCacheDriver.getQueryCacheProperties();
5513+
}
5514+
5515+
/**
5516+
* Changes the configuration for the AQL query cache (since ArangoDB 2.7)
5517+
*
5518+
* @return QueryCachePropertiesEntity
5519+
* @throws ArangoException
5520+
*/
5521+
public QueryCachePropertiesEntity setQueryCacheProperties(QueryCachePropertiesEntity properties)
5522+
throws ArangoException {
5523+
return queryCacheDriver.setQueryCacheProperties(properties);
5524+
}
54875525
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.arangodb;
2+
3+
import com.arangodb.entity.DefaultEntity;
4+
import com.arangodb.entity.QueryCachePropertiesEntity;
5+
import com.arangodb.impl.BaseDriverInterface;
6+
7+
/**
8+
* Created by a-brandt on 2015-09-11.
9+
*/
10+
public interface InternalQueryCacheDriver extends BaseDriverInterface {
11+
12+
DefaultEntity deleteQueryCache() throws ArangoException;
13+
14+
QueryCachePropertiesEntity getQueryCacheProperties() throws ArangoException;
15+
16+
QueryCachePropertiesEntity setQueryCacheProperties(QueryCachePropertiesEntity properties) throws ArangoException;
17+
18+
}

src/main/java/com/arangodb/entity/EntityDeserializers.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,34 @@ public static class ShortestPathEntityDeserializer implements JsonDeserializer<S
20032003
}
20042004
}
20052005

2006+
public static class QueryCachePropertiesEntityDeserializer implements JsonDeserializer<QueryCachePropertiesEntity> {
2007+
2008+
@Override
2009+
public QueryCachePropertiesEntity deserialize(
2010+
JsonElement json,
2011+
Type typeOfT,
2012+
JsonDeserializationContext context) throws JsonParseException {
2013+
2014+
if (json.isJsonNull()) {
2015+
return null;
2016+
}
2017+
2018+
JsonObject obj = json.getAsJsonObject();
2019+
QueryCachePropertiesEntity entity = deserializeBaseParameter(obj, new QueryCachePropertiesEntity());
2020+
2021+
if (obj.has("mode")) {
2022+
entity.setMode(obj.getAsJsonPrimitive("mode").getAsString());
2023+
}
2024+
2025+
if (obj.has("maxResults")) {
2026+
entity.setMaxResults(obj.getAsJsonPrimitive("maxResults").getAsLong());
2027+
}
2028+
2029+
return entity;
2030+
}
2031+
2032+
}
2033+
20062034
private static JsonObject getFirstResultAsJsonObject(JsonObject obj) {
20072035
if (obj.has("result")) {
20082036
if (obj.get("result").isJsonArray()) {

src/main/java/com/arangodb/entity/EntityFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public class EntityFactory {
5050
private static Gson gsonNull;
5151

5252
public static GsonBuilder getGsonBuilder() {
53-
return new GsonBuilder()
54-
.addSerializationExclusionStrategy(new ExcludeExclusionStrategy(true))
53+
return new GsonBuilder().addSerializationExclusionStrategy(new ExcludeExclusionStrategy(true))
5554
.addDeserializationExclusionStrategy(new ExcludeExclusionStrategy(false))
5655
.setFieldNamingStrategy(new ArangoFieldNamingStrategy())
5756
.registerTypeAdapter(CollectionStatus.class, new CollectionStatusTypeAdapter())
@@ -114,7 +113,9 @@ public static GsonBuilder getGsonBuilder() {
114113
.registerTypeAdapter(VertexEntity.class, new EntityDeserializers.VertexEntityDeserializer())
115114
.registerTypeAdapter(EdgeEntity.class, new EntityDeserializers.EdgeEntityDeserializer())
116115
.registerTypeAdapter(TraversalEntity.class, new EntityDeserializers.TraversalEntityDeserializer())
117-
.registerTypeAdapter(ShortestPathEntity.class, new EntityDeserializers.ShortestPathEntityDeserializer());
116+
.registerTypeAdapter(ShortestPathEntity.class, new EntityDeserializers.ShortestPathEntityDeserializer())
117+
.registerTypeAdapter(QueryCachePropertiesEntity.class,
118+
new EntityDeserializers.QueryCachePropertiesEntityDeserializer());
118119
}
119120

120121
static {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2012,2013 tamtam180
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.arangodb.entity;
18+
19+
/**
20+
* @author a-brandt
21+
*/
22+
public class QueryCachePropertiesEntity extends BaseEntity {
23+
24+
/**
25+
* The mode the AQL query cache operates in. The mode is one of the
26+
* following values: "off", "on" or "demand".
27+
*/
28+
private String mode;
29+
30+
/**
31+
* The maximum number of query results that will be stored per
32+
* database-specific cache.
33+
*/
34+
private Long maxResults;
35+
36+
public QueryCachePropertiesEntity() {
37+
}
38+
39+
/**
40+
* Returns the mode the AQL query cache operates in.
41+
*
42+
* @return The mode is one of the following values: "off", "on" or "demand".
43+
*/
44+
public String getMode() {
45+
return mode;
46+
}
47+
48+
/**
49+
* Sets the mode the AQL query cache operates in.
50+
*
51+
* @param mode
52+
* The mode is one of the following values: "off", "on" or
53+
* "demand".
54+
*/
55+
public void setMode(String mode) {
56+
this.mode = mode;
57+
}
58+
59+
/**
60+
* Returns the maximum number of query results that will be stored per
61+
* database-specific cache.
62+
*
63+
* @return the maximum number
64+
*/
65+
public Long getMaxResults() {
66+
return maxResults;
67+
}
68+
69+
/**
70+
* Sets the maximum number of query results that will be stored per
71+
* database-specific cache.
72+
*
73+
* @param maxResults
74+
* the maximum number
75+
*/
76+
public void setMaxResults(Long maxResults) {
77+
this.maxResults = maxResults;
78+
}
79+
80+
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public static InternalCursorDriverImpl createCursorDriver(ArangoConfigure config
3232
return new InternalCursorDriverImpl(configure, httpManager);
3333
}
3434

35-
public static InternalCollectionDriverImpl createCollectionDriver(ArangoConfigure configure, HttpManager httpManager) {
35+
public static InternalCollectionDriverImpl createCollectionDriver(
36+
ArangoConfigure configure,
37+
HttpManager httpManager) {
3638
return new InternalCollectionDriverImpl(configure, httpManager);
3739
}
3840

@@ -44,7 +46,9 @@ public static InternalJobsDriverImpl createJobsDriver(ArangoConfigure configure,
4446
return new InternalJobsDriverImpl(configure, httpManager);
4547
}
4648

47-
public static InternalTransactionDriver createTransactionDriver(ArangoConfigure configure, HttpManager httpManager) {
49+
public static InternalTransactionDriver createTransactionDriver(
50+
ArangoConfigure configure,
51+
HttpManager httpManager) {
4852
return new InternalTransactionDriverImpl(configure, httpManager);
4953
}
5054

@@ -113,8 +117,16 @@ public static InternalEdgeDriverImpl createEdgeDriver(
113117
return new InternalEdgeDriverImpl(configure, cursorDriver, httpManager);
114118
}
115119

116-
public static InternalTraversalDriverImpl createTraversalDriver(ArangoConfigure configure, HttpManager httpManager) {
120+
public static InternalTraversalDriverImpl createTraversalDriver(
121+
ArangoConfigure configure,
122+
HttpManager httpManager) {
117123
return new InternalTraversalDriverImpl(configure, httpManager);
118124
}
119125

126+
public static InternalQueryCacheDriverImpl createQueryCacheDriver(
127+
ArangoConfigure configure,
128+
HttpManager httpManager) {
129+
return new InternalQueryCacheDriverImpl(configure, httpManager);
130+
}
131+
120132
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2012,2013 tamtam180
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.arangodb.impl;
18+
19+
import com.arangodb.ArangoConfigure;
20+
import com.arangodb.ArangoException;
21+
import com.arangodb.entity.DefaultEntity;
22+
import com.arangodb.entity.EntityFactory;
23+
import com.arangodb.entity.QueryCachePropertiesEntity;
24+
import com.arangodb.http.HttpManager;
25+
import com.arangodb.http.HttpResponseEntity;
26+
27+
/**
28+
* @author a-brandt
29+
*
30+
*/
31+
public class InternalQueryCacheDriverImpl extends BaseArangoDriverImpl
32+
implements com.arangodb.InternalQueryCacheDriver {
33+
34+
InternalQueryCacheDriverImpl(ArangoConfigure configure, HttpManager httpManager) {
35+
super(configure, httpManager);
36+
}
37+
38+
@Override
39+
public DefaultEntity deleteQueryCache() throws ArangoException {
40+
41+
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(null, "/_api/query-cache"), null);
42+
43+
return createEntity(res, DefaultEntity.class);
44+
}
45+
46+
@Override
47+
public QueryCachePropertiesEntity getQueryCacheProperties() throws ArangoException {
48+
49+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(null, "/_api/query-cache"), null);
50+
51+
return createEntity(res, QueryCachePropertiesEntity.class);
52+
53+
}
54+
55+
@Override
56+
public QueryCachePropertiesEntity setQueryCacheProperties(QueryCachePropertiesEntity properties)
57+
throws ArangoException {
58+
59+
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(null, "/_api/query-cache/properties"), null,
60+
EntityFactory.toJsonString(properties));
61+
62+
return createEntity(res, QueryCachePropertiesEntity.class);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)