Skip to content

Commit

Permalink
GraphReadOptions (#303)
Browse files Browse the repository at this point in the history
* GraphReadOptions

* changelog upd
  • Loading branch information
rashtao authored Aug 20, 2019
1 parent 92a6749 commit 8cff380
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 63 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

### Added

- split `GraphDocumentReadOptions` from `DocumentReadOptions` (breaking change)
- added `ArangoCollection#getResponsibleShard(Object)`
- added support for Analyzers
- added support for Stream Transactions
- added support for named indices
- added support for TTL indices
- added minReplicationAttribute for collections and graphs
- added batched thread support in ArangoCollection.importDocuments (by @rkhaja)

## [5.0.7] - 2019-07-19

Expand Down
4 changes: 2 additions & 2 deletions docs/Drivers/Java/Reference/Graph/Edges.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## ArangoEdgeCollection.getEdge

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

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

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

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

- **options**: `DocumentReadOptions`
- **options**: `GraphDocumentReadOptions`

- **ifNoneMatch**: `String`

Expand Down
4 changes: 2 additions & 2 deletions docs/Drivers/Java/Reference/Graph/Vertices.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## ArangoVertexCollection.getVertex

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

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

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

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

- **options**: `DocumentReadOptions`
- **options**: `GraphDocumentReadOptions`

- **ifNoneMatch**: `String`

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/arangodb/ArangoEdgeCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

import com.arangodb.entity.EdgeEntity;
import com.arangodb.entity.EdgeUpdateEntity;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.EdgeCreateOptions;
import com.arangodb.model.EdgeDeleteOptions;
import com.arangodb.model.EdgeReplaceOptions;
import com.arangodb.model.EdgeUpdateOptions;
import com.arangodb.model.*;

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

/**
* Replaces the edge with key with the one in the body, provided there is such a edge and no precondition is
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/arangodb/ArangoVertexCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

import com.arangodb.entity.VertexEntity;
import com.arangodb.entity.VertexUpdateEntity;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.VertexCreateOptions;
import com.arangodb.model.VertexDeleteOptions;
import com.arangodb.model.VertexReplaceOptions;
import com.arangodb.model.VertexUpdateOptions;
import com.arangodb.model.*;

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

/**
* Replaces the vertex with key with the one in the body, provided there is such a vertex and no precondition is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@

package com.arangodb.internal;

import com.arangodb.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.arangodb.ArangoDBException;
import com.arangodb.ArangoEdgeCollection;
import com.arangodb.entity.EdgeEntity;
import com.arangodb.entity.EdgeUpdateEntity;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.EdgeCreateOptions;
import com.arangodb.model.EdgeDeleteOptions;
import com.arangodb.model.EdgeReplaceOptions;
import com.arangodb.model.EdgeUpdateOptions;

/**
* @author Mark Vollmary
Expand Down Expand Up @@ -61,7 +57,7 @@ public <T> EdgeEntity insertEdge(final T value, final EdgeCreateOptions options)
@Override
public <T> T getEdge(final String key, final Class<T> type) throws ArangoDBException {
try {
return executor.execute(getEdgeRequest(key, new DocumentReadOptions()), getEdgeResponseDeserializer(type));
return executor.execute(getEdgeRequest(key, new GraphDocumentReadOptions()), getEdgeResponseDeserializer(type));
} catch (final ArangoDBException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(e.getMessage(), e);
Expand All @@ -71,7 +67,7 @@ public <T> T getEdge(final String key, final Class<T> type) throws ArangoDBExcep
}

@Override
public <T> T getEdge(final String key, final Class<T> type, final DocumentReadOptions options)
public <T> T getEdge(final String key, final Class<T> type, final GraphDocumentReadOptions options)
throws ArangoDBException {
try {
return executor.execute(getEdgeRequest(key, options), getEdgeResponseDeserializer(type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@

package com.arangodb.internal;

import com.arangodb.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.arangodb.ArangoDBException;
import com.arangodb.ArangoVertexCollection;
import com.arangodb.entity.VertexEntity;
import com.arangodb.entity.VertexUpdateEntity;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.VertexCreateOptions;
import com.arangodb.model.VertexDeleteOptions;
import com.arangodb.model.VertexReplaceOptions;
import com.arangodb.model.VertexUpdateOptions;

/**
* @author Mark Vollmary
Expand Down Expand Up @@ -66,7 +62,7 @@ public <T> VertexEntity insertVertex(final T value, final VertexCreateOptions op
@Override
public <T> T getVertex(final String key, final Class<T> type) throws ArangoDBException {
try {
return executor.execute(getVertexRequest(key, new DocumentReadOptions()),
return executor.execute(getVertexRequest(key, new GraphDocumentReadOptions()),
getVertexResponseDeserializer(type));
} catch (final ArangoDBException e) {
if (LOGGER.isDebugEnabled()) {
Expand All @@ -77,7 +73,7 @@ public <T> T getVertex(final String key, final Class<T> type) throws ArangoDBExc
}

@Override
public <T> T getVertex(final String key, final Class<T> type, final DocumentReadOptions options)
public <T> T getVertex(final String key, final Class<T> type, final GraphDocumentReadOptions options)
throws ArangoDBException {
try {
return executor.execute(getVertexRequest(key, options), getVertexResponseDeserializer(type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
import com.arangodb.internal.util.DocumentUtil;
import com.arangodb.internal.util.RequestUtils;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.EdgeCreateOptions;
import com.arangodb.model.EdgeDeleteOptions;
import com.arangodb.model.EdgeReplaceOptions;
import com.arangodb.model.EdgeUpdateOptions;
import com.arangodb.model.*;
import com.arangodb.util.ArangoSerializer;
import com.arangodb.velocypack.VPackSlice;
import com.arangodb.velocypack.exception.VPackException;
Expand Down Expand Up @@ -94,10 +90,10 @@ public EdgeEntity deserialize(final Response response) throws VPackException {
};
}

protected Request getEdgeRequest(final String key, final DocumentReadOptions options) {
protected Request getEdgeRequest(final String key, final GraphDocumentReadOptions options) {
final Request request = request(graph.db().name(), RequestType.GET, PATH_API_GHARIAL, graph.name(), EDGE,
DocumentUtil.createDocumentHandle(name, key));
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
final GraphDocumentReadOptions params = (options != null ? options : new GraphDocumentReadOptions());
request.putHeaderParam(ArangoRequestParam.IF_NONE_MATCH, params.getIfNoneMatch());
request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch());
if (params.getAllowDirtyRead() == Boolean.TRUE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
import com.arangodb.internal.util.DocumentUtil;
import com.arangodb.internal.util.RequestUtils;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.VertexCreateOptions;
import com.arangodb.model.VertexDeleteOptions;
import com.arangodb.model.VertexReplaceOptions;
import com.arangodb.model.VertexUpdateOptions;
import com.arangodb.model.*;
import com.arangodb.util.ArangoSerializer;
import com.arangodb.velocypack.VPackSlice;
import com.arangodb.velocypack.exception.VPackException;
Expand Down Expand Up @@ -98,10 +94,10 @@ public VertexEntity deserialize(final Response response) throws VPackException {
};
}

protected Request getVertexRequest(final String key, final DocumentReadOptions options) {
protected Request getVertexRequest(final String key, final GraphDocumentReadOptions options) {
final Request request = request(graph.db().name(), RequestType.GET, PATH_API_GHARIAL, graph.name(), VERTEX,
DocumentUtil.createDocumentHandle(name, key));
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
final GraphDocumentReadOptions params = (options != null ? options : new GraphDocumentReadOptions());
request.putHeaderParam(ArangoRequestParam.IF_NONE_MATCH, params.getIfNoneMatch());
request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch());
if (params.getAllowDirtyRead() == Boolean.TRUE) {
Expand Down
96 changes: 96 additions & 0 deletions src/main/java/com/arangodb/model/GraphDocumentReadOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.model;

import com.arangodb.velocypack.annotations.Expose;

/**
* @author Mark Vollmary
*/
public class GraphDocumentReadOptions {

private String ifNoneMatch;
private String ifMatch;
private boolean catchException;
@Expose(serialize = false)
private Boolean allowDirtyRead;

public GraphDocumentReadOptions() {
super();
catchException = true;
}

public String getIfNoneMatch() {
return ifNoneMatch;
}

/**
* @param ifNoneMatch document revision must not contain If-None-Match
* @return options
*/
public GraphDocumentReadOptions ifNoneMatch(final String ifNoneMatch) {
this.ifNoneMatch = ifNoneMatch;
return this;
}

public String getIfMatch() {
return ifMatch;
}

/**
* @param ifMatch document revision must contain If-Match
* @return options
*/
public GraphDocumentReadOptions ifMatch(final String ifMatch) {
this.ifMatch = ifMatch;
return this;
}

public boolean isCatchException() {
return catchException;
}

/**
* @param catchException whether or not catch possible thrown exceptions
* @return options
*/
public GraphDocumentReadOptions catchException(final boolean catchException) {
this.catchException = catchException;
return this;
}

/**
* @param allowDirtyRead Set to {@code true} allows reading from followers in an active-failover setup.
* @return options
* @see <a href="https://docs.arangodb.com/current/Manual/Administration/ActiveFailover/#reading-from-follower">API
* Documentation</a>
* @since ArangoDB 3.4.0
*/
public GraphDocumentReadOptions allowDirtyRead(final Boolean allowDirtyRead) {
this.allowDirtyRead = allowDirtyRead;
return this;
}

public Boolean getAllowDirtyRead() {
return allowDirtyRead;
}

}
14 changes: 5 additions & 9 deletions src/test/java/com/arangodb/ArangoEdgeCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.Collection;

import com.arangodb.model.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -45,11 +46,6 @@
import com.arangodb.entity.EdgeEntity;
import com.arangodb.entity.EdgeUpdateEntity;
import com.arangodb.entity.VertexEntity;
import com.arangodb.model.CollectionCreateOptions;
import com.arangodb.model.DocumentReadOptions;
import com.arangodb.model.EdgeDeleteOptions;
import com.arangodb.model.EdgeReplaceOptions;
import com.arangodb.model.EdgeUpdateOptions;

/**
* @author Mark Vollmary
Expand Down Expand Up @@ -148,7 +144,7 @@ public void getEdge() {
public void getEdgeIfMatch() {
final BaseEdgeDocument value = createEdgeValue();
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
final DocumentReadOptions options = new DocumentReadOptions().ifMatch(edge.getRev());
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifMatch(edge.getRev());
final BaseDocument document = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
BaseDocument.class, options);
assertThat(document, is(notNullValue()));
Expand All @@ -159,7 +155,7 @@ public void getEdgeIfMatch() {
public void getEdgeIfMatchFail() {
final BaseEdgeDocument value = createEdgeValue();
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
final DocumentReadOptions options = new DocumentReadOptions().ifMatch("no");
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifMatch("no");
final BaseEdgeDocument edge2 = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
BaseEdgeDocument.class, options);
assertThat(edge2, is(nullValue()));
Expand All @@ -169,7 +165,7 @@ public void getEdgeIfMatchFail() {
public void getEdgeIfNoneMatch() {
final BaseEdgeDocument value = createEdgeValue();
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
final DocumentReadOptions options = new DocumentReadOptions().ifNoneMatch("no");
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifNoneMatch("no");
final BaseDocument document = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
BaseDocument.class, options);
assertThat(document, is(notNullValue()));
Expand All @@ -180,7 +176,7 @@ public void getEdgeIfNoneMatch() {
public void getEdgeIfNoneMatchFail() {
final BaseEdgeDocument value = createEdgeValue();
final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null);
final DocumentReadOptions options = new DocumentReadOptions().ifNoneMatch(edge.getRev());
final GraphDocumentReadOptions options = new GraphDocumentReadOptions().ifNoneMatch(edge.getRev());
final BaseEdgeDocument edge2 = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).getEdge(edge.getKey(),
BaseEdgeDocument.class, options);
assertThat(edge2, is(nullValue()));
Expand Down
Loading

0 comments on commit 8cff380

Please sign in to comment.