Skip to content

Commit 1ac45b1

Browse files
author
a-brandt
committed
2 parents 6b7a491 + c36b5d4 commit 1ac45b1

File tree

7 files changed

+240
-30
lines changed

7 files changed

+240
-30
lines changed

src/main/java/com/arangodb/ArangoClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ private void importDocumentsImpl(String collectionName, List<String> values, Imp
4242
total.setCreated(total.getCreated() + result.getCreated());
4343
total.setErrors(total.getErrors() + result.getErrors());
4444
total.setEmpty(total.getEmpty() + result.getEmpty());
45+
total.setUpdated(total.getUpdated() + result.getUpdated());
46+
total.setIgnored(total.getIgnored() + result.getIgnored());
47+
total.getDetails().addAll(result.getDetails());
4548
}
4649

4750
public ImportResultEntity importRawJsonDocuments(String collectionName, Iterator<String> itr, int bufferCount)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,7 @@ public <T> VertexCursor<T> executeVertexQuery(
44054405
/**
44064406
* Returns an EdgeCursor by a given vertex example and some options
44074407
*
4408+
* @deprecated use AQL instead
44084409
* @param graphName
44094410
* The name of the graph.
44104411
* @param clazz
@@ -4417,6 +4418,7 @@ public <T> VertexCursor<T> executeVertexQuery(
44174418
* @return EdgeCursor<T>
44184419
* @throws ArangoException
44194420
*/
4421+
@Deprecated
44204422
@SuppressWarnings("unchecked")
44214423
public <T> EdgeCursor<T> graphGetEdgeCursor(
44224424
final String graphName,
@@ -4451,6 +4453,7 @@ public <T> EdgeCursor<T> graphGetEdgeCursor(
44514453
/**
44524454
* Returns a VertexCursor by a given vertex example and some options
44534455
*
4456+
* @deprecated use AQL instead
44544457
* @param graphName
44554458
* The name of the graph.
44564459
* @param clazz
@@ -4463,6 +4466,7 @@ public <T> EdgeCursor<T> graphGetEdgeCursor(
44634466
* @return VertexCursor<T>
44644467
* @throws ArangoException
44654468
*/
4469+
@Deprecated
44664470
public <T> VertexCursor<T> graphGetVertexCursor(
44674471
final String graphName,
44684472
final Class<T> clazz,
@@ -4517,6 +4521,10 @@ public <T> EdgeCursor<T> graphGetEdgeCursorByExample(
45174521
return graphGetEdgeCursor(graphName, clazz, vertexExample, new GraphEdgesOptions(), null);
45184522
}
45194523

4524+
/**
4525+
* @deprecated use AQL instead
4526+
*/
4527+
@Deprecated
45204528
public <V, E> ShortestPathEntity<V, E> graphGetShortestPath(
45214529
final String graphName,
45224530
final Object startVertexExample,

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ public class EntityDeserializers {
170170

171171
private static final String MESSAGE = "message";
172172

173+
private static final String CREATED = "created";
174+
private static final String ERRORS = "errors";
175+
private static final String EMPTY = "empty";
176+
private static final String IGNORED = "ignored";
177+
private static final String DETAILS = "details";
178+
173179
private static Logger logger = LoggerFactory.getLogger(EntityDeserializers.class);
174180

175181
private static class ClassHolder {
@@ -1308,6 +1314,7 @@ public UserEntity deserialize(
13081314
}
13091315

13101316
public static class ImportResultEntityDeserializer implements JsonDeserializer<ImportResultEntity> {
1317+
13111318
@Override
13121319
public ImportResultEntity deserialize(
13131320
final JsonElement json,
@@ -1321,16 +1328,31 @@ public ImportResultEntity deserialize(
13211328
final JsonObject obj = json.getAsJsonObject();
13221329
final ImportResultEntity entity = deserializeBaseParameter(obj, new ImportResultEntity());
13231330

1324-
if (obj.has("created")) {
1325-
entity.created = obj.getAsJsonPrimitive("created").getAsInt();
1331+
if (obj.has(CREATED)) {
1332+
entity.setCreated(obj.getAsJsonPrimitive(CREATED).getAsInt());
1333+
}
1334+
1335+
if (obj.has(ERRORS)) {
1336+
entity.setErrors(obj.getAsJsonPrimitive(ERRORS).getAsInt());
1337+
}
1338+
1339+
if (obj.has(EMPTY)) {
1340+
entity.setEmpty(obj.getAsJsonPrimitive(EMPTY).getAsInt());
13261341
}
13271342

1328-
if (obj.has("errors")) {
1329-
entity.errors = obj.getAsJsonPrimitive("errors").getAsInt();
1343+
if (obj.has(UPDATED)) {
1344+
entity.setUpdated(obj.getAsJsonPrimitive(UPDATED).getAsInt());
13301345
}
13311346

1332-
if (obj.has("empty")) {
1333-
entity.empty = obj.getAsJsonPrimitive("empty").getAsInt();
1347+
if (obj.has(IGNORED)) {
1348+
entity.setIgnored(obj.getAsJsonPrimitive(IGNORED).getAsInt());
1349+
}
1350+
1351+
if (obj.has(DETAILS)) {
1352+
final JsonArray asJsonArray = obj.getAsJsonArray(DETAILS);
1353+
for (JsonElement jsonElement : asJsonArray) {
1354+
entity.getDetails().add(jsonElement.getAsString());
1355+
}
13341356
}
13351357

13361358
return entity;

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

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,73 @@
1616

1717
package com.arangodb.entity;
1818

19+
import java.util.ArrayList;
20+
import java.util.List;
21+
1922
/**
2023
* @author tamtam180 - kirscheless at gmail.com
2124
*
2225
*/
2326
public class ImportResultEntity extends BaseEntity {
2427

25-
int created;
26-
int errors;
27-
int empty;
28-
29-
public int getCreated() {
30-
return created;
31-
}
32-
public int getErrors() {
33-
return errors;
34-
}
35-
public int getEmpty() {
36-
return empty;
37-
}
38-
public void setCreated(int created) {
39-
this.created = created;
40-
}
41-
public void setErrors(int errors) {
42-
this.errors = errors;
43-
}
44-
public void setEmpty(int empty) {
45-
this.empty = empty;
46-
}
47-
28+
private int created;
29+
private int errors;
30+
private int empty;
31+
private int updated;
32+
private int ignored;
33+
private List<String> details;
34+
35+
public ImportResultEntity() {
36+
super();
37+
details = new ArrayList<String>();
38+
}
39+
40+
public int getCreated() {
41+
return created;
42+
}
43+
44+
public void setCreated(int created) {
45+
this.created = created;
46+
}
47+
48+
public int getErrors() {
49+
return errors;
50+
}
51+
52+
public void setErrors(int errors) {
53+
this.errors = errors;
54+
}
55+
56+
public int getEmpty() {
57+
return empty;
58+
}
59+
60+
public void setEmpty(int empty) {
61+
this.empty = empty;
62+
}
63+
64+
public int getUpdated() {
65+
return updated;
66+
}
67+
68+
public void setUpdated(int updated) {
69+
this.updated = updated;
70+
}
71+
72+
public int getIgnored() {
73+
return ignored;
74+
}
75+
76+
public void setIgnored(int ignored) {
77+
this.ignored = ignored;
78+
}
79+
80+
public List<String> getDetails() {
81+
return details;
82+
}
83+
84+
public void setDetails(List<String> details) {
85+
this.details = details;
86+
}
87+
4888
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public CursorRawResult executeAqlQueryRaw(
163163
return new CursorRawResult(database, this, entity);
164164
}
165165

166+
/**
167+
* @deprecated use AQL instead
168+
*/
169+
@Deprecated
166170
@SuppressWarnings("unchecked")
167171
@Override
168172
public <V, E> ShortestPathEntity<V, E> getShortestPath(

src/main/java/com/arangodb/util/AqlQueryOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public AqlQueryOptions setTtl(Integer ttl) {
134134
* @return boolean flag
135135
*/
136136
public Boolean getCache() {
137-
return fullCount;
137+
return cache;
138138
}
139139

140140
/**
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.arangodb;
2+
3+
import java.util.Map;
4+
5+
import org.junit.AfterClass;
6+
import org.junit.Assert;
7+
import org.junit.BeforeClass;
8+
import org.junit.Ignore;
9+
import org.junit.Test;
10+
11+
import com.arangodb.entity.QueryCachePropertiesEntity;
12+
import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode;
13+
import com.arangodb.util.AqlQueryOptions;
14+
import com.arangodb.util.MapBuilder;
15+
16+
/**
17+
* @author Mark - mark@arangodb.com
18+
*
19+
*/
20+
@Ignore
21+
public class ArangoDriverCacheTest {
22+
23+
private static final String COLLECTION_NAME = "unitTestCollection";
24+
private static final String DATABASE_NAME = "unitTestDatabase";
25+
private static ArangoConfigure configure;
26+
private static ArangoDriver driver;
27+
28+
@BeforeClass
29+
public static void setup() throws ArangoException {
30+
31+
configure = new ArangoConfigure();
32+
configure.init();
33+
driver = new ArangoDriver(configure);
34+
35+
// create test database
36+
try {
37+
driver.createDatabase(DATABASE_NAME);
38+
} catch (ArangoException e) {
39+
}
40+
driver.setDefaultDatabase(DATABASE_NAME);
41+
42+
// create test collection
43+
try {
44+
driver.createCollection(COLLECTION_NAME);
45+
} catch (final ArangoException e) {
46+
}
47+
driver.truncateCollection(COLLECTION_NAME);
48+
49+
// create some test data
50+
for (int i = 0; i < 1000000; i++) {
51+
final TestEntity value = new TestEntity("user_" + (i % 10), "desc" + (i % 10), i);
52+
driver.createDocument(COLLECTION_NAME, value, null);
53+
}
54+
55+
}
56+
57+
@AfterClass
58+
public static void shutdown() {
59+
try {
60+
driver.deleteDatabase(DATABASE_NAME);
61+
} catch (final ArangoException e) {
62+
}
63+
configure.shutdown();
64+
}
65+
66+
private AqlQueryOptions createAqlQueryOptions(
67+
final Boolean count,
68+
final Integer batchSize,
69+
final Boolean fullCount,
70+
final Boolean cache) {
71+
return new AqlQueryOptions().setCount(count).setBatchSize(batchSize).setFullCount(fullCount).setCache(cache);
72+
}
73+
74+
@Test
75+
public void test_withoutCache() throws ArangoException {
76+
// set cache mode off
77+
final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
78+
properties.setMode(CacheMode.off);
79+
driver.setQueryCacheProperties(properties);
80+
81+
final AqlQueryOptions aqlQueryOptions = createAqlQueryOptions(true, 1000, null, false);
82+
83+
exceuteQuery(aqlQueryOptions);
84+
}
85+
86+
@Test
87+
public void test_withCache() throws ArangoException {
88+
// set cache mode on
89+
final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
90+
properties.setMode(CacheMode.on);
91+
driver.setQueryCacheProperties(properties);
92+
93+
// set caching to true for the query
94+
final AqlQueryOptions aqlQueryOptions = createAqlQueryOptions(true, 1000, null, true);
95+
96+
exceuteQuery(aqlQueryOptions);
97+
}
98+
99+
private void exceuteQuery(AqlQueryOptions aqlQueryOptions) throws ArangoException {
100+
101+
final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= @age SORT t.age RETURN t";
102+
final Map<String, Object> bindVars = new MapBuilder().put("age", 90).get();
103+
104+
DocumentCursor<TestEntity> rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestEntity.class);
105+
// first time, the query isn't cached
106+
Assert.assertEquals(false, rs.isCached());
107+
108+
final long start = System.currentTimeMillis();
109+
110+
// query the cached value
111+
rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestEntity.class);
112+
Assert.assertEquals(aqlQueryOptions.getCache(), rs.isCached());
113+
114+
// load all results
115+
rs.asEntityList();
116+
117+
final long time = System.currentTimeMillis() - start;
118+
System.out.println(time);
119+
}
120+
121+
private static class TestEntity {
122+
private String user;
123+
private String desc;
124+
private Integer age;
125+
126+
public TestEntity(String user, String desc, Integer age) {
127+
super();
128+
this.user = user;
129+
this.desc = desc;
130+
this.age = age;
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)