From 492c815ac57c54be959997f381a650ac1469f07c Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 17 Aug 2022 09:14:46 +0200 Subject: [PATCH 1/5] RawData --- .../java/com/arangodb/ArangoCollection.java | 63 +++++++------------ .../java/com/arangodb/ArangoDatabase.java | 24 +++---- .../com/arangodb/ArangoEdgeCollection.java | 24 +++---- .../com/arangodb/ArangoVertexCollection.java | 24 +++---- .../arangodb/async/ArangoCollectionAsync.java | 63 +++++++------------ .../arangodb/async/ArangoDatabaseAsync.java | 24 +++---- .../async/ArangoEdgeCollectionAsync.java | 12 ++-- .../async/ArangoVertexCollectionAsync.java | 12 ++-- src/main/java/com/arangodb/util/RawBytes.java | 2 +- src/main/java/com/arangodb/util/RawData.java | 17 +++++ src/main/java/com/arangodb/util/RawJson.java | 2 +- 11 files changed, 103 insertions(+), 164 deletions(-) create mode 100644 src/main/java/com/arangodb/util/RawData.java diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index d0c7d31f5..a21c69a80 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -54,8 +54,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData} * @return information about the document * @see API * Documentation @@ -66,8 +65,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the document * @see API @@ -79,8 +77,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the document @@ -93,7 +90,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 values A List of documents * @return information about the documents * @see API * Documentation @@ -104,8 +101,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the documents * @see API @@ -118,8 +114,7 @@ MultiDocumentEntity> insertDocuments( * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the documents @@ -167,8 +162,7 @@ MultiDocumentEntity> insertDocuments( * Retrieves the document with the given {@code key} from the collection. * * @param key The key of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @return the document identified by the key * @see API * Documentation @@ -179,8 +173,7 @@ MultiDocumentEntity> insertDocuments( * Retrieves the document with the given {@code key} from the collection. * * @param key The key of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the document identified by the key * @see API @@ -192,8 +185,7 @@ MultiDocumentEntity> insertDocuments( * Retrieves multiple documents with the given {@code _key} from the collection. * * @param keys The keys of the documents - * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the documents (POJO or {@link com.arangodb.util.RawData}) * @return the documents and possible errors */ MultiDocumentEntity getDocuments(Collection keys, Class type); @@ -202,8 +194,7 @@ MultiDocumentEntity> insertDocuments( * Retrieves multiple documents with the given {@code _key} from the collection. * * @param keys The keys of the documents - * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the documents and possible errors */ @@ -214,8 +205,7 @@ MultiDocumentEntity> insertDocuments( * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @return information about the document * @see * API @@ -228,8 +218,7 @@ MultiDocumentEntity> insertDocuments( * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the document * @see @@ -243,8 +232,7 @@ MultiDocumentEntity> insertDocuments( * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the document @@ -258,7 +246,7 @@ MultiDocumentEntity> insertDocuments( * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the documents * @see * API @@ -270,8 +258,7 @@ MultiDocumentEntity> insertDocuments( * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the documents * @see @@ -285,8 +272,7 @@ MultiDocumentEntity> replaceDocuments( * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the documents @@ -303,8 +289,7 @@ MultiDocumentEntity> replaceDocuments( * they do not yet exist, and overwritten in the existing document if they do exist there. * * @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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @return information about the document * @see API * Documentation @@ -317,8 +302,7 @@ MultiDocumentEntity> replaceDocuments( * they do not yet exist, and overwritten in the existing document if they do exist there. * * @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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the document * @see API @@ -332,8 +316,7 @@ MultiDocumentEntity> replaceDocuments( * they do not yet exist, and overwritten in the existing document if they do exist there. * * @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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the document @@ -349,7 +332,7 @@ DocumentUpdateEntity updateDocument(String key, Object value, DocumentUpd * attributes from the patch documents will be added to the existing documents if they do not yet exist, and * overwritten in the existing documents if they do exist there. * - * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param values A list of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the documents * @see * API @@ -363,8 +346,7 @@ DocumentUpdateEntity updateDocument(String key, Object value, DocumentUpd * attributes from the patch documents will be added to the existing documents if they do not yet exist, and * overwritten in the existing documents if they do exist there. * - * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param values A list of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the documents * @see @@ -380,8 +362,7 @@ MultiDocumentEntity> updateDocuments( * attributes from the patch documents will be added to the existing documents if they do not yet exist, and * overwritten in the existing documents if they do exist there. * - * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param values A list of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the documents diff --git a/src/main/java/com/arangodb/ArangoDatabase.java b/src/main/java/com/arangodb/ArangoDatabase.java index af8b02808..16cd93cbf 100644 --- a/src/main/java/com/arangodb/ArangoDatabase.java +++ b/src/main/java/com/arangodb/ArangoDatabase.java @@ -245,8 +245,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * @param query An AQL query string * @param bindVars key/value pairs defining the variables to bind the query to * @param options Additional options that will be passed to the query API, can be null - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -260,8 +259,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * * @param query An AQL query string * @param options Additional options that will be passed to the query API, can be null - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -275,8 +273,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * * @param query An AQL query string * @param bindVars key/value pairs defining the variables to bind the query to - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -289,8 +286,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * result list. * * @param query An AQL query string - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -302,8 +298,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * Return an cursor from the given cursor-ID if still existing * * @param cursorId The ID of the cursor - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see API @@ -586,8 +580,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @return the document identified by the id * @see API * Documentation @@ -598,8 +591,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the document identified by the id * @see API diff --git a/src/main/java/com/arangodb/ArangoEdgeCollection.java b/src/main/java/com/arangodb/ArangoEdgeCollection.java index 333cdeb34..7558d9f65 100644 --- a/src/main/java/com/arangodb/ArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/ArangoEdgeCollection.java @@ -49,8 +49,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData}) * @return information about the edge * @see API Documentation */ @@ -59,8 +58,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the edge * @see API Documentation @@ -71,8 +69,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the edge-document (POJO or {@link com.arangodb.util.RawData}) * @return the edge identified by the key * @see API Documentation */ @@ -82,8 +79,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the edge-document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the edge identified by the key * @see API Documentation @@ -95,8 +91,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * violated * * @param key The key of the edge - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData}) * @return information about the edge * @see API Documentation */ @@ -107,8 +102,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * violated * * @param key The key of the edge - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the edge * @see API Documentation @@ -121,8 +115,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the edge - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData}) * @return information about the edge * @see API Documentation */ @@ -134,8 +127,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the edge - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the edge * @see API Documentation diff --git a/src/main/java/com/arangodb/ArangoVertexCollection.java b/src/main/java/com/arangodb/ArangoVertexCollection.java index 7a3954195..03d755327 100644 --- a/src/main/java/com/arangodb/ArangoVertexCollection.java +++ b/src/main/java/com/arangodb/ArangoVertexCollection.java @@ -58,8 +58,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @return information about the vertex * @see * API Documentation @@ -69,8 +68,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the vertex * @see @@ -82,8 +80,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * Retrieves the vertex document with the given {@code key} from the collection. * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the vertex-document (POJO or {@link com.arangodb.util.RawData}) * @return the vertex identified by the key * @see API Documentation */ @@ -93,8 +90,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * Retrieves the vertex document with the given {@code key} from the collection. * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the vertex-document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the vertex identified by the key * @see API Documentation @@ -106,8 +102,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * violated * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @return information about the vertex * @see API * Documentation @@ -119,8 +114,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * violated * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the vertex * @see API @@ -134,8 +128,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @return information about the vertex * @see * API Documentation @@ -148,8 +141,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the vertex * @see diff --git a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index d155ba0ed..c8e659674 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -54,8 +54,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @return information about the document * @see API * Documentation @@ -66,8 +65,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the document * @see API @@ -79,8 +77,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the document @@ -94,7 +91,7 @@ CompletableFuture> insertDocument(final T value, fin * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the documents * @see API * Documentation @@ -105,8 +102,7 @@ CompletableFuture> insertDocument(final T value, fin * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the documents * @see API @@ -120,8 +116,7 @@ CompletableFuture>> insertDocume * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the documents @@ -173,8 +168,7 @@ CompletableFuture importDocuments( * Reads a single document * * @param key The key of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @return the document identified by the key * @see API * Documentation @@ -185,8 +179,7 @@ CompletableFuture importDocuments( * Reads a single document * * @param key The key of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the document identified by the key * @see API @@ -198,8 +191,7 @@ CompletableFuture importDocuments( * Reads multiple documents * * @param keys The keys of the documents - * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the documents (POJO or {@link com.arangodb.util.RawData}) * @return the documents and possible errors */ CompletableFuture> getDocuments(final Collection keys, final Class type); @@ -208,8 +200,7 @@ CompletableFuture importDocuments( * Reads multiple documents * * @param keys The keys of the documents - * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the documents and possible errors */ @@ -223,8 +214,7 @@ CompletableFuture> getDocuments( * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @return information about the document * @see * API @@ -237,8 +227,7 @@ CompletableFuture> getDocuments( * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the document * @see @@ -255,8 +244,7 @@ CompletableFuture> replaceDocument( * 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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the document @@ -274,7 +262,7 @@ CompletableFuture> replaceDocument( * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the documents * @see * API @@ -286,8 +274,7 @@ CompletableFuture> replaceDocument( * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the documents * @see @@ -302,8 +289,7 @@ CompletableFuture>> replaceDocum * 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 values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param type Deserialization target type for the returned documents. * @return information about the documents @@ -322,8 +308,7 @@ CompletableFuture>> replaceDocum * they do not yet exist, and overwritten in the existing document if they do exist there. * * @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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @return information about the document * @see API * Documentation @@ -336,8 +321,7 @@ CompletableFuture>> replaceDocum * they do not yet exist, and overwritten in the existing document if they do exist there. * * @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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the document * @see API @@ -354,8 +338,7 @@ CompletableFuture> updateDocument( * they do not yet exist, and overwritten in the existing document if they do exist there. * * @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 value A representation of a single document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the document @@ -374,7 +357,7 @@ CompletableFuture> updateDocument( * attributes from the patch documents will be added to the existing documents if they do not yet exist, and * overwritten in the existing documents if they do exist there. * - * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) + * @param values A list of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the documents * @see * API @@ -388,8 +371,7 @@ CompletableFuture> updateDocument( * attributes from the patch documents will be added to the existing documents if they do not yet exist, and * overwritten in the existing documents if they do exist there. * - * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param values A list of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @return information about the documents * @see @@ -406,8 +388,7 @@ CompletableFuture>> updateDocume * attributes from the patch documents will be added to the existing documents if they do not yet exist, and * overwritten in the existing documents if they do exist there. * - * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param values A list of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the documents diff --git a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java index 6dc963151..73db9152e 100644 --- a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java @@ -250,8 +250,7 @@ public interface ArangoDatabaseAsync extends ArangoSerdeAccessor { * @param query contains the query string to be executed * @param bindVars key/value pairs representing the bind parameters * @param options Additional options, can be null - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -269,8 +268,7 @@ CompletableFuture> query( * * @param query contains the query string to be executed * @param options Additional options, can be null - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -287,8 +285,7 @@ CompletableFuture> query( * * @param query contains the query string to be executed * @param bindVars key/value pairs representing the bind parameters - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -304,8 +301,7 @@ CompletableFuture> query( * result list. * * @param query contains the query string to be executed - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see * API @@ -317,8 +313,7 @@ CompletableFuture> query( * Return an cursor from the given cursor-ID if still existing * * @param cursorId The ID of the cursor - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @return cursor of the results * @see createGraph( * Execute a server-side transaction * * @param action the actual transaction operations to be executed, in the form of stringified JavaScript code - * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the result (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the result of the transaction if it succeeded * @see API @@ -615,8 +609,7 @@ CompletableFuture createGraph( * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @return the document identified by the id * @see API * Documentation @@ -627,8 +620,7 @@ CompletableFuture createGraph( * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the document identified by the id * @see API diff --git a/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java index d2465cd8f..eab16f39c 100644 --- a/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java @@ -52,8 +52,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData} * @return information about the edge * @see API Documentation */ @@ -62,8 +61,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single edge (POJO or {@link com.arangodb.util.RawData} * @param options Additional options, can be null * @return information about the edge * @see API Documentation @@ -74,8 +72,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the edge-document (POJO or {@link com.arangodb.util.RawData} * @return the edge identified by the key * @see API Documentation */ @@ -85,8 +82,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the edge-document (POJO or {@link com.arangodb.util.RawData} * @param options Additional options, can be null * @return the edge identified by the key * @see API Documentation diff --git a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java index 38e22d660..c26be8f55 100644 --- a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java @@ -62,8 +62,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @return information about the vertex * @see * API Documentation @@ -73,8 +72,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param value A representation of a single vertex (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the vertex * @see @@ -86,8 +84,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the vertex-document (POJO or {@link com.arangodb.util.RawData}) * @return the vertex identified by the key * @see API Documentation */ @@ -97,8 +94,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or - * {@link com.arangodb.util.RawBytes}) + * @param type The type of the vertex-document (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return the vertex identified by the key * @see API Documentation diff --git a/src/main/java/com/arangodb/util/RawBytes.java b/src/main/java/com/arangodb/util/RawBytes.java index 82c9adaae..8e9aded1b 100644 --- a/src/main/java/com/arangodb/util/RawBytes.java +++ b/src/main/java/com/arangodb/util/RawBytes.java @@ -19,7 +19,7 @@ * The driver's {@link InternalSerde} supports serializing and deserializing to and from * {@code RawBytes}. */ -public class RawBytes { +public class RawBytes implements RawData { private final byte[] value; protected RawBytes(final byte[] value) { diff --git a/src/main/java/com/arangodb/util/RawData.java b/src/main/java/com/arangodb/util/RawData.java new file mode 100644 index 000000000..610ec7827 --- /dev/null +++ b/src/main/java/com/arangodb/util/RawData.java @@ -0,0 +1,17 @@ +package com.arangodb.util; + +/** + * Wrapper for raw data, current implementations are: + * - {@link RawBytes} + * - {@link RawJson} + */ +public interface RawData { + static RawJson of(final String value) { + return RawJson.of(value); + } + + static RawBytes of(final byte[] value) { + return RawBytes.of(value); + } + +} diff --git a/src/main/java/com/arangodb/util/RawJson.java b/src/main/java/com/arangodb/util/RawJson.java index 45bad862d..3642af973 100644 --- a/src/main/java/com/arangodb/util/RawJson.java +++ b/src/main/java/com/arangodb/util/RawJson.java @@ -13,7 +13,7 @@ * The driver's {@link InternalSerde} supports serializing and deserializing to and from * {@code RawJson}. */ -public class RawJson { +public class RawJson implements RawData { private final String value; protected RawJson(final String value) { From 63d94bbe6d561ce2070ffc227df19edc11f3c0ea Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 17 Aug 2022 10:14:18 +0200 Subject: [PATCH 2/5] addded API methods to handle multi documents from raw data --- .../java/com/arangodb/ArangoCollection.java | 117 ++++++++++++++++- .../arangodb/async/ArangoCollectionAsync.java | 121 +++++++++++++++++- .../internal/ArangoCollectionAsyncImpl.java | 48 ++++++- .../internal/ArangoCollectionImpl.java | 48 ++++++- .../internal/InternalArangoCollection.java | 5 +- 5 files changed, 318 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index a21c69a80..86c42cbb1 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -22,6 +22,7 @@ import com.arangodb.entity.*; import com.arangodb.model.*; +import com.arangodb.util.RawData; import java.util.Collection; @@ -86,6 +87,30 @@ public interface ArangoCollection extends ArangoSerdeAccessor { */ DocumentCreateEntity insertDocument(T value, 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. + * + * @param values Raw data representing a collection of documents + * @return information about the documents + * @see API + * Documentation + */ + MultiDocumentEntity> insertDocuments(RawData values); + + /** + * 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 Raw data representing a collection of documents + * @param options Additional options + * @return information about the documents + * @see API + * Documentation + */ + MultiDocumentEntity> insertDocuments( + RawData values, 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. @@ -127,7 +152,7 @@ MultiDocumentEntity> insertDocuments( /** * Bulk imports the given values into the collection. * - * @param values a list of Objects that will be stored as documents + * @param values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the import */ DocumentImportEntity importDocuments(Collection values); @@ -135,7 +160,7 @@ MultiDocumentEntity> insertDocuments( /** * Bulk imports the given values into the collection. * - * @param values a list of Objects that will be stored as documents + * @param values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the import */ @@ -144,19 +169,19 @@ MultiDocumentEntity> insertDocuments( /** * Bulk imports the given values into the collection. * - * @param values JSON-encoded array of objects that will be stored as documents + * @param values Raw data representing a collection of documents * @return information about the import */ - DocumentImportEntity importDocuments(String values); + DocumentImportEntity importDocuments(RawData values); /** * Bulk imports the given values into the collection. * - * @param values JSON-encoded array of objects that will be stored as documents + * @param values Raw data representing a collection of documents * @param options Additional options, can be null * @return information about the import */ - DocumentImportEntity importDocuments(String values, DocumentImportOptions options); + DocumentImportEntity importDocuments(RawData values, DocumentImportOptions options); /** * Retrieves the document with the given {@code key} from the collection. @@ -242,6 +267,32 @@ MultiDocumentEntity> insertDocuments( */ DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplaceOptions options, 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. + * + * @param values Raw data representing a collection of documents + * @return information about the documents + * @see + * API + * Documentation + */ + MultiDocumentEntity> replaceDocuments(RawData values); + + /** + * 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 Raw data representing a collection of documents + * @param options Additional options + * @return information about the documents + * @see + * API + * Documentation + */ + MultiDocumentEntity> replaceDocuments( + RawData values, 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. @@ -326,6 +377,36 @@ MultiDocumentEntity> replaceDocuments( DocumentUpdateEntity updateDocument(String key, Object value, DocumentUpdateOptions options, Class returnType); + /** + * Partially updates documents, the documents to update are specified by the _key attributes in the objects on + * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All + * attributes from the patch documents will be added to the existing documents if they do not yet exist, and + * overwritten in the existing documents if they do exist there. + * + * @param values Raw data representing a collection of documents + * @return information about the documents + * @see + * API + * Documentation + */ + MultiDocumentEntity> updateDocuments(RawData values); + + /** + * Partially updates documents, the documents to update are specified by the _key attributes in the objects on + * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All + * attributes from the patch documents will be added to the existing documents if they do not yet exist, and + * overwritten in the existing documents if they do exist there. + * + * @param values Raw data representing a collection of documents + * @param options Additional options + * @return information about the documents + * @see + * API + * Documentation + */ + MultiDocumentEntity> updateDocuments( + RawData values, DocumentUpdateOptions options); + /** * Partially updates documents, the documents to update are specified by the _key attributes in the objects on * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All @@ -409,6 +490,30 @@ MultiDocumentEntity> updateDocuments( */ DocumentDeleteEntity deleteDocument(String key, DocumentDeleteOptions options, Class type); + /** + * Deletes multiple documents from the collection. + * + * @param values Raw data representing the keys of the documents or the documents themselves + * @return information about the documents + * @see API + * Documentation + */ + MultiDocumentEntity> deleteDocuments(RawData values); + + /** + * Deletes multiple documents from the collection. + * + * @param values Raw data representing the keys of the documents or the documents themselves + * @param options Additional options + * @return information about the documents + * @see API + * Documentation + */ + MultiDocumentEntity> deleteDocuments( + RawData values, DocumentDeleteOptions options); + /** * Deletes multiple documents from the collection. * diff --git a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index c8e659674..b2d21d01b 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -23,6 +23,7 @@ import com.arangodb.ArangoSerdeAccessor; import com.arangodb.entity.*; import com.arangodb.model.*; +import com.arangodb.util.RawData; import java.util.Collection; import java.util.concurrent.CompletableFuture; @@ -87,6 +88,31 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { 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. + * + * @param values Raw data representing a collection of documents + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> insertDocuments(final RawData values); + + /** + * 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 Raw data representing a collection of documents + * @param options Additional options + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> insertDocuments( + final RawData 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. @@ -131,7 +157,7 @@ CompletableFuture>> insertDocume /** * Imports documents * - * @param values a list of Objects that will be stored as documents + * @param values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @return information about the import */ CompletableFuture importDocuments(final Collection values); @@ -139,7 +165,7 @@ CompletableFuture>> insertDocume /** * Imports documents * - * @param values a list of Objects that will be stored as documents + * @param values A List of documents (POJO or {@link com.arangodb.util.RawData}) * @param options Additional options, can be null * @return information about the import */ @@ -150,19 +176,19 @@ CompletableFuture importDocuments( /** * Imports documents * - * @param values JSON-encoded array of objects that will be stored as documents + * @param values Raw data representing a collection of documents * @return information about the import */ - CompletableFuture importDocuments(final String values); + CompletableFuture importDocuments(final RawData values); /** * Imports documents * - * @param values JSON-encoded array of objects that will be stored as documents + * @param values Raw data representing a collection of documents * @param options Additional options, can be null * @return information about the import */ - CompletableFuture importDocuments(final String values, final DocumentImportOptions options); + CompletableFuture importDocuments(final RawData values, final DocumentImportOptions options); /** * Reads a single document @@ -258,6 +284,33 @@ CompletableFuture> replaceDocument( 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. + * + * @param values Raw data representing a collection of documents + * @return information about the documents + * @see + * API + * Documentation + */ + CompletableFuture>> replaceDocuments(final RawData values); + + /** + * 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 Raw data representing a collection of documents + * @param options Additional options + * @return information about the documents + * @see + * API + * Documentation + */ + CompletableFuture>> replaceDocuments( + final RawData 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. @@ -351,6 +404,37 @@ CompletableFuture> updateDocument( final DocumentUpdateOptions options, final Class returnType); + /** + * Partially updates documents, the documents to update are specified by the _key attributes in the objects on + * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All + * attributes from the patch documents will be added to the existing documents if they do not yet exist, and + * overwritten in the existing documents if they do exist there. + * + * @param values Raw data representing a collection of documents + * @return information about the documents + * @see + * API + * Documentation + */ + CompletableFuture>> updateDocuments(final RawData values); + + /** + * Partially updates documents, the documents to update are specified by the _key attributes in the objects on + * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All + * attributes from the patch documents will be added to the existing documents if they do not yet exist, and + * overwritten in the existing documents if they do exist there. + * + * @param values Raw data representing a collection of documents + * @param options Additional options + * @return information about the documents + * @see + * API + * Documentation + */ + CompletableFuture>> updateDocuments( + final RawData values, + final DocumentUpdateOptions options); + /** * Partially updates documents, the documents to update are specified by the _key attributes in the objects on * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All @@ -442,6 +526,31 @@ CompletableFuture> deleteDocument( final DocumentDeleteOptions options, final Class type); + /** + * Removes multiple document + * + * @param values Raw data representing the keys of the documents or the documents themselves + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> deleteDocuments(final RawData values); + + /** + * Removes multiple document + * + * @param values Raw data representing the keys of the documents or the documents themselves + * @param options Additional options + * @return information about the documents + * @see API + * Documentation + */ + CompletableFuture>> deleteDocuments( + final RawData values, + final DocumentDeleteOptions options); + /** * Removes multiple document * diff --git a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java index ba93556ba..514d3dcb3 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java @@ -25,6 +25,7 @@ import com.arangodb.internal.InternalArangoCollection; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; +import com.arangodb.util.RawData; import java.util.Collection; import java.util.Objects; @@ -65,6 +66,17 @@ public CompletableFuture> insertDocument(T value, Do constructParametricType(DocumentCreateEntity.class, type)); } + @Override + public CompletableFuture>> insertDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public CompletableFuture>> insertDocuments(RawData values, + DocumentCreateOptions options) { + return null; // TODO: implement + } + @Override public CompletableFuture>> insertDocuments( final Collection values) { @@ -101,15 +113,13 @@ public CompletableFuture importDocuments( } @Override - public CompletableFuture importDocuments(final String values) { + public CompletableFuture importDocuments(RawData values) { return executor.execute(importDocumentsRequest(values, new DocumentImportOptions()), DocumentImportEntity.class); } @Override - public CompletableFuture importDocuments( - final String values, - final DocumentImportOptions options) { + public CompletableFuture importDocuments(RawData values, DocumentImportOptions options) { return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class); } @@ -167,6 +177,16 @@ public CompletableFuture> replaceDocument(String key constructParametricType(DocumentUpdateEntity.class, type)); } + @Override + public CompletableFuture>> replaceDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public CompletableFuture>> replaceDocuments(RawData values, DocumentReplaceOptions options) { + return null; // TODO: implement + } + @Override public CompletableFuture>> replaceDocuments( final Collection values) { @@ -212,6 +232,16 @@ public CompletableFuture> updateDocument( constructParametricType(DocumentUpdateEntity.class, returnType)); } + @Override + public CompletableFuture>> updateDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public CompletableFuture>> updateDocuments(RawData values, DocumentUpdateOptions options) { + return null; // TODO: implement + } + @Override public CompletableFuture>> updateDocuments( final Collection values) { @@ -254,6 +284,16 @@ public CompletableFuture> deleteDocument( constructParametricType(DocumentDeleteEntity.class, type)); } + @Override + public CompletableFuture>> deleteDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public CompletableFuture>> deleteDocuments(RawData values, DocumentDeleteOptions options) { + return null; // TODO: implement + } + @Override public CompletableFuture>> deleteDocuments( final Collection values) { diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 9c211d35d..8d16637a8 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java @@ -25,6 +25,7 @@ import com.arangodb.entity.*; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; +import com.arangodb.util.RawData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,6 +65,17 @@ public DocumentCreateEntity insertDocument(final T value, final DocumentC constructParametricType(DocumentCreateEntity.class, type)); } + @Override + public MultiDocumentEntity> insertDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public MultiDocumentEntity> insertDocuments(RawData values, + DocumentCreateOptions options) { + return null; // TODO: implement + } + @Override public MultiDocumentEntity> insertDocuments(final Collection values) { return executor @@ -97,12 +109,12 @@ public DocumentImportEntity importDocuments(final Collection values, final Do } @Override - public DocumentImportEntity importDocuments(final String values) { + public DocumentImportEntity importDocuments(RawData values) { return importDocuments(values, new DocumentImportOptions()); } @Override - public DocumentImportEntity importDocuments(final String values, final DocumentImportOptions options) { + public DocumentImportEntity importDocuments(RawData values, DocumentImportOptions options) { return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class); } @@ -128,7 +140,7 @@ public T getDocument(final String key, final Class type, final DocumentRe if ((e.getResponseCode() != null && (e.getResponseCode() == 404 || e.getResponseCode() == 304 || e.getResponseCode() == 412))) { - return null; + return null; // TODO: implement } throw e; } @@ -165,6 +177,16 @@ public DocumentUpdateEntity replaceDocument(String key, T value, Document constructParametricType(DocumentUpdateEntity.class, type)); } + @Override + public MultiDocumentEntity> replaceDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public MultiDocumentEntity> replaceDocuments(RawData values, DocumentReplaceOptions options) { + return null; // TODO: implement + } + @Override public MultiDocumentEntity> replaceDocuments(final Collection values) { return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), @@ -204,6 +226,16 @@ public DocumentUpdateEntity updateDocument( constructParametricType(DocumentUpdateEntity.class, returnType)); } + @Override + public MultiDocumentEntity> updateDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public MultiDocumentEntity> updateDocuments(RawData values, DocumentUpdateOptions options) { + return null; // TODO: implement + } + @Override public MultiDocumentEntity> updateDocuments(final Collection values) { return updateDocuments(values, new DocumentUpdateOptions(), Void.class); @@ -240,6 +272,16 @@ public DocumentDeleteEntity deleteDocument( constructParametricType(DocumentDeleteEntity.class, type)); } + @Override + public MultiDocumentEntity> deleteDocuments(RawData values) { + return null; // TODO: implement + } + + @Override + public MultiDocumentEntity> deleteDocuments(RawData values, DocumentDeleteOptions options) { + return null; // TODO: implement + } + @Override public MultiDocumentEntity> deleteDocuments(final Collection values) { return deleteDocuments(values, new DocumentDeleteOptions(), Void.class); diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 58061cc0e..a26bee796 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -28,6 +28,7 @@ import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; +import com.arangodb.util.RawData; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.fasterxml.jackson.databind.JsonNode; @@ -141,8 +142,8 @@ protected ResponseDeserializer>> }; } - protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getSerde().serialize(SerdeUtils.INSTANCE.parseJson(values))); + protected Request importDocumentsRequest(final RawData values, final DocumentImportOptions options) { + return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getSerde().serialize(values)); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { From 154f80e2eb9222ef4b103549b45ce635b0b75e73 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 17 Aug 2022 10:14:32 +0200 Subject: [PATCH 3/5] test fixes --- .../com/arangodb/ArangoCollectionTest.java | 23 ++++++++++--------- .../arangodb/async/ArangoCollectionTest.java | 23 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index ca0c813c3..06facf0da 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -26,6 +26,7 @@ import com.arangodb.serde.JacksonSerde; import com.arangodb.util.MapBuilder; import com.arangodb.util.RawBytes; +import com.arangodb.util.RawData; import com.arangodb.util.RawJson; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonTypeInfo; @@ -2175,7 +2176,7 @@ void importDocumentsFromToPrefix(ArangoCollection edgeCollection) { void importDocumentsJson(ArangoCollection collection) throws JsonProcessingException { final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", rnd()), Collections.singletonMap("_key", rnd()))); - final DocumentImportEntity docs = collection.importDocuments(values); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2193,7 +2194,7 @@ void importDocumentsJsonDuplicateDefaultError(ArangoCollection collection) throw final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", k1), Collections.singletonMap("_key", k2), Collections.singletonMap("_key", k2))); - final DocumentImportEntity docs = collection.importDocuments(values); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2211,7 +2212,7 @@ void importDocumentsJsonDuplicateError(ArangoCollection collection) throws JsonP final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", k1), Collections.singletonMap("_key", k2), Collections.singletonMap("_key", k2))); - final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.error)); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.error)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2228,7 +2229,7 @@ void importDocumentsJsonDuplicateIgnore(ArangoCollection collection) throws Json String k2 = rnd(); final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", k1), Collections.singletonMap("_key", k2), Collections.singletonMap("_key", k2))); - final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.ignore)); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.ignore)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2246,7 +2247,7 @@ void importDocumentsJsonDuplicateReplace(ArangoCollection collection) throws Jso final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", k1), Collections.singletonMap("_key", k2), Collections.singletonMap("_key", k2))); - final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.replace)); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.replace)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2264,7 +2265,7 @@ void importDocumentsJsonDuplicateUpdate(ArangoCollection collection) throws Json final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", k1), Collections.singletonMap("_key", k2), Collections.singletonMap("_key", k2))); - final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.update)); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.update)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2278,7 +2279,7 @@ void importDocumentsJsonDuplicateUpdate(ArangoCollection collection) throws Json @MethodSource("cols") void importDocumentsJsonCompleteFail(ArangoCollection collection) { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - Throwable thrown = catchThrowable(() -> collection.importDocuments(values, new DocumentImportOptions().complete(true))); + Throwable thrown = catchThrowable(() -> collection.importDocuments(RawData.of(values), new DocumentImportOptions().complete(true))); assertThat(thrown).isInstanceOf(ArangoDBException.class); ArangoDBException e = (ArangoDBException) thrown; assertThat(e.getErrorNum()).isEqualTo(1210); @@ -2292,7 +2293,7 @@ void importDocumentsJsonDetails(ArangoCollection collection) throws JsonProcessi final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", k1), Collections.singletonMap("_key", k2), Collections.singletonMap("_key", k2))); - final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().details(true)); + final DocumentImportEntity docs = collection.importDocuments(RawData.of(values), new DocumentImportOptions().details(true)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2310,7 +2311,7 @@ void importDocumentsJsonOverwriteFalse(ArangoCollection collection) throws JsonP Long initialCount = collection.count().getCount(); final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", rnd()), Collections.singletonMap("_key", rnd()))); - collection.importDocuments(values, new DocumentImportOptions().overwrite(false)); + collection.importDocuments(RawData.of(values), new DocumentImportOptions().overwrite(false)); assertThat(collection.count().getCount()).isEqualTo(initialCount + 2L); } @@ -2320,7 +2321,7 @@ void importDocumentsJsonOverwriteTrue(ArangoCollection collection) throws JsonPr collection.insertDocument(new BaseDocument()); final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", rnd()), Collections.singletonMap("_key", rnd()))); - collection.importDocuments(values, new DocumentImportOptions().overwrite(true)); + collection.importDocuments(RawData.of(values), new DocumentImportOptions().overwrite(true)); assertThat(collection.count().getCount()).isEqualTo(2L); } @@ -2334,7 +2335,7 @@ void importDocumentsJsonFromToPrefix(ArangoCollection edgeCollection) throws Jso final String values = mapper.writeValueAsString(Arrays.asList(new MapBuilder().put("_key", k1).put("_from", "from").put("_to", "to").get(), new MapBuilder().put("_key", k2).put("_from", "from").put("_to", "to").get())); - final DocumentImportEntity importResult = edgeCollection.importDocuments(values, new DocumentImportOptions().fromPrefix("foo").toPrefix("bar")); + final DocumentImportEntity importResult = edgeCollection.importDocuments(RawData.of(values), new DocumentImportOptions().fromPrefix("foo").toPrefix("bar")); assertThat(importResult).isNotNull(); assertThat(importResult.getCreated()).isEqualTo(2); for (String key : keys) { diff --git a/src/test/java/com/arangodb/async/ArangoCollectionTest.java b/src/test/java/com/arangodb/async/ArangoCollectionTest.java index 793e03e3c..09d4626bb 100644 --- a/src/test/java/com/arangodb/async/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoCollectionTest.java @@ -26,6 +26,7 @@ import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.serde.JacksonSerde; +import com.arangodb.util.RawData; import com.arangodb.util.RawJson; import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.junit.jupiter.api.AfterEach; @@ -1712,7 +1713,7 @@ void importDocumentsFromToPrefix() throws InterruptedException, ExecutionExcepti @Test void importDocumentsJson() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1728,7 +1729,7 @@ void importDocumentsJson() throws InterruptedException, ExecutionException { @Test void importDocumentsJsonDuplicateDefaultError() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1744,7 +1745,7 @@ void importDocumentsJsonDuplicateDefaultError() throws InterruptedException, Exe @Test void importDocumentsJsonDuplicateError() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.error)) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.error)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1760,7 +1761,7 @@ void importDocumentsJsonDuplicateError() throws InterruptedException, ExecutionE @Test void importDocumentsJsonDuplicateIgnore() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.ignore)) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.ignore)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1776,7 +1777,7 @@ void importDocumentsJsonDuplicateIgnore() throws InterruptedException, Execution @Test void importDocumentsJsonDuplicateReplace() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.replace)) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.replace)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1792,7 +1793,7 @@ void importDocumentsJsonDuplicateReplace() throws InterruptedException, Executio @Test void importDocumentsJsonDuplicateUpdate() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.update)) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values), new DocumentImportOptions().onDuplicate(OnDuplicate.update)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1809,7 +1810,7 @@ void importDocumentsJsonDuplicateUpdate() throws InterruptedException, Execution void importDocumentsJsonCompleteFail() throws InterruptedException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; try { - db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().complete(true)).get(); + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values), new DocumentImportOptions().complete(true)).get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause()).isInstanceOf(ArangoDBException.class); @@ -1820,7 +1821,7 @@ void importDocumentsJsonCompleteFail() throws InterruptedException { @Test void importDocumentsJsonDetails() throws InterruptedException, ExecutionException { final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"},{\"_key\":\"2\"}]"; - db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().details(true)) + db.collection(COLLECTION_NAME).importDocuments(RawData.of(values), new DocumentImportOptions().details(true)) .whenComplete((docs, ex) -> { assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); @@ -1841,7 +1842,7 @@ void importDocumentsJsonOverwriteFalse() throws InterruptedException, ExecutionE assertThat(collection.count().get().getCount()).isEqualTo(1L); final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"}]"; - collection.importDocuments(values, new DocumentImportOptions().overwrite(false)).get(); + collection.importDocuments(RawData.of(values), new DocumentImportOptions().overwrite(false)).get(); assertThat(collection.count().get().getCount()).isEqualTo(3L); } @@ -1852,7 +1853,7 @@ void importDocumentsJsonOverwriteTrue() throws InterruptedException, ExecutionEx assertThat(collection.count().get().getCount()).isEqualTo(1L); final String values = "[{\"_key\":\"1\"},{\"_key\":\"2\"}]"; - collection.importDocuments(values, new DocumentImportOptions().overwrite(true)).get(); + collection.importDocuments(RawData.of(values), new DocumentImportOptions().overwrite(true)).get(); assertThat(collection.count().get().getCount()).isEqualTo(2L); } @@ -1865,7 +1866,7 @@ void importDocumentsJsonFromToPrefix() throws InterruptedException, ExecutionExc final String values = "[{\"_key\":\"1\",\"_from\":\"from\",\"_to\":\"to\"},{\"_key\":\"2\",\"_from\":\"from\",\"_to\":\"to\"}]"; final DocumentImportEntity importResult = collection - .importDocuments(values, new DocumentImportOptions().fromPrefix("foo").toPrefix("bar")).get(); + .importDocuments(RawData.of(values), new DocumentImportOptions().fromPrefix("foo").toPrefix("bar")).get(); assertThat(importResult).isNotNull(); assertThat(importResult.getCreated()).isEqualTo(2); for (String key : keys) { From 8699d44d7ecc4f06f3d29adfd5175be95c803dcd Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 17 Aug 2022 12:16:18 +0200 Subject: [PATCH 4/5] sync implementation --- .../internal/ArangoCollectionImpl.java | 43 ++++-- .../internal/InternalArangoCollection.java | 118 ++++++++-------- .../com/arangodb/ArangoCollectionTest.java | 127 ++++++++++++++++++ 3 files changed, 221 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 8d16637a8..8fd3102e7 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java @@ -67,13 +67,18 @@ public DocumentCreateEntity insertDocument(final T value, final DocumentC @Override public MultiDocumentEntity> insertDocuments(RawData values) { - return null; // TODO: implement + return executor + .execute(insertDocumentsRequest(values, new DocumentCreateOptions()), + insertDocumentsResponseDeserializer(Void.class)); } @Override + @SuppressWarnings("unchecked") public MultiDocumentEntity> insertDocuments(RawData values, DocumentCreateOptions options) { - return null; // TODO: implement + return executor + .execute(insertDocumentsRequest(values, options), + insertDocumentsResponseDeserializer((Class) values.getClass())); } @Override @@ -140,7 +145,7 @@ public T getDocument(final String key, final Class type, final DocumentRe if ((e.getResponseCode() != null && (e.getResponseCode() == 404 || e.getResponseCode() == 304 || e.getResponseCode() == 412))) { - return null; // TODO: implement + return null; } throw e; } @@ -179,12 +184,16 @@ public DocumentUpdateEntity replaceDocument(String key, T value, Document @Override public MultiDocumentEntity> replaceDocuments(RawData values) { - return null; // TODO: implement + return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), + replaceDocumentsResponseDeserializer(Void.class)); } @Override - public MultiDocumentEntity> replaceDocuments(RawData values, DocumentReplaceOptions options) { - return null; // TODO: implement + @SuppressWarnings("unchecked") + public MultiDocumentEntity> replaceDocuments(RawData values, + DocumentReplaceOptions options) { + return executor.execute(replaceDocumentsRequest(values, options), + replaceDocumentsResponseDeserializer((Class) values.getClass())); } @Override @@ -228,12 +237,18 @@ public DocumentUpdateEntity updateDocument( @Override public MultiDocumentEntity> updateDocuments(RawData values) { - return null; // TODO: implement + return executor + .execute(updateDocumentsRequest(values, new DocumentUpdateOptions()), + updateDocumentsResponseDeserializer(Void.class)); } @Override - public MultiDocumentEntity> updateDocuments(RawData values, DocumentUpdateOptions options) { - return null; // TODO: implement + @SuppressWarnings("unchecked") + public MultiDocumentEntity> updateDocuments(RawData values, + DocumentUpdateOptions options) { + return executor + .execute(updateDocumentsRequest(values, options), + updateDocumentsResponseDeserializer((Class) values.getClass())); } @Override @@ -274,12 +289,16 @@ public DocumentDeleteEntity deleteDocument( @Override public MultiDocumentEntity> deleteDocuments(RawData values) { - return null; // TODO: implement + return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()), + deleteDocumentsResponseDeserializer(Void.class)); } @Override - public MultiDocumentEntity> deleteDocuments(RawData values, DocumentDeleteOptions options) { - return null; // TODO: implement + @SuppressWarnings("unchecked") + public MultiDocumentEntity> deleteDocuments(RawData values, + DocumentDeleteOptions options) { + return executor.execute(deleteDocumentsRequest(values, options), + deleteDocumentsResponseDeserializer((Class) values.getClass())); } @Override diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index a26bee796..4d6831533 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -24,7 +24,6 @@ import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.serde.SerdeUtils; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; @@ -85,22 +84,25 @@ public String name() { } protected Request insertDocumentRequest(final T value, final DocumentCreateOptions options) { - final Request request = request(db.dbName(), RequestType.POST, PATH_API_DOCUMENT, name); - final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); - request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.putQueryParam(RETURN_NEW, params.getReturnNew()); - request.putQueryParam(RETURN_OLD, params.getReturnOld()); - request.putQueryParam(SILENT, params.getSilent()); - request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ? - params.getOverwriteMode().getValue() : null); - request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); - request.putQueryParam(KEEP_NULL, params.getKeepNull()); - request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); + final Request request = createInsertDocumentRequest(options); request.setBody(getSerde().serializeUserData(value)); return request; } - protected Request insertDocumentsRequest(final Collection values, final DocumentCreateOptions params) { + protected Request insertDocumentsRequest(final RawData values, final DocumentCreateOptions options) { + Request request = createInsertDocumentRequest(options); + request.setBody(getSerde().serialize(values)); + return request; + } + + protected Request insertDocumentsRequest(final Collection values, final DocumentCreateOptions options) { + Request request = createInsertDocumentRequest(options); + request.setBody(getSerde().serializeCollectionUserData(values)); + return request; + } + + private Request createInsertDocumentRequest(final DocumentCreateOptions options) { + final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); final Request request = request(db.dbName(), RequestType.POST, PATH_API_DOCUMENT, name); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putQueryParam(RETURN_NEW, params.getReturnNew()); @@ -111,7 +113,6 @@ protected Request insertDocumentsRequest(final Collection values, final D request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putQueryParam(KEEP_NULL, params.getKeepNull()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - request.setBody(getSerde().serializeCollectionUserData(values)); return request; } @@ -219,22 +220,26 @@ protected ResponseDeserializer> getDocumentsResponseD protected Request replaceDocumentRequest( final String key, final T value, final DocumentReplaceOptions options) { - final Request request = request(db.dbName(), RequestType.PUT, PATH_API_DOCUMENT, - DocumentUtil.createDocumentHandle(name, key)); - final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions()); - request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.putQueryParam(IGNORE_REVS, params.getIgnoreRevs()); - request.putQueryParam(RETURN_NEW, params.getReturnNew()); - request.putQueryParam(RETURN_OLD, params.getReturnOld()); - request.putQueryParam(SILENT, params.getSilent()); + final Request request = createReplaceDocumentRequest(options, DocumentUtil.createDocumentHandle(name, key)); request.setBody(getSerde().serializeUserData(value)); return request; } - protected Request replaceDocumentsRequest(final Collection values, final DocumentReplaceOptions params) { - final Request request = request(db.dbName(), RequestType.PUT, PATH_API_DOCUMENT, name); + protected Request replaceDocumentsRequest(final Collection values, final DocumentReplaceOptions options) { + final Request request = createReplaceDocumentRequest(options, name); + request.setBody(getSerde().serializeCollectionUserData(values)); + return request; + } + + protected Request replaceDocumentsRequest(final RawData values, final DocumentReplaceOptions options) { + final Request request = createReplaceDocumentRequest(options, name); + request.setBody(getSerde().serialize(values)); + return request; + } + + private Request createReplaceDocumentRequest(final DocumentReplaceOptions options, String path) { + final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions()); + final Request request = request(db.dbName(), RequestType.PUT, PATH_API_DOCUMENT, path); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); @@ -242,7 +247,6 @@ protected Request replaceDocumentsRequest(final Collection values, final request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(getSerde().serializeCollectionUserData(values)); return request; } @@ -275,35 +279,35 @@ protected ResponseDeserializer>> } protected Request updateDocumentRequest(final String key, final T value, final DocumentUpdateOptions options) { - final Request request = request(db.dbName(), RequestType.PATCH, PATH_API_DOCUMENT, - DocumentUtil.createDocumentHandle(name, key)); - final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions()); - request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); - request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); - request.putQueryParam(IGNORE_REVS, params.getIgnoreRevs()); - request.putQueryParam(RETURN_NEW, params.getReturnNew()); - request.putQueryParam(RETURN_OLD, params.getReturnOld()); - request.putQueryParam(SILENT, params.getSilent()); + final Request request = createUpdateDocumentRequest(options, DocumentUtil.createDocumentHandle(name, key)); request.setBody(getSerde().serializeUserData(value)); return request; } - protected Request updateDocumentsRequest(final Collection values, final DocumentUpdateOptions params) { - final Request request = request(db.dbName(), RequestType.PATCH, PATH_API_DOCUMENT, name); - final Boolean keepNull = params.getKeepNull(); + protected Request updateDocumentsRequest(final Collection values, final DocumentUpdateOptions options) { + final Request request = createUpdateDocumentRequest(options, name); + request.setBody(getSerde().serializeCollectionUserData(values)); + return request; + } + + protected Request updateDocumentsRequest(final RawData values, final DocumentUpdateOptions options) { + final Request request = createUpdateDocumentRequest(options, name); + request.setBody(getSerde().serialize(values)); + return request; + } + + private Request createUpdateDocumentRequest(final DocumentUpdateOptions options, String path) { + final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions()); + final Request request = request(db.dbName(), RequestType.PATCH, PATH_API_DOCUMENT, path); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - request.putQueryParam(ArangoRequestParam.KEEP_NULL, keepNull); + request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putQueryParam(IGNORE_REVS, params.getIgnoreRevs()); request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(getSerde().serializeCollectionUserData(values)); return request; } @@ -336,25 +340,29 @@ protected ResponseDeserializer>> } protected Request deleteDocumentRequest(final String key, final DocumentDeleteOptions options) { - final Request request = request(db.dbName(), RequestType.DELETE, PATH_API_DOCUMENT, - DocumentUtil.createDocumentHandle(name, key)); - final DocumentDeleteOptions params = (options != null ? options : new DocumentDeleteOptions()); - request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.putQueryParam(RETURN_OLD, params.getReturnOld()); - request.putQueryParam(SILENT, params.getSilent()); + return createDeleteDocumentRequest(options, DocumentUtil.createDocumentHandle(name, key)); + } + + protected Request deleteDocumentsRequest(final Collection docs, final DocumentDeleteOptions options) { + final Request request = createDeleteDocumentRequest(options, name); + request.setBody(getSerde().serializeCollectionUserData(docs)); return request; } - protected Request deleteDocumentsRequest(final Collection keys, final DocumentDeleteOptions options) { - final Request request = request(db.dbName(), RequestType.DELETE, PATH_API_DOCUMENT, name); + protected Request deleteDocumentsRequest(final RawData docs, final DocumentDeleteOptions options) { + final Request request = createDeleteDocumentRequest(options, name); + request.setBody(getSerde().serialize(docs)); + return request; + } + + private Request createDeleteDocumentRequest(final DocumentDeleteOptions options, String path){ final DocumentDeleteOptions params = (options != null ? options : new DocumentDeleteOptions()); + final Request request = request(db.dbName(), RequestType.DELETE, PATH_API_DOCUMENT, path); + request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(getSerde().serialize(keys)); return request; } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 06facf0da..0c3df4279 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -21,6 +21,7 @@ package com.arangodb; import com.arangodb.entity.*; +import com.arangodb.internal.serde.SerdeUtils; import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.serde.JacksonSerde; @@ -31,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; @@ -1905,6 +1907,42 @@ void insertDocumentsJson(ArangoCollection collection) { assertThat(docs.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void insertDocumentsRawData(ArangoCollection collection) { + final RawData values = RawData.of("[{},{},{}]"); + final MultiDocumentEntity docs = collection.insertDocuments(values); + assertThat(docs).isNotNull(); + assertThat(docs.getDocuments()).isNotNull(); + assertThat(docs.getDocuments()).hasSize(3); + assertThat(docs.getErrors()).isNotNull(); + assertThat(docs.getErrors()).isEmpty(); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void insertDocumentsRawDataReturnNew(ArangoCollection collection) { + final RawData values = RawData.of("[{\"aaa\":33},{\"aaa\":33},{\"aaa\":33}]"); + final MultiDocumentEntity> docs = + collection.insertDocuments(values, new DocumentCreateOptions().returnNew(true)); + assertThat(docs).isNotNull(); + assertThat(docs.getDocuments()).isNotNull(); + assertThat(docs.getDocuments()).hasSize(3); + assertThat(docs.getErrors()).isNotNull(); + assertThat(docs.getErrors()).isEmpty(); + + for (final DocumentCreateEntity doc : docs.getDocuments()) { + RawData d = doc.getNew(); + assertThat(d) + .isNotNull() + .isInstanceOf(RawJson.class); + + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) d).getValue()); + assertThat(jn.has("aaa")).isTrue(); + assertThat(jn.get("aaa").intValue()).isEqualTo(33); + } + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentsOne(ArangoCollection collection) { @@ -2373,6 +2411,25 @@ void deleteDocumentsByKey(ArangoCollection collection) { assertThat(deleteResult.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void deleteDocumentsRawDataByKeyReturnOld(ArangoCollection collection) { + final RawData values = RawData.of("[{\"_key\":\"1\"},{\"_key\":\"2\"}]"); + collection.insertDocuments(values); + final RawData keys = RawData.of("[\"1\",\"2\"]"); + MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, + new DocumentDeleteOptions().returnOld(true)); + assertThat(deleteResult).isNotNull(); + assertThat(deleteResult.getDocuments()).hasSize(2); + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + assertThat(i.getKey()).isIn("1", "2"); + assertThat(i.getOld()).isNotNull().isInstanceOf(RawJson.class); + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) i.getOld()).getValue()); + assertThat(jn.get("_key").asText()).isEqualTo(i.getKey()); + } + assertThat(deleteResult.getErrors()).isEmpty(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void deleteDocumentsByDocuments(ArangoCollection collection) { @@ -2579,6 +2636,41 @@ void updateDocumentsJson(ArangoCollection collection) { assertThat(updateResult.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void updateDocumentsRawData(ArangoCollection collection) { + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void updateDocumentsRawDataReturnNew(ArangoCollection collection) { + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + MultiDocumentEntity> updateResult = + collection.updateDocuments(updatedValues, new DocumentUpdateOptions().returnNew(true)); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + for (DocumentUpdateEntity doc : updateResult.getDocuments()) { + RawData d = doc.getNew(); + assertThat(d) + .isNotNull() + .isInstanceOf(RawJson.class); + + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) d).getValue()); + assertThat(jn.has("foo")).isTrue(); + assertThat(jn.get("foo").textValue()).isEqualTo("bar"); + } + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void replaceDocuments(ArangoCollection collection) { @@ -2661,6 +2753,41 @@ void replaceDocumentsJson(ArangoCollection collection) { assertThat(updateResult.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void replaceDocumentsRawData(ArangoCollection collection) { + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + final MultiDocumentEntity updateResult = collection.replaceDocuments(updatedValues); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void replaceDocumentsRawDataReturnNew(ArangoCollection collection) { + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + MultiDocumentEntity> updateResult = + collection.replaceDocuments(updatedValues, new DocumentReplaceOptions().returnNew(true)); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + for (DocumentUpdateEntity doc : updateResult.getDocuments()) { + RawData d = doc.getNew(); + assertThat(d) + .isNotNull() + .isInstanceOf(RawJson.class); + + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) d).getValue()); + assertThat(jn.has("foo")).isTrue(); + assertThat(jn.get("foo").textValue()).isEqualTo("bar"); + } + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void getInfo(ArangoCollection collection) { From d934ebefadfb8a2c7fd29bfc93b4ef9916c6b300 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 17 Aug 2022 13:28:50 +0200 Subject: [PATCH 5/5] async implementation --- .../internal/ArangoCollectionAsyncImpl.java | 41 ++++-- .../arangodb/async/ArangoCollectionTest.java | 132 +++++++++++++++++- 2 files changed, 159 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java index 514d3dcb3..b06bc0ebf 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java @@ -68,13 +68,18 @@ public CompletableFuture> insertDocument(T value, Do @Override public CompletableFuture>> insertDocuments(RawData values) { - return null; // TODO: implement + return executor + .execute(insertDocumentsRequest(values, new DocumentCreateOptions()), + insertDocumentsResponseDeserializer(Void.class)); } @Override + @SuppressWarnings("unchecked") public CompletableFuture>> insertDocuments(RawData values, DocumentCreateOptions options) { - return null; // TODO: implement + return executor + .execute(insertDocumentsRequest(values, options), + insertDocumentsResponseDeserializer((Class) values.getClass())); } @Override @@ -179,12 +184,16 @@ public CompletableFuture> replaceDocument(String key @Override public CompletableFuture>> replaceDocuments(RawData values) { - return null; // TODO: implement + return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()), + replaceDocumentsResponseDeserializer(Void.class)); } @Override - public CompletableFuture>> replaceDocuments(RawData values, DocumentReplaceOptions options) { - return null; // TODO: implement + @SuppressWarnings("unchecked") + public CompletableFuture>> replaceDocuments(RawData values, + DocumentReplaceOptions options) { + return executor.execute(replaceDocumentsRequest(values, options), + replaceDocumentsResponseDeserializer((Class) values.getClass())); } @Override @@ -234,12 +243,18 @@ public CompletableFuture> updateDocument( @Override public CompletableFuture>> updateDocuments(RawData values) { - return null; // TODO: implement + return executor + .execute(updateDocumentsRequest(values, new DocumentUpdateOptions()), + updateDocumentsResponseDeserializer(Void.class)); } @Override - public CompletableFuture>> updateDocuments(RawData values, DocumentUpdateOptions options) { - return null; // TODO: implement + @SuppressWarnings("unchecked") + public CompletableFuture>> updateDocuments(RawData values, + DocumentUpdateOptions options) { + return executor + .execute(updateDocumentsRequest(values, options), + updateDocumentsResponseDeserializer((Class) values.getClass())); } @Override @@ -286,12 +301,16 @@ public CompletableFuture> deleteDocument( @Override public CompletableFuture>> deleteDocuments(RawData values) { - return null; // TODO: implement + return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()), + deleteDocumentsResponseDeserializer(Void.class)); } @Override - public CompletableFuture>> deleteDocuments(RawData values, DocumentDeleteOptions options) { - return null; // TODO: implement + @SuppressWarnings("unchecked") + public CompletableFuture>> deleteDocuments(RawData values, + DocumentDeleteOptions options) { + return executor.execute(deleteDocumentsRequest(values, options), + deleteDocumentsResponseDeserializer((Class) values.getClass())); } @Override diff --git a/src/test/java/com/arangodb/async/ArangoCollectionTest.java b/src/test/java/com/arangodb/async/ArangoCollectionTest.java index 09d4626bb..b41d7613c 100644 --- a/src/test/java/com/arangodb/async/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoCollectionTest.java @@ -20,20 +20,19 @@ package com.arangodb.async; -import com.arangodb.ArangoCollection; import com.arangodb.ArangoDBException; import com.arangodb.entity.*; +import com.arangodb.internal.serde.SerdeUtils; import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.serde.JacksonSerde; import com.arangodb.util.RawData; import com.arangodb.util.RawJson; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.JsonNode; 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; @@ -1507,6 +1506,40 @@ void insertDocumentsFail() throws InterruptedException, ExecutionException { .get(); } + @Test + void insertDocumentsRawData() throws ExecutionException, InterruptedException { + final RawData values = RawData.of("[{},{},{}]"); + final MultiDocumentEntity docs = db.collection(COLLECTION_NAME).insertDocuments(values).get(); + assertThat(docs).isNotNull(); + assertThat(docs.getDocuments()).isNotNull(); + assertThat(docs.getDocuments()).hasSize(3); + assertThat(docs.getErrors()).isNotNull(); + assertThat(docs.getErrors()).isEmpty(); + } + + @Test + void insertDocumentsRawDataReturnNew() throws ExecutionException, InterruptedException { + final RawData values = RawData.of("[{\"aaa\":33},{\"aaa\":33},{\"aaa\":33}]"); + final MultiDocumentEntity> docs = + db.collection(COLLECTION_NAME).insertDocuments(values, new DocumentCreateOptions().returnNew(true)).get(); + assertThat(docs).isNotNull(); + assertThat(docs.getDocuments()).isNotNull(); + assertThat(docs.getDocuments()).hasSize(3); + assertThat(docs.getErrors()).isNotNull(); + assertThat(docs.getErrors()).isEmpty(); + + for (final DocumentCreateEntity doc : docs.getDocuments()) { + RawData d = doc.getNew(); + assertThat(d) + .isNotNull() + .isInstanceOf(RawJson.class); + + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) d).getValue()); + assertThat(jn.has("aaa")).isTrue(); + assertThat(jn.get("aaa").intValue()).isEqualTo(33); + } + } + @Test void importDocuments() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); @@ -2032,6 +2065,26 @@ void deleteDocumentsByDocumentsNotExisting() throws InterruptedException, Execut .get(); } + @Test + void deleteDocumentsRawDataByKeyReturnOld() throws ExecutionException, InterruptedException { + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); + final RawData values = RawData.of("[{\"_key\":\"1\"},{\"_key\":\"2\"}]"); + collection.insertDocuments(values).get(); + final RawData keys = RawData.of("[\"1\",\"2\"]"); + MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, + new DocumentDeleteOptions().returnOld(true)).get(); + assertThat(deleteResult).isNotNull(); + assertThat(deleteResult.getDocuments()).hasSize(2); + for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { + assertThat(i.getKey()).isIn("1", "2"); + assertThat(i.getOld()).isNotNull().isInstanceOf(RawJson.class); + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) i.getOld()).getValue()); + assertThat(jn.get("_key").asText()).isEqualTo(i.getKey()); + } + assertThat(deleteResult.getErrors()).isEmpty(); + } + + @Test void updateDocuments() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); @@ -2143,6 +2196,41 @@ void updateDocumentsWithoutKey() throws InterruptedException, ExecutionException .get(); } + @Test + void updateDocumentsRawData() throws ExecutionException, InterruptedException { + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values).get(); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + final MultiDocumentEntity updateResult = collection.updateDocuments(updatedValues).get(); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + } + + @Test + void updateDocumentsRawDataReturnNew() throws ExecutionException, InterruptedException { + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values).get(); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + MultiDocumentEntity> updateResult = + collection.updateDocuments(updatedValues, new DocumentUpdateOptions().returnNew(true)).get(); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + for (DocumentUpdateEntity doc : updateResult.getDocuments()) { + RawData d = doc.getNew(); + assertThat(d) + .isNotNull() + .isInstanceOf(RawJson.class); + + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) d).getValue()); + assertThat(jn.has("foo")).isTrue(); + assertThat(jn.get("foo").textValue()).isEqualTo("bar"); + } + } + @Test void replaceDocuments() throws InterruptedException, ExecutionException { final Collection values = new ArrayList<>(); @@ -2217,6 +2305,44 @@ void replaceDocumentsWithoutKey() throws InterruptedException, ExecutionExceptio .get(); } + @Test + void replaceDocumentsRawData() throws ExecutionException, InterruptedException { + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); + + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values).get(); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + final MultiDocumentEntity updateResult = collection.replaceDocuments(updatedValues).get(); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + } + + @Test + void replaceDocumentsRawDataReturnNew() throws ExecutionException, InterruptedException { + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); + + final RawData values = RawData.of("[{\"_key\":\"1\"}, {\"_key\":\"2\"}]"); + collection.insertDocuments(values).get(); + + final RawData updatedValues = RawData.of("[{\"_key\":\"1\", \"foo\":\"bar\"}, {\"_key\":\"2\", \"foo\":\"bar\"}]"); + MultiDocumentEntity> updateResult = + collection.replaceDocuments(updatedValues, new DocumentReplaceOptions().returnNew(true)).get(); + assertThat(updateResult.getDocuments()).hasSize(2); + assertThat(updateResult.getErrors()).isEmpty(); + for (DocumentUpdateEntity doc : updateResult.getDocuments()) { + RawData d = doc.getNew(); + assertThat(d) + .isNotNull() + .isInstanceOf(RawJson.class); + + JsonNode jn = SerdeUtils.INSTANCE.parseJson(((RawJson) d).getValue()); + assertThat(jn.has("foo")).isTrue(); + assertThat(jn.get("foo").textValue()).isEqualTo("bar"); + } + } + + @Test void getInfo() throws InterruptedException, ExecutionException { db.collection(COLLECTION_NAME).getInfo()