3939import com .arangodb .entity .DocumentDeleteEntity ;
4040import com .arangodb .entity .DocumentField ;
4141import com .arangodb .entity .DocumentUpdateEntity ;
42+ import com .arangodb .entity .ErrorEntity ;
4243import com .arangodb .entity .IndexEntity ;
44+ import com .arangodb .entity .MultiDocumentEntity ;
4345import com .arangodb .internal .ArangoDBConstants ;
4446import com .arangodb .model .CollectionPropertiesOptions ;
4547import com .arangodb .model .CollectionRenameOptions ;
@@ -197,7 +199,7 @@ private <T> ResponseDeserializer<DocumentCreateEntity<T>> insertDocumentResponse
197199 * @return information about the documents
198200 * @throws ArangoDBException
199201 */
200- public <T > Collection <DocumentCreateEntity <T >> insertDocuments (final Collection <T > values )
202+ public <T > MultiDocumentEntity <DocumentCreateEntity <T >> insertDocuments (final Collection <T > values )
201203 throws ArangoDBException {
202204 final DocumentCreateOptions params = new DocumentCreateOptions ();
203205 return executeSync (insertDocumentsRequest (values , params ), insertDocumentsResponseDeserializer (values , params ));
@@ -216,7 +218,7 @@ public <T> Collection<DocumentCreateEntity<T>> insertDocuments(final Collection<
216218 * @return information about the documents
217219 * @throws ArangoDBException
218220 */
219- public <T > Collection <DocumentCreateEntity <T >> insertDocuments (
221+ public <T > MultiDocumentEntity <DocumentCreateEntity <T >> insertDocuments (
220222 final Collection <T > values ,
221223 final DocumentCreateOptions options ) throws ArangoDBException {
222224 final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions ());
@@ -233,7 +235,8 @@ public <T> Collection<DocumentCreateEntity<T>> insertDocuments(
233235 * A List of documents (POJO, VPackSlice or String for Json)
234236 * @return information about the documents
235237 */
236- public <T > CompletableFuture <Collection <DocumentCreateEntity <T >>> insertDocumentsAsync (final Collection <T > values ) {
238+ public <T > CompletableFuture <MultiDocumentEntity <DocumentCreateEntity <T >>> insertDocumentsAsync (
239+ final Collection <T > values ) {
237240 final DocumentCreateOptions params = new DocumentCreateOptions ();
238241 return executeAsync (insertDocumentsRequest (values , params ),
239242 insertDocumentsResponseDeserializer (values , params ));
@@ -251,7 +254,7 @@ public <T> CompletableFuture<Collection<DocumentCreateEntity<T>>> insertDocument
251254 * Additional options, can be null
252255 * @return information about the documents
253256 */
254- public <T > CompletableFuture <Collection <DocumentCreateEntity <T >>> insertDocumentsAsync (
257+ public <T > CompletableFuture <MultiDocumentEntity <DocumentCreateEntity <T >>> insertDocumentsAsync (
255258 final Collection <T > values ,
256259 final DocumentCreateOptions options ) {
257260 final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions ());
@@ -269,7 +272,7 @@ private <T> Request insertDocumentsRequest(final Collection<T> values, final Doc
269272 }
270273
271274 @ SuppressWarnings ("unchecked" )
272- private <T > ResponseDeserializer <Collection <DocumentCreateEntity <T >>> insertDocumentsResponseDeserializer (
275+ private <T > ResponseDeserializer <MultiDocumentEntity <DocumentCreateEntity <T >>> insertDocumentsResponseDeserializer (
273276 final Collection <T > values ,
274277 final DocumentCreateOptions params ) {
275278 return response -> {
@@ -280,18 +283,26 @@ private <T> ResponseDeserializer<Collection<DocumentCreateEntity<T>>> insertDocu
280283 type = (Class <T >) first .get ().getClass ();
281284 }
282285 }
286+ final MultiDocumentEntity <DocumentCreateEntity <T >> multiDocument = new MultiDocumentEntity <>();
283287 final Collection <DocumentCreateEntity <T >> docs = new ArrayList <>();
288+ final Collection <ErrorEntity > errors = new ArrayList <>();
284289 final VPackSlice body = response .getBody ().get ();
285290 for (final Iterator <VPackSlice > iterator = body .arrayIterator (); iterator .hasNext ();) {
286291 final VPackSlice next = iterator .next ();
287- final DocumentCreateEntity <T > doc = deserialize (next , DocumentCreateEntity .class );
288- final VPackSlice newDoc = next .get (ArangoDBConstants .NEW );
289- if (newDoc .isObject ()) {
290- doc .setNew (deserialize (newDoc , type ));
292+ if (next .get (ArangoDBConstants .ERROR ).isTrue ()) {
293+ errors .add (deserialize (next , ErrorEntity .class ));
294+ } else {
295+ final DocumentCreateEntity <T > doc = deserialize (next , DocumentCreateEntity .class );
296+ final VPackSlice newDoc = next .get (ArangoDBConstants .NEW );
297+ if (newDoc .isObject ()) {
298+ doc .setNew (deserialize (newDoc , type ));
299+ }
300+ docs .add (doc );
291301 }
292- docs .add (doc );
293302 }
294- return docs ;
303+ multiDocument .setDocuments (docs );
304+ multiDocument .setErrors (errors );
305+ return multiDocument ;
295306 };
296307 }
297308
@@ -522,7 +533,7 @@ private <T> ResponseDeserializer<DocumentUpdateEntity<T>> replaceDocumentRespons
522533 * @return information about the documents
523534 * @throws ArangoDBException
524535 */
525- public <T > Collection <DocumentUpdateEntity <T >> replaceDocuments (final Collection <T > values )
536+ public <T > MultiDocumentEntity <DocumentUpdateEntity <T >> replaceDocuments (final Collection <T > values )
526537 throws ArangoDBException {
527538 final DocumentReplaceOptions params = new DocumentReplaceOptions ();
528539 return executeSync (replaceDocumentsRequest (values , params ),
@@ -542,7 +553,7 @@ public <T> Collection<DocumentUpdateEntity<T>> replaceDocuments(final Collection
542553 * @return information about the documents
543554 * @throws ArangoDBException
544555 */
545- public <T > Collection <DocumentUpdateEntity <T >> replaceDocuments (
556+ public <T > MultiDocumentEntity <DocumentUpdateEntity <T >> replaceDocuments (
546557 final Collection <T > values ,
547558 final DocumentReplaceOptions options ) throws ArangoDBException {
548559 final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions ());
@@ -560,7 +571,7 @@ public <T> Collection<DocumentUpdateEntity<T>> replaceDocuments(
560571 * A List of documents (POJO, VPackSlice or String for Json)
561572 * @return information about the documents
562573 */
563- public <T > CompletableFuture <Collection <DocumentUpdateEntity <T >>> replaceDocumentsAsync (
574+ public <T > CompletableFuture <MultiDocumentEntity <DocumentUpdateEntity <T >>> replaceDocumentsAsync (
564575 final Collection <T > values ) {
565576 final DocumentReplaceOptions params = new DocumentReplaceOptions ();
566577 return executeAsync (replaceDocumentsRequest (values , params ),
@@ -579,7 +590,7 @@ public <T> CompletableFuture<Collection<DocumentUpdateEntity<T>>> replaceDocumen
579590 * Additional options, can be null
580591 * @return information about the documents
581592 */
582- public <T > CompletableFuture <Collection <DocumentUpdateEntity <T >>> replaceDocumentsAsync (
593+ public <T > CompletableFuture <MultiDocumentEntity <DocumentUpdateEntity <T >>> replaceDocumentsAsync (
583594 final Collection <T > values ,
584595 final DocumentReplaceOptions options ) {
585596 final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions ());
@@ -600,7 +611,7 @@ private <T> Request replaceDocumentsRequest(final Collection<T> values, final Do
600611 }
601612
602613 @ SuppressWarnings ("unchecked" )
603- private <T > ResponseDeserializer <Collection <DocumentUpdateEntity <T >>> replaceDocumentsResponseDeserializer (
614+ private <T > ResponseDeserializer <MultiDocumentEntity <DocumentUpdateEntity <T >>> replaceDocumentsResponseDeserializer (
604615 final Collection <T > values ,
605616 final DocumentReplaceOptions params ) {
606617 return response -> {
@@ -612,22 +623,30 @@ private <T> ResponseDeserializer<Collection<DocumentUpdateEntity<T>>> replaceDoc
612623 type = (Class <T >) first .get ().getClass ();
613624 }
614625 }
626+ final MultiDocumentEntity <DocumentUpdateEntity <T >> multiDocument = new MultiDocumentEntity <>();
615627 final Collection <DocumentUpdateEntity <T >> docs = new ArrayList <>();
628+ final Collection <ErrorEntity > errors = new ArrayList <>();
616629 final VPackSlice body = response .getBody ().get ();
617630 for (final Iterator <VPackSlice > iterator = body .arrayIterator (); iterator .hasNext ();) {
618631 final VPackSlice next = iterator .next ();
619- final DocumentUpdateEntity <T > doc = deserialize (next , DocumentUpdateEntity .class );
620- final VPackSlice newDoc = next .get (ArangoDBConstants .NEW );
621- if (newDoc .isObject ()) {
622- doc .setNew (deserialize (newDoc , type ));
623- }
624- final VPackSlice oldDoc = next .get (ArangoDBConstants .OLD );
625- if (oldDoc .isObject ()) {
626- doc .setOld (deserialize (oldDoc , type ));
632+ if (next .get (ArangoDBConstants .ERROR ).isTrue ()) {
633+ errors .add (deserialize (next , ErrorEntity .class ));
634+ } else {
635+ final DocumentUpdateEntity <T > doc = deserialize (next , DocumentUpdateEntity .class );
636+ final VPackSlice newDoc = next .get (ArangoDBConstants .NEW );
637+ if (newDoc .isObject ()) {
638+ doc .setNew (deserialize (newDoc , type ));
639+ }
640+ final VPackSlice oldDoc = next .get (ArangoDBConstants .OLD );
641+ if (oldDoc .isObject ()) {
642+ doc .setOld (deserialize (oldDoc , type ));
643+ }
644+ docs .add (doc );
627645 }
628- docs .add (doc );
629646 }
630- return docs ;
647+ multiDocument .setDocuments (docs );
648+ multiDocument .setErrors (errors );
649+ return multiDocument ;
631650 };
632651 }
633652
@@ -758,7 +777,7 @@ private <T> ResponseDeserializer<DocumentUpdateEntity<T>> updateDocumentResponse
758777 * @return information about the documents
759778 * @throws ArangoDBException
760779 */
761- public <T > Collection <DocumentUpdateEntity <T >> updateDocuments (final Collection <T > values )
780+ public <T > MultiDocumentEntity <DocumentUpdateEntity <T >> updateDocuments (final Collection <T > values )
762781 throws ArangoDBException {
763782 final DocumentUpdateOptions params = new DocumentUpdateOptions ();
764783 return executeSync (updateDocumentsRequest (values , params ), updateDocumentsResponseDeserializer (values , params ));
@@ -779,7 +798,7 @@ public <T> Collection<DocumentUpdateEntity<T>> updateDocuments(final Collection<
779798 * @return information about the documents
780799 * @throws ArangoDBException
781800 */
782- public <T > Collection <DocumentUpdateEntity <T >> updateDocuments (
801+ public <T > MultiDocumentEntity <DocumentUpdateEntity <T >> updateDocuments (
783802 final Collection <T > values ,
784803 final DocumentUpdateOptions options ) throws ArangoDBException {
785804 final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions ());
@@ -798,7 +817,8 @@ public <T> Collection<DocumentUpdateEntity<T>> updateDocuments(
798817 * A list of documents (POJO, VPackSlice or String for Json)
799818 * @return information about the documents
800819 */
801- public <T > CompletableFuture <Collection <DocumentUpdateEntity <T >>> updateDocumentsAsync (final Collection <T > values ) {
820+ public <T > CompletableFuture <MultiDocumentEntity <DocumentUpdateEntity <T >>> updateDocumentsAsync (
821+ final Collection <T > values ) {
802822 final DocumentUpdateOptions params = new DocumentUpdateOptions ();
803823 return executeAsync (updateDocumentsRequest (values , params ),
804824 updateDocumentsResponseDeserializer (values , params ));
@@ -818,7 +838,7 @@ public <T> CompletableFuture<Collection<DocumentUpdateEntity<T>>> updateDocument
818838 * Additional options, can be null
819839 * @return information about the documents
820840 */
821- public <T > CompletableFuture <Collection <DocumentUpdateEntity <T >>> updateDocumentsAsync (
841+ public <T > CompletableFuture <MultiDocumentEntity <DocumentUpdateEntity <T >>> updateDocumentsAsync (
822842 final Collection <T > values ,
823843 final DocumentUpdateOptions options ) {
824844 final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions ());
@@ -842,7 +862,7 @@ private <T> Request updateDocumentsRequest(final Collection<T> values, final Doc
842862 }
843863
844864 @ SuppressWarnings ("unchecked" )
845- private <T > ResponseDeserializer <Collection <DocumentUpdateEntity <T >>> updateDocumentsResponseDeserializer (
865+ private <T > ResponseDeserializer <MultiDocumentEntity <DocumentUpdateEntity <T >>> updateDocumentsResponseDeserializer (
846866 final Collection <T > values ,
847867 final DocumentUpdateOptions params ) {
848868 return response -> {
@@ -854,22 +874,30 @@ private <T> ResponseDeserializer<Collection<DocumentUpdateEntity<T>>> updateDocu
854874 type = (Class <T >) first .get ().getClass ();
855875 }
856876 }
877+ final MultiDocumentEntity <DocumentUpdateEntity <T >> multiDocument = new MultiDocumentEntity <>();
857878 final Collection <DocumentUpdateEntity <T >> docs = new ArrayList <>();
879+ final Collection <ErrorEntity > errors = new ArrayList <>();
858880 final VPackSlice body = response .getBody ().get ();
859881 for (final Iterator <VPackSlice > iterator = body .arrayIterator (); iterator .hasNext ();) {
860882 final VPackSlice next = iterator .next ();
861- final DocumentUpdateEntity <T > doc = deserialize (next , DocumentUpdateEntity .class );
862- final VPackSlice newDoc = next .get (ArangoDBConstants .NEW );
863- if (newDoc .isObject ()) {
864- doc .setNew (deserialize (newDoc , type ));
865- }
866- final VPackSlice oldDoc = next .get (ArangoDBConstants .OLD );
867- if (oldDoc .isObject ()) {
868- doc .setOld (deserialize (oldDoc , type ));
883+ if (next .get (ArangoDBConstants .ERROR ).isTrue ()) {
884+ errors .add (deserialize (next , ErrorEntity .class ));
885+ } else {
886+ final DocumentUpdateEntity <T > doc = deserialize (next , DocumentUpdateEntity .class );
887+ final VPackSlice newDoc = next .get (ArangoDBConstants .NEW );
888+ if (newDoc .isObject ()) {
889+ doc .setNew (deserialize (newDoc , type ));
890+ }
891+ final VPackSlice oldDoc = next .get (ArangoDBConstants .OLD );
892+ if (oldDoc .isObject ()) {
893+ doc .setOld (deserialize (oldDoc , type ));
894+ }
895+ docs .add (doc );
869896 }
870- docs .add (doc );
871897 }
872- return docs ;
898+ multiDocument .setDocuments (docs );
899+ multiDocument .setErrors (errors );
900+ return multiDocument ;
873901 };
874902 }
875903
@@ -990,7 +1018,7 @@ private <T> ResponseDeserializer<DocumentDeleteEntity<T>> deleteDocumentResponse
9901018 * @return information about the documents
9911019 * @throws ArangoDBException
9921020 */
993- public Collection <DocumentDeleteEntity <Void >> deleteDocuments (final Collection <String > keys )
1021+ public MultiDocumentEntity <DocumentDeleteEntity <Void >> deleteDocuments (final Collection <String > keys )
9941022 throws ArangoDBException {
9951023 return executeSync (deleteDocumentsRequest (keys , new DocumentDeleteOptions ()),
9961024 deleteDocumentsResponseDeserializer (Void .class ));
@@ -1012,7 +1040,7 @@ public Collection<DocumentDeleteEntity<Void>> deleteDocuments(final Collection<S
10121040 * @return information about the documents
10131041 * @throws ArangoDBException
10141042 */
1015- public <T > Collection <DocumentDeleteEntity <T >> deleteDocuments (
1043+ public <T > MultiDocumentEntity <DocumentDeleteEntity <T >> deleteDocuments (
10161044 final Collection <String > keys ,
10171045 final Class <T > type ,
10181046 final DocumentDeleteOptions options ) throws ArangoDBException {
@@ -1032,7 +1060,7 @@ public <T> Collection<DocumentDeleteEntity<T>> deleteDocuments(
10321060 * options.returnOld is set to true, otherwise can be null.
10331061 * @return information about the documents
10341062 */
1035- public CompletableFuture <Collection <DocumentDeleteEntity <Void >>> deleteDocumentsAsync (
1063+ public CompletableFuture <MultiDocumentEntity <DocumentDeleteEntity <Void >>> deleteDocumentsAsync (
10361064 final Collection <String > keys ) {
10371065 return executeAsync (deleteDocumentsRequest (keys , new DocumentDeleteOptions ()),
10381066 deleteDocumentsResponseDeserializer (Void .class ));
@@ -1053,7 +1081,7 @@ public CompletableFuture<Collection<DocumentDeleteEntity<Void>>> deleteDocuments
10531081 * Additional options, can be null
10541082 * @return information about the documents
10551083 */
1056- public <T > CompletableFuture <Collection <DocumentDeleteEntity <T >>> deleteDocumentsAsync (
1084+ public <T > CompletableFuture <MultiDocumentEntity <DocumentDeleteEntity <T >>> deleteDocumentsAsync (
10571085 final Collection <String > keys ,
10581086 final Class <T > type ,
10591087 final DocumentDeleteOptions options ) {
@@ -1070,21 +1098,29 @@ private Request deleteDocumentsRequest(final Collection<String> keys, final Docu
10701098 return request ;
10711099 }
10721100
1073- private <T > ResponseDeserializer <Collection <DocumentDeleteEntity <T >>> deleteDocumentsResponseDeserializer (
1101+ private <T > ResponseDeserializer <MultiDocumentEntity <DocumentDeleteEntity <T >>> deleteDocumentsResponseDeserializer (
10741102 final Class <T > type ) {
10751103 return response -> {
1104+ final MultiDocumentEntity <DocumentDeleteEntity <T >> multiDocument = new MultiDocumentEntity <>();
10761105 final Collection <DocumentDeleteEntity <T >> docs = new ArrayList <>();
1106+ final Collection <ErrorEntity > errors = new ArrayList <>();
10771107 final VPackSlice body = response .getBody ().get ();
10781108 for (final Iterator <VPackSlice > iterator = body .arrayIterator (); iterator .hasNext ();) {
10791109 final VPackSlice next = iterator .next ();
1080- final DocumentDeleteEntity <T > doc = deserialize (next , DocumentDeleteEntity .class );
1081- final VPackSlice oldDoc = next .get (ArangoDBConstants .OLD );
1082- if (oldDoc .isObject ()) {
1083- doc .setOld (deserialize (oldDoc , type ));
1110+ if (next .get (ArangoDBConstants .ERROR ).isTrue ()) {
1111+ errors .add (deserialize (next , ErrorEntity .class ));
1112+ } else {
1113+ final DocumentDeleteEntity <T > doc = deserialize (next , DocumentDeleteEntity .class );
1114+ final VPackSlice oldDoc = next .get (ArangoDBConstants .OLD );
1115+ if (oldDoc .isObject ()) {
1116+ doc .setOld (deserialize (oldDoc , type ));
1117+ }
1118+ docs .add (doc );
10841119 }
1085- docs .add (doc );
10861120 }
1087- return docs ;
1121+ multiDocument .setDocuments (docs );
1122+ multiDocument .setErrors (errors );
1123+ return multiDocument ;
10881124 };
10891125 }
10901126
0 commit comments