diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index c77a228f4..b2d332760 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -61,7 +61,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * @see API * Documentation */ - DocumentCreateEntity insertDocument(T value) throws ArangoDBException; + DocumentCreateEntity insertDocument(Object value) throws ArangoDBException; /** * Creates a new document from the given document, unless there is already a document with the _key given. If no @@ -76,12 +76,23 @@ public interface ArangoCollection extends ArangoSerdeAccessor { */ DocumentCreateEntity insertDocument(T value, DocumentCreateOptions options) throws ArangoDBException; + /** + * Creates a new document from the given document, unless there is already a document with the _key given. If no + * _key is given, a new unique _key is generated automatically. + * + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the document + * @throws ArangoDBException + * @see API + * Documentation + */ + DocumentCreateEntity insertDocument(T value, DocumentCreateOptions options, Class type) throws ArangoDBException; + /** * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. - *

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents @@ -89,14 +100,11 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * @see API * Documentation */ - MultiDocumentEntity> insertDocuments(Collection values) throws ArangoDBException; + MultiDocumentEntity> insertDocuments(Collection values) throws ArangoDBException; /** * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. - *

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null @@ -108,11 +116,23 @@ public interface ArangoCollection extends ArangoSerdeAccessor { MultiDocumentEntity> insertDocuments( Collection values, DocumentCreateOptions options) throws ArangoDBException; + /** + * Creates new documents from the given documents, unless there is already a document with the _key given. If no + * _key is given, a new unique _key is generated automatically. + * + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the documents + * @throws ArangoDBException + * @see API + * Documentation + */ + MultiDocumentEntity> insertDocuments( + Collection values, DocumentCreateOptions options, Class type) throws ArangoDBException; + /** * Bulk imports the given values into the collection. - *

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values a list of Objects that will be stored as documents * @return information about the import @@ -122,9 +142,6 @@ MultiDocumentEntity> insertDocuments( /** * Bulk imports the given values into the collection. - *

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values a list of Objects that will be stored as documents * @param options Additional options, can be null @@ -135,9 +152,6 @@ MultiDocumentEntity> insertDocuments( /** * Bulk imports the given values into the collection. - *

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

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values JSON-encoded array of objects that will be stored as documents * @param options Additional options, can be null @@ -216,7 +227,7 @@ MultiDocumentEntity getDocuments(Collection keys, Class type, * @see API * Documentation */ - DocumentUpdateEntity replaceDocument(String key, T value) throws ArangoDBException; + DocumentUpdateEntity replaceDocument(String key, Object value) throws ArangoDBException; /** * Replaces the document with {@code key} with the one in the body, provided there is such a document and no @@ -233,12 +244,25 @@ MultiDocumentEntity getDocuments(Collection keys, Class type, DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplaceOptions options) throws ArangoDBException; + /** + * Replaces the document with {@code key} with the one in the body, provided there is such a document and no + * precondition is violated + * + * @param key The key of the document + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the document + * @throws ArangoDBException + * @see API + * Documentation + */ + DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplaceOptions options, Class type) + throws ArangoDBException; + /** * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are * specified by the _key attributes in the documents in values. - *

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents @@ -246,14 +270,11 @@ DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplace * @see API * Documentation */ - MultiDocumentEntity> replaceDocuments(Collection values) throws ArangoDBException; + MultiDocumentEntity> replaceDocuments(Collection values) throws ArangoDBException; /** * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are * specified by the _key attributes in the documents in values. - *

- * Limitations: - * - the fields having {@code null} value are always removed during serialization * * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null @@ -265,6 +286,21 @@ DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplace MultiDocumentEntity> replaceDocuments( Collection values, DocumentReplaceOptions options) throws ArangoDBException; + /** + * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are + * specified by the _key attributes in the documents in values. + * + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the documents + * @throws ArangoDBException + * @see API + * Documentation + */ + MultiDocumentEntity> replaceDocuments( + Collection values, DocumentReplaceOptions options, Class type) throws ArangoDBException; + /** * Partially updates the document identified by document-key. The value must contain a document with the attributes * to patch (the patch document). All attributes from the patch document will be added to the existing document if @@ -277,7 +313,7 @@ MultiDocumentEntity> replaceDocuments( * @see API * Documentation */ - DocumentUpdateEntity updateDocument(String key, T value) throws ArangoDBException; + DocumentUpdateEntity updateDocument(String key, Object value) throws ArangoDBException; /** * Partially updates the document identified by document-key. The value must contain a document with the attributes @@ -324,7 +360,7 @@ DocumentUpdateEntity updateDocument(String key, T value, DocumentUpdat * @see API * Documentation */ - MultiDocumentEntity> updateDocuments(Collection values) throws ArangoDBException; + MultiDocumentEntity> updateDocuments(Collection values) throws ArangoDBException; /** * Partially updates documents, the documents to update are specified by the _key attributes in the objects on @@ -370,6 +406,19 @@ MultiDocumentEntity> updateDocuments( */ DocumentDeleteEntity deleteDocument(String key) throws ArangoDBException; + /** + * Deletes the document with the given {@code key} from the collection. + * + * @param key The key of the document + * @param options Additional options, can be null + * @return information about the document + * @throws ArangoDBException + * @see API + * Documentation + */ + DocumentDeleteEntity deleteDocument(String key, DocumentDeleteOptions options) + throws ArangoDBException; + /** * Deletes the document with the given {@code key} from the collection. * @@ -382,7 +431,7 @@ MultiDocumentEntity> updateDocuments( * @see API * Documentation */ - DocumentDeleteEntity deleteDocument(String key, Class type, DocumentDeleteOptions options) + DocumentDeleteEntity deleteDocument(String key, DocumentDeleteOptions options, Class type) throws ArangoDBException; /** @@ -397,6 +446,20 @@ DocumentDeleteEntity deleteDocument(String key, Class type, DocumentDe */ MultiDocumentEntity> deleteDocuments(Collection values) throws ArangoDBException; + /** + * Deletes multiple documents from the collection. + * + * @param values The keys of the documents or the documents themselves + * @param options Additional options, can be null + * @return information about the documents + * @throws ArangoDBException + * @see API + * Documentation + */ + MultiDocumentEntity> deleteDocuments( + Collection values, DocumentDeleteOptions options) throws ArangoDBException; + /** * Deletes multiple documents from the collection. * @@ -411,7 +474,7 @@ DocumentDeleteEntity deleteDocument(String key, Class type, DocumentDe * Documentation */ MultiDocumentEntity> deleteDocuments( - Collection values, Class type, DocumentDeleteOptions options) throws ArangoDBException; + Collection values, DocumentDeleteOptions options, Class type) throws ArangoDBException; /** * Checks if the document exists by reading a single document head diff --git a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index 1df9efcd3..2869b5f82 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -61,7 +61,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * @see API * Documentation */ - CompletableFuture> insertDocument(final T value); + CompletableFuture> insertDocument(final Object value); /** * Creates a new document from the given document, unless there is already a document with the _key given. If no @@ -75,6 +75,19 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { */ CompletableFuture> insertDocument(final T value, final DocumentCreateOptions options); + /** + * Creates a new document from the given document, unless there is already a document with the _key given. If no + * _key is given, a new unique _key is generated automatically. + * + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the document + * @see API + * Documentation + */ + CompletableFuture> insertDocument(final T value, final DocumentCreateOptions options, Class type); + /** * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. @@ -84,7 +97,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * @see API * Documentation */ - CompletableFuture>> insertDocuments(final Collection values); + CompletableFuture>> insertDocuments(final Collection values); /** * Creates new documents from the given documents, unless there is already a document with the _key given. If no @@ -100,6 +113,22 @@ CompletableFuture>> insertDocume final Collection values, final DocumentCreateOptions options); + /** + * Creates new documents from the given documents, unless there is already a document with the _key given. If no + * _key is given, a new unique _key is generated automatically. + * + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> insertDocuments( + final Collection values, + final DocumentCreateOptions options, + final Class type); + /** * Imports documents * @@ -192,7 +221,7 @@ CompletableFuture> getDocuments( * @see API * Documentation */ - CompletableFuture> replaceDocument(final String key, final T value); + CompletableFuture> replaceDocument(final String key, final Object value); /** * Replaces the document with key with the one in the body, provided there is such a document and no precondition is @@ -210,6 +239,24 @@ CompletableFuture> replaceDocument( final T value, final DocumentReplaceOptions options); + /** + * Replaces the document with key with the one in the body, provided there is such a document and no precondition is + * violated + * + * @param key The key of the document + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the document + * @see API + * Documentation + */ + CompletableFuture> replaceDocument( + final String key, + final T value, + final DocumentReplaceOptions options, + final Class type); + /** * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are * specified by the _key attributes in the documents in values. @@ -219,7 +266,7 @@ CompletableFuture> replaceDocument( * @see API * Documentation */ - CompletableFuture>> replaceDocuments(final Collection values); + CompletableFuture>> replaceDocuments(final Collection values); /** * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are @@ -235,6 +282,22 @@ CompletableFuture>> replaceDocum final Collection values, final DocumentReplaceOptions options); + /** + * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are + * specified by the _key attributes in the documents in values. + * + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param options Additional options, can be null + * @param type Deserialization target type for the returned documents. + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> replaceDocuments( + final Collection values, + final DocumentReplaceOptions options, + final Class type); + /** * Partially updates the document identified by document-key. The value must contain a document with the attributes * to patch (the patch document). All attributes from the patch document will be added to the existing document if @@ -246,7 +309,7 @@ CompletableFuture>> replaceDocum * @see API * Documentation */ - CompletableFuture> updateDocument(final String key, final T value); + CompletableFuture> updateDocument(final String key, final Object value); /** * Partially updates the document identified by document-key. The value must contain a document with the attributes @@ -295,7 +358,7 @@ CompletableFuture> updateDocument( * @see API * Documentation */ - CompletableFuture>> updateDocuments(final Collection values); + CompletableFuture>> updateDocuments(final Collection values); /** * Partially updates documents, the documents to update are specified by the _key attributes in the objects on @@ -341,6 +404,19 @@ CompletableFuture>> updateDoc */ CompletableFuture> deleteDocument(final String key); + /** + * Removes a document + * + * @param key The key of the document + * @param options Additional options, can be null + * @return information about the document + * @see API + * Documentation + */ + CompletableFuture> deleteDocument( + final String key, + final DocumentDeleteOptions options); + /** * Removes a document * @@ -354,8 +430,8 @@ CompletableFuture>> updateDoc */ CompletableFuture> deleteDocument( final String key, - final Class type, - final DocumentDeleteOptions options); + final DocumentDeleteOptions options, + final Class type); /** * Removes multiple document @@ -368,6 +444,20 @@ CompletableFuture> deleteDocument( */ CompletableFuture>> deleteDocuments(final Collection values); + /** + * Removes multiple document + * + * @param values The keys of the documents or the documents themselves + * @param options Additional options, can be null + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> deleteDocuments( + final Collection values, + final DocumentDeleteOptions options); + /** * Removes multiple document * @@ -382,8 +472,8 @@ CompletableFuture> deleteDocument( */ CompletableFuture>> deleteDocuments( final Collection values, - final Class type, - final DocumentDeleteOptions options); + final DocumentDeleteOptions options, + final Class type); /** * Checks if the document exists by reading a single document head diff --git a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java index 90c9bfab0..3544d2298 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java @@ -46,35 +46,44 @@ public class ArangoCollectionAsyncImpl } @Override - public CompletableFuture> insertDocument(final T value) { - final DocumentCreateOptions options = new DocumentCreateOptions(); - return executor.execute(insertDocumentRequest(value, options), - constructParametricType(DocumentCreateEntity.class, value.getClass())); + public CompletableFuture> insertDocument(final Object value) { + return executor.execute(insertDocumentRequest(value, new DocumentCreateOptions()), + constructParametricType(DocumentCreateEntity.class, Void.class)); } @Override + @SuppressWarnings("unchecked") public CompletableFuture> insertDocument( final T value, final DocumentCreateOptions options) { + return insertDocument(value, options, (Class) value.getClass()); + } + + @Override + public CompletableFuture> insertDocument(T value, DocumentCreateOptions options, Class type) { return executor.execute(insertDocumentRequest(value, options), - constructParametricType(DocumentCreateEntity.class, value.getClass())); + constructParametricType(DocumentCreateEntity.class, type)); } @Override - public CompletableFuture>> insertDocuments( - final Collection values) { - final DocumentCreateOptions params = new DocumentCreateOptions(); - return executor.execute(insertDocumentsRequest(values, params), - insertDocumentsResponseDeserializer(values, params)); + public CompletableFuture>> insertDocuments( + final Collection values) { + return executor + .execute(insertDocumentsRequest(values, new DocumentCreateOptions()), insertDocumentsResponseDeserializer(Void.class)); } @Override + @SuppressWarnings("unchecked") public CompletableFuture>> insertDocuments( final Collection values, final DocumentCreateOptions options) { - final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); - return executor.execute(insertDocumentsRequest(values, params), - insertDocumentsResponseDeserializer(values, params)); + return insertDocuments(values, options, (Class) getCollectionContentClass(values)); + } + + @Override + public CompletableFuture>> insertDocuments(Collection values, DocumentCreateOptions options, Class type) { + return executor + .execute(insertDocumentsRequest(values, options), insertDocumentsResponseDeserializer(type)); } @Override @@ -134,41 +143,49 @@ public CompletableFuture> getDocuments( } @Override - public CompletableFuture> replaceDocument(final String key, final T value) { + public CompletableFuture> replaceDocument(final String key, final Object value) { final DocumentReplaceOptions options = new DocumentReplaceOptions(); return executor.execute(replaceDocumentRequest(key, value, options), - constructParametricType(DocumentUpdateEntity.class, value.getClass())); + constructParametricType(DocumentUpdateEntity.class, Void.class)); } @Override + @SuppressWarnings("unchecked") public CompletableFuture> replaceDocument( final String key, final T value, final DocumentReplaceOptions options) { + return replaceDocument(key, value, options, (Class) value.getClass()); + } + + @Override + public CompletableFuture> replaceDocument(String key, T value, DocumentReplaceOptions options, Class type) { return executor.execute(replaceDocumentRequest(key, value, options), - constructParametricType(DocumentUpdateEntity.class, value.getClass())); + constructParametricType(DocumentUpdateEntity.class, type)); } @Override - public CompletableFuture>> replaceDocuments( - final Collection values) { - final DocumentReplaceOptions params = new DocumentReplaceOptions(); - return executor.execute(replaceDocumentsRequest(values, params), - replaceDocumentsResponseDeserializer(values)); + public CompletableFuture>> replaceDocuments( + final Collection values) { + return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), replaceDocumentsResponseDeserializer(Void.class)); } @Override + @SuppressWarnings("unchecked") public CompletableFuture>> replaceDocuments( final Collection values, final DocumentReplaceOptions options) { - final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions()); - return executor.execute(replaceDocumentsRequest(values, params), - replaceDocumentsResponseDeserializer(values)); + return replaceDocuments(values, options, (Class) getCollectionContentClass(values)); } @Override - public CompletableFuture> updateDocument(final String key, final T value) { - return updateDocument(key, value, new DocumentUpdateOptions()); + public CompletableFuture>> replaceDocuments(Collection values, DocumentReplaceOptions options, Class type) { + return executor.execute(replaceDocumentsRequest(values, options), replaceDocumentsResponseDeserializer(type)); + } + + @Override + public CompletableFuture> updateDocument(final String key, final Object value) { + return updateDocument(key, value, new DocumentUpdateOptions(), Void.class); } @Override @@ -191,9 +208,9 @@ public CompletableFuture> updateDocument( } @Override - public CompletableFuture>> updateDocuments( - final Collection values) { - return updateDocuments(values, new DocumentUpdateOptions()); + public CompletableFuture>> updateDocuments( + final Collection values) { + return updateDocuments(values, new DocumentUpdateOptions(), Void.class); } @Override @@ -201,7 +218,7 @@ public CompletableFuture>> updat public CompletableFuture>> updateDocuments( final Collection values, final DocumentUpdateOptions options) { - return updateDocuments(values, options, values.isEmpty() ? null : (Class) getCollectionContentClass(values)); + return updateDocuments(values, options, (Class) getCollectionContentClass(values)); } @Override @@ -209,22 +226,26 @@ public CompletableFuture>> up final Collection values, final DocumentUpdateOptions options, final Class returnType) { - final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions()); - return executor.execute(updateDocumentsRequest(values, params), - updateDocumentsResponseDeserializer(returnType)); + return executor + .execute(updateDocumentsRequest(values, options), updateDocumentsResponseDeserializer(returnType)); } @Override public CompletableFuture> deleteDocument(final String key) { - return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()), - constructParametricType(DocumentDeleteEntity.class, Void.class)); + return deleteDocument(key, new DocumentDeleteOptions()); + } + + @Override + @SuppressWarnings("unchecked") + public CompletableFuture> deleteDocument(String key, DocumentDeleteOptions options) { + return deleteDocument(key, options, (Class) Void.class); } @Override public CompletableFuture> deleteDocument( final String key, - final Class type, - final DocumentDeleteOptions options) { + final DocumentDeleteOptions options, + final Class type) { return executor.execute(deleteDocumentRequest(key, options), constructParametricType(DocumentDeleteEntity.class, type)); } @@ -232,15 +253,20 @@ public CompletableFuture> deleteDocument( @Override public CompletableFuture>> deleteDocuments( final Collection values) { - return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()), - deleteDocumentsResponseDeserializer(Void.class)); + return deleteDocuments(values, new DocumentDeleteOptions(), Void.class); + } + + @Override + @SuppressWarnings("unchecked") + public CompletableFuture>> deleteDocuments(Collection values, DocumentDeleteOptions options) { + return deleteDocuments(values, options, (Class) getCollectionContentClass(values)); } @Override public CompletableFuture>> deleteDocuments( final Collection values, - final Class type, - final DocumentDeleteOptions options) { + final DocumentDeleteOptions options, + final Class type) { return executor.execute(deleteDocumentsRequest(values, options), deleteDocumentsResponseDeserializer(type)); } diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 625182c86..e57dda57d 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java @@ -25,7 +25,6 @@ import com.arangodb.entity.*; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; -import com.arangodb.serde.SerdeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,29 +46,42 @@ protected ArangoCollectionImpl(final ArangoDatabaseImpl db, final String name) { } @Override - public DocumentCreateEntity insertDocument(final T value) throws ArangoDBException { - return insertDocument(value, new DocumentCreateOptions()); + public DocumentCreateEntity insertDocument(final Object value) throws ArangoDBException { + return executor.execute(insertDocumentRequest(value, new DocumentCreateOptions()), + constructParametricType(DocumentCreateEntity.class, Void.class)); } @Override + @SuppressWarnings("unchecked") public DocumentCreateEntity insertDocument(final T value, final DocumentCreateOptions options) throws ArangoDBException { + return insertDocument(value, options, (Class) value.getClass()); + } + + @Override + public DocumentCreateEntity insertDocument(final T value, final DocumentCreateOptions options, final Class type) throws ArangoDBException { return executor.execute(insertDocumentRequest(value, options), - constructParametricType(DocumentCreateEntity.class, value.getClass())); + constructParametricType(DocumentCreateEntity.class, type)); } @Override - public MultiDocumentEntity> insertDocuments(final Collection values) + public MultiDocumentEntity> insertDocuments(final Collection values) throws ArangoDBException { - return insertDocuments(values, new DocumentCreateOptions()); + return executor + .execute(insertDocumentsRequest(values, new DocumentCreateOptions()), insertDocumentsResponseDeserializer(Void.class)); } @Override + @SuppressWarnings("unchecked") public MultiDocumentEntity> insertDocuments( final Collection values, final DocumentCreateOptions options) throws ArangoDBException { - final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); + return insertDocuments(values, options, (Class) getCollectionContentClass(values)); + } + + @Override + public MultiDocumentEntity> insertDocuments(Collection values, DocumentCreateOptions options, Class type) throws ArangoDBException { return executor - .execute(insertDocumentsRequest(values, params), insertDocumentsResponseDeserializer(values, params)); + .execute(insertDocumentsRequest(values, options), insertDocumentsResponseDeserializer(type)); } @Override @@ -137,34 +149,45 @@ public MultiDocumentEntity getDocuments( } @Override - public DocumentUpdateEntity replaceDocument(final String key, final T value) throws ArangoDBException { - return replaceDocument(key, value, new DocumentReplaceOptions()); + public DocumentUpdateEntity replaceDocument(final String key, final Object value) throws ArangoDBException { + return executor.execute(replaceDocumentRequest(key, value, new DocumentReplaceOptions()), + constructParametricType(DocumentUpdateEntity.class, Void.class)); } @Override + @SuppressWarnings("unchecked") public DocumentUpdateEntity replaceDocument( final String key, final T value, final DocumentReplaceOptions options) throws ArangoDBException { + return replaceDocument(key, value, options, (Class) value.getClass()); + } + + @Override + public DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplaceOptions options, Class type) throws ArangoDBException { return executor.execute(replaceDocumentRequest(key, value, options), - constructParametricType(DocumentUpdateEntity.class, value.getClass())); + constructParametricType(DocumentUpdateEntity.class, type)); } @Override - public MultiDocumentEntity> replaceDocuments(final Collection values) + public MultiDocumentEntity> replaceDocuments(final Collection values) throws ArangoDBException { - return replaceDocuments(values, new DocumentReplaceOptions()); + return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), replaceDocumentsResponseDeserializer(Void.class)); } @Override + @SuppressWarnings("unchecked") public MultiDocumentEntity> replaceDocuments( final Collection values, final DocumentReplaceOptions options) throws ArangoDBException { - final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions()); - return executor - .execute(replaceDocumentsRequest(values, params), replaceDocumentsResponseDeserializer(values)); + return replaceDocuments(values, options, (Class) getCollectionContentClass(values)); + } + + @Override + public MultiDocumentEntity> replaceDocuments(Collection values, DocumentReplaceOptions options, Class type) throws ArangoDBException { + return executor.execute(replaceDocumentsRequest(values, options), replaceDocumentsResponseDeserializer(type)); } @Override - public DocumentUpdateEntity updateDocument(final String key, final T value) throws ArangoDBException { - return updateDocument(key, value, new DocumentUpdateOptions()); + public DocumentUpdateEntity updateDocument(final String key, final Object value) throws ArangoDBException { + return updateDocument(key, value, new DocumentUpdateOptions(), Void.class); } @Override @@ -182,35 +205,39 @@ public DocumentUpdateEntity updateDocument( } @Override - public MultiDocumentEntity> updateDocuments(final Collection values) + public MultiDocumentEntity> updateDocuments(final Collection values) throws ArangoDBException { - return updateDocuments(values, new DocumentUpdateOptions()); + return updateDocuments(values, new DocumentUpdateOptions(), Void.class); } @Override @SuppressWarnings("unchecked") public MultiDocumentEntity> updateDocuments( final Collection values, final DocumentUpdateOptions options) throws ArangoDBException { - return updateDocuments(values, options, values.isEmpty() ? null : (Class) getCollectionContentClass(values)); + return updateDocuments(values, options, (Class) getCollectionContentClass(values)); } @Override public MultiDocumentEntity> updateDocuments( final Collection values, final DocumentUpdateOptions options, final Class returnType) throws ArangoDBException { - final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions()); return executor - .execute(updateDocumentsRequest(values, params), updateDocumentsResponseDeserializer(returnType)); + .execute(updateDocumentsRequest(values, options), updateDocumentsResponseDeserializer(returnType)); } @Override public DocumentDeleteEntity deleteDocument(final String key) throws ArangoDBException { - return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()), - constructParametricType(DocumentDeleteEntity.class, Void.class)); + return deleteDocument(key, new DocumentDeleteOptions()); + } + + @Override + @SuppressWarnings("unchecked") + public DocumentDeleteEntity deleteDocument(String key, DocumentDeleteOptions options) throws ArangoDBException { + return deleteDocument(key, options, (Class) Void.class); } @Override public DocumentDeleteEntity deleteDocument( - final String key, final Class type, final DocumentDeleteOptions options) throws ArangoDBException { + final String key, final DocumentDeleteOptions options, final Class type) throws ArangoDBException { return executor.execute(deleteDocumentRequest(key, options), constructParametricType(DocumentDeleteEntity.class, type)); } @@ -218,13 +245,20 @@ public DocumentDeleteEntity deleteDocument( @Override public MultiDocumentEntity> deleteDocuments(final Collection values) throws ArangoDBException { - return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()), - deleteDocumentsResponseDeserializer(Void.class)); + return deleteDocuments(values, new DocumentDeleteOptions(), Void.class); + } + + @Override + @SuppressWarnings("unchecked") + public MultiDocumentEntity> deleteDocuments( + final Collection values, final DocumentDeleteOptions options) + throws ArangoDBException { + return deleteDocuments(values, options, (Class) getCollectionContentClass(values)); } @Override public MultiDocumentEntity> deleteDocuments( - final Collection values, final Class type, final DocumentDeleteOptions options) + final Collection values, final DocumentDeleteOptions options, final Class type) throws ArangoDBException { return executor.execute(deleteDocumentsRequest(values, options), deleteDocumentsResponseDeserializer(type)); } diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 0a46a5c12..55b4a993f 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -109,10 +109,8 @@ protected Request insertDocumentsRequest(final Collection values, final D return request; } - protected ResponseDeserializer>> insertDocumentsResponseDeserializer( - final Collection values, final DocumentCreateOptions params) { + protected ResponseDeserializer>> insertDocumentsResponseDeserializer(Class userDataClass) { return response -> { - Class userDataClass = getCollectionContentClass(values); final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>(); final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); @@ -243,9 +241,8 @@ protected Request replaceDocumentsRequest(final Collection values, final } protected ResponseDeserializer>> replaceDocumentsResponseDeserializer( - final Collection values) { + final Class returnType) { return response -> { - Class userDataClass = getCollectionContentClass(values); final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>(); final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); @@ -258,7 +255,7 @@ protected ResponseDeserializer>> errors.add(error); documentsAndErrors.add(error); } else { - Type type = constructParametricType(DocumentUpdateEntity.class, userDataClass); + Type type = constructParametricType(DocumentUpdateEntity.class, returnType); final DocumentUpdateEntity doc = getSerde().deserialize(next, type); docs.add(doc); documentsAndErrors.add(doc); diff --git a/src/main/java/com/arangodb/model/DocumentCreateOptions.java b/src/main/java/com/arangodb/model/DocumentCreateOptions.java index 8d796966a..b0722c541 100644 --- a/src/main/java/com/arangodb/model/DocumentCreateOptions.java +++ b/src/main/java/com/arangodb/model/DocumentCreateOptions.java @@ -86,11 +86,6 @@ public OverwriteMode getOverwriteMode() { } /** - * Limitations: - * - {@code keepNull} parameter is not supported - * - the fields having {@code null} value are always removed during serialization - * Therefore in case of {@link OverwriteMode#update}, existing attributes cannot be removed. - * * @param overwriteMode This parameter can be set to replace or update. If given it sets implicitly the overwrite * flag. In case it is set to update, the replace-insert becomes an update-insert. Otherwise * this option follows the rules of the overwrite parameter. diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 5bb82657d..bf2196786 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -20,27 +20,15 @@ package com.arangodb; -import com.arangodb.entity.BaseDocument; -import com.arangodb.entity.BaseEdgeDocument; -import com.arangodb.entity.CollectionEntity; -import com.arangodb.entity.CollectionPropertiesEntity; -import com.arangodb.entity.CollectionRevisionEntity; -import com.arangodb.entity.DocumentCreateEntity; -import com.arangodb.entity.DocumentDeleteEntity; -import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.DocumentImportEntity; -import com.arangodb.entity.DocumentUpdateEntity; -import com.arangodb.entity.IndexEntity; -import com.arangodb.entity.IndexType; -import com.arangodb.entity.MultiDocumentEntity; -import com.arangodb.entity.Permissions; -import com.arangodb.entity.ShardEntity; +import com.arangodb.entity.*; import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; +import com.arangodb.serde.JacksonSerde; import com.arangodb.util.MapBuilder; import com.arangodb.util.RawBytes; import com.arangodb.util.RawJson; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeAll; @@ -90,6 +78,78 @@ static void init() { initEdgeCollections(EDGE_COLLECTION_NAME); } + @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "type") + public interface Animal { + String getKey(); + + String getName(); + } + + public static class Dog implements Animal { + + @Key + private String key; + private String name; + + public Dog() { + } + + public Dog(String key, String name) { + this.key = key; + this.name = name; + } + + @Override + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + public static class Cat implements Animal { + @Key + private String key; + private String name; + + public Cat() { + } + + public Cat(String key, String name) { + this.key = key; + this.name = name; + } + + @Override + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocument(ArangoCollection collection) { @@ -160,6 +220,40 @@ void insertDocumentReturnNew(ArangoCollection collection) { assertThat(doc.getNew()).isNotNull(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void insertDocumentWithTypeOverwriteModeReplace(ArangoCollection collection) { + assumeTrue(isAtLeastVersion(3, 7)); + assumeTrue(collection.getSerde().getUserSerde() instanceof JacksonSerde, "polymorphic deserialization support required"); + + String key = UUID.randomUUID().toString(); + Dog dog = new Dog(key, "Teddy"); + Cat cat = new Cat(key, "Luna"); + + final DocumentCreateOptions options = new DocumentCreateOptions() + .returnNew(true) + .returnOld(true) + .overwriteMode(OverwriteMode.replace); + collection.insertDocument(dog, options); + final DocumentCreateEntity doc = collection.insertDocument(cat, options, Animal.class); + assertThat(doc).isNotNull(); + assertThat(doc.getId()).isNotNull(); + assertThat(doc.getKey()).isNotNull().isEqualTo(key); + assertThat(doc.getRev()).isNotNull(); + + assertThat(doc.getOld()) + .isNotNull() + .isInstanceOf(Dog.class); + assertThat(doc.getOld().getKey()).isEqualTo(key); + assertThat(doc.getOld().getName()).isEqualTo("Teddy"); + + assertThat(doc.getNew()) + .isNotNull() + .isInstanceOf(Cat.class); + assertThat(doc.getNew().getKey()).isEqualTo(key); + assertThat(doc.getNew().getName()).isEqualTo("Luna"); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentOverwriteModeIgnore(ArangoCollection collection) { @@ -168,7 +262,7 @@ void insertDocumentOverwriteModeIgnore(ArangoCollection collection) { String key = "key-" + UUID.randomUUID(); final BaseDocument doc = new BaseDocument(key); doc.addAttribute("foo", "a"); - final DocumentCreateEntity meta = collection.insertDocument(doc); + final DocumentCreateEntity meta = collection.insertDocument(doc); final BaseDocument doc2 = new BaseDocument(key); doc2.addAttribute("bar", "b"); @@ -204,7 +298,7 @@ void insertDocumentOverwriteModeReplace(ArangoCollection collection) { String key = "key-" + UUID.randomUUID(); final BaseDocument doc = new BaseDocument(key); doc.addAttribute("foo", "a"); - final DocumentCreateEntity meta = collection.insertDocument(doc); + final DocumentCreateEntity meta = collection.insertDocument(doc); final BaseDocument doc2 = new BaseDocument(key); doc2.addAttribute("bar", "b"); @@ -223,7 +317,7 @@ void insertDocumentOverwriteModeUpdate(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); doc.addAttribute("foo", "a"); - final DocumentCreateEntity meta = collection.insertDocument(doc); + final DocumentCreateEntity meta = collection.insertDocument(doc); doc.addAttribute("bar", "b"); final DocumentCreateEntity updated = collection.insertDocument(doc, new DocumentCreateOptions().overwriteMode(OverwriteMode.update).returnNew(true)); @@ -242,7 +336,7 @@ void insertDocumentOverwriteModeUpdateMergeObjectsFalse(ArangoCollection collect final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); Map fieldA = Collections.singletonMap("a", "a"); doc.addAttribute("foo", fieldA); - final DocumentCreateEntity meta = collection.insertDocument(doc); + final DocumentCreateEntity meta = collection.insertDocument(doc); Map fieldB = Collections.singletonMap("b", "b"); doc.addAttribute("foo", fieldB); @@ -270,7 +364,7 @@ void insertDocumentWaitForSync(ArangoCollection collection) { void insertDocumentAsJson(ArangoCollection collection) { String key = "doc-" + UUID.randomUUID(); RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\",\"a\":\"test\"}"); - final DocumentCreateEntity doc = collection.insertDocument(rawJson); + final DocumentCreateEntity doc = collection.insertDocument(rawJson); assertThat(doc).isNotNull(); assertThat(doc.getId()).isEqualTo(collection.name() + "/" + key); assertThat(doc.getKey()).isEqualTo(key); @@ -464,7 +558,7 @@ void getDocumentsWithCustomShardingKey(ArangoCollection c) { List values = IntStream.range(0, 10).mapToObj(String::valueOf).map(key -> new BaseDocument()).peek(it -> it.addAttribute("customField", rnd())).collect(Collectors.toList()); - MultiDocumentEntity> inserted = collection.insertDocuments(values); + MultiDocumentEntity> inserted = collection.insertDocuments(values); List insertedKeys = inserted.getDocuments().stream().map(DocumentEntity::getKey).collect(Collectors.toList()); final Collection documents = collection.getDocuments(insertedKeys, BaseDocument.class).getDocuments(); @@ -724,10 +818,10 @@ void updateDocumentSerializeNullTrue(ArangoCollection collection) { final TestUpdateEntity doc = new TestUpdateEntity(); doc.a = "foo"; doc.b = "foo"; - final DocumentCreateEntity createResult = collection.insertDocument(doc); + final DocumentCreateEntity createResult = collection.insertDocument(doc); final TestUpdateEntity patchDoc = new TestUpdateEntity(); patchDoc.a = "bar"; - final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); assertThat(updateResult).isNotNull(); assertThat(updateResult.getKey()).isEqualTo(createResult.getKey()); @@ -743,10 +837,10 @@ void updateDocumentSerializeNullFalse(ArangoCollection collection) { final TestUpdateEntitySerializeNullFalse doc = new TestUpdateEntitySerializeNullFalse(); doc.a = "foo"; doc.b = "foo"; - final DocumentCreateEntity createResult = collection.insertDocument(doc); + final DocumentCreateEntity createResult = collection.insertDocument(doc); final TestUpdateEntitySerializeNullFalse patchDoc = new TestUpdateEntitySerializeNullFalse(); patchDoc.a = "bar"; - final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); assertThat(updateResult).isNotNull(); assertThat(updateResult.getKey()).isEqualTo(createResult.getKey()); @@ -830,7 +924,7 @@ void updateDocumentIgnoreRevsFalse(ArangoCollection collection) { @MethodSource("cols") void updateDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); final DocumentUpdateEntity meta = collection.updateDocument(createResult.getKey(), new BaseDocument(), new DocumentUpdateOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); @@ -842,7 +936,7 @@ void updateDocumentSilent(ArangoCollection collection) { @MethodSource("cols") void updateDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); final MultiDocumentEntity> info = collection.updateDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), new DocumentUpdateOptions().silent(true)); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); @@ -1020,7 +1114,7 @@ void replaceDocumentReturnOld(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); final DocumentUpdateEntity meta = collection.replaceDocument(createResult.getKey(), new BaseDocument(), new DocumentReplaceOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); @@ -1033,7 +1127,7 @@ void replaceDocumentSilent(ArangoCollection collection) { void replaceDocumentSilentDontTouchInstance(ArangoCollection collection) { assumeTrue(isSingleServer()); final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); - final DocumentCreateEntity createResult = collection.insertDocument(doc); + final DocumentCreateEntity createResult = collection.insertDocument(doc); final DocumentUpdateEntity meta = collection.replaceDocument(createResult.getKey(), doc, new DocumentReplaceOptions().silent(true)); assertThat(meta.getRev()).isNull(); assertThat(doc.getRevision()).isNull(); @@ -1044,7 +1138,7 @@ void replaceDocumentSilentDontTouchInstance(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); final MultiDocumentEntity> info = collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), new DocumentReplaceOptions().silent(true)); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); @@ -1057,7 +1151,7 @@ void replaceDocumentsSilent(ArangoCollection collection) { void deleteDocument(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); final DocumentCreateEntity createResult = collection.insertDocument(doc, null); - collection.deleteDocument(createResult.getKey(), null, null); + collection.deleteDocument(createResult.getKey()); final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(document).isNull(); } @@ -1069,7 +1163,7 @@ void deleteDocumentReturnOld(ArangoCollection collection) { doc.addAttribute("a", "test"); final DocumentCreateEntity createResult = collection.insertDocument(doc, null); final DocumentDeleteOptions options = new DocumentDeleteOptions().returnOld(true); - final DocumentDeleteEntity deleteResult = collection.deleteDocument(createResult.getKey(), BaseDocument.class, options); + final DocumentDeleteEntity deleteResult = collection.deleteDocument(createResult.getKey(), options, BaseDocument.class); assertThat(deleteResult.getOld()).isNotNull(); assertThat(deleteResult.getOld()).isInstanceOf(BaseDocument.class); assertThat(deleteResult.getOld().getAttribute("a")).isNotNull(); @@ -1082,7 +1176,7 @@ void deleteDocumentIfMatch(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); final DocumentCreateEntity createResult = collection.insertDocument(doc, null); final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch(createResult.getRev()); - collection.deleteDocument(createResult.getKey(), null, options); + collection.deleteDocument(createResult.getKey(), options); final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(document).isNull(); } @@ -1091,9 +1185,9 @@ void deleteDocumentIfMatch(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentIfMatchFail(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); - final DocumentCreateEntity createResult = collection.insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc); final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch("no"); - Throwable thrown = catchThrowable(() -> collection.deleteDocument(createResult.getKey(), null, options)); + Throwable thrown = catchThrowable(() -> collection.deleteDocument(createResult.getKey(), options)); assertThat(thrown).isInstanceOf(ArangoDBException.class); } @@ -1101,8 +1195,8 @@ void deleteDocumentIfMatchFail(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); - final DocumentDeleteEntity meta = collection.deleteDocument(createResult.getKey(), BaseDocument.class, new DocumentDeleteOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentDeleteEntity meta = collection.deleteDocument(createResult.getKey(), new DocumentDeleteOptions().silent(true), BaseDocument.class); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); assertThat(meta.getKey()).isNull(); @@ -1113,8 +1207,11 @@ void deleteDocumentSilent(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); - final MultiDocumentEntity> info = collection.deleteDocuments(Collections.singletonList(createResult.getKey()), BaseDocument.class, new DocumentDeleteOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = collection.deleteDocuments( + Collections.singletonList(createResult.getKey()), + new DocumentDeleteOptions().silent(true), + BaseDocument.class); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); assertThat(info.getDocumentsAndErrors()).isEmpty(); @@ -1696,7 +1793,7 @@ void documentExistsThrowExcpetion(ArangoCollection collection) { void documentExistsIfMatch(ArangoCollection collection) { String key = rnd(); RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); - final DocumentCreateEntity createResult = collection.insertDocument(rawJson); + final DocumentCreateEntity createResult = collection.insertDocument(rawJson); final DocumentExistsOptions options = new DocumentExistsOptions().ifMatch(createResult.getRev()); final Boolean exists = collection.documentExists(key, options); assertThat(exists).isTrue(); @@ -1729,7 +1826,7 @@ void documentExistsIfNoneMatch(ArangoCollection collection) { void documentExistsIfNoneMatchFail(ArangoCollection collection) { String key = rnd(); RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); - final DocumentCreateEntity createResult = collection.insertDocument(rawJson); + final DocumentCreateEntity createResult = collection.insertDocument(rawJson); final DocumentExistsOptions options = new DocumentExistsOptions().ifNoneMatch(createResult.getRev()); final Boolean exists = collection.documentExists(key, options); assertThat(exists).isFalse(); @@ -1740,7 +1837,7 @@ void documentExistsIfNoneMatchFail(ArangoCollection collection) { void insertDocuments(ArangoCollection collection) { final Collection values = Arrays.asList(new BaseDocument(), new BaseDocument(), new BaseDocument()); - final MultiDocumentEntity> docs = collection.insertDocuments(values, null); + final MultiDocumentEntity docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1755,11 +1852,11 @@ void insertDocumentsOverwriteModeUpdate(ArangoCollection collection) { final BaseDocument doc1 = new BaseDocument(UUID.randomUUID().toString()); doc1.addAttribute("foo", "a"); - final DocumentCreateEntity meta1 = collection.insertDocument(doc1); + final DocumentCreateEntity meta1 = collection.insertDocument(doc1); final BaseDocument doc2 = new BaseDocument(UUID.randomUUID().toString()); doc2.addAttribute("foo", "a"); - final DocumentCreateEntity meta2 = collection.insertDocument(doc2); + final DocumentCreateEntity meta2 = collection.insertDocument(doc2); doc1.addAttribute("bar", "b"); doc2.addAttribute("bar", "b"); @@ -1783,7 +1880,7 @@ void insertDocumentsJson(ArangoCollection collection) { values.add(RawJson.of("{}")); values.add(RawJson.of("{}")); values.add(RawJson.of("{}")); - final MultiDocumentEntity> docs = collection.insertDocuments(values); + final MultiDocumentEntity docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1796,7 +1893,7 @@ void insertDocumentsJson(ArangoCollection collection) { void insertDocumentsOne(ArangoCollection collection) { final Collection values = new ArrayList<>(); values.add(new BaseDocument()); - final MultiDocumentEntity> docs = collection.insertDocuments(values, null); + final MultiDocumentEntity docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(1); @@ -1808,7 +1905,7 @@ void insertDocumentsOne(ArangoCollection collection) { @MethodSource("cols") void insertDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - final MultiDocumentEntity> docs = collection.insertDocuments(values, null); + final MultiDocumentEntity docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).isEmpty(); @@ -1845,7 +1942,7 @@ void insertDocumentsFail(ArangoCollection collection) { String k2 = rnd(); final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final MultiDocumentEntity> docs = collection.insertDocuments(values); + final MultiDocumentEntity docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(2); @@ -2246,14 +2343,14 @@ void deleteDocumentsByKey(ArangoCollection collection) { e.setKey("2"); values.add(e); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection keys = new ArrayList<>(); keys.add("1"); keys.add("2"); - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(2); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isIn("1", "2"); } assertThat(deleteResult.getErrors()).isEmpty(); @@ -2273,11 +2370,11 @@ void deleteDocumentsByDocuments(ArangoCollection collection) { e.setKey("2"); values.add(e); } - collection.insertDocuments(values, null); - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values, null, null); + collection.insertDocuments(values); + MultiDocumentEntity> deleteResult = collection.deleteDocuments(values); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(2); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isIn("1", "2"); } assertThat(deleteResult.getErrors()).isEmpty(); @@ -2292,13 +2389,13 @@ void deleteDocumentsByKeyOne(ArangoCollection collection) { e.setKey("1"); values.add(e); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection keys = new ArrayList<>(); keys.add("1"); - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(1); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isEqualTo("1"); } assertThat(deleteResult.getErrors()).isEmpty(); @@ -2313,11 +2410,11 @@ void deleteDocumentsByDocumentOne(ArangoCollection collection) { e.setKey("1"); values.add(e); } - collection.insertDocuments(values, null); - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values, null, null); + collection.insertDocuments(values); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(1); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isEqualTo("1"); } assertThat(deleteResult.getErrors()).isEmpty(); @@ -2327,9 +2424,9 @@ void deleteDocumentsByDocumentOne(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection keys = new ArrayList<>(); - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); + final MultiDocumentEntity deleteResult = collection.deleteDocuments(keys); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).isEmpty(); assertThat(deleteResult.getErrors()).isEmpty(); @@ -2339,10 +2436,10 @@ void deleteDocumentsEmpty(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentsByKeyNotExisting(ArangoCollection collection) { final Collection values = new ArrayList<>(); - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection keys = Arrays.asList(rnd(), rnd()); - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); + final MultiDocumentEntity deleteResult = collection.deleteDocuments(keys); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).isEmpty(); assertThat(deleteResult.getErrors()).hasSize(2); @@ -2362,7 +2459,7 @@ void deleteDocumentsByDocumentsNotExisting(ArangoCollection collection) { e.setKey("2"); values.add(e); } - final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values, null, null); + final MultiDocumentEntity deleteResult = collection.deleteDocuments(values); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).isEmpty(); assertThat(deleteResult.getErrors()).hasSize(2); @@ -2372,10 +2469,10 @@ void deleteDocumentsByDocumentsNotExisting(ArangoCollection collection) { @MethodSource("cols") void updateDocuments(ArangoCollection collection) { final Collection values = Arrays.asList(new BaseDocument(rnd()), new BaseDocument(rnd())); - collection.insertDocuments(values, null); + collection.insertDocuments(values); values.forEach(it -> it.addAttribute("a", "test")); - final MultiDocumentEntity> updateResult = collection.updateDocuments(values, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(values); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2411,12 +2508,12 @@ void updateDocumentsOne(ArangoCollection collection) { e.setKey("1"); values.add(e); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection updatedValues = new ArrayList<>(); final BaseDocument first = values.iterator().next(); first.addAttribute("a", "test"); updatedValues.add(first); - final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2425,7 +2522,7 @@ void updateDocumentsOne(ArangoCollection collection) { @MethodSource("cols") void updateDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - final MultiDocumentEntity> updateResult = collection.updateDocuments(values, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(values); assertThat(updateResult.getDocuments()).isEmpty(); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2437,14 +2534,14 @@ void updateDocumentsWithoutKey(ArangoCollection collection) { { values.add(new BaseDocument("1")); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } updatedValues.add(new BaseDocument()); - final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).hasSize(1); } @@ -2460,7 +2557,7 @@ void updateDocumentsJson(ArangoCollection collection) { final Collection updatedValues = new ArrayList<>(); updatedValues.add(RawJson.of("{\"_key\":\"1\", \"foo\":\"bar\"}")); updatedValues.add(RawJson.of("{\"_key\":\"2\", \"foo\":\"bar\"}")); - final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2473,13 +2570,13 @@ void replaceDocuments(ArangoCollection collection) { values.add(new BaseDocument("1")); values.add(new BaseDocument("2")); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } - final MultiDocumentEntity> updateResult = collection.replaceDocuments(updatedValues, null); + final MultiDocumentEntity updateResult = collection.replaceDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2493,12 +2590,12 @@ void replaceDocumentsOne(ArangoCollection collection) { e.setKey("1"); values.add(e); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection updatedValues = new ArrayList<>(); final BaseDocument first = values.iterator().next(); first.addAttribute("a", "test"); updatedValues.add(first); - final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2507,7 +2604,7 @@ void replaceDocumentsOne(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - final MultiDocumentEntity> updateResult = collection.updateDocuments(values, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(values); assertThat(updateResult.getDocuments()).isEmpty(); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2519,14 +2616,14 @@ void replaceDocumentsWithoutKey(ArangoCollection collection) { { values.add(new BaseDocument("1")); } - collection.insertDocuments(values, null); + collection.insertDocuments(values); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } updatedValues.add(new BaseDocument()); - final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).hasSize(1); } @@ -2542,7 +2639,7 @@ void replaceDocumentsJson(ArangoCollection collection) { final Collection updatedValues = new ArrayList<>(); updatedValues.add(RawJson.of("{\"_key\":\"1\", \"foo\":\"bar\"}")); updatedValues.add(RawJson.of("{\"_key\":\"2\", \"foo\":\"bar\"}")); - final MultiDocumentEntity> updateResult = collection.replaceDocuments(updatedValues); + final MultiDocumentEntity updateResult = collection.replaceDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } diff --git a/src/test/java/com/arangodb/DocumentTest.java b/src/test/java/com/arangodb/DocumentTest.java index 55f0724f0..a921a213d 100644 --- a/src/test/java/com/arangodb/DocumentTest.java +++ b/src/test/java/com/arangodb/DocumentTest.java @@ -83,7 +83,7 @@ void insertAsJson(ArangoCollection collection) { + "}" ); //@formatter:on - final DocumentCreateEntity createResult = collection.insertDocument(json); + final DocumentCreateEntity createResult = collection.insertDocument(json); final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class); assertThat(doc).isNotNull(); final Object article = doc.getAttribute("article"); @@ -116,7 +116,7 @@ void insertAsBaseDocument(ArangoCollection collection) { stock.addAttribute("status", "RMV"); stock.addAttribute("lastUpdate", "2016-11-01 00:00"); } - final DocumentCreateEntity createResult = collection.insertDocument(document); + final DocumentCreateEntity createResult = collection.insertDocument(document); final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class); assertThat(doc).isNotNull(); final Object article = doc.getAttribute("article"); @@ -131,7 +131,7 @@ void insertAsBaseDocument(ArangoCollection collection) { void documentKeyWithSpecialChars(ArangoCollection collection) { final String key = "_-:.@()+,=;$!*'%" + UUID.randomUUID(); final BaseDocument document = new BaseDocument(key); - final DocumentCreateEntity createResult = collection.insertDocument(document); + final DocumentCreateEntity createResult = collection.insertDocument(document); final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class); assertThat(doc).isNotNull(); assertThat(doc.getKey()).isEqualTo(key); diff --git a/src/test/java/com/arangodb/StreamTransactionTest.java b/src/test/java/com/arangodb/StreamTransactionTest.java index d17d9e6d7..bc52a0673 100644 --- a/src/test/java/com/arangodb/StreamTransactionTest.java +++ b/src/test/java/com/arangodb/StreamTransactionTest.java @@ -552,7 +552,7 @@ void deleteDocument(ArangoDatabase db) { // delete document from within the tx collection - .deleteDocument(createdDoc.getKey(), null, new DocumentDeleteOptions().streamTransactionId(tx.getId())); + .deleteDocument(createdDoc.getKey(), new DocumentDeleteOptions().streamTransactionId(tx.getId())); // assert that the document has not been deleted from outside the tx assertThat(collection.getDocument(createdDoc.getKey(), BaseDocument.class, null)).isNotNull(); @@ -576,7 +576,7 @@ void deleteDocuments(ArangoDatabase db) { ArangoCollection collection = db.collection(COLLECTION_NAME); List keys = collection - .insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument(), new BaseDocument()), null) + .insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument(), new BaseDocument())) .getDocuments().stream().map(DocumentEntity::getKey).collect(Collectors.toList()); StreamTransactionEntity tx = db.beginStreamTransaction( @@ -584,7 +584,7 @@ void deleteDocuments(ArangoDatabase db) { // delete document from within the tx collection - .deleteDocuments(keys, null, new DocumentDeleteOptions().streamTransactionId(tx.getId())); + .deleteDocuments(keys, new DocumentDeleteOptions().streamTransactionId(tx.getId())); // assert that the documents has not been deleted from outside the tx assertThat(collection.getDocuments(keys, BaseDocument.class, null).getDocuments()).hasSize(keys.size()); diff --git a/src/test/java/com/arangodb/async/ArangoCollectionTest.java b/src/test/java/com/arangodb/async/ArangoCollectionTest.java index db72e4e42..1024dc609 100644 --- a/src/test/java/com/arangodb/async/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoCollectionTest.java @@ -20,14 +20,19 @@ package com.arangodb.async; +import com.arangodb.ArangoCollection; import com.arangodb.ArangoDBException; import com.arangodb.entity.*; import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; +import com.arangodb.serde.JacksonSerde; import com.arangodb.util.RawJson; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -48,6 +53,78 @@ class ArangoCollectionTest extends BaseTest { private static final String COLLECTION_NAME = "db_collection_test"; + @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "type") + public interface Animal { + String getKey(); + + String getName(); + } + + public static class Dog implements Animal { + + @Key + private String key; + private String name; + + public Dog() { + } + + public Dog(String key, String name) { + this.key = key; + this.name = name; + } + + @Override + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + public static class Cat implements Animal { + @Key + private String key; + private String name; + + public Cat() { + } + + public Cat(String key, String name) { + this.key = key; + this.name = name; + } + + @Override + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + ArangoCollectionTest() throws ExecutionException, InterruptedException { ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); if (!collection.exists().get()) { @@ -103,6 +180,41 @@ void insertDocumentReturnNew() throws InterruptedException, ExecutionException { .get(); } + + @Test + void insertDocumentWithTypeOverwriteModeReplace() throws InterruptedException, ExecutionException { + assumeTrue(isAtLeastVersion(3, 7)); + assumeTrue(db.getSerde().getUserSerde() instanceof JacksonSerde, "polymorphic deserialization support required"); + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); + String key = UUID.randomUUID().toString(); + Dog dog = new Dog(key, "Teddy"); + Cat cat = new Cat(key, "Luna"); + + final DocumentCreateOptions options = new DocumentCreateOptions() + .returnNew(true) + .returnOld(true) + .overwriteMode(OverwriteMode.replace); + collection.insertDocument(dog, options).get(); + final DocumentCreateEntity doc = collection.insertDocument(cat, options, Animal.class).get(); + assertThat(doc).isNotNull(); + assertThat(doc.getId()).isNotNull(); + assertThat(doc.getKey()).isNotNull().isEqualTo(key); + assertThat(doc.getRev()).isNotNull(); + + assertThat(doc.getOld()) + .isNotNull() + .isInstanceOf(Dog.class); + assertThat(doc.getOld().getKey()).isEqualTo(key); + assertThat(doc.getOld().getName()).isEqualTo("Teddy"); + + assertThat(doc.getNew()) + .isNotNull() + .isInstanceOf(Cat.class); + assertThat(doc.getNew().getKey()).isEqualTo(key); + assertThat(doc.getNew().getName()).isEqualTo("Luna"); + } + + @Test void insertDocumentWaitForSync() throws InterruptedException, ExecutionException { final DocumentCreateOptions options = new DocumentCreateOptions().waitForSync(true); @@ -679,7 +791,7 @@ void deleteDocument() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString()); final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) .get(); - db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), null, null).get(); + db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey()).get(); db.collection(COLLECTION_NAME).getDocument(createResult.getKey(), BaseDocument.class, null) .whenComplete((document, ex) -> assertThat(document).isNull()) .get(); @@ -692,7 +804,7 @@ void deleteDocumentReturnOld() throws InterruptedException, ExecutionException { final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) .get(); final DocumentDeleteOptions options = new DocumentDeleteOptions().returnOld(true); - db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), BaseDocument.class, options) + db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), options, BaseDocument.class) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult.getOld()).isNotNull(); assertThat(deleteResult.getOld()).isInstanceOf(BaseDocument.class); @@ -708,7 +820,7 @@ void deleteDocumentIfMatch() throws InterruptedException, ExecutionException { final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) .get(); final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch(createResult.getRev()); - db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), null, options).get(); + db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), options).get(); db.collection(COLLECTION_NAME).getDocument(createResult.getKey(), BaseDocument.class, null) .whenComplete((document, ex) -> assertThat(document).isNull()) .get(); @@ -721,7 +833,7 @@ void deleteDocumentIfMatchFail() throws InterruptedException, ExecutionException .get(); final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch("no"); try { - db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), null, options).get(); + db.collection(COLLECTION_NAME).deleteDocument(createResult.getKey(), options).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause()).isInstanceOf(ArangoDBException.class); @@ -1273,7 +1385,7 @@ void documentExists() throws InterruptedException, ExecutionException { @Test void documentExistsIfMatch() throws InterruptedException, ExecutionException { - final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) .insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); final DocumentExistsOptions options = new DocumentExistsOptions().ifMatch(createResult.getRev()); db.collection(COLLECTION_NAME).documentExists("abc", options) @@ -1301,7 +1413,7 @@ void documentExistsIfNoneMatch() throws InterruptedException, ExecutionException @Test void documentExistsIfNoneMatchFail() throws InterruptedException, ExecutionException { - final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) .insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); final DocumentExistsOptions options = new DocumentExistsOptions().ifNoneMatch(createResult.getRev()); db.collection(COLLECTION_NAME).documentExists("abc", options) @@ -1315,7 +1427,7 @@ void insertDocuments() throws InterruptedException, ExecutionException { values.add(new BaseDocument()); values.add(new BaseDocument()); values.add(new BaseDocument()); - db.collection(COLLECTION_NAME).insertDocuments(values, null) + db.collection(COLLECTION_NAME).insertDocuments(values) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); @@ -1330,7 +1442,7 @@ void insertDocuments() throws InterruptedException, ExecutionException { void insertDocumentsOne() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); values.add(new BaseDocument()); - db.collection(COLLECTION_NAME).insertDocuments(values, null) + db.collection(COLLECTION_NAME).insertDocuments(values) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); @@ -1344,7 +1456,7 @@ void insertDocumentsOne() throws InterruptedException, ExecutionException { @Test void insertDocumentsEmpty() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); - db.collection(COLLECTION_NAME).insertDocuments(values, null) + db.collection(COLLECTION_NAME).insertDocuments(values) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); @@ -1783,15 +1895,15 @@ void deleteDocumentsByKey() throws InterruptedException, ExecutionException { e.setKey("2"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection keys = new ArrayList<>(); keys.add("1"); keys.add("2"); - db.collection(COLLECTION_NAME).deleteDocuments(keys, null, null) + db.collection(COLLECTION_NAME).deleteDocuments(keys) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(2); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isIn("1", "2"); } assertThat(deleteResult.getErrors().size()).isEqualTo(0); @@ -1812,12 +1924,12 @@ void deleteDocumentsByDocuments() throws InterruptedException, ExecutionExceptio e.setKey("2"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); - db.collection(COLLECTION_NAME).deleteDocuments(values, null, null) + db.collection(COLLECTION_NAME).insertDocuments(values).get(); + db.collection(COLLECTION_NAME).deleteDocuments(values) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(2); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isIn("1", "2"); } assertThat(deleteResult.getErrors().size()).isEqualTo(0); @@ -1833,14 +1945,14 @@ void deleteDocumentsByKeyOne() throws InterruptedException, ExecutionException { e.setKey("1"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection keys = new ArrayList<>(); keys.add("1"); - db.collection(COLLECTION_NAME).deleteDocuments(keys, null, null) + db.collection(COLLECTION_NAME).deleteDocuments(keys) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(1); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isEqualTo("1"); } assertThat(deleteResult.getErrors().size()).isEqualTo(0); @@ -1856,12 +1968,12 @@ void deleteDocumentsByDocumentOne() throws InterruptedException, ExecutionExcept e.setKey("1"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); - db.collection(COLLECTION_NAME).deleteDocuments(values, null, null) + db.collection(COLLECTION_NAME).insertDocuments(values).get(); + db.collection(COLLECTION_NAME).deleteDocuments(values) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(1); - for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { assertThat(i.getKey()).isEqualTo("1"); } assertThat(deleteResult.getErrors().size()).isEqualTo(0); @@ -1872,9 +1984,9 @@ void deleteDocumentsByDocumentOne() throws InterruptedException, ExecutionExcept @Test void deleteDocumentsEmpty() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection keys = new ArrayList<>(); - db.collection(COLLECTION_NAME).deleteDocuments(keys, null, null) + db.collection(COLLECTION_NAME).deleteDocuments(keys) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(0); @@ -1886,11 +1998,11 @@ void deleteDocumentsEmpty() throws InterruptedException, ExecutionException { @Test void deleteDocumentsByKeyNotExisting() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection keys = new ArrayList<>(); keys.add("1"); keys.add("2"); - db.collection(COLLECTION_NAME).deleteDocuments(keys, null, null) + db.collection(COLLECTION_NAME).deleteDocuments(keys) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(0); @@ -1912,7 +2024,7 @@ void deleteDocumentsByDocumentsNotExisting() throws InterruptedException, Execut e.setKey("2"); values.add(e); } - db.collection(COLLECTION_NAME).deleteDocuments(values, null, null) + db.collection(COLLECTION_NAME).deleteDocuments(values) .whenComplete((deleteResult, ex) -> { assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments().size()).isEqualTo(0); @@ -1934,13 +2046,13 @@ void updateDocuments() throws InterruptedException, ExecutionException { e.setKey("2"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } - db.collection(COLLECTION_NAME).updateDocuments(updatedValues, null) + db.collection(COLLECTION_NAME).updateDocuments(updatedValues) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(2); assertThat(updateResult.getErrors().size()).isEqualTo(0); @@ -1987,12 +2099,12 @@ void updateDocumentsOne() throws InterruptedException, ExecutionException { e.setKey("1"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection updatedValues = new ArrayList<>(); final BaseDocument first = values.iterator().next(); first.addAttribute("a", "test"); updatedValues.add(first); - db.collection(COLLECTION_NAME).updateDocuments(updatedValues, null) + db.collection(COLLECTION_NAME).updateDocuments(updatedValues) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(1); assertThat(updateResult.getErrors().size()).isEqualTo(0); @@ -2003,7 +2115,7 @@ void updateDocumentsOne() throws InterruptedException, ExecutionException { @Test void updateDocumentsEmpty() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); - db.collection(COLLECTION_NAME).updateDocuments(values, null) + db.collection(COLLECTION_NAME).updateDocuments(values) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(0); assertThat(updateResult.getErrors().size()).isEqualTo(0); @@ -2017,14 +2129,14 @@ void updateDocumentsWithoutKey() throws InterruptedException, ExecutionException { values.add(new BaseDocument("1")); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } updatedValues.add(new BaseDocument()); - db.collection(COLLECTION_NAME).updateDocuments(updatedValues, null) + db.collection(COLLECTION_NAME).updateDocuments(updatedValues) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(1); assertThat(updateResult.getErrors().size()).isEqualTo(1); @@ -2039,13 +2151,13 @@ void replaceDocuments() throws InterruptedException, ExecutionException { values.add(new BaseDocument("1")); values.add(new BaseDocument("2")); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } - db.collection(COLLECTION_NAME).replaceDocuments(updatedValues, null) + db.collection(COLLECTION_NAME).replaceDocuments(updatedValues) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(2); assertThat(updateResult.getErrors().size()).isEqualTo(0); @@ -2061,12 +2173,12 @@ void replaceDocumentsOne() throws InterruptedException, ExecutionException { e.setKey("1"); values.add(e); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection updatedValues = new ArrayList<>(); final BaseDocument first = values.iterator().next(); first.addAttribute("a", "test"); updatedValues.add(first); - db.collection(COLLECTION_NAME).updateDocuments(updatedValues, null) + db.collection(COLLECTION_NAME).updateDocuments(updatedValues) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(1); assertThat(updateResult.getErrors().size()).isEqualTo(0); @@ -2077,7 +2189,7 @@ void replaceDocumentsOne() throws InterruptedException, ExecutionException { @Test void replaceDocumentsEmpty() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); - db.collection(COLLECTION_NAME).updateDocuments(values, null) + db.collection(COLLECTION_NAME).updateDocuments(values) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(0); assertThat(updateResult.getErrors().size()).isEqualTo(0); @@ -2091,14 +2203,14 @@ void replaceDocumentsWithoutKey() throws InterruptedException, ExecutionExceptio { values.add(new BaseDocument("1")); } - db.collection(COLLECTION_NAME).insertDocuments(values, null).get(); + db.collection(COLLECTION_NAME).insertDocuments(values).get(); final Collection updatedValues = new ArrayList<>(); for (final BaseDocument i : values) { i.addAttribute("a", "test"); updatedValues.add(i); } updatedValues.add(new BaseDocument()); - db.collection(COLLECTION_NAME).updateDocuments(updatedValues, null) + db.collection(COLLECTION_NAME).updateDocuments(updatedValues) .whenComplete((updateResult, ex) -> { assertThat(updateResult.getDocuments().size()).isEqualTo(1); assertThat(updateResult.getErrors().size()).isEqualTo(1); diff --git a/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java index 6251385a8..2b74c8ad2 100644 --- a/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java @@ -46,8 +46,7 @@ class GetDocumentExampleTest extends ExampleBase { static void before() throws InterruptedException, ExecutionException { final BaseDocument value = new BaseDocument(UUID.randomUUID().toString()); value.addAttribute("foo", "bar"); - final DocumentCreateEntity doc = collection.insertDocument(value).get(); - key = doc.getKey(); + key = collection.insertDocument(value).get().getKey(); } @Test diff --git a/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java index 0b5fbb50a..be78c92a1 100644 --- a/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java @@ -72,7 +72,7 @@ static void tearDown() throws InterruptedException, ExecutionException { arangoDB.shutdown(); } - private static DocumentCreateEntity saveMovie( + private static DocumentCreateEntity saveMovie( final ArangoCollectionAsync movies, final String key, final String title, @@ -86,7 +86,7 @@ private static DocumentCreateEntity saveMovie( return movies.insertDocument(value).get(); } - private static DocumentCreateEntity saveActor( + private static DocumentCreateEntity saveActor( final ArangoCollectionAsync actors, final String key, final String name, diff --git a/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java index 16816ec0b..231f6a1e7 100644 --- a/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java @@ -115,7 +115,7 @@ void aqlDeserialization() throws ExecutionException, InterruptedException { doc.put("arr", Collections.singletonList("hello")); doc.put("int", 10); - collection.insertDocument(doc, null).get(); + collection.insertDocument(doc).get(); final Map result = db.query( "RETURN DOCUMENT(@docId)", @@ -158,7 +158,7 @@ void getDocument() throws ExecutionException, InterruptedException { doc.put("arr", Collections.singletonList("hello")); doc.put("int", 10); - collection.insertDocument(doc, null).get(); + collection.insertDocument(doc).get(); final Map result = db.collection(COLLECTION_NAME).getDocument( key, diff --git a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java index 21885281f..26fee1747 100644 --- a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java @@ -46,8 +46,7 @@ class GetDocumentExampleTest extends ExampleBase { static void before() { final BaseDocument value = new BaseDocument(UUID.randomUUID().toString()); value.addAttribute("foo", "bar"); - final DocumentCreateEntity doc = collection.insertDocument(value); - key = doc.getKey(); + key = collection.insertDocument(value).getKey(); } @Test diff --git a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java index 1594b4f91..000b6ddd6 100644 --- a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java @@ -24,7 +24,6 @@ import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; import com.arangodb.util.RawJson; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; @@ -41,7 +40,7 @@ class InsertDocumentExampleTest extends ExampleBase { @Test void insertBean() { - final DocumentCreateEntity doc = collection.insertDocument(new TestEntity("bar")); + final DocumentCreateEntity doc = collection.insertDocument(new TestEntity("bar")); assertThat(doc.getKey()).isNotNull(); } @@ -49,7 +48,7 @@ void insertBean() { void insertBaseDocument() { final BaseDocument value = new BaseDocument(UUID.randomUUID().toString()); value.addAttribute("foo", "bar"); - final DocumentCreateEntity doc = collection.insertDocument(value); + final DocumentCreateEntity doc = collection.insertDocument(value); assertThat(doc.getKey()).isNotNull(); } @@ -58,13 +57,13 @@ void insertJsonNode() { ObjectMapper mapper = new ObjectMapper(); ObjectNode node = mapper.createObjectNode(); node.put("foo", "bar"); - final DocumentCreateEntity doc = collection.insertDocument(node); + final DocumentCreateEntity doc = collection.insertDocument(node); assertThat(doc.getKey()).isNotNull(); } @Test void insertJson() { - final DocumentCreateEntity doc = collection.insertDocument(RawJson.of("{\"foo\":\"bar\"}")); + final DocumentCreateEntity doc = collection.insertDocument(RawJson.of("{\"foo\":\"bar\"}")); assertThat(doc.getKey()).isNotNull(); } diff --git a/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java index cf8f67ddc..da93131f1 100644 --- a/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java @@ -313,7 +313,7 @@ public boolean equals(final Object obj) { } - private static DocumentCreateEntity saveMovie( + private static DocumentCreateEntity saveMovie( final ArangoCollection movies, final String key, final String title, @@ -327,7 +327,7 @@ private static DocumentCreateEntity saveMovie( return movies.insertDocument(value); } - private static DocumentCreateEntity saveActor( + private static DocumentCreateEntity saveActor( final ArangoCollection actors, final String key, final String name, diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index ae2cd1e6e..de4301b44 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -171,7 +171,7 @@ void aqlDeserialization() { doc.put("arr", Collections.singletonList("hello")); doc.put("int", 10); - collection.insertDocument(doc, null); + collection.insertDocument(doc); final Map result = db.query( "RETURN DOCUMENT(@docId)", @@ -214,7 +214,7 @@ void getDocument() { doc.put("arr", Collections.singletonList("hello")); doc.put("int", 10); - collection.insertDocument(doc, null); + collection.insertDocument(doc); final Map result = db.collection(COLLECTION_NAME).getDocument( key,