Skip to content

Commit

Permalink
Fix replace-insert with for ArangoCollection#insertDocuments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpv1989 committed Sep 26, 2018
1 parent 3abfaba commit 58a3751
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
### Fixed

- fixed compatibility of `ArangoCursor#filter` with Java 6
- fixed replace-insert with `DocumentCreateOptions#overwrite(Boolean)` for `ArangoCollection#insertDocuments`

## [5.0.1] - 2018-09-25

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public abstract class InternalArangoCollection<A extends InternalArangoDB<E>, D
private static final String RETURN_NEW = "returnNew";
private static final String NEW = "new";
private static final String RETURN_OLD = "returnOld";
private static final String OVERWRITE = "overwrite";
private static final String OLD = "old";
private static final String SILENT = "silent";

Expand Down Expand Up @@ -111,7 +112,7 @@ protected <T> Request insertDocumentRequest(final T value, final DocumentCreateO
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam("overwrite", params.getOverwrite());
request.putQueryParam(OVERWRITE, params.getOverwrite());
request.setBody(util(Serializer.CUSTOM).serialize(value));
return request;
}
Expand Down Expand Up @@ -149,7 +150,9 @@ protected <T> Request insertDocumentsRequest(final Collection<T> values, final D
final Request request = request(db.name(), RequestType.POST, PATH_API_DOCUMENT, name);
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(OVERWRITE, params.getOverwrite());
request.setBody(util(Serializer.CUSTOM).serialize(values,
new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true)));
return request;
Expand Down Expand Up @@ -186,6 +189,10 @@ public MultiDocumentEntity<DocumentCreateEntity<T>> deserialize(final Response r
if (newDoc.isObject()) {
doc.setNew((T) util(Serializer.CUSTOM).deserialize(newDoc, type));
}
final VPackSlice oldDoc = next.get(OLD);
if (oldDoc.isObject()) {
doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type));
}
docs.add(doc);
documentsAndErrors.add(doc);
}
Expand All @@ -212,7 +219,7 @@ protected Request importDocumentsRequest(final DocumentImportOptions options) {
return request(db.name(), RequestType.POST, PATH_API_IMPORT).putQueryParam(COLLECTION, name)
.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync())
.putQueryParam("fromPrefix", params.getFromPrefix()).putQueryParam("toPrefix", params.getToPrefix())
.putQueryParam("overwrite", params.getOverwrite()).putQueryParam("onDuplicate", params.getOnDuplicate())
.putQueryParam(OVERWRITE, params.getOverwrite()).putQueryParam("onDuplicate", params.getOnDuplicate())
.putQueryParam("complete", params.getComplete()).putQueryParam("details", params.getDetails());
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ public void insertDocumentsOverwrite() {
.insertDocuments(Arrays.asList(doc1, doc2),
new DocumentCreateOptions().overwrite(true).returnOld(true).returnNew(true));
assertThat(repsert, is(notNullValue()));
assertThat(repsert.getDocuments().size(), is(2));
assertThat(repsert.getErrors().size(), is(0));
for (final DocumentCreateEntity<BaseDocument> documentCreateEntity : repsert.getDocuments()) {
assertThat(documentCreateEntity.getRev(), is(not(meta1.getRev())));
assertThat(documentCreateEntity.getRev(), is(not(meta2.getRev())));
Expand Down

0 comments on commit 58a3751

Please sign in to comment.