Skip to content

Commit 3bca4a7

Browse files
authored
[DE-313] Allow specifying the return type in CRUD document operations (#448)
* typed ArangoCollection#insertDocument * typed ArangoCollection#updateDocument * typed ArangoCollection#replaceDocument * typed ArangoCollection#insertDocuments * typed ArangoCollection#deleteDocument * typed ArangoCollection#updateDocuments * typed ArangoCollection#replaceDocuments * typed ArangoCollection#deleteDocuments
1 parent 0e45426 commit 3bca4a7

17 files changed

+678
-267
lines changed

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

+95-32
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor {
6161
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#create-document">API
6262
* Documentation</a>
6363
*/
64-
<T> DocumentCreateEntity<T> insertDocument(T value) throws ArangoDBException;
64+
DocumentCreateEntity<Void> insertDocument(Object value) throws ArangoDBException;
6565

6666
/**
6767
* Creates a new document from the given document, unless there is already a document with the _key given. If no
@@ -76,27 +76,35 @@ public interface ArangoCollection extends ArangoSerdeAccessor {
7676
*/
7777
<T> DocumentCreateEntity<T> insertDocument(T value, DocumentCreateOptions options) throws ArangoDBException;
7878

79+
/**
80+
* Creates a new document from the given document, unless there is already a document with the _key given. If no
81+
* _key is given, a new unique _key is generated automatically.
82+
*
83+
* @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
84+
* @param options Additional options, can be null
85+
* @param type Deserialization target type for the returned documents.
86+
* @return information about the document
87+
* @throws ArangoDBException
88+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#create-document">API
89+
* Documentation</a>
90+
*/
91+
<T> DocumentCreateEntity<T> insertDocument(T value, DocumentCreateOptions options, Class<T> type) throws ArangoDBException;
92+
7993
/**
8094
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
8195
* _key is given, a new unique _key is generated automatically.
82-
* <p>
83-
* Limitations:
84-
* - the fields having {@code null} value are always removed during serialization
8596
*
8697
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
8798
* @return information about the documents
8899
* @throws ArangoDBException
89100
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#create-document">API
90101
* Documentation</a>
91102
*/
92-
<T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(Collection<T> values) throws ArangoDBException;
103+
MultiDocumentEntity<DocumentCreateEntity<Void>> insertDocuments(Collection<?> values) throws ArangoDBException;
93104

94105
/**
95106
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
96107
* _key is given, a new unique _key is generated automatically.
97-
* <p>
98-
* Limitations:
99-
* - the fields having {@code null} value are always removed during serialization
100108
*
101109
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
102110
* @param options Additional options, can be null
@@ -108,11 +116,23 @@ public interface ArangoCollection extends ArangoSerdeAccessor {
108116
<T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
109117
Collection<T> values, DocumentCreateOptions options) throws ArangoDBException;
110118

119+
/**
120+
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
121+
* _key is given, a new unique _key is generated automatically.
122+
*
123+
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
124+
* @param options Additional options, can be null
125+
* @param type Deserialization target type for the returned documents.
126+
* @return information about the documents
127+
* @throws ArangoDBException
128+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#create-document">API
129+
* Documentation</a>
130+
*/
131+
<T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
132+
Collection<T> values, DocumentCreateOptions options, Class<T> type) throws ArangoDBException;
133+
111134
/**
112135
* Bulk imports the given values into the collection.
113-
* <p>
114-
* Limitations:
115-
* - the fields having {@code null} value are always removed during serialization
116136
*
117137
* @param values a list of Objects that will be stored as documents
118138
* @return information about the import
@@ -122,9 +142,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
122142

123143
/**
124144
* Bulk imports the given values into the collection.
125-
* <p>
126-
* Limitations:
127-
* - the fields having {@code null} value are always removed during serialization
128145
*
129146
* @param values a list of Objects that will be stored as documents
130147
* @param options Additional options, can be null
@@ -135,9 +152,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
135152

136153
/**
137154
* Bulk imports the given values into the collection.
138-
* <p>
139-
* Limitations:
140-
* - the fields having {@code null} value are always removed during serialization
141155
*
142156
* @param values JSON-encoded array of objects that will be stored as documents
143157
* @return information about the import
@@ -147,9 +161,6 @@ <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(
147161

148162
/**
149163
* Bulk imports the given values into the collection.
150-
* <p>
151-
* Limitations:
152-
* - the fields having {@code null} value are always removed during serialization
153164
*
154165
* @param values JSON-encoded array of objects that will be stored as documents
155166
* @param options Additional options, can be null
@@ -216,7 +227,7 @@ <T> MultiDocumentEntity<T> getDocuments(Collection<String> keys, Class<T> type,
216227
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-document">API
217228
* Documentation</a>
218229
*/
219-
<T> DocumentUpdateEntity<T> replaceDocument(String key, T value) throws ArangoDBException;
230+
DocumentUpdateEntity<Void> replaceDocument(String key, Object value) throws ArangoDBException;
220231

221232
/**
222233
* Replaces the document with {@code key} with the one in the body, provided there is such a document and no
@@ -233,27 +244,37 @@ <T> MultiDocumentEntity<T> getDocuments(Collection<String> keys, Class<T> type,
233244
<T> DocumentUpdateEntity<T> replaceDocument(String key, T value, DocumentReplaceOptions options)
234245
throws ArangoDBException;
235246

247+
/**
248+
* Replaces the document with {@code key} with the one in the body, provided there is such a document and no
249+
* precondition is violated
250+
*
251+
* @param key The key of the document
252+
* @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
253+
* @param options Additional options, can be null
254+
* @param type Deserialization target type for the returned documents.
255+
* @return information about the document
256+
* @throws ArangoDBException
257+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-document">API
258+
* Documentation</a>
259+
*/
260+
<T> DocumentUpdateEntity<T> replaceDocument(String key, T value, DocumentReplaceOptions options, Class<T> type)
261+
throws ArangoDBException;
262+
236263
/**
237264
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
238265
* specified by the _key attributes in the documents in values.
239-
* <p>
240-
* Limitations:
241-
* - the fields having {@code null} value are always removed during serialization
242266
*
243267
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
244268
* @return information about the documents
245269
* @throws ArangoDBException
246270
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#replace-documents">API
247271
* Documentation</a>
248272
*/
249-
<T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(Collection<T> values) throws ArangoDBException;
273+
MultiDocumentEntity<DocumentUpdateEntity<Void>> replaceDocuments(Collection<?> values) throws ArangoDBException;
250274

251275
/**
252276
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
253277
* specified by the _key attributes in the documents in values.
254-
* <p>
255-
* Limitations:
256-
* - the fields having {@code null} value are always removed during serialization
257278
*
258279
* @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes})
259280
* @param options Additional options, can be null
@@ -265,6 +286,21 @@ <T> DocumentUpdateEntity<T> replaceDocument(String key, T value, DocumentReplace
265286
<T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(
266287
Collection<T> values, DocumentReplaceOptions options) throws ArangoDBException;
267288

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+
268304
/**
269305
* Partially updates the document identified by document-key. The value must contain a document with the attributes
270306
* to patch (the patch document). All attributes from the patch document will be added to the existing document if
@@ -277,7 +313,7 @@ <T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(
277313
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#update-document">API
278314
* Documentation</a>
279315
*/
280-
<T> DocumentUpdateEntity<T> updateDocument(String key, T value) throws ArangoDBException;
316+
DocumentUpdateEntity<Void> updateDocument(String key, Object value) throws ArangoDBException;
281317

282318
/**
283319
* Partially updates the document identified by document-key. The value must contain a document with the attributes
@@ -324,7 +360,7 @@ <T, U> DocumentUpdateEntity<U> updateDocument(String key, T value, DocumentUpdat
324360
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#update-documents">API
325361
* Documentation</a>
326362
*/
327-
<T> MultiDocumentEntity<DocumentUpdateEntity<T>> updateDocuments(Collection<T> values) throws ArangoDBException;
363+
MultiDocumentEntity<DocumentUpdateEntity<Void>> updateDocuments(Collection<?> values) throws ArangoDBException;
328364

329365
/**
330366
* Partially updates documents, the documents to update are specified by the _key attributes in the objects on
@@ -370,6 +406,19 @@ <T, U> MultiDocumentEntity<DocumentUpdateEntity<U>> updateDocuments(
370406
*/
371407
DocumentDeleteEntity<Void> deleteDocument(String key) throws ArangoDBException;
372408

409+
/**
410+
* Deletes the document with the given {@code key} from the collection.
411+
*
412+
* @param key The key of the document
413+
* @param options Additional options, can be null
414+
* @return information about the document
415+
* @throws ArangoDBException
416+
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#removes-a-document">API
417+
* Documentation</a>
418+
*/
419+
<T> DocumentDeleteEntity<T> deleteDocument(String key, DocumentDeleteOptions options)
420+
throws ArangoDBException;
421+
373422
/**
374423
* Deletes the document with the given {@code key} from the collection.
375424
*
@@ -382,7 +431,7 @@ <T, U> MultiDocumentEntity<DocumentUpdateEntity<U>> updateDocuments(
382431
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#removes-a-document">API
383432
* Documentation</a>
384433
*/
385-
<T> DocumentDeleteEntity<T> deleteDocument(String key, Class<T> type, DocumentDeleteOptions options)
434+
<T> DocumentDeleteEntity<T> deleteDocument(String key, DocumentDeleteOptions options, Class<T> type)
386435
throws ArangoDBException;
387436

388437
/**
@@ -397,6 +446,20 @@ <T> DocumentDeleteEntity<T> deleteDocument(String key, Class<T> type, DocumentDe
397446
*/
398447
MultiDocumentEntity<DocumentDeleteEntity<Void>> deleteDocuments(Collection<?> values) throws ArangoDBException;
399448

449+
/**
450+
* Deletes multiple documents from the collection.
451+
*
452+
* @param values The keys of the documents or the documents themselves
453+
* @param options Additional options, can be null
454+
* @return information about the documents
455+
* @throws ArangoDBException
456+
* @see <a href=
457+
* "https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#removes-multiple-documents">API
458+
* Documentation</a>
459+
*/
460+
<T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteDocuments(
461+
Collection<?> values, DocumentDeleteOptions options) throws ArangoDBException;
462+
400463
/**
401464
* Deletes multiple documents from the collection.
402465
*
@@ -411,7 +474,7 @@ <T> DocumentDeleteEntity<T> deleteDocument(String key, Class<T> type, DocumentDe
411474
* Documentation</a>
412475
*/
413476
<T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteDocuments(
414-
Collection<?> values, Class<T> type, DocumentDeleteOptions options) throws ArangoDBException;
477+
Collection<?> values, DocumentDeleteOptions options, Class<T> type) throws ArangoDBException;
415478

416479
/**
417480
* Checks if the document exists by reading a single document head

0 commit comments

Comments
 (0)