Skip to content

Commit 58a3751

Browse files
author
mpv1989
committed
Fix replace-insert with for ArangoCollection#insertDocuments
1 parent 3abfaba commit 58a3751

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
99
### Fixed
1010

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

1314
## [5.0.1] - 2018-09-25
1415

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public abstract class InternalArangoCollection<A extends InternalArangoDB<E>, D
8484
private static final String RETURN_NEW = "returnNew";
8585
private static final String NEW = "new";
8686
private static final String RETURN_OLD = "returnOld";
87+
private static final String OVERWRITE = "overwrite";
8788
private static final String OLD = "old";
8889
private static final String SILENT = "silent";
8990

@@ -111,7 +112,7 @@ protected <T> Request insertDocumentRequest(final T value, final DocumentCreateO
111112
request.putQueryParam(RETURN_NEW, params.getReturnNew());
112113
request.putQueryParam(RETURN_OLD, params.getReturnOld());
113114
request.putQueryParam(SILENT, params.getSilent());
114-
request.putQueryParam("overwrite", params.getOverwrite());
115+
request.putQueryParam(OVERWRITE, params.getOverwrite());
115116
request.setBody(util(Serializer.CUSTOM).serialize(value));
116117
return request;
117118
}
@@ -149,7 +150,9 @@ protected <T> Request insertDocumentsRequest(final Collection<T> values, final D
149150
final Request request = request(db.name(), RequestType.POST, PATH_API_DOCUMENT, name);
150151
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
151152
request.putQueryParam(RETURN_NEW, params.getReturnNew());
153+
request.putQueryParam(RETURN_OLD, params.getReturnOld());
152154
request.putQueryParam(SILENT, params.getSilent());
155+
request.putQueryParam(OVERWRITE, params.getOverwrite());
153156
request.setBody(util(Serializer.CUSTOM).serialize(values,
154157
new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true)));
155158
return request;
@@ -186,6 +189,10 @@ public MultiDocumentEntity<DocumentCreateEntity<T>> deserialize(final Response r
186189
if (newDoc.isObject()) {
187190
doc.setNew((T) util(Serializer.CUSTOM).deserialize(newDoc, type));
188191
}
192+
final VPackSlice oldDoc = next.get(OLD);
193+
if (oldDoc.isObject()) {
194+
doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type));
195+
}
189196
docs.add(doc);
190197
documentsAndErrors.add(doc);
191198
}
@@ -212,7 +219,7 @@ protected Request importDocumentsRequest(final DocumentImportOptions options) {
212219
return request(db.name(), RequestType.POST, PATH_API_IMPORT).putQueryParam(COLLECTION, name)
213220
.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync())
214221
.putQueryParam("fromPrefix", params.getFromPrefix()).putQueryParam("toPrefix", params.getToPrefix())
215-
.putQueryParam("overwrite", params.getOverwrite()).putQueryParam("onDuplicate", params.getOnDuplicate())
222+
.putQueryParam(OVERWRITE, params.getOverwrite()).putQueryParam("onDuplicate", params.getOnDuplicate())
216223
.putQueryParam("complete", params.getComplete()).putQueryParam("details", params.getDetails());
217224
}
218225

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,8 @@ public void insertDocumentsOverwrite() {
12181218
.insertDocuments(Arrays.asList(doc1, doc2),
12191219
new DocumentCreateOptions().overwrite(true).returnOld(true).returnNew(true));
12201220
assertThat(repsert, is(notNullValue()));
1221+
assertThat(repsert.getDocuments().size(), is(2));
1222+
assertThat(repsert.getErrors().size(), is(0));
12211223
for (final DocumentCreateEntity<BaseDocument> documentCreateEntity : repsert.getDocuments()) {
12221224
assertThat(documentCreateEntity.getRev(), is(not(meta1.getRev())));
12231225
assertThat(documentCreateEntity.getRev(), is(not(meta2.getRev())));

0 commit comments

Comments
 (0)