Skip to content

Commit 89ef22a

Browse files
committed
typed ArangoCollection#replaceDocuments
1 parent e5a860c commit 89ef22a

8 files changed

+57
-53
lines changed

src/main/java/com/arangodb/ArangoCollection.java

+16-28
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ public interface ArangoCollection extends ArangoSerdeAccessor {
9393
/**
9494
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
9595
* _key is given, a new unique _key is generated automatically.
96-
* <p>
97-
* Limitations:
98-
* - the fields having {@code null} value are always removed during serialization
9996
*
10097
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
10198
* @return information about the documents
@@ -108,9 +105,6 @@ public interface ArangoCollection extends ArangoSerdeAccessor {
108105
/**
109106
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
110107
* _key is given, a new unique _key is generated automatically.
111-
* <p>
112-
* Limitations:
113-
* - the fields having {@code null} value are always removed during serialization
114108
*
115109
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
116110
* @param options Additional options, can be null
@@ -125,9 +119,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
125119
/**
126120
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
127121
* _key is given, a new unique _key is generated automatically.
128-
* <p>
129-
* Limitations:
130-
* - the fields having {@code null} value are always removed during serialization
131122
*
132123
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
133124
* @param options Additional options, can be null
@@ -142,9 +133,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
142133

143134
/**
144135
* Bulk imports the given values into the collection.
145-
* <p>
146-
* Limitations:
147-
* - the fields having {@code null} value are always removed during serialization
148136
*
149137
* @param values a list of Objects that will be stored as documents
150138
* @return information about the import
@@ -154,9 +142,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
154142

155143
/**
156144
* Bulk imports the given values into the collection.
157-
* <p>
158-
* Limitations:
159-
* - the fields having {@code null} value are always removed during serialization
160145
*
161146
* @param values a list of Objects that will be stored as documents
162147
* @param options Additional options, can be null
@@ -167,9 +152,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
167152

168153
/**
169154
* Bulk imports the given values into the collection.
170-
* <p>
171-
* Limitations:
172-
* - the fields having {@code null} value are always removed during serialization
173155
*
174156
* @param values JSON-encoded array of objects that will be stored as documents
175157
* @return information about the import
@@ -179,9 +161,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
179161

180162
/**
181163
* Bulk imports the given values into the collection.
182-
* <p>
183-
* Limitations:
184-
* - the fields having {@code null} value are always removed during serialization
185164
*
186165
* @param values JSON-encoded array of objects that will be stored as documents
187166
* @param options Additional options, can be null
@@ -284,24 +263,18 @@ <T> DocumentUpdateEntity<T> replaceDocument(String key, T value, DocumentReplace
284263
/**
285264
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
286265
* specified by the _key attributes in the documents in values.
287-
* <p>
288-
* Limitations:
289-
* - the fields having {@code null} value are always removed during serialization
290266
*
291267
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
292268
* @return information about the documents
293269
* @throws ArangoDBException
294270
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-documents">API
295271
* Documentation</a>
296272
*/
297-
<T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(Collection<T> values) throws ArangoDBException;
273+
MultiDocumentEntity<DocumentUpdateEntity<Void>> replaceDocuments(Collection<?> values) throws ArangoDBException;
298274

299275
/**
300276
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
301277
* specified by the _key attributes in the documents in values.
302-
* <p>
303-
* Limitations:
304-
* - the fields having {@code null} value are always removed during serialization
305278
*
306279
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
307280
* @param options Additional options, can be null
@@ -313,6 +286,21 @@ <T> DocumentUpdateEntity<T> replaceDocument(String key, T value, DocumentReplace
313286
<T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(
314287
Collection<T> values, DocumentReplaceOptions options) throws ArangoDBException;
315288

289+
/**
290+
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
291+
* specified by the _key attributes in the documents in values.
292+
*
293+
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
294+
* @param options Additional options, can be null
295+
* @param type Deserialization target type for the returned documents.
296+
* @return information about the documents
297+
* @throws ArangoDBException
298+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-documents">API
299+
* Documentation</a>
300+
*/
301+
<T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(
302+
Collection<T> values, DocumentReplaceOptions options, Class<T> type) throws ArangoDBException;
303+
316304
/**
317305
* Partially updates the document identified by document-key. The value must contain a document with the attributes
318306
* to patch (the patch document). All attributes from the patch document will be added to the existing document if

src/main/java/com/arangodb/async/ArangoCollectionAsync.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ <T> CompletableFuture<DocumentUpdateEntity<T>> replaceDocument(
266266
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-documents">API
267267
* Documentation</a>
268268
*/
269-
<T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocuments(final Collection<T> values);
269+
CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<Void>>> replaceDocuments(final Collection<?> values);
270270

271271
/**
272272
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
@@ -282,6 +282,22 @@ <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocum
282282
final Collection<T> values,
283283
final DocumentReplaceOptions options);
284284

285+
/**
286+
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
287+
* specified by the _key attributes in the documents in values.
288+
*
289+
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
290+
* @param options Additional options, can be null
291+
* @param type Deserialization target type for the returned documents.
292+
* @return information about the documents
293+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-documents">API
294+
* Documentation</a>
295+
*/
296+
<T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocuments(
297+
final Collection<T> values,
298+
final DocumentReplaceOptions options,
299+
final Class<T> type);
300+
285301
/**
286302
* Partially updates the document identified by document-key. The value must contain a document with the attributes
287303
* to patch (the patch document). All attributes from the patch document will be added to the existing document if

src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,22 @@ public <T> CompletableFuture<DocumentUpdateEntity<T>> replaceDocument(String key
165165
}
166166

167167
@Override
168-
public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocuments(
169-
final Collection<T> values) {
170-
final DocumentReplaceOptions params = new DocumentReplaceOptions();
171-
return executor.execute(replaceDocumentsRequest(values, params),
172-
replaceDocumentsResponseDeserializer(values));
168+
public CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<Void>>> replaceDocuments(
169+
final Collection<?> values) {
170+
return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), replaceDocumentsResponseDeserializer(Void.class));
173171
}
174172

175173
@Override
174+
@SuppressWarnings("unchecked")
176175
public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocuments(
177176
final Collection<T> values,
178177
final DocumentReplaceOptions options) {
179-
final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions());
180-
return executor.execute(replaceDocumentsRequest(values, params),
181-
replaceDocumentsResponseDeserializer(values));
178+
return replaceDocuments(values, options, (Class<T>) getCollectionContentClass(values));
179+
}
180+
181+
@Override
182+
public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocuments(Collection<T> values, DocumentReplaceOptions options, Class<T> type) {
183+
return executor.execute(replaceDocumentsRequest(values, options), replaceDocumentsResponseDeserializer(type));
182184
}
183185

184186
@Override

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,21 @@ public <T> DocumentUpdateEntity<T> replaceDocument(String key, T value, Document
168168
}
169169

170170
@Override
171-
public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(final Collection<T> values)
171+
public MultiDocumentEntity<DocumentUpdateEntity<Void>> replaceDocuments(final Collection<?> values)
172172
throws ArangoDBException {
173-
return replaceDocuments(values, new DocumentReplaceOptions());
173+
return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), replaceDocumentsResponseDeserializer(Void.class));
174174
}
175175

176176
@Override
177+
@SuppressWarnings("unchecked")
177178
public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(
178179
final Collection<T> values, final DocumentReplaceOptions options) throws ArangoDBException {
179-
final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions());
180-
return executor
181-
.execute(replaceDocumentsRequest(values, params), replaceDocumentsResponseDeserializer(values));
180+
return replaceDocuments(values, options, (Class<T>) getCollectionContentClass(values));
181+
}
182+
183+
@Override
184+
public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(Collection<T> values, DocumentReplaceOptions options, Class<T> type) throws ArangoDBException {
185+
return executor.execute(replaceDocumentsRequest(values, options), replaceDocumentsResponseDeserializer(type));
182186
}
183187

184188
@Override

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,8 @@ protected <T> Request replaceDocumentsRequest(final Collection<T> values, final
241241
}
242242

243243
protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocumentsResponseDeserializer(
244-
final Collection<T> values) {
244+
final Class<T> returnType) {
245245
return response -> {
246-
Class<?> userDataClass = getCollectionContentClass(values);
247246
final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>();
248247
final Collection<DocumentUpdateEntity<T>> docs = new ArrayList<>();
249248
final Collection<ErrorEntity> errors = new ArrayList<>();
@@ -256,7 +255,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>>
256255
errors.add(error);
257256
documentsAndErrors.add(error);
258257
} else {
259-
Type type = constructParametricType(DocumentUpdateEntity.class, userDataClass);
258+
Type type = constructParametricType(DocumentUpdateEntity.class, returnType);
260259
final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type);
261260
docs.add(doc);
262261
documentsAndErrors.add(doc);

src/main/java/com/arangodb/model/DocumentCreateOptions.java

-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ public OverwriteMode getOverwriteMode() {
8686
}
8787

8888
/**
89-
* Limitations:
90-
* - {@code keepNull} parameter is not supported
91-
* - the fields having {@code null} value are always removed during serialization
92-
* Therefore in case of {@link OverwriteMode#update}, existing attributes cannot be removed.
93-
*
9489
* @param overwriteMode This parameter can be set to replace or update. If given it sets implicitly the overwrite
9590
* flag. In case it is set to update, the replace-insert becomes an update-insert. Otherwise
9691
* this option follows the rules of the overwrite parameter.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ void replaceDocuments(ArangoCollection collection) {
25732573
i.addAttribute("a", "test");
25742574
updatedValues.add(i);
25752575
}
2576-
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> updateResult = collection.replaceDocuments(updatedValues, null);
2576+
final MultiDocumentEntity<?> updateResult = collection.replaceDocuments(updatedValues);
25772577
assertThat(updateResult.getDocuments()).hasSize(2);
25782578
assertThat(updateResult.getErrors()).isEmpty();
25792579
}
@@ -2636,7 +2636,7 @@ void replaceDocumentsJson(ArangoCollection collection) {
26362636
final Collection<RawJson> updatedValues = new ArrayList<>();
26372637
updatedValues.add(RawJson.of("{\"_key\":\"1\", \"foo\":\"bar\"}"));
26382638
updatedValues.add(RawJson.of("{\"_key\":\"2\", \"foo\":\"bar\"}"));
2639-
final MultiDocumentEntity<DocumentUpdateEntity<RawJson>> updateResult = collection.replaceDocuments(updatedValues);
2639+
final MultiDocumentEntity<?> updateResult = collection.replaceDocuments(updatedValues);
26402640
assertThat(updateResult.getDocuments()).hasSize(2);
26412641
assertThat(updateResult.getErrors()).isEmpty();
26422642
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ void replaceDocuments() throws InterruptedException, ExecutionException {
21572157
i.addAttribute("a", "test");
21582158
updatedValues.add(i);
21592159
}
2160-
db.collection(COLLECTION_NAME).replaceDocuments(updatedValues, null)
2160+
db.collection(COLLECTION_NAME).replaceDocuments(updatedValues)
21612161
.whenComplete((updateResult, ex) -> {
21622162
assertThat(updateResult.getDocuments().size()).isEqualTo(2);
21632163
assertThat(updateResult.getErrors().size()).isEqualTo(0);

0 commit comments

Comments
 (0)