Skip to content

Commit 8d67d78

Browse files
author
Mark
committed
Merge remote-tracking branch 'origin/3.0'
Conflicts: README.md
2 parents d343eda + 1e8bd6e commit 8d67d78

20 files changed

+516
-85
lines changed

ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
v3.0.4 (2016-XX-XX)
2+
---------------------------
3+
* fixed edges deserializer (issue #50)
4+
5+
v3.0.3 (2016-09-12)
6+
---------------------------
7+
* added error handling in getBatchResponseByRequestId()
8+
* added function createPersistentIndex() (issue #48)
9+
* added deserializer for BaseDocument (issue #50)
10+
11+
v3.0.2 (2016-08-05)
12+
---------------------------
13+
* added profile flag to AqlQueryOptions (issue #47)
14+
* added getExtra() to DocumentCursor<> (issue #47)
15+
* added IndexType.PERSISTENT (issue #48)
16+
117
v3.0.1 (2016-07-08)
218
---------------------------
319
* added flag complete and details in ImportOptions

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
![ArangoDB-Logo](https://www.arangodb.com/wp-content/uploads/2012/10/logo_arangodb_transp.png)
2+
![ArangoDB-Logo](https://docs.arangodb.com/assets/arangodb_logo_2016_inverted.png)
33

44
# arangodb-java-driver
55

@@ -33,7 +33,7 @@ ArangoDB 3.0.X
3333
<dependency>
3434
<groupId>com.arangodb</groupId>
3535
<artifactId>arangodb-java-driver</artifactId>
36-
<version>3.0.0</version>
36+
<version>3.0.3</version>
3737
</dependency>
3838
....
3939
</dependencies>
@@ -387,10 +387,10 @@ Now an edge can be created to set a relation between vertices
387387

388388
# Learn more
389389
* [ArangoDB](https://www.arangodb.com/)
390-
* [ChangeLog](https://github.com/arangodb/arangodb-java-driver/tree/master/ChangeLog)
391-
* [Examples](https://github.com/arangodb/arangodb-java-driver/tree/master/src/test/java/com/arangodb/example)
392-
* [Document examples](https://github.com/arangodb/arangodb-java-driver/tree/master/src/test/java/com/arangodb/example/document)
393-
* [Graph examples](https://github.com/arangodb/arangodb-java-driver/tree/master/src/test/java/com/arangodb/example/graph)
394-
* [HTTPS examples](https://github.com/arangodb/arangodb-java-driver/tree/master/src/test/java/com/arangodb/example/ssl)
390+
* [ChangeLog](ChangeLog)
391+
* [Examples](src/test/java/com/arangodb/example)
392+
* [Document examples](src/test/java/com/arangodb/example/document)
393+
* [Graph examples](src/test/java/com/arangodb/example/graph)
394+
* [HTTPS examples](src/test/java/com/arangodb/example/ssl)
395395
* [Tutorial](https://www.arangodb.com/tutorial-java/)
396396

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.arangodb</groupId>
66
<artifactId>arangodb-java-driver</artifactId>
7-
<version>3.0.2-SNAPSHOT</version>
7+
<version>3.0.4-SNAPSHOT</version>
88
<inceptionYear>2012</inceptionYear>
99
<packaging>jar</packaging>
1010

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.arangodb.http.BatchHttpManager;
7474
import com.arangodb.http.BatchPart;
7575
import com.arangodb.http.HttpManager;
76+
import com.arangodb.http.HttpResponseEntity;
7677
import com.arangodb.http.InvocationHandlerImpl;
7778
import com.arangodb.impl.ImplFactory;
7879
import com.arangodb.impl.InternalBatchDriverImpl;
@@ -408,8 +409,21 @@ public <T> T getBatchResponseByRequestId(final String requestId) throws ArangoEx
408409
this.httpManager.setPreDefinedResponse(null);
409410
return result;
410411
} catch (final InvocationTargetException e) {
411-
final T result = (T) createEntity(batchResponseEntity.getHttpResponseEntity(), DefaultEntity.class);
412412
this.httpManager.setPreDefinedResponse(null);
413+
414+
HttpResponseEntity httpResponse = batchResponseEntity.getHttpResponseEntity();
415+
if (httpResponse.getStatusCode() >= 300) {
416+
DefaultEntity de = new DefaultEntity();
417+
de.setCode(httpResponse.getStatusCode());
418+
de.setError(true);
419+
if (httpResponse.getText() != null) {
420+
de.setErrorMessage(httpResponse.getText().trim());
421+
}
422+
de.setErrorNumber(httpResponse.getStatusCode());
423+
throw new ArangoException(de);
424+
}
425+
426+
final T result = (T) createEntity(batchResponseEntity.getHttpResponseEntity(), DefaultEntity.class);
413427
return result;
414428
} catch (final Exception e) {
415429
this.httpManager.setPreDefinedResponse(null);
@@ -2385,6 +2399,32 @@ public IndexEntity createSkipListIndex(
23852399
fields);
23862400
}
23872401

2402+
/**
2403+
* It is possible to define a persistent index on one or more attributes (or
2404+
* paths) of documents. The index is then used in queries to locate
2405+
* documents within a given range. If the index is declared unique, then no
2406+
* two documents are allowed to have the same set of attribute values.
2407+
*
2408+
* @param collectionName
2409+
* The collection name.
2410+
* @param unique
2411+
* if set to true the index will be a unique index
2412+
* @param sparse
2413+
* if set to true the index will be sparse
2414+
* @param fields
2415+
* the fields (document attributes) the index is created on
2416+
* @return IndexEntity
2417+
* @throws ArangoException
2418+
*/
2419+
public IndexEntity createPersistentIndex(
2420+
final String collectionName,
2421+
final boolean unique,
2422+
final boolean sparse,
2423+
final String... fields) throws ArangoException {
2424+
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.PERSISTENT, unique, sparse,
2425+
fields);
2426+
}
2427+
23882428
/**
23892429
* This method creates a full text index for a collection.
23902430
*

src/main/java/com/arangodb/BaseCursorProxy.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Iterator;
44
import java.util.List;
5+
import java.util.Map;
56

67
import com.arangodb.entity.DocumentEntity;
78

@@ -115,7 +116,7 @@ public String getRequestId() {
115116
* @return true, if the cursor can load more data from the database
116117
*/
117118
public boolean hasMore() {
118-
return baseCursor.getEntity().hasMore();
119+
return baseCursor.hasMore();
119120
}
120121

121122
/**
@@ -124,7 +125,7 @@ public boolean hasMore() {
124125
* @return the cursor identifier
125126
*/
126127
public Long getCursorId() {
127-
return baseCursor.getEntity().getCursorId();
128+
return baseCursor.getCursorId();
128129
}
129130

130131
/**
@@ -137,7 +138,16 @@ public Long getCursorId() {
137138
*
138139
*/
139140
public boolean isCached() {
140-
return baseCursor.getEntity().isCached();
141+
return baseCursor.isCached();
142+
}
143+
144+
/**
145+
* A list of extra stats returned by the query
146+
*
147+
* @return query stats
148+
*/
149+
public Map<String, Object> getExtra() {
150+
return baseCursor.getExtra();
141151
}
142152

143153
}

src/main/java/com/arangodb/CursorResult.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Iterator;
2121
import java.util.List;
22+
import java.util.Map;
2223
import java.util.NoSuchElementException;
2324

2425
import com.arangodb.entity.CursorEntity;
@@ -175,6 +176,37 @@ public void remove() {
175176

176177
}
177178

179+
/**
180+
* Returns true if the cursor can load more data from the database
181+
*
182+
* @return true, if the cursor can load more data from the database
183+
*/
184+
public boolean hasMore() {
185+
return entity.hasMore();
186+
}
187+
188+
/**
189+
* Returns the cursor identifier
190+
*
191+
* @return the cursor identifier
192+
*/
193+
public Long getCursorId() {
194+
return entity.getCursorId();
195+
}
196+
197+
/**
198+
* a boolean flag indicating whether the query result was served from the
199+
* query cache or not. If the query result is served from the query cache,
200+
* the extra return attribute will not contain any stats sub-attribute and
201+
* no profile sub-attribute. (since ArangoDB 2.7)
202+
*
203+
* @return true, if the result is cached
204+
*
205+
*/
206+
public boolean isCached() {
207+
return entity.isCached();
208+
}
209+
178210
/**
179211
* Returns true, if there are AQL warnings
180212
*
@@ -193,4 +225,13 @@ public List<WarningEntity> getWarnings() {
193225
return entity.getWarnings();
194226
}
195227

228+
/**
229+
* A list of extra stats returned by the query
230+
*
231+
* @return query stats
232+
*/
233+
public Map<String, Object> getExtra() {
234+
return entity.getExtra();
235+
}
236+
196237
}

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,28 @@ public GraphsEntity deserialize(
20902090
}
20912091
}
20922092

2093+
public static class BaseDocumentDeserializer implements JsonDeserializer<BaseDocument> {
2094+
@Override
2095+
public BaseDocument deserialize(
2096+
final JsonElement json,
2097+
final Type typeOfT,
2098+
final JsonDeserializationContext context) {
2099+
2100+
if (json.isJsonNull()) {
2101+
return null;
2102+
}
2103+
2104+
final JsonObject obj = json.getAsJsonObject();
2105+
final BaseDocument entity = deserializeDocumentParameter(obj, new BaseDocument());
2106+
2107+
if (entity instanceof BaseDocument) {
2108+
entity.setProperties(DeserializeSingleEntry.deserializeJsonObject(obj));
2109+
}
2110+
2111+
return entity;
2112+
}
2113+
}
2114+
20932115
public static class DeleteEntityDeserializer implements JsonDeserializer<DeletedEntity> {
20942116
@Override
20952117
public DeletedEntity deserialize(
@@ -2491,13 +2513,7 @@ private static List<EdgeEntity<Object>> getEdges(
24912513
if (edges != null) {
24922514
for (int i = 0, imax = edges.size(); i < imax; i++) {
24932515
final JsonObject edge = edges.get(i).getAsJsonObject();
2494-
final EdgeEntity<Object> ve = deserializeBaseParameter(edge, new EdgeEntity<Object>());
2495-
deserializeDocumentParameter(edge, ve);
2496-
if (edgeClazz != null) {
2497-
ve.setEntity(context.deserialize(edge, edgeClazz));
2498-
} else {
2499-
ve.setEntity(context.deserialize(edge, Object.class));
2500-
}
2516+
final EdgeEntity<Object> ve = context.deserialize(edge, EdgeEntity.class);
25012517
list.add(ve);
25022518
}
25032519
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public static GsonBuilder getGsonBuilder() {
112112
new EntityDeserializers.ReplicationLoggerStateEntityDeserializer())
113113
.registerTypeAdapter(ReplicationLoggerStateEntity.Client.class,
114114
new EntityDeserializers.ReplicationLoggerStateEntityClientDeserializer())
115+
.registerTypeAdapter(BaseDocument.class, new EntityDeserializers.BaseDocumentDeserializer())
115116
.registerTypeAdapter(GraphEntity.class, new EntityDeserializers.GraphEntityDeserializer())
116117
.registerTypeAdapter(GraphsEntity.class, new EntityDeserializers.GraphsEntityDeserializer())
117118
.registerTypeAdapter(DeletedEntity.class, new EntityDeserializers.DeleteEntityDeserializer())
@@ -136,13 +137,10 @@ public static GsonBuilder getGsonBuilder() {
136137
* Configures instances of Gson used by this factory.
137138
*
138139
* @param builders
139-
* one or two GsonBuilder instances. If only one is provided it
140-
* will be used for initializing both <code>gson</code> and
141-
* <code>gsonNull</code> fields (latter with
142-
* <code>serializeNulls()</code> called prior to creating). If
143-
* two are given - first initializes <code>gson</code> field,
144-
* second initializes <code>gsonNull</code> (used when
145-
* serialization of nulls is requested).
140+
* one or two GsonBuilder instances. If only one is provided it will be used for initializing both
141+
* <code>gson</code> and <code>gsonNull</code> fields (latter with <code>serializeNulls()</code> called
142+
* prior to creating). If two are given - first initializes <code>gson</code> field, second initializes
143+
* <code>gsonNull</code> (used when serialization of nulls is requested).
146144
*/
147145
public static void configure(GsonBuilder... builders) {
148146
if (builders.length < 1) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
* Index Type.
2121
*
2222
* @author tamtam180 - kirscheless at gmail.com
23-
* @see <a href=
24-
* "http://www.arangodb.com/manuals/current/HttpIndex.html#HttpIndexIntro">
25-
* HttpIndexIntro</a>
23+
* @see <a https://docs.arangodb.com/current/HTTP/Indexes/index.html">
24+
* Indexes</a>
2625
*/
2726
public enum IndexType {
2827
/** Primary Index */
@@ -36,5 +35,7 @@ public enum IndexType {
3635
/** Skiplist Index */
3736
SKIPLIST,
3837
/** Fulltext Inex */
39-
FULLTEXT
38+
FULLTEXT,
39+
/** Persistent Index */
40+
PERSISTENT
4041
}

src/main/java/com/arangodb/http/HttpManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,11 @@ private HttpResponseEntity buildHttpResponseEntity(
485485
// // TODO etag特殊処理は削除する。
486486
final Header etagHeader = response.getLastHeader("etag");
487487
if (etagHeader != null) {
488-
responseEntity.etag = Long.parseLong(etagHeader.getValue().replace("\"", ""));
488+
try {
489+
responseEntity.etag = Long.parseLong(etagHeader.getValue().replace("\"", ""));
490+
} catch (NumberFormatException e) {
491+
responseEntity.etag = 0;
492+
}
489493
}
490494
// ヘッダをMapに変換する
491495
responseEntity.headers = new TreeMap<String, String>();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ public <T> VertexEntity<T> createVertex(
389389
if (isInBatchMode()) {
390390
result = new VertexEntity<T>();
391391
result.setEntity(vertex);
392+
result.setRequestId(res.getRequestId());
392393
} else {
393394
if (vertex != null) {
394395
result = createEntity(res, VertexEntity.class, vertex.getClass());

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class AqlQueryOptions implements OptionsInterface {
99
private Boolean fullCount;
1010
private Boolean cache;
1111
private Integer ttl;
12+
private Boolean profile;
1213

1314
/**
1415
* boolean flag that indicates whether the number of documents in the result
@@ -67,6 +68,31 @@ public AqlQueryOptions setBatchSize(Integer batchSize) {
6768
return this;
6869
}
6970

71+
/**
72+
* if set to true, then the additional query profiling information will be
73+
* returned in the extra.stats return attribute if the query result is not
74+
* served from the query cache.
75+
*
76+
* @return boolean flag
77+
*/
78+
public Boolean getProfile() {
79+
return profile;
80+
}
81+
82+
/**
83+
* if set to true, then the additional query profiling information will be
84+
* returned in the extra.stats return attribute if the query result is not
85+
* served from the query cache.
86+
*
87+
* @param profile
88+
* boolean flag
89+
* @return this
90+
*/
91+
public AqlQueryOptions setProfile(Boolean profile) {
92+
this.profile = profile;
93+
return this;
94+
}
95+
7096
/**
7197
* if set to true and the query contains a LIMIT clause, then the result
7298
* will contain an extra attribute extra with a sub-attribute fullCount.
@@ -174,6 +200,10 @@ public Map<String, Object> toMap() {
174200
optionsMp.put("fullCount", fullCount);
175201
}
176202

203+
if (profile != null) {
204+
optionsMp.put("profile", profile);
205+
}
206+
177207
// TODO add maxPlans
178208

179209
// TODO add optimizer.rules

0 commit comments

Comments
 (0)