Skip to content

Commit b029b51

Browse files
author
Mark
committed
QueryCacheProperties Mode in enum
1 parent 4d0d4a7 commit b029b51

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.slf4j.LoggerFactory;
3838

3939
import com.arangodb.entity.CollectionEntity.Figures;
40+
import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode;
4041
import com.arangodb.entity.ReplicationApplierState.LastError;
4142
import com.arangodb.entity.ReplicationApplierState.Progress;
4243
import com.arangodb.entity.ReplicationInventoryEntity.Collection;
@@ -2302,7 +2303,8 @@ public QueryCachePropertiesEntity deserialize(
23022303
final QueryCachePropertiesEntity entity = deserializeBaseParameter(obj, new QueryCachePropertiesEntity());
23032304

23042305
if (obj.has("mode")) {
2305-
entity.setMode(obj.getAsJsonPrimitive("mode").getAsString());
2306+
final String modeAsString = obj.getAsJsonPrimitive("mode").getAsString();
2307+
entity.setMode(CacheMode.valueOf(modeAsString));
23062308
}
23072309

23082310
if (obj.has("maxResults")) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
*/
2222
public class QueryCachePropertiesEntity extends BaseEntity {
2323

24+
public enum CacheMode {
25+
off, on, demand;
26+
}
27+
2428
/**
2529
* The mode the AQL query cache operates in. The mode is one of the
2630
* following values: "off", "on" or "demand".
2731
*/
28-
private String mode;
32+
private CacheMode mode;
2933

3034
/**
3135
* The maximum number of query results that will be stored per
@@ -41,7 +45,7 @@ public QueryCachePropertiesEntity() {
4145
*
4246
* @return The mode is one of the following values: "off", "on" or "demand".
4347
*/
44-
public String getMode() {
48+
public CacheMode getMode() {
4549
return mode;
4650
}
4751

@@ -52,7 +56,7 @@ public String getMode() {
5256
* The mode is one of the following values: "off", "on" or
5357
* "demand".
5458
*/
55-
public void setMode(String mode) {
59+
public void setMode(CacheMode mode) {
5660
this.mode = mode;
5761
}
5862

src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import com.arangodb.entity.DocumentEntity;
3232
import com.arangodb.entity.QueryCachePropertiesEntity;
33+
import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode;
3334
import com.arangodb.util.AqlQueryOptions;
3435
import com.arangodb.util.MapBuilder;
3536
import com.arangodb.util.TestUtils;
@@ -154,7 +155,7 @@ public void test_withCache() throws ArangoException {
154155
if (isMinimumVersion(TestUtils.VERSION_2_7)) {
155156
// start caching
156157
final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
157-
properties.setMode("on");
158+
properties.setMode(CacheMode.on);
158159
driver.setQueryCacheProperties(properties);
159160

160161
final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t";

src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import com.arangodb.entity.DefaultEntity;
2525
import com.arangodb.entity.QueryCachePropertiesEntity;
26+
import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode;
2627
import com.arangodb.util.TestUtils;
2728

2829
/**
@@ -53,25 +54,23 @@ public void test_getQueryCacheProperties() throws ArangoException {
5354

5455
@Test
5556
public void test_setQueryCacheProperties() throws ArangoException {
56-
final String on = "on";
57-
final String off = "off";
5857

5958
if (isMinimumVersion(TestUtils.VERSION_2_7)) {
6059
final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
61-
properties.setMode(on);
60+
properties.setMode(CacheMode.on);
6261
properties.setMaxResults(100L);
6362

6463
QueryCachePropertiesEntity ret = driver.setQueryCacheProperties(properties);
6564
assertEquals(200, ret.getStatusCode());
66-
assertEquals(on, ret.getMode());
65+
assertEquals(CacheMode.on, ret.getMode());
6766
assertEquals(new Long(100L), ret.getMaxResults());
6867

69-
properties.setMode(off);
68+
properties.setMode(CacheMode.off);
7069
properties.setMaxResults(200L);
7170

7271
ret = driver.setQueryCacheProperties(properties);
7372
assertEquals(200, ret.getStatusCode());
74-
assertEquals(off, ret.getMode());
73+
assertEquals(CacheMode.off, ret.getMode());
7574
assertEquals(new Long(200L), ret.getMaxResults());
7675
}
7776
}

0 commit comments

Comments
 (0)