Skip to content

Commit 1519fff

Browse files
authored
Feature/stream tx graph (#310)
* streamTx: createVertex * streamTx: vertex operations * streamTx: edges operations * documentation streamTx on graphs * catchGetDocumentExceptions for async graph APIs * async StreamTransactionGraphTest * changelog upd * bugfix ArangoDatabaseTest * updated CI matrix * code inspection fixes
1 parent 6c275bd commit 1519fff

29 files changed

+1097
-77
lines changed

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ jobs:
3131
docker-img:
3232
- docker.io/arangodb:3.3.23
3333
- docker.io/arangodb:3.4.8
34-
- docker.io/arangodb:3.5.0
34+
- docker.io/arangodb:3.5.1
3535
- docker.io/arangodb/enterprise:3.4.8
36-
- docker.io/arangodb/enterprise:3.5.0
36+
- docker.io/arangodb/enterprise:3.5.1
3737
topology:
3838
- single
3939
- cluster

ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Stream Transactions support for graph APIs
12+
13+
### Fixed
14+
15+
- `catchExceptions` option in async `getEdge` and `getVertex`
16+
917
## [6.3.0] - 2019-09-16
1018

1119
### Added

docker/start_db_cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# ./start_db_cluster.sh <dockerImage>
66

77
# EXAMPLE:
8-
# ./start_db_cluster.sh docker.io/arangodb:3.5.0
8+
# ./start_db_cluster.sh docker.io/arangodb/arangodb:3.5.1
99

1010
docker pull "$1"
1111

docker/start_db_single.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# ./start_db_single.sh <dockerImage>
66

77
# EXAMPLE:
8-
# ./start_db_single.sh docker.io/arangodb:3.5.0
8+
# ./start_db_single.sh docker.io/arangodb/arangodb:3.5.1
99

1010
docker pull "$1"
1111

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Retrieves the edge document with the given `key` from the collection.
3030

3131
Whether or not catch possible thrown exceptions
3232

33+
- **streamTransactionId**: `String`
34+
35+
If set, the operation will be executed within the transaction
36+
3337
## ArangoEdgeCollection.insertEdge
3438

3539
`ArangoEdgeCollection.insertEdge(T value, EdgeCreateOptions options) : EdgeEntity`
@@ -88,6 +92,10 @@ a edge and no precondition is violated.
8892

8993
Replace a document based on target revision
9094

95+
- **streamTransactionId**: `String`
96+
97+
If set, the operation will be executed within the transaction
98+
9199
**Examples**
92100

93101
```Java
@@ -135,6 +143,10 @@ edge and no precondition is violated.
135143
from the existing document that are contained in the patch document with an
136144
attribute value of null.
137145

146+
- **streamTransactionId**: `String`
147+
148+
If set, the operation will be executed within the transaction
149+
138150
**Examples**
139151

140152
```Java
@@ -169,6 +181,10 @@ Deletes the edge with the given _key_ from the collection.
169181

170182
Remove a document based on target revision
171183

184+
- **streamTransactionId**: `String`
185+
186+
If set, the operation will be executed within the transaction
187+
172188
**Examples**
173189

174190
```Java

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Retrieves the vertex document with the given `key` from the collection.
3030

3131
Whether or not catch possible thrown exceptions
3232

33+
- **streamTransactionId**: `String`
34+
35+
If set, the operation will be executed within the transaction
36+
3337
## ArangoVertexCollection.insertVertex
3438

3539
`ArangoVertexCollection.insertVertex(T value, VertexCreateOptions options) : VertexEntity`
@@ -48,6 +52,14 @@ Creates a new vertex in the collection.
4852

4953
Wait until document has been synced to disk.
5054

55+
- **streamTransactionId**: `String`
56+
57+
If set, the operation will be executed within the transaction
58+
59+
- **streamTransactionId**: `String`
60+
61+
If set, the operation will be executed within the transaction
62+
5163
**Examples**
5264

5365
```Java
@@ -88,6 +100,10 @@ a vertex and no precondition is violated.
88100

89101
Replace a document based on target revision
90102

103+
- **streamTransactionId**: `String`
104+
105+
If set, the operation will be executed within the transaction
106+
91107
**Examples**
92108

93109
```Java
@@ -135,6 +151,10 @@ a vertex and no precondition is violated.
135151
from the existing document that are contained in the patch document with
136152
an attribute value of null.
137153

154+
- **streamTransactionId**: `String`
155+
156+
If set, the operation will be executed within the transaction
157+
138158
**Examples**
139159

140160
```Java
@@ -169,6 +189,10 @@ Deletes the vertex with the given _key_ from the collection.
169189

170190
Remove a document based on target revision
171191

192+
- **streamTransactionId**: `String`
193+
194+
If set, the operation will be executed within the transaction
195+
172196
**Examples**
173197

174198
```Java

src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import java.util.Collection;
3131
import java.util.Objects;
3232
import java.util.concurrent.CompletableFuture;
33-
import java.util.concurrent.CompletionException;
34-
import java.util.function.Function;
3533

3634
/**
3735
* @author Mark Vollmary
@@ -116,29 +114,7 @@ public <T> CompletableFuture<T> getDocument(
116114
DocumentUtil.validateDocumentKey(key);
117115
boolean isCatchException = options != null ? options.isCatchException() : new DocumentReadOptions().isCatchException();
118116
return (CompletableFuture<T>) executor.execute(getDocumentRequest(key, options), type)
119-
.exceptionally(handleGetDocumentExceptions(isCatchException));
120-
}
121-
122-
private <T> Function<Throwable, T> handleGetDocumentExceptions(Boolean isCatchException) {
123-
return throwable -> {
124-
if (throwable instanceof CompletionException) {
125-
if (throwable.getCause() instanceof ArangoDBException) {
126-
ArangoDBException arangoDBException = (ArangoDBException) throwable.getCause();
127-
128-
// handle Response: 404, Error: 1655 - transaction not found
129-
if (arangoDBException.getErrorNum() != null && arangoDBException.getErrorNum() == 1655) {
130-
throw (CompletionException) throwable;
131-
}
132-
133-
if ((arangoDBException.getResponseCode() != null && (arangoDBException.getResponseCode() == 404 || arangoDBException.getResponseCode() == 304
134-
|| arangoDBException.getResponseCode() == 412)) && isCatchException) {
135-
return null;
136-
}
137-
}
138-
throw (CompletionException) throwable;
139-
}
140-
throw new CompletionException(throwable);
141-
};
117+
.exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException));
142118
}
143119

144120
@Override
@@ -260,7 +236,7 @@ public CompletableFuture<Boolean> documentExists(final String key) {
260236
public CompletableFuture<Boolean> documentExists(final String key, final DocumentExistsOptions options) {
261237
boolean isCatchException = options != null ? options.isCatchException() : new DocumentExistsOptions().isCatchException();
262238
return executor.execute(documentExistsRequest(key, options), response -> response)
263-
.exceptionally(handleGetDocumentExceptions(isCatchException))
239+
.exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException))
264240
.thenApply(Objects::nonNull);
265241
}
266242

src/main/java/com/arangodb/async/internal/ArangoEdgeCollectionAsyncImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ public <T> CompletableFuture<EdgeEntity> insertEdge(final T value, final EdgeCre
5252

5353
@Override
5454
public <T> CompletableFuture<T> getEdge(final String key, final Class<T> type) {
55-
return executor.execute(getEdgeRequest(key, new GraphDocumentReadOptions()), getEdgeResponseDeserializer(type));
55+
return getEdge(key, type, null);
5656
}
5757

5858
@Override
5959
public <T> CompletableFuture<T> getEdge(final String key, final Class<T> type, final GraphDocumentReadOptions options) {
60-
return executor.execute(getEdgeRequest(key, options), getEdgeResponseDeserializer(type));
60+
boolean isCatchException = options != null ? options.isCatchException() : new GraphDocumentReadOptions().isCatchException();
61+
return executor.execute(getEdgeRequest(key, options), getEdgeResponseDeserializer(type))
62+
.exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException));
6163
}
6264

6365
@Override

src/main/java/com/arangodb/async/internal/ArangoVertexCollectionAsyncImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ public <T> CompletableFuture<VertexEntity> insertVertex(final T value, final Ver
5757

5858
@Override
5959
public <T> CompletableFuture<T> getVertex(final String key, final Class<T> type) {
60-
return executor.execute(getVertexRequest(key, new GraphDocumentReadOptions()), getVertexResponseDeserializer(type));
60+
return getVertex(key, type, null);
6161
}
6262

6363
@Override
6464
public <T> CompletableFuture<T> getVertex(
6565
final String key,
6666
final Class<T> type,
6767
final GraphDocumentReadOptions options) {
68-
return executor.execute(getVertexRequest(key, options), getVertexResponseDeserializer(type));
68+
boolean isCatchException = options != null ? options.isCatchException() : new GraphDocumentReadOptions().isCatchException();
69+
return executor.execute(getVertexRequest(key, options), getVertexResponseDeserializer(type))
70+
.exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException));
6971
}
7072

7173
@Override
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.arangodb.async.internal;/*
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+
22+
import com.arangodb.ArangoDBException;
23+
24+
import java.util.concurrent.CompletionException;
25+
import java.util.function.Function;
26+
27+
/**
28+
* @author Michele Rastelli
29+
*/
30+
class ExceptionUtil {
31+
static <T> Function<Throwable, T> catchGetDocumentExceptions(Boolean isCatchException) {
32+
return throwable -> {
33+
if (throwable instanceof CompletionException) {
34+
if (throwable.getCause() instanceof ArangoDBException) {
35+
ArangoDBException arangoDBException = (ArangoDBException) throwable.getCause();
36+
37+
// handle Response: 404, Error: 1655 - transaction not found
38+
if (arangoDBException.getErrorNum() != null && arangoDBException.getErrorNum() == 1655) {
39+
throw (CompletionException) throwable;
40+
}
41+
42+
if ((arangoDBException.getResponseCode() != null && (arangoDBException.getResponseCode() == 404 || arangoDBException.getResponseCode() == 304
43+
|| arangoDBException.getResponseCode() == 412)) && isCatchException) {
44+
return null;
45+
}
46+
}
47+
throw (CompletionException) throwable;
48+
}
49+
throw new CompletionException(throwable);
50+
};
51+
}
52+
}

0 commit comments

Comments
 (0)