Skip to content

Commit 8cff380

Browse files
authored
GraphReadOptions (#303)
* GraphReadOptions * changelog upd
1 parent 92a6749 commit 8cff380

12 files changed

+127
-63
lines changed

ChangeLog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88

99
### Added
1010

11+
- split `GraphDocumentReadOptions` from `DocumentReadOptions` (breaking change)
1112
- added `ArangoCollection#getResponsibleShard(Object)`
1213
- added support for Analyzers
1314
- added support for Stream Transactions
1415
- added support for named indices
1516
- added support for TTL indices
1617
- added minReplicationAttribute for collections and graphs
17-
- added batched thread support in ArangoCollection.importDocuments (by @rkhaja)
1818

1919
## [5.0.7] - 2019-07-19
2020

docs/Drivers/Java/Reference/Graph/Edges.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## ArangoEdgeCollection.getEdge
44

5-
`ArangoEdgeCollection.getEdge(String key, Class<T> type, DocumentReadOptions options) : T`
5+
`ArangoEdgeCollection.getEdge(String key, Class<T> type, GraphDocumentReadOptions options) : T`
66

77
Retrieves the edge document with the given `key` from the collection.
88

@@ -16,7 +16,7 @@ Retrieves the edge document with the given `key` from the collection.
1616

1717
The type of the edge-document (POJO class, `VPackSlice` or `String` for JSON)
1818

19-
- **options**: `DocumentReadOptions`
19+
- **options**: `GraphDocumentReadOptions`
2020

2121
- **ifNoneMatch**: `String`
2222

docs/Drivers/Java/Reference/Graph/Vertices.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## ArangoVertexCollection.getVertex
44

5-
`ArangoVertexCollection.getVertex(String key, Class<T> type, DocumentReadOptions options) : T`
5+
`ArangoVertexCollection.getVertex(String key, Class<T> type, GraphDocumentReadOptions options) : T`
66

77
Retrieves the vertex document with the given `key` from the collection.
88

@@ -16,7 +16,7 @@ Retrieves the vertex document with the given `key` from the collection.
1616

1717
The type of the vertex-document (POJO class, `VPackSlice` or `String` for JSON)
1818

19-
- **options**: `DocumentReadOptions`
19+
- **options**: `GraphDocumentReadOptions`
2020

2121
- **ifNoneMatch**: `String`
2222

src/main/java/com/arangodb/ArangoEdgeCollection.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222

2323
import com.arangodb.entity.EdgeEntity;
2424
import com.arangodb.entity.EdgeUpdateEntity;
25-
import com.arangodb.model.DocumentReadOptions;
26-
import com.arangodb.model.EdgeCreateOptions;
27-
import com.arangodb.model.EdgeDeleteOptions;
28-
import com.arangodb.model.EdgeReplaceOptions;
29-
import com.arangodb.model.EdgeUpdateOptions;
25+
import com.arangodb.model.*;
3026

3127
/**
3228
* Interface for operations on ArangoDB edge collection level.
@@ -100,7 +96,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor {
10096
* @return the edge identified by the key
10197
* @throws ArangoDBException
10298
*/
103-
<T> T getEdge(String key, Class<T> type, DocumentReadOptions options) throws ArangoDBException;
99+
<T> T getEdge(String key, Class<T> type, GraphDocumentReadOptions options) throws ArangoDBException;
104100

105101
/**
106102
* Replaces the edge with key with the one in the body, provided there is such a edge and no precondition is

src/main/java/com/arangodb/ArangoVertexCollection.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222

2323
import com.arangodb.entity.VertexEntity;
2424
import com.arangodb.entity.VertexUpdateEntity;
25-
import com.arangodb.model.DocumentReadOptions;
26-
import com.arangodb.model.VertexCreateOptions;
27-
import com.arangodb.model.VertexDeleteOptions;
28-
import com.arangodb.model.VertexReplaceOptions;
29-
import com.arangodb.model.VertexUpdateOptions;
25+
import com.arangodb.model.*;
3026

3127
/**
3228
* Interface for operations on ArangoDB vertex collection level.
@@ -110,7 +106,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor {
110106
* @return the vertex identified by the key
111107
* @throws ArangoDBException
112108
*/
113-
<T> T getVertex(String key, Class<T> type, DocumentReadOptions options) throws ArangoDBException;
109+
<T> T getVertex(String key, Class<T> type, GraphDocumentReadOptions options) throws ArangoDBException;
114110

115111
/**
116112
* Replaces the vertex with key with the one in the body, provided there is such a vertex and no precondition is

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020

2121
package com.arangodb.internal;
2222

23+
import com.arangodb.model.*;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

2627
import com.arangodb.ArangoDBException;
2728
import com.arangodb.ArangoEdgeCollection;
2829
import com.arangodb.entity.EdgeEntity;
2930
import com.arangodb.entity.EdgeUpdateEntity;
30-
import com.arangodb.model.DocumentReadOptions;
31-
import com.arangodb.model.EdgeCreateOptions;
32-
import com.arangodb.model.EdgeDeleteOptions;
33-
import com.arangodb.model.EdgeReplaceOptions;
34-
import com.arangodb.model.EdgeUpdateOptions;
3531

3632
/**
3733
* @author Mark Vollmary
@@ -61,7 +57,7 @@ public <T> EdgeEntity insertEdge(final T value, final EdgeCreateOptions options)
6157
@Override
6258
public <T> T getEdge(final String key, final Class<T> type) throws ArangoDBException {
6359
try {
64-
return executor.execute(getEdgeRequest(key, new DocumentReadOptions()), getEdgeResponseDeserializer(type));
60+
return executor.execute(getEdgeRequest(key, new GraphDocumentReadOptions()), getEdgeResponseDeserializer(type));
6561
} catch (final ArangoDBException e) {
6662
if (LOGGER.isDebugEnabled()) {
6763
LOGGER.debug(e.getMessage(), e);
@@ -71,7 +67,7 @@ public <T> T getEdge(final String key, final Class<T> type) throws ArangoDBExcep
7167
}
7268

7369
@Override
74-
public <T> T getEdge(final String key, final Class<T> type, final DocumentReadOptions options)
70+
public <T> T getEdge(final String key, final Class<T> type, final GraphDocumentReadOptions options)
7571
throws ArangoDBException {
7672
try {
7773
return executor.execute(getEdgeRequest(key, options), getEdgeResponseDeserializer(type));

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020

2121
package com.arangodb.internal;
2222

23+
import com.arangodb.model.*;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

2627
import com.arangodb.ArangoDBException;
2728
import com.arangodb.ArangoVertexCollection;
2829
import com.arangodb.entity.VertexEntity;
2930
import com.arangodb.entity.VertexUpdateEntity;
30-
import com.arangodb.model.DocumentReadOptions;
31-
import com.arangodb.model.VertexCreateOptions;
32-
import com.arangodb.model.VertexDeleteOptions;
33-
import com.arangodb.model.VertexReplaceOptions;
34-
import com.arangodb.model.VertexUpdateOptions;
3531

3632
/**
3733
* @author Mark Vollmary
@@ -66,7 +62,7 @@ public <T> VertexEntity insertVertex(final T value, final VertexCreateOptions op
6662
@Override
6763
public <T> T getVertex(final String key, final Class<T> type) throws ArangoDBException {
6864
try {
69-
return executor.execute(getVertexRequest(key, new DocumentReadOptions()),
65+
return executor.execute(getVertexRequest(key, new GraphDocumentReadOptions()),
7066
getVertexResponseDeserializer(type));
7167
} catch (final ArangoDBException e) {
7268
if (LOGGER.isDebugEnabled()) {
@@ -77,7 +73,7 @@ public <T> T getVertex(final String key, final Class<T> type) throws ArangoDBExc
7773
}
7874

7975
@Override
80-
public <T> T getVertex(final String key, final Class<T> type, final DocumentReadOptions options)
76+
public <T> T getVertex(final String key, final Class<T> type, final GraphDocumentReadOptions options)
8177
throws ArangoDBException {
8278
try {
8379
return executor.execute(getVertexRequest(key, options), getVertexResponseDeserializer(type));

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
3131
import com.arangodb.internal.util.DocumentUtil;
3232
import com.arangodb.internal.util.RequestUtils;
33-
import com.arangodb.model.DocumentReadOptions;
34-
import com.arangodb.model.EdgeCreateOptions;
35-
import com.arangodb.model.EdgeDeleteOptions;
36-
import com.arangodb.model.EdgeReplaceOptions;
37-
import com.arangodb.model.EdgeUpdateOptions;
33+
import com.arangodb.model.*;
3834
import com.arangodb.util.ArangoSerializer;
3935
import com.arangodb.velocypack.VPackSlice;
4036
import com.arangodb.velocypack.exception.VPackException;
@@ -94,10 +90,10 @@ public EdgeEntity deserialize(final Response response) throws VPackException {
9490
};
9591
}
9692

97-
protected Request getEdgeRequest(final String key, final DocumentReadOptions options) {
93+
protected Request getEdgeRequest(final String key, final GraphDocumentReadOptions options) {
9894
final Request request = request(graph.db().name(), RequestType.GET, PATH_API_GHARIAL, graph.name(), EDGE,
9995
DocumentUtil.createDocumentHandle(name, key));
100-
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
96+
final GraphDocumentReadOptions params = (options != null ? options : new GraphDocumentReadOptions());
10197
request.putHeaderParam(ArangoRequestParam.IF_NONE_MATCH, params.getIfNoneMatch());
10298
request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch());
10399
if (params.getAllowDirtyRead() == Boolean.TRUE) {

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
3131
import com.arangodb.internal.util.DocumentUtil;
3232
import com.arangodb.internal.util.RequestUtils;
33-
import com.arangodb.model.DocumentReadOptions;
34-
import com.arangodb.model.VertexCreateOptions;
35-
import com.arangodb.model.VertexDeleteOptions;
36-
import com.arangodb.model.VertexReplaceOptions;
37-
import com.arangodb.model.VertexUpdateOptions;
33+
import com.arangodb.model.*;
3834
import com.arangodb.util.ArangoSerializer;
3935
import com.arangodb.velocypack.VPackSlice;
4036
import com.arangodb.velocypack.exception.VPackException;
@@ -98,10 +94,10 @@ public VertexEntity deserialize(final Response response) throws VPackException {
9894
};
9995
}
10096

101-
protected Request getVertexRequest(final String key, final DocumentReadOptions options) {
97+
protected Request getVertexRequest(final String key, final GraphDocumentReadOptions options) {
10298
final Request request = request(graph.db().name(), RequestType.GET, PATH_API_GHARIAL, graph.name(), VERTEX,
10399
DocumentUtil.createDocumentHandle(name, key));
104-
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
100+
final GraphDocumentReadOptions params = (options != null ? options : new GraphDocumentReadOptions());
105101
request.putHeaderParam(ArangoRequestParam.IF_NONE_MATCH, params.getIfNoneMatch());
106102
request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch());
107103
if (params.getAllowDirtyRead() == Boolean.TRUE) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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.model;
22+
23+
import com.arangodb.velocypack.annotations.Expose;
24+
25+
/**
26+
* @author Mark Vollmary
27+
*/
28+
public class GraphDocumentReadOptions {
29+
30+
private String ifNoneMatch;
31+
private String ifMatch;
32+
private boolean catchException;
33+
@Expose(serialize = false)
34+
private Boolean allowDirtyRead;
35+
36+
public GraphDocumentReadOptions() {
37+
super();
38+
catchException = true;
39+
}
40+
41+
public String getIfNoneMatch() {
42+
return ifNoneMatch;
43+
}
44+
45+
/**
46+
* @param ifNoneMatch document revision must not contain If-None-Match
47+
* @return options
48+
*/
49+
public GraphDocumentReadOptions ifNoneMatch(final String ifNoneMatch) {
50+
this.ifNoneMatch = ifNoneMatch;
51+
return this;
52+
}
53+
54+
public String getIfMatch() {
55+
return ifMatch;
56+
}
57+
58+
/**
59+
* @param ifMatch document revision must contain If-Match
60+
* @return options
61+
*/
62+
public GraphDocumentReadOptions ifMatch(final String ifMatch) {
63+
this.ifMatch = ifMatch;
64+
return this;
65+
}
66+
67+
public boolean isCatchException() {
68+
return catchException;
69+
}
70+
71+
/**
72+
* @param catchException whether or not catch possible thrown exceptions
73+
* @return options
74+
*/
75+
public GraphDocumentReadOptions catchException(final boolean catchException) {
76+
this.catchException = catchException;
77+
return this;
78+
}
79+
80+
/**
81+
* @param allowDirtyRead Set to {@code true} allows reading from followers in an active-failover setup.
82+
* @return options
83+
* @see <a href="https://docs.arangodb.com/current/Manual/Administration/ActiveFailover/#reading-from-follower">API
84+
* Documentation</a>
85+
* @since ArangoDB 3.4.0
86+
*/
87+
public GraphDocumentReadOptions allowDirtyRead(final Boolean allowDirtyRead) {
88+
this.allowDirtyRead = allowDirtyRead;
89+
return this;
90+
}
91+
92+
public Boolean getAllowDirtyRead() {
93+
return allowDirtyRead;
94+
}
95+
96+
}

src/test/java/com/arangodb/ArangoEdgeCollectionTest.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.ArrayList;
3232
import java.util.Collection;
3333

34+
import com.arangodb.model.*;
3435
import org.junit.After;
3536
import org.junit.Before;
3637
import org.junit.Test;
@@ -45,11 +46,6 @@
4546
import com.arangodb.entity.EdgeEntity;
4647
import com.arangodb.entity.EdgeUpdateEntity;
4748
import com.arangodb.entity.VertexEntity;
48-
import com.arangodb.model.CollectionCreateOptions;
49-
import com.arangodb.model.DocumentReadOptions;
50-
import com.arangodb.model.EdgeDeleteOptions;
51-
import com.arangodb.model.EdgeReplaceOptions;
52-
import com.arangodb.model.EdgeUpdateOptions;
5349

5450
/**
5551
* @author Mark Vollmary
@@ -148,7 +144,7 @@ public void getEdge() {
148144
public void getEdgeIfMatch() {
149145
final BaseEdgeDocument value = createEdgeValue();
150146
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
151-
final DocumentReadOptions options = new DocumentReadOptions().ifMatch(edge.getRev());
147+
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifMatch(edge.getRev());
152148
final BaseDocument document = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
153149
BaseDocument.class, options);
154150
assertThat(document, is(notNullValue()));
@@ -159,7 +155,7 @@ public void getEdgeIfMatch() {
159155
public void getEdgeIfMatchFail() {
160156
final BaseEdgeDocument value = createEdgeValue();
161157
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
162-
final DocumentReadOptions options = new DocumentReadOptions().ifMatch("no");
158+
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifMatch("no");
163159
final BaseEdgeDocument edge2 = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
164160
BaseEdgeDocument.class, options);
165161
assertThat(edge2, is(nullValue()));
@@ -169,7 +165,7 @@ public void getEdgeIfMatchFail() {
169165
public void getEdgeIfNoneMatch() {
170166
final BaseEdgeDocument value = createEdgeValue();
171167
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
172-
final DocumentReadOptions options = new DocumentReadOptions().ifNoneMatch("no");
168+
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifNoneMatch("no");
173169
final BaseDocument document = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
174170
BaseDocument.class, options);
175171
assertThat(document, is(notNullValue()));
@@ -180,7 +176,7 @@ public void getEdgeIfNoneMatch() {
180176
public void getEdgeIfNoneMatchFail() {
181177
final BaseEdgeDocument value = createEdgeValue();
182178
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
183-
final DocumentReadOptions options = new DocumentReadOptions().ifNoneMatch(edge.getRev());
179+
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifNoneMatch(edge.getRev());
184180
final BaseEdgeDocument edge2 = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
185181
BaseEdgeDocument.class, options);
186182
assertThat(edge2, is(nullValue()));

0 commit comments

Comments
 (0)