|
32 | 32 | import java.lang.reflect.Type;
|
33 | 33 | import java.util.ArrayList;
|
34 | 34 | import java.util.Collection;
|
35 | | -import java.util.List; |
36 | 35 |
|
37 | 36 | import static com.arangodb.internal.serde.SerdeUtils.constructParametricType;
|
38 | 37 |
|
@@ -109,31 +108,11 @@ private InternalRequest createInsertDocumentRequest(final DocumentCreateOptions
|
109 | 108 | return request;
|
110 | 109 | }
|
111 | 110 |
|
112 | | - // TODO: avoid serialization-deserialization round-trip |
113 | 111 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocumentsResponseDeserializer(Class<T> userDataClass) {
|
114 | 112 | return (response) -> {
|
115 | | - final MultiDocumentEntity<DocumentCreateEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
116 | | - final List<DocumentCreateEntity<T>> docs = new ArrayList<>(); |
117 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
118 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
119 | | - final JsonNode body = getSerde().parse(response.getBody()); |
120 | | - for (final JsonNode next : body) { |
121 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
122 | | - if (isError != null && isError.booleanValue()) { |
123 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
124 | | - errors.add(error); |
125 | | - documentsAndErrors.add(error); |
126 | | - } else { |
127 | | - Type type = constructParametricType(DocumentCreateEntity.class, userDataClass); |
128 | | - final DocumentCreateEntity<T> doc = getSerde().deserialize(next, type); |
129 | | - docs.add(doc); |
130 | | - documentsAndErrors.add(doc); |
131 | | - } |
132 | | - } |
133 | | - multiDocument.setDocuments(docs); |
134 | | - multiDocument.setErrors(errors); |
135 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
136 | | - return multiDocument; |
| 113 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 114 | + constructParametricType(DocumentCreateEntity.class, userDataClass)); |
| 115 | + return getSerde().deserialize(response.getBody(), type); |
137 | 116 | };
|
138 | 117 | }
|
139 | 118 |
|
@@ -185,32 +164,12 @@ protected InternalRequest getDocumentsRequest(final Iterable<String> keys, final
|
185 | 164 | return request;
|
186 | 165 | }
|
187 | 166 |
|
188 | | - // TODO: avoid serialization-deserialization round-trip |
189 | | - protected <T> ResponseDeserializer<MultiDocumentEntity<T>> getDocumentsResponseDeserializer( |
190 | | - final Class<T> type) { |
| 167 | + protected <T> ResponseDeserializer<MultiDocumentEntity<T>> getDocumentsResponseDeserializer(final Class<T> type) { |
191 | 168 | return (response) -> {
|
192 | | - final MultiDocumentEntity<T> multiDocument = new MultiDocumentEntity<>(); |
| 169 | + MultiDocumentEntity<T> multiDocument = getSerde().deserialize(response.getBody(), |
| 170 | + constructParametricType(MultiDocumentEntity.class, type)); |
193 | 171 | boolean potentialDirtyRead = Boolean.parseBoolean(response.getMeta("X-Arango-Potential-Dirty-Read"));
|
194 | 172 | multiDocument.setPotentialDirtyRead(potentialDirtyRead);
|
195 | | - final List<T> docs = new ArrayList<>(); |
196 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
197 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
198 | | - final JsonNode body = getSerde().parse(response.getBody()); |
199 | | - for (final JsonNode next : body) { |
200 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
201 | | - if (isError != null && isError.booleanValue()) { |
202 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
203 | | - errors.add(error); |
204 | | - documentsAndErrors.add(error); |
205 | | - } else { |
206 | | - final T doc = getSerde().deserializeUserData(getSerde().serialize(next), type); |
207 | | - docs.add(doc); |
208 | | - documentsAndErrors.add(doc); |
209 | | - } |
210 | | - } |
211 | | - multiDocument.setDocuments(docs); |
212 | | - multiDocument.setErrors(errors); |
213 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
214 | 173 | return multiDocument;
|
215 | 174 | };
|
216 | 175 | }
|
@@ -249,32 +208,12 @@ private InternalRequest createReplaceDocumentRequest(final DocumentReplaceOption
|
249 | 208 | return request;
|
250 | 209 | }
|
251 | 210 |
|
252 | | - // TODO: avoid serialization-deserialization round-trip |
253 | 211 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocumentsResponseDeserializer(
|
254 | 212 | final Class<T> returnType) {
|
255 | 213 | return (response) -> {
|
256 | | - final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
257 | | - final List<DocumentUpdateEntity<T>> docs = new ArrayList<>(); |
258 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
259 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
260 | | - final JsonNode body = getSerde().parse(response.getBody()); |
261 | | - for (final JsonNode next : body) { |
262 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
263 | | - if (isError != null && isError.booleanValue()) { |
264 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
265 | | - errors.add(error); |
266 | | - documentsAndErrors.add(error); |
267 | | - } else { |
268 | | - Type type = constructParametricType(DocumentUpdateEntity.class, returnType); |
269 | | - final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type); |
270 | | - docs.add(doc); |
271 | | - documentsAndErrors.add(doc); |
272 | | - } |
273 | | - } |
274 | | - multiDocument.setDocuments(docs); |
275 | | - multiDocument.setErrors(errors); |
276 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
277 | | - return multiDocument; |
| 214 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 215 | + constructParametricType(DocumentUpdateEntity.class, returnType)); |
| 216 | + return getSerde().deserialize(response.getBody(), type); |
278 | 217 | };
|
279 | 218 | }
|
280 | 219 |
|
@@ -313,32 +252,12 @@ private InternalRequest createUpdateDocumentRequest(final DocumentUpdateOptions
|
313 | 252 | return request;
|
314 | 253 | }
|
315 | 254 |
|
316 | | - // TODO: avoid serialization-deserialization round-trip |
317 | 255 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> updateDocumentsResponseDeserializer(
|
318 | 256 | final Class<T> returnType) {
|
319 | 257 | return (response) -> {
|
320 | | - final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
321 | | - final List<DocumentUpdateEntity<T>> docs = new ArrayList<>(); |
322 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
323 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
324 | | - final JsonNode body = getSerde().parse(response.getBody()); |
325 | | - for (final JsonNode next : body) { |
326 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
327 | | - if (isError != null && isError.booleanValue()) { |
328 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
329 | | - errors.add(error); |
330 | | - documentsAndErrors.add(error); |
331 | | - } else { |
332 | | - Type type = constructParametricType(DocumentUpdateEntity.class, returnType); |
333 | | - final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type); |
334 | | - docs.add(doc); |
335 | | - documentsAndErrors.add(doc); |
336 | | - } |
337 | | - } |
338 | | - multiDocument.setDocuments(docs); |
339 | | - multiDocument.setErrors(errors); |
340 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
341 | | - return multiDocument; |
| 258 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 259 | + constructParametricType(DocumentUpdateEntity.class, returnType)); |
| 260 | + return getSerde().deserialize(response.getBody(), type); |
342 | 261 | };
|
343 | 262 | }
|
344 | 263 |
|
@@ -371,32 +290,12 @@ private InternalRequest createDeleteDocumentRequest(final DocumentDeleteOptions
|
371 | 290 | return request;
|
372 | 291 | }
|
373 | 292 |
|
374 | | - // TODO: avoid serialization-deserialization round-trip |
375 | 293 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentDeleteEntity<T>>> deleteDocumentsResponseDeserializer(
|
376 | 294 | final Class<T> userDataClass) {
|
377 | 295 | return (response) -> {
|
378 | | - final MultiDocumentEntity<DocumentDeleteEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
379 | | - final List<DocumentDeleteEntity<T>> docs = new ArrayList<>(); |
380 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
381 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
382 | | - final JsonNode body = getSerde().parse(response.getBody()); |
383 | | - for (final JsonNode next : body) { |
384 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
385 | | - if (isError != null && isError.booleanValue()) { |
386 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
387 | | - errors.add(error); |
388 | | - documentsAndErrors.add(error); |
389 | | - } else { |
390 | | - Type type = constructParametricType(DocumentDeleteEntity.class, userDataClass); |
391 | | - final DocumentDeleteEntity<T> doc = getSerde().deserialize(next, type); |
392 | | - docs.add(doc); |
393 | | - documentsAndErrors.add(doc); |
394 | | - } |
395 | | - } |
396 | | - multiDocument.setDocuments(docs); |
397 | | - multiDocument.setErrors(errors); |
398 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
399 | | - return multiDocument; |
| 296 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 297 | + constructParametricType(DocumentDeleteEntity.class, userDataClass)); |
| 298 | + return getSerde().deserialize(response.getBody(), type); |
400 | 299 | };
|
401 | 300 | }
|
402 | 301 |
|
|
0 commit comments