diff --git a/ChangeLog.md b/ChangeLog.md index 98d3e1de2..20a296012 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +### Fixed + +- fixed bug with multi document operations when using parameter `silent` (issue #241) + ## [5.0.3] - 2018-11-12 ### Fixed diff --git a/docs/Drivers/Java/Reference/Setup.md b/docs/Drivers/Java/Reference/Setup.md index 1dbe1cf5f..f2717e94d 100644 --- a/docs/Drivers/Java/Reference/Setup.md +++ b/docs/Drivers/Java/Reference/Setup.md @@ -10,16 +10,16 @@ ArangoDB arangoDB = new ArangoDB.Builder().build(); The driver is configured with some default values: -property-key | description | default value --------------------------|-----------------------------------------|---------------- -arangodb.hosts | ArangoDB hosts | 127.0.0.1:8529 -arangodb.timeout | connect & request timeout (millisecond) | 0 -arangodb.user | Basic Authentication User | -arangodb.password | Basic Authentication Password | -arangodb.useSsl | use SSL connection | false -arangodb.chunksize | VelocyStream Chunk content-size (bytes) | 30000 -arangodb.connections.max | max number of connections | 1 VST, 20 HTTP -arangodb.protocol | used network protocol | VST +| property-key | description | default value | +| ------------------------ | --------------------------------------- | -------------- | +| arangodb.hosts | ArangoDB hosts | 127.0.0.1:8529 | +| arangodb.timeout | connect & request timeout (millisecond) | 0 | +| arangodb.user | Basic Authentication User | +| arangodb.password | Basic Authentication Password | +| arangodb.useSsl | use SSL connection | false | +| arangodb.chunksize | VelocyStream Chunk content-size (bytes) | 30000 | +| arangodb.connections.max | max number of connections | 1 VST, 20 HTTP | +| arangodb.protocol | used network protocol | VST | To customize the configuration the parameters can be changed in the code... diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 77a08c744..1aee8ace9 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -177,24 +177,26 @@ public MultiDocumentEntity> deserialize(final Response r final Collection errors = new ArrayList(); final Collection documentsAndErrors = new ArrayList(); final VPackSlice body = response.getBody(); - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentCreateEntity doc = util().deserialize(next, DocumentCreateEntity.class); - final VPackSlice newDoc = next.get(NEW); - 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)); + if (body.isArray()) { + for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { + final VPackSlice next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).isTrue()) { + final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentCreateEntity doc = util().deserialize(next, DocumentCreateEntity.class); + final VPackSlice newDoc = next.get(NEW); + 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); } - docs.add(doc); - documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -355,24 +357,26 @@ public MultiDocumentEntity> deserialize(final Response r final Collection errors = new ArrayList(); final Collection documentsAndErrors = new ArrayList(); final VPackSlice body = response.getBody(); - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); - final VPackSlice newDoc = next.get(NEW); - 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)); + if (body.isArray()) { + for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { + final VPackSlice next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).isTrue()) { + final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); + final VPackSlice newDoc = next.get(NEW); + 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); } - docs.add(doc); - documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -464,24 +468,26 @@ public MultiDocumentEntity> deserialize(final Response r final Collection errors = new ArrayList(); final Collection documentsAndErrors = new ArrayList(); final VPackSlice body = response.getBody(); - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); - final VPackSlice newDoc = next.get(NEW); - 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)); + if (body.isArray()) { + for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { + final VPackSlice next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).isTrue()) { + final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); + final VPackSlice newDoc = next.get(NEW); + 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); } - docs.add(doc); - documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -542,20 +548,22 @@ public MultiDocumentEntity> deserialize(final Response r final Collection errors = new ArrayList(); final Collection documentsAndErrors = new ArrayList(); final VPackSlice body = response.getBody(); - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentDeleteEntity doc = util().deserialize(next, DocumentDeleteEntity.class); - final VPackSlice oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type)); + if (body.isArray()) { + for (final Iterator iterator = body.arrayIterator(); iterator.hasNext();) { + final VPackSlice next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).isTrue()) { + final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentDeleteEntity doc = util().deserialize(next, DocumentDeleteEntity.class); + final VPackSlice oldDoc = next.get(OLD); + if (oldDoc.isObject()) { + doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type)); + } + docs.add(doc); + documentsAndErrors.add(doc); } - docs.add(doc); - documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index e5f99deba..5064bdb59 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -206,6 +206,19 @@ public void insertDocumentSilentDontTouchInstance() { assertThat(doc.getKey(), is(key)); } + @Test + public void insertDocumentsSilent() { + if (arangoDB.getRole() != ServerRole.SINGLE) { + return; + } + final MultiDocumentEntity> info = db.collection(COLLECTION_NAME).insertDocuments( + Arrays.asList(new BaseDocument(), new BaseDocument()), new DocumentCreateOptions().silent(true)); + assertThat(info, is(notNullValue())); + assertThat(info.getDocuments().isEmpty(), is(true)); + assertThat(info.getDocumentsAndErrors().isEmpty(), is(true)); + assertThat(info.getErrors().isEmpty(), is(true)); + } + @Test public void getDocument() { final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) @@ -675,6 +688,21 @@ public void updateDocumentSilent() { assertThat(meta.getRev(), is(nullValue())); } + @Test + public void updateDocumentsSilent() { + if (arangoDB.getRole() != ServerRole.SINGLE) { + return; + } + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + .insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = db.collection(COLLECTION_NAME).updateDocuments( + Arrays.asList(new BaseDocument(createResult.getKey())), new DocumentUpdateOptions().silent(true)); + assertThat(info, is(notNullValue())); + assertThat(info.getDocuments().isEmpty(), is(true)); + assertThat(info.getDocumentsAndErrors().isEmpty(), is(true)); + assertThat(info.getErrors().isEmpty(), is(true)); + } + @Test public void replaceDocument() { final BaseDocument doc = new BaseDocument(); @@ -844,6 +872,22 @@ public void replaceDocumentSilentDontTouchInstance() { assertThat(doc.getRevision(), is(revision)); } + @Test + public void replaceDocumentsSilent() { + if (arangoDB.getRole() != ServerRole.SINGLE) { + return; + } + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + .insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = db.collection(COLLECTION_NAME) + .replaceDocuments(Arrays.asList(new BaseDocument(createResult.getKey())), + new DocumentReplaceOptions().silent(true)); + assertThat(info, is(notNullValue())); + assertThat(info.getDocuments().isEmpty(), is(true)); + assertThat(info.getDocumentsAndErrors().isEmpty(), is(true)); + assertThat(info.getErrors().isEmpty(), is(true)); + } + @Test public void deleteDocument() { final BaseDocument doc = new BaseDocument(); @@ -910,6 +954,21 @@ public void deleteDocumentSilent() { assertThat(meta.getRev(), is(nullValue())); } + @Test + public void deleteDocumentsSilent() { + if (arangoDB.getRole() != ServerRole.SINGLE) { + return; + } + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + .insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = db.collection(COLLECTION_NAME).deleteDocuments( + Arrays.asList(createResult.getKey()), BaseDocument.class, new DocumentDeleteOptions().silent(true)); + assertThat(info, is(notNullValue())); + assertThat(info.getDocuments().isEmpty(), is(true)); + assertThat(info.getDocumentsAndErrors().isEmpty(), is(true)); + assertThat(info.getErrors().isEmpty(), is(true)); + } + @Test public void getIndex() { final Collection fields = new ArrayList();