Skip to content

Bugfix multi document operations when using parameter silent #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions docs/Drivers/Java/Reference/Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...

Expand Down
136 changes: 72 additions & 64 deletions src/main/java/com/arangodb/internal/InternalArangoCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,26 @@ public MultiDocumentEntity<DocumentCreateEntity<T>> deserialize(final Response r
final Collection<ErrorEntity> errors = new ArrayList<ErrorEntity>();
final Collection<Object> documentsAndErrors = new ArrayList<Object>();
final VPackSlice body = response.getBody();
for (final Iterator<VPackSlice> 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<T> 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<VPackSlice> 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<T> 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);
Expand Down Expand Up @@ -355,24 +357,26 @@ public MultiDocumentEntity<DocumentUpdateEntity<T>> deserialize(final Response r
final Collection<ErrorEntity> errors = new ArrayList<ErrorEntity>();
final Collection<Object> documentsAndErrors = new ArrayList<Object>();
final VPackSlice body = response.getBody();
for (final Iterator<VPackSlice> 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<T> 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<VPackSlice> 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<T> 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);
Expand Down Expand Up @@ -464,24 +468,26 @@ public MultiDocumentEntity<DocumentUpdateEntity<T>> deserialize(final Response r
final Collection<ErrorEntity> errors = new ArrayList<ErrorEntity>();
final Collection<Object> documentsAndErrors = new ArrayList<Object>();
final VPackSlice body = response.getBody();
for (final Iterator<VPackSlice> 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<T> 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<VPackSlice> 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<T> 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);
Expand Down Expand Up @@ -542,20 +548,22 @@ public MultiDocumentEntity<DocumentDeleteEntity<T>> deserialize(final Response r
final Collection<ErrorEntity> errors = new ArrayList<ErrorEntity>();
final Collection<Object> documentsAndErrors = new ArrayList<Object>();
final VPackSlice body = response.getBody();
for (final Iterator<VPackSlice> 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<T> 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<VPackSlice> 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<T> 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);
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ public void insertDocumentSilentDontTouchInstance() {
assertThat(doc.getKey(), is(key));
}

@Test
public void insertDocumentsSilent() {
if (arangoDB.getRole() != ServerRole.SINGLE) {
return;
}
final MultiDocumentEntity<DocumentCreateEntity<BaseDocument>> 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<BaseDocument> createResult = db.collection(COLLECTION_NAME)
Expand Down Expand Up @@ -675,6 +688,21 @@ public void updateDocumentSilent() {
assertThat(meta.getRev(), is(nullValue()));
}

@Test
public void updateDocumentsSilent() {
if (arangoDB.getRole() != ServerRole.SINGLE) {
return;
}
final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME)
.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> 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();
Expand Down Expand Up @@ -844,6 +872,22 @@ public void replaceDocumentSilentDontTouchInstance() {
assertThat(doc.getRevision(), is(revision));
}

@Test
public void replaceDocumentsSilent() {
if (arangoDB.getRole() != ServerRole.SINGLE) {
return;
}
final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME)
.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> 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();
Expand Down Expand Up @@ -910,6 +954,21 @@ public void deleteDocumentSilent() {
assertThat(meta.getRev(), is(nullValue()));
}

@Test
public void deleteDocumentsSilent() {
if (arangoDB.getRole() != ServerRole.SINGLE) {
return;
}
final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME)
.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentDeleteEntity<BaseDocument>> 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<String> fields = new ArrayList<String>();
Expand Down