diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 896069eb4..52114c15d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -129,3 +129,46 @@ jobs: run: mvn -version - name: Test run: mvn --no-transfer-progress test -DargLine="-Duser.language=${{matrix.user-language}}" + + jackson-test: + timeout-minutes: 20 + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + jackson-version: + - 2.13.3 + - 2.12.7 + - 2.11.4 + - 2.10.5 + docker-img: + - docker.io/arangodb/arangodb:3.9.1 + topology: + - single + db-ext-names: + - false + java-version: + - 17 + user-language: + - en + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: ${{matrix.java-version}} + distribution: 'adopt' + cache: maven + - name: Start Database + run: ./docker/start_db.sh + env: + ARANGO_LICENSE_KEY: ${{ secrets.ARANGO_LICENSE_KEY }} + STARTER_MODE: ${{matrix.topology}} + DOCKER_IMAGE: ${{matrix.docker-img}} + DATABASE_EXTENDED_NAMES: ${{matrix.db-ext-names}} + - name: Info + run: mvn -version + - name: Test + run: mvn --no-transfer-progress test -Djackson.version=${{jackson-version}} diff --git a/pom.xml b/pom.xml index 649739b52..355b4c4dc 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ UTF-8 + 2.13.3 @@ -89,7 +90,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.11 + 0.9.13 true @@ -102,6 +103,7 @@ + true false --no-fallback @@ -233,10 +235,6 @@ - - com.arangodb - velocypack - org.slf4j slf4j-api @@ -245,11 +243,28 @@ org.apache.httpcomponents httpclient + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + com.arangodb jackson-dataformat-velocypack true + + jakarta.json.bind + jakarta.json.bind-api + 3.0.0 + ch.qos.logback logback-classic @@ -288,10 +303,23 @@ 22.1.0 test + + org.eclipse + yasson + 3.0.0 + test + + + com.fasterxml.jackson + jackson-bom + ${jackson.version} + import + pom + com.arangodb jackson-dataformat-velocypack @@ -317,11 +345,6 @@ commons-logging 1.2 - - com.arangodb - velocypack - 2.5.4 - org.slf4j slf4j-api diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index 2073ff689..c77a228f4 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -35,7 +35,7 @@ * @see Documents API Documentation */ @SuppressWarnings("UnusedReturnValue") -public interface ArangoCollection extends ArangoSerializationAccessor { +public interface ArangoCollection extends ArangoSerdeAccessor { /** * The the handler of the database the collection is within @@ -55,7 +55,7 @@ public interface ArangoCollection extends ArangoSerializationAccessor { * 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, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the document * @throws ArangoDBException * @see API @@ -67,7 +67,7 @@ public interface ArangoCollection extends ArangoSerializationAccessor { * 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, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the document * @throws ArangoDBException @@ -83,7 +83,7 @@ public interface ArangoCollection extends ArangoSerializationAccessor { * Limitations: * - the fields having {@code null} value are always removed during serialization * - * @param values A List of documents (POJO, VPackSlice or String for JSON) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents * @throws ArangoDBException * @see API @@ -98,7 +98,7 @@ public interface ArangoCollection extends ArangoSerializationAccessor { * Limitations: * - the fields having {@code null} value are always removed during serialization * - * @param values A List of documents (POJO, VPackSlice or String for JSON) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the documents * @throws ArangoDBException @@ -162,7 +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 class, VPackSlice or String for JSON) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the document identified by the key * @throws ArangoDBException * @see API @@ -174,7 +174,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 class, VPackSlice or String for JSON) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the document identified by the key * @throws ArangoDBException @@ -187,7 +187,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 class, VPackSlice or String for JSON) + * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the documents and possible errors * @throws ArangoDBException */ @@ -197,7 +197,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 class, VPackSlice or String for JSON) + * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the documents and possible errors * @throws ArangoDBException @@ -210,7 +210,7 @@ MultiDocumentEntity getDocuments(Collection keys, Class type, * precondition is violated * * @param key The key of the document - * @param value A representation of a single document (POJO, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the document * @throws ArangoDBException * @see API @@ -223,7 +223,7 @@ MultiDocumentEntity getDocuments(Collection keys, Class type, * precondition is violated * * @param key The key of the document - * @param value A representation of a single document (POJO, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the document * @throws ArangoDBException @@ -240,7 +240,7 @@ DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplace * Limitations: * - the fields having {@code null} value are always removed during serialization * - * @param values A List of documents (POJO, VPackSlice or String for JSON) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents * @throws ArangoDBException * @see API @@ -255,7 +255,7 @@ DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplace * Limitations: * - the fields having {@code null} value are always removed during serialization * - * @param values A List of documents (POJO, VPackSlice or String for JSON) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the documents * @throws ArangoDBException @@ -271,7 +271,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, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the document * @throws ArangoDBException * @see API @@ -285,7 +285,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, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the document * @throws ArangoDBException @@ -301,7 +301,7 @@ DocumentUpdateEntity updateDocument(String key, T value, DocumentUpdateOp * 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, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the document @@ -318,7 +318,7 @@ DocumentUpdateEntity updateDocument(String key, T value, DocumentUpdat * 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, VPackSlice or String for JSON) + * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents * @throws ArangoDBException * @see API @@ -332,7 +332,7 @@ DocumentUpdateEntity updateDocument(String key, T value, DocumentUpdat * 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, VPackSlice or String for JSON) + * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the documents * @throws ArangoDBException @@ -348,7 +348,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, VPackSlice or String for JSON) + * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the documents @@ -374,7 +374,7 @@ MultiDocumentEntity> updateDocuments( * Deletes 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 class, VPackSlice or String for JSON). Only necessary if + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}). Only necessary if * options.returnOld is set to true, otherwise can be null. * @param options Additional options, can be null * @return information about the document @@ -401,7 +401,7 @@ DocumentDeleteEntity deleteDocument(String key, Class type, DocumentDe * Deletes multiple documents from the collection. * * @param values The keys of the documents or the documents themselves - * @param type The type of the documents (POJO class, VPackSlice or String for JSON). Only necessary if + * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}). Only necessary if * options.returnOld is set to true, otherwise can be null. * @param options Additional options, can be null * @return information about the documents diff --git a/src/main/java/com/arangodb/ArangoCursor.java b/src/main/java/com/arangodb/ArangoCursor.java index eab1e2a88..928f14239 100644 --- a/src/main/java/com/arangodb/ArangoCursor.java +++ b/src/main/java/com/arangodb/ArangoCursor.java @@ -20,8 +20,8 @@ package com.arangodb; -import com.arangodb.entity.CursorEntity.Stats; -import com.arangodb.entity.CursorEntity.Warning; +import com.arangodb.entity.CursorStats; +import com.arangodb.entity.CursorWarning; import java.io.Closeable; import java.util.Collection; @@ -53,12 +53,12 @@ public interface ArangoCursor extends ArangoIterable, ArangoIterator, C * number of modified documents and the number of documents that could not be modified due to an error (if * ignoreErrors query option is specified) */ - Stats getStats(); + CursorStats getStats(); /** * @return warnings which the query could have been produced */ - Collection getWarnings(); + Collection getWarnings(); /** * @return indicating whether the query result was served from the query cache or not diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index f58064a08..9b112c97e 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -28,22 +28,19 @@ import com.arangodb.internal.http.HttpCommunication; import com.arangodb.internal.http.HttpConnectionFactory; import com.arangodb.internal.net.*; -import com.arangodb.internal.util.ArangoDeserializerImpl; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializerImpl; -import com.arangodb.internal.util.DefaultArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; import com.arangodb.model.LogOptions; import com.arangodb.model.UserCreateOptions; import com.arangodb.model.UserUpdateOptions; +import com.arangodb.serde.DataType; +import com.arangodb.serde.InternalSerde; +import com.arangodb.serde.JacksonSerde; import com.arangodb.util.ArangoCursorInitializer; -import com.arangodb.util.ArangoDeserializer; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackParser; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.apache.http.client.HttpRequestRetryHandler; @@ -73,7 +70,7 @@ * @author Michele Rastelli */ @SuppressWarnings("UnusedReturnValue") -public interface ArangoDB extends ArangoSerializationAccessor { +public interface ArangoDB extends ArangoSerdeAccessor { /** * Builder class to build an instance of {@link ArangoDB}. @@ -336,7 +333,7 @@ public Builder responseQueueTimeSamples(final Integer responseQueueTimeSamples) * @param serialization custom serializer/deserializer * @return {@link ArangoDB.Builder} */ - public Builder serializer(final ArangoSerialization serialization) { + public Builder serializer(final ArangoSerde serialization) { setSerializer(serialization); return this; } @@ -347,25 +344,11 @@ public Builder serializer(final ArangoSerialization serialization) { * @return {@link ArangoDB} */ public synchronized ArangoDB build() { - if (customSerializer == null) { - logger.warn("Usage of VelocyPack Java serialization is now deprecated for removal. " + - "Future driver versions will only support Jackson serialization (for both JSON and VPACK formats). " + - "Please configure according to: https://www.arangodb.com/docs/stable/drivers/java-reference-serialization.html"); - } if (hosts.isEmpty()) { hosts.add(host); } - final VPack vpacker = vpackBuilder.serializeNullValues(false).build(); - final VPack vpackerNull = vpackBuilder.serializeNullValues(true).build(); - final VPackParser vpackParser = vpackParserBuilder.build(); - final ArangoSerializer serializerTemp = serializer != null ? serializer - : new ArangoSerializerImpl(vpacker, vpackerNull, vpackParser); - final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer - : new ArangoDeserializerImpl(vpackerNull, vpackParser); - final DefaultArangoSerialization internal = new DefaultArangoSerialization(serializerTemp, - deserializerTemp); - final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; - final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); + final ArangoSerde userSerde = customSerializer != null ? customSerializer : JacksonSerde.of(DataType.of(protocol)); + final InternalSerde serde = InternalSerde.of(DataType.of(protocol), userSerde); int protocolMaxConnections = protocol == Protocol.VST ? ArangoDefaults.MAX_CONNECTIONS_VST_DEFAULT : @@ -374,7 +357,7 @@ public synchronized ArangoDB build() { final ConnectionFactory connectionFactory = (protocol == null || Protocol.VST == protocol) ? new VstConnectionFactorySync(host, timeout, connectionTtl, keepAliveInterval, useSsl, sslContext) - : new HttpConnectionFactory(timeout, user, password, useSsl, sslContext, hostnameVerifier, custom, + : new HttpConnectionFactory(timeout, user, password, useSsl, sslContext, hostnameVerifier, serde, protocol, connectionTtl, httpCookieSpec, httpRequestRetryHandler); final Collection hostList = createHostList(max, connectionFactory); @@ -387,7 +370,7 @@ public synchronized ArangoDB build() { .jwt(jwt).useSsl(useSsl).sslContext(sslContext).chunksize(chunksize) .maxConnections(maxConnections).connectionTtl(connectionTtl), new HttpCommunication.Builder(hostHandler), - util, + serde, protocol, hostResolver, hostHandler, diff --git a/src/main/java/com/arangodb/ArangoDatabase.java b/src/main/java/com/arangodb/ArangoDatabase.java index 24146626c..58d055418 100644 --- a/src/main/java/com/arangodb/ArangoDatabase.java +++ b/src/main/java/com/arangodb/ArangoDatabase.java @@ -38,7 +38,7 @@ * @see Query API Documentation */ @SuppressWarnings("UnusedReturnValue") -public interface ArangoDatabase extends ArangoSerializationAccessor { +public interface ArangoDatabase extends ArangoSerdeAccessor { /** * Return the main entry point for the ArangoDB driver @@ -260,7 +260,7 @@ public interface ArangoDatabase extends ArangoSerializationAccessor { * @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 class, VPackSlice, String for JSON, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @throws ArangoDBException * @see API @@ -275,7 +275,7 @@ ArangoCursor query(String query, Map bindVars, AqlQueryOp * * @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 class, VPackSlice, String for JSON, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @throws ArangoDBException * @see API @@ -289,7 +289,7 @@ ArangoCursor query(String query, Map bindVars, AqlQueryOp * * @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 class, VPackSlice, String for JSON, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @throws ArangoDBException * @see API @@ -302,7 +302,7 @@ ArangoCursor query(String query, Map bindVars, AqlQueryOp * result list. * * @param query An AQL query string - * @param type The type of the result (POJO class, VPackSlice, String for JSON, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @throws ArangoDBException * @see API @@ -314,7 +314,7 @@ ArangoCursor query(String query, Map bindVars, AqlQueryOp * 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 class, VPackSlice, String for JSON, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @throws ArangoDBException * @see edgeDefinitions, * Performs a server-side transaction and returns its return value. * * @param action A String evaluating to a JavaScript function to be executed on the server. - * @param type The type of the result (POJO class, VPackSlice or String for JSON) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the result of the transaction if it succeeded * @throws ArangoDBException @@ -615,7 +615,7 @@ GraphEntity createGraph(String name, Collection edgeDefinitions, * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO class, VPackSlice or String for JSON) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the document identified by the id * @throws ArangoDBException * @see API @@ -627,7 +627,7 @@ GraphEntity createGraph(String name, Collection edgeDefinitions, * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO class, VPackSlice or String for JSON) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the document identified by the id * @throws ArangoDBException diff --git a/src/main/java/com/arangodb/ArangoEdgeCollection.java b/src/main/java/com/arangodb/ArangoEdgeCollection.java index 17d6d054b..0c8bbc45d 100644 --- a/src/main/java/com/arangodb/ArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/ArangoEdgeCollection.java @@ -31,7 +31,7 @@ * @see API Documentation */ @SuppressWarnings("UnusedReturnValue") -public interface ArangoEdgeCollection extends ArangoSerializationAccessor { +public interface ArangoEdgeCollection extends ArangoSerdeAccessor { /** * The the handler of the named graph the edge collection is within @@ -50,7 +50,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, VPackSlice or String for JSON) + * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the edge * @throws ArangoDBException * @see API Documentation @@ -60,7 +60,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, VPackSlice or String for JSON) + * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the edge * @throws ArangoDBException @@ -72,7 +72,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the edge identified by the key * @throws ArangoDBException * @see API Documentation @@ -83,7 +83,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the edge identified by the key * @throws ArangoDBException @@ -96,7 +96,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { * violated * * @param key The key of the edge - * @param The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the edge * @throws ArangoDBException * @see API Documentation @@ -108,7 +108,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { * violated * * @param key The key of the edge - * @param The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the edge * @throws ArangoDBException @@ -122,7 +122,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the edge - * @param The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the edge * @throws ArangoDBException * @see API Documentation @@ -135,7 +135,7 @@ public interface ArangoEdgeCollection extends ArangoSerializationAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the edge - * @param The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the edge * @throws ArangoDBException diff --git a/src/main/java/com/arangodb/ArangoGraph.java b/src/main/java/com/arangodb/ArangoGraph.java index 873405cda..a9b562a68 100644 --- a/src/main/java/com/arangodb/ArangoGraph.java +++ b/src/main/java/com/arangodb/ArangoGraph.java @@ -33,7 +33,7 @@ * @author Mark Vollmary * @see API Documentation */ -public interface ArangoGraph extends ArangoSerializationAccessor { +public interface ArangoGraph extends ArangoSerdeAccessor { /** * The the handler of the database the named graph is within diff --git a/src/main/java/com/arangodb/ArangoRoute.java b/src/main/java/com/arangodb/ArangoRoute.java index fd32eb6e5..b9a393add 100644 --- a/src/main/java/com/arangodb/ArangoRoute.java +++ b/src/main/java/com/arangodb/ArangoRoute.java @@ -27,7 +27,7 @@ * * @author Mark Vollmary */ -public interface ArangoRoute extends ArangoSerializationAccessor { +public interface ArangoRoute extends ArangoSerdeAccessor { /** * Returns a new {@link ArangoRoute} instance for the given path (relative to the current route) that can be used to @@ -57,7 +57,7 @@ public interface ArangoRoute extends ArangoSerializationAccessor { ArangoRoute withQueryParam(String key, Object value); /** - * The response body. The body will be serialized to {@link com.arangodb.velocypack.VPackSlice}. + * The response body. * * @param body The request body * @return {@link ArangoRoute} diff --git a/src/main/java/com/arangodb/entity/Entity.java b/src/main/java/com/arangodb/ArangoSerdeAccessor.java similarity index 58% rename from src/main/java/com/arangodb/entity/Entity.java rename to src/main/java/com/arangodb/ArangoSerdeAccessor.java index 146e561ae..c3075a1b4 100644 --- a/src/main/java/com/arangodb/entity/Entity.java +++ b/src/main/java/com/arangodb/ArangoSerdeAccessor.java @@ -18,11 +18,28 @@ * Copyright holder is ArangoDB GmbH, Cologne, Germany */ -package com.arangodb.entity; +package com.arangodb; + +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.InternalSerde; /** * @author Mark Vollmary */ -public interface Entity { +public interface ArangoSerdeAccessor { + + /** + * Returns driver internal serialization implementation for serializing and deserializing driver's classes. + * + * @return ArangoSerde + */ + InternalSerde getSerde(); + + /** + * Returns serialization implementation for serializing and deserializing user's classes. + * + * @return ArangoSerde + */ + ArangoSerde getUserSerde(); } diff --git a/src/main/java/com/arangodb/ArangoSerializationAccessor.java b/src/main/java/com/arangodb/ArangoSerializationAccessor.java deleted file mode 100644 index f140f054e..000000000 --- a/src/main/java/com/arangodb/ArangoSerializationAccessor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2018 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb; - -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; -import com.arangodb.util.ArangoSerialization; - -/** - * @author Mark Vollmary - */ -public interface ArangoSerializationAccessor { - - /** - * Returns driver internal serialization API for serializing and deserializing Java POJOs to/from {@link com.arangodb.velocypack.VPackSlice} - * - * @return ArangoSerialization - */ - ArangoSerialization util(); - - /** - * Returns serialization API for serializing and deserializing Java POJOs to/from {@link com.arangodb.velocypack.VPackSlice} by the given - * type - * - * @param serializer type of serializer - * @return ArangoSerialization - */ - ArangoSerialization util(Serializer serializer); - -} diff --git a/src/main/java/com/arangodb/ArangoVertexCollection.java b/src/main/java/com/arangodb/ArangoVertexCollection.java index e34705cf4..0d514a9fc 100644 --- a/src/main/java/com/arangodb/ArangoVertexCollection.java +++ b/src/main/java/com/arangodb/ArangoVertexCollection.java @@ -30,7 +30,7 @@ * @author Mark Vollmary * @see API Documentation */ -public interface ArangoVertexCollection extends ArangoSerializationAccessor { +public interface ArangoVertexCollection extends ArangoSerdeAccessor { /** * The the handler of the named graph the edge collection is within @@ -59,7 +59,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, VPackSlice or String for JSON) + * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the vertex * @throws ArangoDBException * @see API Documentation @@ -69,7 +69,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, VPackSlice or String for JSON) + * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the vertex * @throws ArangoDBException @@ -81,7 +81,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { * 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 class, VPackSlice or String for JSON) + * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the vertex identified by the key * @throws ArangoDBException * @see API Documentation @@ -92,7 +92,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { * 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 class, VPackSlice or String for JSON) + * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the vertex identified by the key * @throws ArangoDBException @@ -105,7 +105,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { * violated * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO, VPackSlice or String for JSON) + * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the vertex * @throws ArangoDBException * @see API @@ -118,7 +118,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { * violated * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO, VPackSlice or String for JSON) + * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the vertex * @throws ArangoDBException @@ -133,7 +133,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the vertex - * @param The type of the vertex-document (POJO class, VPackSlice or String for JSON) + * @param The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the vertex * @throws ArangoDBException * @see API Documentation @@ -146,7 +146,7 @@ public interface ArangoVertexCollection extends ArangoSerializationAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the vertex - * @param The type of the vertex-document (POJO class, VPackSlice or String for JSON) + * @param The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the vertex * @throws ArangoDBException diff --git a/src/main/java/com/arangodb/ArangoView.java b/src/main/java/com/arangodb/ArangoView.java index 56a3a7995..b275d1131 100644 --- a/src/main/java/com/arangodb/ArangoView.java +++ b/src/main/java/com/arangodb/ArangoView.java @@ -30,7 +30,7 @@ * @since ArangoDB 3.4.0 */ @SuppressWarnings("UnusedReturnValue") -public interface ArangoView extends ArangoSerializationAccessor { +public interface ArangoView extends ArangoSerdeAccessor { /** * The the handler of the database the collection is within diff --git a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index 91837285b..1df9efcd3 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -21,7 +21,7 @@ package com.arangodb.async; import com.arangodb.ArangoDBException; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.entity.*; import com.arangodb.model.*; @@ -36,7 +36,7 @@ * @see Documents API Documentation */ @SuppressWarnings("unused") -public interface ArangoCollectionAsync extends ArangoSerializationAccessor { +public interface ArangoCollectionAsync extends ArangoSerdeAccessor { /** * The the handler of the database the collection is within @@ -56,7 +56,7 @@ public interface ArangoCollectionAsync extends ArangoSerializationAccessor { * 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, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the document * @see API * Documentation @@ -67,7 +67,7 @@ public interface ArangoCollectionAsync extends ArangoSerializationAccessor { * 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, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the document * @see API @@ -79,7 +79,7 @@ public interface ArangoCollectionAsync extends ArangoSerializationAccessor { * 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, VPackSlice or String for Json) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents * @see API * Documentation @@ -90,7 +90,7 @@ public interface ArangoCollectionAsync extends ArangoSerializationAccessor { * 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, VPackSlice or String for Json) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the documents * @see API @@ -140,7 +140,7 @@ CompletableFuture importDocuments( * Reads a single document * * @param key The key of the document - * @param type The type of the document (POJO class, VPackSlice or String for Json) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the document identified by the key * @see API * Documentation @@ -151,7 +151,7 @@ CompletableFuture importDocuments( * Reads a single document * * @param key The key of the document - * @param type The type of the document (POJO class, VPackSlice or String for Json) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the document identified by the key * @see API @@ -164,7 +164,7 @@ CompletableFuture getDocument(final String key, final Class type, fina * Reads multiple documents * * @param keys The keys of the documents - * @param type The type of the documents (POJO class, VPackSlice or String for Json) + * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the documents and possible errors */ CompletableFuture> getDocuments(final Collection keys, final Class type); @@ -173,7 +173,7 @@ CompletableFuture getDocument(final String key, final Class type, fina * Reads multiple documents * * @param keys The keys of the documents - * @param type The type of the documents (POJO class, VPackSlice or String for Json) + * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the documents and possible errors */ @@ -187,7 +187,7 @@ CompletableFuture> getDocuments( * violated * * @param key The key of the document - * @param value A representation of a single document (POJO, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the document * @see API * Documentation @@ -199,7 +199,7 @@ CompletableFuture> getDocuments( * violated * * @param key The key of the document - * @param value A representation of a single document (POJO, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the document * @see API @@ -214,7 +214,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, VPackSlice or String for Json) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents * @see API * Documentation @@ -225,7 +225,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, VPackSlice or String for Json) + * @param values A List of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the documents * @see API @@ -241,7 +241,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, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the document * @see API * Documentation @@ -254,7 +254,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, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the document * @see API @@ -271,7 +271,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, VPackSlice or String for Json) + * @param value A representation of a single document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the document @@ -290,7 +290,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, VPackSlice or String for Json) + * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the documents * @see API * Documentation @@ -303,7 +303,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, VPackSlice or String for Json) + * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the documents * @see API @@ -319,7 +319,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, VPackSlice or String for Json) + * @param values A list of documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @param returnType Type of the returned newDocument and/or oldDocument * @return information about the documents @@ -345,7 +345,7 @@ CompletableFuture>> updateDoc * Removes a document * * @param key The key of the document - * @param type The type of the document (POJO class, VPackSlice or String for Json). Only necessary if + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}). Only necessary if * options.returnOld is set to true, otherwise can be null. * @param options Additional options, can be null * @return information about the document @@ -372,7 +372,7 @@ CompletableFuture> deleteDocument( * Removes multiple document * * @param values The keys of the documents or the documents themselves - * @param type The type of the documents (POJO class, VPackSlice or String for Json). Only necessary if + * @param type The type of the documents (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}). Only necessary if * options.returnOld is set to true, otherwise can be null. * @param options Additional options, can be null * @return information about the documents diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 8b3b0b75d..77a3bdabd 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -31,20 +31,17 @@ import com.arangodb.internal.net.ConnectionFactory; import com.arangodb.internal.net.HostHandler; import com.arangodb.internal.net.HostResolver; -import com.arangodb.internal.util.ArangoDeserializerImpl; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializerImpl; -import com.arangodb.internal.util.DefaultArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; import com.arangodb.model.LogOptions; import com.arangodb.model.UserCreateOptions; import com.arangodb.model.UserUpdateOptions; -import com.arangodb.util.ArangoDeserializer; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.*; +import com.arangodb.serde.DataType; +import com.arangodb.serde.InternalSerde; +import com.arangodb.serde.JacksonSerde; +import com.arangodb.serde.ArangoSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -69,7 +66,7 @@ * * @author Mark Vollmary */ -public interface ArangoDBAsync extends ArangoSerializationAccessor { +public interface ArangoDBAsync extends ArangoSerdeAccessor { void shutdown() throws ArangoDBException; @@ -497,7 +494,7 @@ public Builder loadBalancingStrategy(final LoadBalancingStrategy loadBalancingSt * @param serialization custom serializer/deserializer * @return {@link ArangoDBAsync.Builder} */ - public Builder serializer(final ArangoSerialization serialization) { + public Builder serializer(final ArangoSerde serialization) { setSerializer(serialization); return this; } @@ -508,25 +505,11 @@ public Builder serializer(final ArangoSerialization serialization) { * @return {@link ArangoDBAsync} */ public synchronized ArangoDBAsync build() { - if (customSerializer == null) { - logger.warn("Usage of VelocyPack Java serialization is now deprecated for removal. " + - "Future driver versions will only support Jackson serialization (for both JSON and VPACK formats). " + - "Please configure according to: https://www.arangodb.com/docs/stable/drivers/java-reference-serialization.html"); - } if (hosts.isEmpty()) { hosts.add(host); } - final VPack vpacker = vpackBuilder.serializeNullValues(false).build(); - final VPack vpackerNull = vpackBuilder.serializeNullValues(true).build(); - final VPackParser vpackParser = vpackParserBuilder.build(); - final ArangoSerializer serializerTemp = serializer != null ? serializer - : new ArangoSerializerImpl(vpacker, vpackerNull, vpackParser); - final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer - : new ArangoDeserializerImpl(vpackerNull, vpackParser); - final DefaultArangoSerialization internal = new DefaultArangoSerialization(serializerTemp, - deserializerTemp); - final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; - final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); + final ArangoSerde userSerde = customSerializer != null ? customSerializer : JacksonSerde.of(DataType.VPACK); + final InternalSerde serde = InternalSerde.of(DataType.VPACK, userSerde); final int max = maxConnections != null ? Math.max(1, maxConnections) : ArangoDefaults.MAX_CONNECTIONS_VST_DEFAULT; @@ -542,7 +525,7 @@ public synchronized ArangoDBAsync build() { final HostHandler asyncHostHandler = createHostHandler(asyncHostResolver); return new ArangoDBAsyncImpl( asyncBuilder(asyncHostHandler), - util, + serde, syncBuilder(syncHostHandler), asyncHostResolver, syncHostResolver, diff --git a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java index d3ed12c32..4f525c838 100644 --- a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java @@ -21,7 +21,7 @@ package com.arangodb.async; import com.arangodb.ArangoDBException; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; @@ -41,7 +41,7 @@ * @see Query API Documentation */ @SuppressWarnings("unused") -public interface ArangoDatabaseAsync extends ArangoSerializationAccessor { +public interface ArangoDatabaseAsync extends ArangoSerdeAccessor { /** * Return the main entry point for the ArangoDB driver @@ -249,7 +249,7 @@ public interface ArangoDatabaseAsync extends ArangoSerializationAccessor { * @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 class, VPackSlice, String for Json, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @see API * Documentation @@ -266,7 +266,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 class, VPackSlice, String for Json, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @see API * Documentation @@ -282,7 +282,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 class, VPackSlice, String for Json, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @see API * Documentation @@ -297,7 +297,7 @@ CompletableFuture> query( * result list. * * @param query contains the query string to be executed - * @param type The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @see API * Documentation @@ -308,7 +308,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 class, VPackSlice, String for Json, or Collection/List/Map) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return cursor of the results * @see API @@ -523,7 +523,7 @@ CompletableFuture 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 class, VPackSlice or String for Json) + * @param type The type of the result (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return the result of the transaction if it succeeded * @see API @@ -595,7 +595,7 @@ CompletableFuture createGraph( * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO class, VPackSlice or String for Json) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the document identified by the id * @see API * Documentation @@ -606,7 +606,7 @@ CompletableFuture createGraph( * Reads a single document * * @param id The id of the document - * @param type The type of the document (POJO class, VPackSlice or String for Json) + * @param type The type of the document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @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 2dea8807c..39a8a3a0d 100644 --- a/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java @@ -20,7 +20,7 @@ package com.arangodb.async; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.entity.EdgeEntity; import com.arangodb.entity.EdgeUpdateEntity; import com.arangodb.model.*; @@ -34,7 +34,7 @@ * @see API Documentation */ @SuppressWarnings("unused") -public interface ArangoEdgeCollectionAsync extends ArangoSerializationAccessor { +public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { /** * The the handler of the named graph the edge collection is within @@ -53,7 +53,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerializationAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, VPackSlice or String for Json) + * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the edge * @see API Documentation */ @@ -62,7 +62,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerializationAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO, VPackSlice or String for Json) + * @param value A representation of a single edge (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the edge * @see API Documentation @@ -73,7 +73,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerializationAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for Json) + * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the edge identified by the key * @see API Documentation */ @@ -83,7 +83,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerializationAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for Json) + * @param type The type of the edge-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @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/ArangoGraphAsync.java b/src/main/java/com/arangodb/async/ArangoGraphAsync.java index 17cb45a95..0fae79e0b 100644 --- a/src/main/java/com/arangodb/async/ArangoGraphAsync.java +++ b/src/main/java/com/arangodb/async/ArangoGraphAsync.java @@ -20,7 +20,7 @@ package com.arangodb.async; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.GraphEntity; import com.arangodb.model.GraphCreateOptions; @@ -36,7 +36,7 @@ * @see API Documentation */ @SuppressWarnings("unused") -public interface ArangoGraphAsync extends ArangoSerializationAccessor { +public interface ArangoGraphAsync extends ArangoSerdeAccessor { /** * The the handler of the database the named graph is within diff --git a/src/main/java/com/arangodb/async/ArangoRouteAsync.java b/src/main/java/com/arangodb/async/ArangoRouteAsync.java index ab384f99b..e79d9ca13 100644 --- a/src/main/java/com/arangodb/async/ArangoRouteAsync.java +++ b/src/main/java/com/arangodb/async/ArangoRouteAsync.java @@ -20,7 +20,7 @@ package com.arangodb.async; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.velocystream.Response; import java.util.concurrent.CompletableFuture; @@ -31,7 +31,7 @@ * @author Mark Vollmary */ @SuppressWarnings("unused") -public interface ArangoRouteAsync extends ArangoSerializationAccessor { +public interface ArangoRouteAsync extends ArangoSerdeAccessor { /** * Returns a new {@link ArangoRouteAsync} instance for the given path (relative to the current route) that can be @@ -61,7 +61,7 @@ public interface ArangoRouteAsync extends ArangoSerializationAccessor { ArangoRouteAsync withQueryParam(String key, Object value); /** - * The response body. The body will be serialized to {@link com.arangodb.velocypack.VPackSlice}. + * The response body. * * @param body The response body * @return {@link ArangoRouteAsync} diff --git a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java index b610a9796..38eb462cd 100644 --- a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java @@ -20,7 +20,7 @@ package com.arangodb.async; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.entity.VertexEntity; import com.arangodb.entity.VertexUpdateEntity; import com.arangodb.model.*; @@ -34,7 +34,7 @@ * @see API Documentation */ @SuppressWarnings("unused") -public interface ArangoVertexCollectionAsync extends ArangoSerializationAccessor { +public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { /** * The the handler of the named graph the edge collection is within @@ -63,7 +63,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerializationAccessor /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, VPackSlice or String for Json) + * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return information about the vertex * @see API Documentation */ @@ -72,7 +72,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerializationAccessor /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO, VPackSlice or String for Json) + * @param value A representation of a single vertex (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @param options Additional options, can be null * @return information about the vertex * @see API Documentation @@ -83,7 +83,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerializationAccessor * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class, VPackSlice or String for Json) + * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @return the vertex identified by the key * @see API Documentation */ @@ -93,7 +93,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerializationAccessor * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class, VPackSlice or String for Json) + * @param type The type of the vertex-document (POJO, {@link com.arangodb.util.RawJson} or {@link com.arangodb.util.RawBytes}) * @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/async/ArangoViewAsync.java b/src/main/java/com/arangodb/async/ArangoViewAsync.java index fed3da081..c06289cee 100644 --- a/src/main/java/com/arangodb/async/ArangoViewAsync.java +++ b/src/main/java/com/arangodb/async/ArangoViewAsync.java @@ -20,7 +20,7 @@ package com.arangodb.async; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.entity.ViewEntity; import java.util.concurrent.CompletableFuture; @@ -33,7 +33,7 @@ * @since ArangoDB 3.4.0 */ @SuppressWarnings("unused") -public interface ArangoViewAsync extends ArangoSerializationAccessor { +public interface ArangoViewAsync extends ArangoSerdeAccessor { /** * The the handler of the database the collection is within diff --git a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java index b5be30c1c..7f444ad9e 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java @@ -106,14 +106,13 @@ public CompletableFuture getDocument(final String key, final Class typ } @Override - @SuppressWarnings("unchecked") public CompletableFuture getDocument( final String key, final Class type, final DocumentReadOptions options) throws ArangoDBException { DocumentUtil.validateDocumentKey(key); boolean isCatchException = options != null ? options.isCatchException() : new DocumentReadOptions().isCatchException(); - return (CompletableFuture) executor.execute(getDocumentRequest(key, options), type) + return executor.execute(getDocumentRequest(key, options), getDocumentResponseDeserializer(type)) .exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException)); } diff --git a/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java index 14988eca3..284a576b8 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java @@ -21,7 +21,7 @@ package com.arangodb.async.internal; import com.arangodb.async.ArangoCursorAsync; -import com.arangodb.entity.CursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; import com.arangodb.internal.cursor.ArangoCursorImpl; @@ -37,7 +37,7 @@ public class ArangoCursorAsyncImpl extends ArangoCursorImpl implements ArangoCursorAsync { ArangoCursorAsyncImpl(final InternalArangoDatabase db, final ArangoCursorExecute execute, - final Class type, final CursorEntity result) { + final Class type, final InternalCursorEntity result) { super(db, execute, type, result); } diff --git a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java index 23cf6af31..e6a56e137 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java @@ -31,8 +31,7 @@ import com.arangodb.internal.net.CommunicationProtocol; import com.arangodb.internal.net.HostHandler; import com.arangodb.internal.net.HostResolver; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunication; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; @@ -63,7 +62,7 @@ public class ArangoDBAsyncImpl extends InternalArangoDB imp public ArangoDBAsyncImpl( final VstCommunicationAsync.Builder asyncCommBuilder, - final ArangoSerializationFactory util, + final InternalSerde util, final VstCommunicationSync.Builder syncCommBuilder, final HostResolver asyncHostResolver, final HostResolver syncHostResolver, @@ -74,10 +73,10 @@ public ArangoDBAsyncImpl( final int timeoutMs ) { - super(new ArangoExecutorAsync(asyncCommBuilder.build(util.get(Serializer.INTERNAL)), util, new DocumentCache(), + super(new ArangoExecutorAsync(asyncCommBuilder.build(util), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, context); - final VstCommunication cacheCom = syncCommBuilder.build(util.get(Serializer.INTERNAL)); + final VstCommunication cacheCom = syncCommBuilder.build(util); cp = new VstProtocol(cacheCom); this.asyncHostHandler = asyncHostHandler; @@ -85,8 +84,8 @@ public ArangoDBAsyncImpl( ArangoExecutorSync arangoExecutorSync = new ArangoExecutorSync(cp, util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs); - asyncHostResolver.init(arangoExecutorSync, util.get(Serializer.INTERNAL)); - syncHostResolver.init(arangoExecutorSync, util.get(Serializer.INTERNAL)); + asyncHostResolver.init(arangoExecutorSync, util); + syncHostResolver.init(arangoExecutorSync, util); } diff --git a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java index 224d80d7c..0e390e736 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java @@ -22,34 +22,19 @@ import com.arangodb.ArangoDBException; import com.arangodb.DbName; -import com.arangodb.async.ArangoCollectionAsync; -import com.arangodb.async.ArangoCursorAsync; -import com.arangodb.async.ArangoDatabaseAsync; -import com.arangodb.async.ArangoGraphAsync; -import com.arangodb.async.ArangoRouteAsync; -import com.arangodb.async.ArangoSearchAsync; -import com.arangodb.async.ArangoViewAsync; +import com.arangodb.async.*; import com.arangodb.entity.*; import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.ArangoErrors; import com.arangodb.internal.InternalArangoDatabase; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; -import com.arangodb.model.AqlFunctionCreateOptions; -import com.arangodb.model.AqlFunctionDeleteOptions; -import com.arangodb.model.AqlFunctionGetOptions; -import com.arangodb.model.AqlQueryExplainOptions; -import com.arangodb.model.AqlQueryOptions; -import com.arangodb.model.CollectionCreateOptions; -import com.arangodb.model.CollectionsReadOptions; -import com.arangodb.model.DocumentReadOptions; -import com.arangodb.model.GraphCreateOptions; -import com.arangodb.model.StreamTransactionOptions; -import com.arangodb.model.TransactionOptions; +import com.arangodb.model.*; import com.arangodb.model.arangosearch.AnalyzerDeleteOptions; import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; -import com.arangodb.velocypack.Type; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import java.util.Collection; @@ -194,7 +179,7 @@ public CompletableFuture> query( final Class type) { final Request request = queryRequest(query, bindVars, options); final HostHandle hostHandle = new HostHandle(); - final CompletableFuture execution = executor.execute(request, CursorEntity.class, hostHandle); + final CompletableFuture execution = executor.execute(request, InternalCursorEntity.class, hostHandle); return execution.thenApply(result -> createCursor(result, type, options, hostHandle)); } @@ -222,20 +207,20 @@ public CompletableFuture> query(final String query, fin @Override public CompletableFuture> cursor(final String cursorId, final Class type) { final HostHandle hostHandle = new HostHandle(); - final CompletableFuture execution = executor.execute(queryNextRequest(cursorId, null, null), CursorEntity.class, hostHandle); + final CompletableFuture execution = executor.execute(queryNextRequest(cursorId, null, null), InternalCursorEntity.class, hostHandle); return execution.thenApply(result -> createCursor(result, type, null, hostHandle)); } private ArangoCursorAsync createCursor( - final CursorEntity result, + final InternalCursorEntity result, final Class type, final AqlQueryOptions options, final HostHandle hostHandle) { return new ArangoCursorAsyncImpl<>(this, new ArangoCursorExecute() { @Override - public CursorEntity next(final String id, Map meta) { - final CompletableFuture result = executor.execute(queryNextRequest(id, options, meta), - CursorEntity.class, hostHandle); + public InternalCursorEntity next(final String id, Map meta) { + final CompletableFuture result = executor.execute(queryNextRequest(id, options, meta), + InternalCursorEntity.class, hostHandle); try { return result.get(); } catch (InterruptedException | ExecutionException e) { @@ -296,14 +281,14 @@ public CompletableFuture setQueryTrackingProperti @Override public CompletableFuture> getCurrentlyRunningQueries() { - return executor.execute(getCurrentlyRunningQueriesRequest(), new Type>() { - }.getType()); + return executor.execute(getCurrentlyRunningQueriesRequest(), + SerdeUtils.INSTANCE.constructListType(QueryEntity.class)); } @Override public CompletableFuture> getSlowQueries() { - return executor.execute(getSlowQueriesRequest(), new Type>() { - }.getType()); + return executor.execute(getSlowQueriesRequest(), + SerdeUtils.INSTANCE.constructListType(QueryEntity.class)); } @Override diff --git a/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java b/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java index 58d7659c5..fc7372da9 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java +++ b/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java @@ -26,7 +26,7 @@ import com.arangodb.internal.DocumentCache; import com.arangodb.internal.QueueTimeMetricsImpl; import com.arangodb.internal.net.HostHandle; -import com.arangodb.internal.util.ArangoSerializationFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import java.io.IOException; @@ -44,18 +44,18 @@ public class ArangoExecutorAsync extends ArangoExecutor { private final VstCommunicationAsync communication; private final ExecutorService outgoingExecutor = Executors.newSingleThreadExecutor(); - public ArangoExecutorAsync(final VstCommunicationAsync communication, final ArangoSerializationFactory util, + public ArangoExecutorAsync(final VstCommunicationAsync communication, final InternalSerde util, final DocumentCache documentCache, final QueueTimeMetricsImpl qtMetrics, final int timeoutMs) { super(util, documentCache, qtMetrics, timeoutMs); this.communication = communication; } public CompletableFuture execute(final Request request, final Type type) { - return execute(request, (response) -> createResult(type, response)); + return execute(request, response -> createResult(type, response)); } public CompletableFuture execute(final Request request, final Type type, final HostHandle hostHandle) { - return execute(request, (response) -> createResult(type, response), hostHandle); + return execute(request, response -> createResult(type, response), hostHandle); } public CompletableFuture execute(final Request request, final ResponseDeserializer responseDeserializer) { @@ -68,7 +68,7 @@ private CompletableFuture execute( final HostHandle hostHandle) { return CompletableFuture.completedFuture(null) - .thenComposeAsync((it) -> communication.execute(interceptRequest(request), hostHandle), outgoingExecutor) + .thenComposeAsync(it -> communication.execute(interceptRequest(request), hostHandle), outgoingExecutor) .thenApplyAsync(response -> { interceptResponse(response); return responseDeserializer.deserialize(response); diff --git a/src/main/java/com/arangodb/async/internal/velocystream/VstCommunicationAsync.java b/src/main/java/com/arangodb/async/internal/velocystream/VstCommunicationAsync.java index 38acb45be..410b8dc9a 100644 --- a/src/main/java/com/arangodb/async/internal/velocystream/VstCommunicationAsync.java +++ b/src/main/java/com/arangodb/async/internal/velocystream/VstCommunicationAsync.java @@ -30,7 +30,7 @@ import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; import com.arangodb.internal.velocystream.internal.Message; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocypack.exception.VPackException; import com.arangodb.velocypack.exception.VPackParserException; import com.arangodb.velocystream.Request; @@ -50,7 +50,7 @@ public class VstCommunicationAsync extends VstCommunicationAPI Documentation */ -public class AqlExecutionExplainEntity implements Entity { +public final class AqlExecutionExplainEntity { - public static class ExecutionPlan { + public static final class ExecutionPlan { private Collection nodes; private Collection rules; private Collection collections; @@ -61,7 +61,7 @@ public Integer getEstimatedNrItems() { } } - public static class ExecutionNode { + public static final class ExecutionNode { private String type; private Collection dependencies; private Long id; @@ -179,7 +179,7 @@ public Boolean getReverse() { } } - public static class ExecutionVariable { + public static final class ExecutionVariable { private Long id; private String name; @@ -192,7 +192,7 @@ public String getName() { } } - public static class ExecutionExpression { + public static final class ExecutionExpression { private String type; private String name; private Long id; @@ -235,7 +235,7 @@ public Collection getSubNodes() { } } - public static class ExecutionCollection { + public static final class ExecutionCollection { private String name; private String type; @@ -248,7 +248,7 @@ public String getType() { } } - public static class ExecutionStats { + public static final class ExecutionStats { private Integer rulesExecuted; private Integer rulesSkipped; private Integer plansCreated; diff --git a/src/main/java/com/arangodb/entity/AqlFunctionEntity.java b/src/main/java/com/arangodb/entity/AqlFunctionEntity.java index 57f5d78c4..cd0d52f5f 100644 --- a/src/main/java/com/arangodb/entity/AqlFunctionEntity.java +++ b/src/main/java/com/arangodb/entity/AqlFunctionEntity.java @@ -26,7 +26,7 @@ * "https://www.arangodb.com/docs/stable/http/aql-user-functions.html#return-registered-aql-user-functions">API * Documentation */ -public class AqlFunctionEntity implements Entity { +public final class AqlFunctionEntity { private String name; private String code; diff --git a/src/main/java/com/arangodb/entity/AqlParseEntity.java b/src/main/java/com/arangodb/entity/AqlParseEntity.java index f5f16e059..9047a23e7 100644 --- a/src/main/java/com/arangodb/entity/AqlParseEntity.java +++ b/src/main/java/com/arangodb/entity/AqlParseEntity.java @@ -26,9 +26,9 @@ * @author Mark Vollmary * @see API Documentation */ -public class AqlParseEntity implements Entity { +public final class AqlParseEntity { - public static class AstNode { + public static final class AstNode { private String type; private Collection subNodes; private String name; diff --git a/src/main/java/com/arangodb/entity/ArangoDBEngine.java b/src/main/java/com/arangodb/entity/ArangoDBEngine.java index 37ea0bfc8..0cd2898d3 100644 --- a/src/main/java/com/arangodb/entity/ArangoDBEngine.java +++ b/src/main/java/com/arangodb/entity/ArangoDBEngine.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class ArangoDBEngine implements Entity { +public final class ArangoDBEngine { public enum StorageEngineName { mmfiles, rocksdb diff --git a/src/main/java/com/arangodb/entity/ArangoDBVersion.java b/src/main/java/com/arangodb/entity/ArangoDBVersion.java index db339bd88..878980e32 100644 --- a/src/main/java/com/arangodb/entity/ArangoDBVersion.java +++ b/src/main/java/com/arangodb/entity/ArangoDBVersion.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class ArangoDBVersion implements Entity { +public final class ArangoDBVersion { private String server; private String version; diff --git a/src/main/java/com/arangodb/entity/BaseDocument.java b/src/main/java/com/arangodb/entity/BaseDocument.java index 2d6fe1967..1946afda1 100644 --- a/src/main/java/com/arangodb/entity/BaseDocument.java +++ b/src/main/java/com/arangodb/entity/BaseDocument.java @@ -21,6 +21,9 @@ package com.arangodb.entity; import com.arangodb.internal.DocumentFields; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonInclude; import java.io.Serializable; import java.util.HashMap; @@ -92,6 +95,8 @@ public void setRevision(final String revision) { this.revision = revision; } + @JsonInclude + @JsonAnyGetter public Map getProperties() { return properties; } @@ -100,6 +105,8 @@ public void setProperties(final Map properties) { this.properties = properties; } + @JsonInclude + @JsonAnySetter public void addAttribute(final String key, final Object value) { properties.put(key, value); } diff --git a/src/main/java/com/arangodb/entity/BaseEdgeDocument.java b/src/main/java/com/arangodb/entity/BaseEdgeDocument.java index c76831b0a..9a82420da 100644 --- a/src/main/java/com/arangodb/entity/BaseEdgeDocument.java +++ b/src/main/java/com/arangodb/entity/BaseEdgeDocument.java @@ -27,7 +27,7 @@ /** * @author Mark Vollmary */ -public class BaseEdgeDocument extends BaseDocument { +public final class BaseEdgeDocument extends BaseDocument { private static final long serialVersionUID = 6904923804449368783L; diff --git a/src/main/java/com/arangodb/entity/CollectionEntity.java b/src/main/java/com/arangodb/entity/CollectionEntity.java index 72530c808..6f9fff3aa 100644 --- a/src/main/java/com/arangodb/entity/CollectionEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionEntity.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class CollectionEntity implements Entity { +public class CollectionEntity { private String id; private String name; diff --git a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java index 73f55d758..9e9388bc3 100644 --- a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java @@ -27,20 +27,19 @@ * @see API * Documentation */ -public class CollectionPropertiesEntity extends CollectionEntity { +public final class CollectionPropertiesEntity extends CollectionEntity { private KeyOptions keyOptions; private Long count; private Integer numberOfShards; private Collection shardKeys; - private final ReplicationFactor replicationFactor; + private ReplicationFactor replicationFactor; private Integer writeConcern; private String shardingStrategy; // cluster option private String smartJoinAttribute; // enterprise option public CollectionPropertiesEntity() { super(); - replicationFactor = new ReplicationFactor(); } public KeyOptions getKeyOptions() { @@ -82,12 +81,12 @@ public void setShardKeys(final Collection shardKeys) { this.shardKeys = shardKeys; } - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } - public void setReplicationFactor(final Integer replicationFactor) { - this.replicationFactor.setReplicationFactor(replicationFactor); + public void setReplicationFactor(final ReplicationFactor replicationFactor) { + this.replicationFactor = replicationFactor; } public Integer getWriteConcern() { @@ -98,17 +97,6 @@ public void setWriteConcern(final Integer writeConcern) { this.writeConcern = writeConcern; } - /** - * @return whether the collection is a satellite collection. Only in an enterprise cluster setup (else returning null). - */ - public Boolean getSatellite() { - return this.replicationFactor.getSatellite(); - } - - public void setSatellite(final Boolean satellite) { - this.replicationFactor.setSatellite(satellite); - } - public String getShardingStrategy() { return shardingStrategy; } diff --git a/src/main/java/com/arangodb/entity/CollectionRevisionEntity.java b/src/main/java/com/arangodb/entity/CollectionRevisionEntity.java index d04ec000d..a65db6d7a 100644 --- a/src/main/java/com/arangodb/entity/CollectionRevisionEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionRevisionEntity.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class CollectionRevisionEntity extends CollectionEntity { +public final class CollectionRevisionEntity extends CollectionEntity { private String revision; diff --git a/src/main/java/com/arangodb/entity/CursorStats.java b/src/main/java/com/arangodb/entity/CursorStats.java new file mode 100644 index 000000000..2bf822561 --- /dev/null +++ b/src/main/java/com/arangodb/entity/CursorStats.java @@ -0,0 +1,44 @@ +package com.arangodb.entity; + +public final class CursorStats { + private Long writesExecuted; + private Long writesIgnored; + private Long scannedFull; + private Long scannedIndex; + private Long filtered; + private Long fullCount; + private Double executionTime; + private Long peakMemoryUsage; + + public Long getWritesExecuted() { + return writesExecuted; + } + + public Long getWritesIgnored() { + return writesIgnored; + } + + public Long getScannedFull() { + return scannedFull; + } + + public Long getScannedIndex() { + return scannedIndex; + } + + public Long getFiltered() { + return filtered; + } + + public Long getFullCount() { + return fullCount; + } + + public Double getExecutionTime() { + return executionTime; + } + + public Long getPeakMemoryUsage() { + return peakMemoryUsage; + } +} diff --git a/src/main/java/com/arangodb/entity/CursorWarning.java b/src/main/java/com/arangodb/entity/CursorWarning.java new file mode 100644 index 000000000..72dc8ff1c --- /dev/null +++ b/src/main/java/com/arangodb/entity/CursorWarning.java @@ -0,0 +1,16 @@ +package com.arangodb.entity; + +public final class CursorWarning { + + private Integer code; + private String message; + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } + +} diff --git a/src/main/java/com/arangodb/entity/DatabaseEntity.java b/src/main/java/com/arangodb/entity/DatabaseEntity.java index 975065f50..3b996d033 100644 --- a/src/main/java/com/arangodb/entity/DatabaseEntity.java +++ b/src/main/java/com/arangodb/entity/DatabaseEntity.java @@ -24,19 +24,18 @@ * @author Mark Vollmary * @see API Documentation */ -public class DatabaseEntity implements Entity { +public final class DatabaseEntity { private String id; private String name; private String path; private Boolean isSystem; - private final ReplicationFactor replicationFactor; + private ReplicationFactor replicationFactor; private Integer writeConcern; private String sharding; public DatabaseEntity() { super(); - replicationFactor = new ReplicationFactor(); } /** @@ -71,8 +70,8 @@ public Boolean getIsSystem() { * @return the default replication factor for collections in this database * @since ArangoDB 3.6.0 */ - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } /** @@ -87,14 +86,6 @@ public Integer getWriteConcern() { return writeConcern; } - /** - * @return whether the collection is a satellite collection. Only in an enterprise cluster setup (else returning null). - * @since ArangoDB 3.6.0 - */ - public Boolean getSatellite() { - return this.replicationFactor.getSatellite(); - } - /** * @return information about the default sharding method for collections created in this database * @since ArangoDB 3.6.0 diff --git a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java index 9469325bf..c2d07bc8c 100644 --- a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java @@ -20,18 +20,16 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.Expose; +import com.arangodb.serde.UserData; /** * @author Mark Vollmary * @see API * Documentation */ -public class DocumentCreateEntity extends DocumentEntity { +public final class DocumentCreateEntity extends DocumentEntity { - @Expose(deserialize = false) private T newDocument; - @Expose(deserialize = false) private T oldDocument; public DocumentCreateEntity() { @@ -45,6 +43,7 @@ public T getNew() { return newDocument; } + @UserData public void setNew(final T newDocument) { this.newDocument = newDocument; } @@ -57,6 +56,7 @@ public T getOld() { return oldDocument; } + @UserData public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java index 336ec53c1..46fa34c56 100644 --- a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java @@ -20,16 +20,15 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.Expose; +import com.arangodb.serde.UserData; /** * @author Mark Vollmary * @see API * Documentation */ -public class DocumentDeleteEntity extends DocumentEntity { +public final class DocumentDeleteEntity extends DocumentEntity { - @Expose(deserialize = false) private T oldDocument; public DocumentDeleteEntity() { @@ -44,6 +43,7 @@ public T getOld() { return oldDocument; } + @UserData public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/entity/DocumentEntity.java b/src/main/java/com/arangodb/entity/DocumentEntity.java index 1b973e32d..fe3ddda5b 100644 --- a/src/main/java/com/arangodb/entity/DocumentEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentEntity.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class DocumentEntity implements Entity { +public class DocumentEntity { @Key private String key; diff --git a/src/main/java/com/arangodb/entity/DocumentImportEntity.java b/src/main/java/com/arangodb/entity/DocumentImportEntity.java index bd57c65fc..b4f6a469f 100644 --- a/src/main/java/com/arangodb/entity/DocumentImportEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentImportEntity.java @@ -26,7 +26,7 @@ /** * @author Mark Vollmary */ -public class DocumentImportEntity implements Entity { +public final class DocumentImportEntity { private Integer created; private Integer errors; diff --git a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java index 009468000..61b9b1f62 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -20,8 +20,8 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.Expose; -import com.arangodb.velocypack.annotations.SerializedName; +import com.arangodb.serde.UserData; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @param @@ -29,13 +29,11 @@ * @see API * Documentation */ -public class DocumentUpdateEntity extends DocumentEntity { +public final class DocumentUpdateEntity extends DocumentEntity { - @SerializedName("_oldRev") + @JsonProperty("_oldRev") private String oldRev; - @Expose(deserialize = false) private T newDocument; - @Expose(deserialize = false) private T oldDocument; public DocumentUpdateEntity() { @@ -53,6 +51,7 @@ public T getNew() { return newDocument; } + @UserData public void setNew(final T newDocument) { this.newDocument = newDocument; } @@ -65,6 +64,7 @@ public T getOld() { return oldDocument; } + @UserData public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/entity/EdgeDefinition.java b/src/main/java/com/arangodb/entity/EdgeDefinition.java index 140e01567..cd39c9a3b 100644 --- a/src/main/java/com/arangodb/entity/EdgeDefinition.java +++ b/src/main/java/com/arangodb/entity/EdgeDefinition.java @@ -22,17 +22,18 @@ import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** * @author Mark Vollmary * @see API Documentation */ -public class EdgeDefinition { +public final class EdgeDefinition { private String collection; private Collection from; private Collection to; - private Options options; + private final Options options = new Options(); public String getCollection() { return collection; @@ -65,6 +66,10 @@ public Collection getSatellites() { return options.satellites; } + public Options getOptions() { + return options; + } + /** * @param satellites collection names that will be used to create SatelliteCollections * for a Hybrid (Disjoint) SmartGraph (Enterprise Edition only). Each array element @@ -73,12 +78,15 @@ public Collection getSatellites() { * @since ArangoDB 3.9.0 */ public EdgeDefinition satellites(final String... satellites) { - options = new Options(); options.satellites = Arrays.asList(satellites); return this; } - public static class Options { - private Collection satellites; + public static final class Options { + private Collection satellites = Collections.emptyList(); + + public Collection getSatellites() { + return satellites; + } } } diff --git a/src/main/java/com/arangodb/entity/EdgeEntity.java b/src/main/java/com/arangodb/entity/EdgeEntity.java index c62f7d131..48107a1e1 100644 --- a/src/main/java/com/arangodb/entity/EdgeEntity.java +++ b/src/main/java/com/arangodb/entity/EdgeEntity.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class EdgeEntity extends DocumentEntity { +public final class EdgeEntity extends DocumentEntity { public EdgeEntity() { super(); diff --git a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java index f872666a3..67b72e76b 100644 --- a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java @@ -20,15 +20,15 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Mark Vollmary * @see API Documentation */ -public class EdgeUpdateEntity extends DocumentEntity { +public final class EdgeUpdateEntity extends DocumentEntity { - @SerializedName("_oldRev") + @JsonProperty("_oldRev") private String oldRev; public EdgeUpdateEntity() { diff --git a/src/main/java/com/arangodb/entity/ErrorEntity.java b/src/main/java/com/arangodb/entity/ErrorEntity.java index 48a1c582b..5677d2301 100644 --- a/src/main/java/com/arangodb/entity/ErrorEntity.java +++ b/src/main/java/com/arangodb/entity/ErrorEntity.java @@ -25,7 +25,7 @@ /** * @author Mark Vollmary */ -public class ErrorEntity implements Serializable, Entity { +public final class ErrorEntity implements Serializable { private static final long serialVersionUID = -5918898261563691261L; diff --git a/src/main/java/com/arangodb/entity/From.java b/src/main/java/com/arangodb/entity/From.java index 056c1e1c6..4d3b63ca0 100644 --- a/src/main/java/com/arangodb/entity/From.java +++ b/src/main/java/com/arangodb/entity/From.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.json.bind.annotation.JsonbAnnotation; +import jakarta.json.bind.annotation.JsonbProperty; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -19,5 +21,7 @@ @JacksonAnnotationsInside @JsonProperty(DocumentFields.FROM) @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonbAnnotation +@JsonbProperty("_from") public @interface From { } diff --git a/src/main/java/com/arangodb/entity/GraphEntity.java b/src/main/java/com/arangodb/entity/GraphEntity.java index 151979131..07145ee60 100644 --- a/src/main/java/com/arangodb/entity/GraphEntity.java +++ b/src/main/java/com/arangodb/entity/GraphEntity.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class GraphEntity implements Entity { +public final class GraphEntity { private String name; /** @@ -66,12 +66,8 @@ public Integer getNumberOfShards() { return numberOfShards; } - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); - } - - public Boolean getSatellite() { - return this.replicationFactor.getSatellite(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } public Integer getWriteConcern() { diff --git a/src/main/java/com/arangodb/entity/Id.java b/src/main/java/com/arangodb/entity/Id.java index f4333438d..5ebd39d46 100644 --- a/src/main/java/com/arangodb/entity/Id.java +++ b/src/main/java/com/arangodb/entity/Id.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.json.bind.annotation.JsonbAnnotation; +import jakarta.json.bind.annotation.JsonbProperty; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -19,5 +21,7 @@ @JacksonAnnotationsInside @JsonProperty(DocumentFields.ID) @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonbAnnotation +@JsonbProperty("_id") public @interface Id { } diff --git a/src/main/java/com/arangodb/entity/IndexEntity.java b/src/main/java/com/arangodb/entity/IndexEntity.java index b359a5146..a379ed161 100644 --- a/src/main/java/com/arangodb/entity/IndexEntity.java +++ b/src/main/java/com/arangodb/entity/IndexEntity.java @@ -25,7 +25,7 @@ /** * @author Mark Vollmary */ -public class IndexEntity implements Entity { +public final class IndexEntity { private String id; private String name; diff --git a/src/main/java/com/arangodb/entity/Key.java b/src/main/java/com/arangodb/entity/Key.java index f510a2c65..2afc552a3 100644 --- a/src/main/java/com/arangodb/entity/Key.java +++ b/src/main/java/com/arangodb/entity/Key.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.json.bind.annotation.JsonbAnnotation; +import jakarta.json.bind.annotation.JsonbProperty; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -19,5 +21,7 @@ @JacksonAnnotationsInside @JsonProperty(DocumentFields.KEY) @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonbAnnotation +@JsonbProperty("_key") public @interface Key { } diff --git a/src/main/java/com/arangodb/entity/KeyOptions.java b/src/main/java/com/arangodb/entity/KeyOptions.java index 261450638..65bd435e5 100644 --- a/src/main/java/com/arangodb/entity/KeyOptions.java +++ b/src/main/java/com/arangodb/entity/KeyOptions.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class KeyOptions { +public final class KeyOptions { private Boolean allowUserKeys; private KeyType type; diff --git a/src/main/java/com/arangodb/entity/License.java b/src/main/java/com/arangodb/entity/License.java index 053b2ca64..92803eed4 100644 --- a/src/main/java/com/arangodb/entity/License.java +++ b/src/main/java/com/arangodb/entity/License.java @@ -20,11 +20,17 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @author Axel Becker */ public enum License { - ENTERPRISE, COMMUNITY + @JsonProperty("enterprise") + ENTERPRISE, + + @JsonProperty("community") + COMMUNITY } diff --git a/src/main/java/com/arangodb/entity/LogEntriesEntity.java b/src/main/java/com/arangodb/entity/LogEntriesEntity.java index 43d0954b5..e43d44713 100644 --- a/src/main/java/com/arangodb/entity/LogEntriesEntity.java +++ b/src/main/java/com/arangodb/entity/LogEntriesEntity.java @@ -28,7 +28,7 @@ * Documentation * @since ArangoDB 3.8 */ -public class LogEntriesEntity implements Entity { +public final class LogEntriesEntity { private Long total; private List messages; @@ -41,7 +41,7 @@ public List getMessages() { return messages; } - public static class Message { + public static final class Message { Long id; String topic; String level; diff --git a/src/main/java/com/arangodb/entity/LogLevelEntity.java b/src/main/java/com/arangodb/entity/LogLevelEntity.java index adcc1b393..a6e9ae702 100644 --- a/src/main/java/com/arangodb/entity/LogLevelEntity.java +++ b/src/main/java/com/arangodb/entity/LogLevelEntity.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class LogLevelEntity implements Entity { +public final class LogLevelEntity { public enum LogLevel { FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, DEFAULT @@ -53,6 +53,10 @@ public LogLevelEntity() { super(); } + public LogLevel getAll() { + return all; + } + public void setAll(final LogLevel all) { this.all = all; } diff --git a/src/main/java/com/arangodb/entity/MultiDocumentEntity.java b/src/main/java/com/arangodb/entity/MultiDocumentEntity.java index bd619c4f9..edf154696 100644 --- a/src/main/java/com/arangodb/entity/MultiDocumentEntity.java +++ b/src/main/java/com/arangodb/entity/MultiDocumentEntity.java @@ -25,7 +25,7 @@ /** * @author Mark Vollmary */ -public class MultiDocumentEntity implements Entity { +public final class MultiDocumentEntity { private Collection documents; private Collection errors; diff --git a/src/main/java/com/arangodb/entity/Permissions.java b/src/main/java/com/arangodb/entity/Permissions.java index 774f36c42..73f8b8105 100644 --- a/src/main/java/com/arangodb/entity/Permissions.java +++ b/src/main/java/com/arangodb/entity/Permissions.java @@ -20,6 +20,8 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @author Mark Vollmary */ @@ -28,11 +30,16 @@ public enum Permissions { /** * read and write access */ + @JsonProperty("rw") RW, + /** * read-only access */ + @JsonProperty("ro") RO, + + @JsonProperty("none") NONE } diff --git a/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java b/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java index d820aa0c9..67000290e 100644 --- a/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java @@ -26,7 +26,7 @@ * "https://www.arangodb.com/docs/stable/http/aql-query-cache.html">API * Documentation */ -public class QueryCachePropertiesEntity implements Entity { +public final class QueryCachePropertiesEntity { public enum CacheMode { off, on, demand diff --git a/src/main/java/com/arangodb/entity/QueryEntity.java b/src/main/java/com/arangodb/entity/QueryEntity.java index 2e78b1ed4..04cff2fe0 100644 --- a/src/main/java/com/arangodb/entity/QueryEntity.java +++ b/src/main/java/com/arangodb/entity/QueryEntity.java @@ -26,7 +26,7 @@ /** * @author Mark Vollmary */ -public class QueryEntity implements Entity { +public final class QueryEntity { public static final String PROPERTY_STARTED = "started"; diff --git a/src/main/java/com/arangodb/entity/QueryExecutionState.java b/src/main/java/com/arangodb/entity/QueryExecutionState.java index 75e75df87..987044880 100644 --- a/src/main/java/com/arangodb/entity/QueryExecutionState.java +++ b/src/main/java/com/arangodb/entity/QueryExecutionState.java @@ -20,19 +20,42 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @author Mark Vollmary */ public enum QueryExecutionState { + @JsonProperty("initializing") INITIALIZING, + + @JsonProperty("parsing") PARSING, + + @JsonProperty("optimizing ast") OPTIMIZING_AST, + + @JsonProperty("loading collections") LOADING_COLLECTIONS, + + @JsonProperty("instantiating plan") INSTANTIATING_PLAN, + + @JsonProperty("optimizing plan") OPTIMIZING_PLAN, + + @JsonProperty("executing") EXECUTING, + + @JsonProperty("finalizing") FINALIZING, + + @JsonProperty("finished") FINISHED, + + @JsonProperty("killed") KILLED, + + @JsonProperty("invalid") INVALID } diff --git a/src/main/java/com/arangodb/entity/QueryTrackingPropertiesEntity.java b/src/main/java/com/arangodb/entity/QueryTrackingPropertiesEntity.java index dc82e447d..f8054ec32 100644 --- a/src/main/java/com/arangodb/entity/QueryTrackingPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/QueryTrackingPropertiesEntity.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class QueryTrackingPropertiesEntity implements Entity { +public final class QueryTrackingPropertiesEntity { private Boolean enabled; private Boolean trackSlowQueries; diff --git a/src/main/java/com/arangodb/entity/ReplicationFactor.java b/src/main/java/com/arangodb/entity/ReplicationFactor.java index b228f3f66..853aad4bb 100644 --- a/src/main/java/com/arangodb/entity/ReplicationFactor.java +++ b/src/main/java/com/arangodb/entity/ReplicationFactor.java @@ -20,32 +20,41 @@ package com.arangodb.entity; -/** - * @author Mark Vollmary - */ -public class ReplicationFactor { +import com.fasterxml.jackson.annotation.JsonValue; - private Integer replicationFactor; - private Boolean satellite; +public interface ReplicationFactor { - public ReplicationFactor() { - super(); + static NumericReplicationFactor of(int value) { + return new NumericReplicationFactor(value); } - public Integer getReplicationFactor() { - return replicationFactor; + static SatelliteReplicationFactor ofSatellite() { + return SatelliteReplicationFactor.INSTANCE; } - public void setReplicationFactor(final Integer replicationFactor) { - this.replicationFactor = replicationFactor; - } + @JsonValue + Object getValue(); - public Boolean getSatellite() { - return satellite; - } + final class NumericReplicationFactor implements ReplicationFactor { + + private Integer value; - public void setSatellite(final Boolean satellite) { - this.satellite = satellite; + public NumericReplicationFactor(Integer value) { + this.value = value; + } + + @Override + public Integer getValue() { + return value; + } } + enum SatelliteReplicationFactor implements ReplicationFactor { + INSTANCE; + + @Override + public String getValue() { + return "satellite"; + } + } } diff --git a/src/main/java/com/arangodb/entity/Rev.java b/src/main/java/com/arangodb/entity/Rev.java index bd5aa7600..08dfa5c22 100644 --- a/src/main/java/com/arangodb/entity/Rev.java +++ b/src/main/java/com/arangodb/entity/Rev.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.json.bind.annotation.JsonbAnnotation; +import jakarta.json.bind.annotation.JsonbProperty; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -19,5 +21,7 @@ @JacksonAnnotationsInside @JsonProperty(DocumentFields.REV) @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonbAnnotation +@JsonbProperty("_rev") public @interface Rev { } diff --git a/src/main/java/com/arangodb/entity/ShardEntity.java b/src/main/java/com/arangodb/entity/ShardEntity.java index deeb49db3..8b853a623 100644 --- a/src/main/java/com/arangodb/entity/ShardEntity.java +++ b/src/main/java/com/arangodb/entity/ShardEntity.java @@ -23,7 +23,7 @@ /** * @author Michele Rastelli */ -public class ShardEntity implements Entity { +public final class ShardEntity { private String shardId; diff --git a/src/main/java/com/arangodb/entity/StreamTransactionEntity.java b/src/main/java/com/arangodb/entity/StreamTransactionEntity.java index b7fee3817..4dbafa475 100644 --- a/src/main/java/com/arangodb/entity/StreamTransactionEntity.java +++ b/src/main/java/com/arangodb/entity/StreamTransactionEntity.java @@ -26,7 +26,7 @@ * "https://www.arangodb.com/docs/stable/http/transaction-stream-transaction.html">API Documentation * @since ArangoDB 3.5.0 */ -public class StreamTransactionEntity implements Entity { +public final class StreamTransactionEntity { private String id; private StreamTransactionStatus status; diff --git a/src/main/java/com/arangodb/entity/To.java b/src/main/java/com/arangodb/entity/To.java index a58db8604..deb60769c 100644 --- a/src/main/java/com/arangodb/entity/To.java +++ b/src/main/java/com/arangodb/entity/To.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.json.bind.annotation.JsonbAnnotation; +import jakarta.json.bind.annotation.JsonbProperty; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -19,5 +21,7 @@ @JacksonAnnotationsInside @JsonProperty(DocumentFields.TO) @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonbAnnotation +@JsonbProperty("_to") public @interface To { } diff --git a/src/main/java/com/arangodb/entity/TransactionEntity.java b/src/main/java/com/arangodb/entity/TransactionEntity.java index a700541f2..f9925927d 100644 --- a/src/main/java/com/arangodb/entity/TransactionEntity.java +++ b/src/main/java/com/arangodb/entity/TransactionEntity.java @@ -26,7 +26,7 @@ * "https://www.arangodb.com/docs/stable/http/transaction-stream-transaction.html#list-currently-ongoing-transactions * @since ArangoDB 3.5.0 */ -public class TransactionEntity implements Entity { +public final class TransactionEntity { private String id; private StreamTransactionStatus state; @@ -35,7 +35,7 @@ public String getId() { return id; } - public StreamTransactionStatus getStatus() { + public StreamTransactionStatus getState() { return state; } diff --git a/src/main/java/com/arangodb/entity/UserEntity.java b/src/main/java/com/arangodb/entity/UserEntity.java index fa082c5c7..244da2d55 100644 --- a/src/main/java/com/arangodb/entity/UserEntity.java +++ b/src/main/java/com/arangodb/entity/UserEntity.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class UserEntity implements Entity { +public final class UserEntity { private String user; private Boolean active; diff --git a/src/main/java/com/arangodb/entity/VertexEntity.java b/src/main/java/com/arangodb/entity/VertexEntity.java index 161ed9fd4..e8348336a 100644 --- a/src/main/java/com/arangodb/entity/VertexEntity.java +++ b/src/main/java/com/arangodb/entity/VertexEntity.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class VertexEntity extends DocumentEntity { +public final class VertexEntity extends DocumentEntity { public VertexEntity() { super(); diff --git a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java index 22d2d1078..c5e8f0ff2 100644 --- a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java @@ -20,14 +20,14 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Mark Vollmary */ -public class VertexUpdateEntity extends DocumentEntity { +public final class VertexUpdateEntity extends DocumentEntity { - @SerializedName("_oldRev") + @JsonProperty("_oldRev") private String oldRev; public VertexUpdateEntity() { diff --git a/src/main/java/com/arangodb/entity/ViewEntity.java b/src/main/java/com/arangodb/entity/ViewEntity.java index 07da45f88..e5eb28299 100644 --- a/src/main/java/com/arangodb/entity/ViewEntity.java +++ b/src/main/java/com/arangodb/entity/ViewEntity.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class ViewEntity implements Entity { +public class ViewEntity { private String id; private String name; diff --git a/src/main/java/com/arangodb/entity/ViewType.java b/src/main/java/com/arangodb/entity/ViewType.java index 21c039906..4844fe560 100644 --- a/src/main/java/com/arangodb/entity/ViewType.java +++ b/src/main/java/com/arangodb/entity/ViewType.java @@ -20,11 +20,14 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @author Mark Vollmary */ public enum ViewType { + @JsonProperty("arangosearch") ARANGO_SEARCH } diff --git a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java deleted file mode 100644 index 7353cba66..000000000 --- a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2018 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.entity.arangosearch; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -/** - * @author Mark Vollmary - * @author Heiko Kernbach - * @author Michele Rastelli - * @see API Documentation - */ -public class ArangoSearchProperties { - - private Long consolidationIntervalMsec; - private Long commitIntervalMsec; - private Long cleanupIntervalStep; - private ConsolidationPolicy consolidationPolicy; - private final Collection primarySorts; - private final Collection links; - private ArangoSearchCompression primarySortCompression; - private final Collection storedValues; - - public ArangoSearchProperties() { - super(); - links = new ArrayList<>(); - primarySorts = new ArrayList<>(); - storedValues = new ArrayList<>(); - } - - public Long getCommitIntervalMsec() { - return commitIntervalMsec; - } - - public void setCommitIntervalMsec(final Long commitIntervalMsec) { - this.commitIntervalMsec = commitIntervalMsec; - } - - public Long getConsolidationIntervalMsec() { - return consolidationIntervalMsec; - } - - public void setConsolidationIntervalMsec(final Long consolidationIntervalMsec) { - this.consolidationIntervalMsec = consolidationIntervalMsec; - } - - public Long getCleanupIntervalStep() { - return cleanupIntervalStep; - } - - public void setCleanupIntervalStep(final Long cleanupIntervalStep) { - this.cleanupIntervalStep = cleanupIntervalStep; - } - - public ConsolidationPolicy getConsolidationPolicy() { - return consolidationPolicy; - } - - public void setConsolidationPolicy(final ConsolidationPolicy consolidationPolicy) { - this.consolidationPolicy = consolidationPolicy; - } - - public Collection getLinks() { - return links; - } - - public void addLink(final CollectionLink... links) { - this.links.addAll(Arrays.asList(links)); - } - - public Collection getPrimarySort() { - return primarySorts; - } - - public void addPrimarySort(final PrimarySort... primarySorts) { - this.primarySorts.addAll(Arrays.asList(primarySorts)); - } - - /** - * @return Defines how to compress the primary sort data (introduced in v3.7.0). ArangoDB v3.5 and v3.6 always - * compress the index using LZ4. - * @since ArangoDB 3.7 - */ - public ArangoSearchCompression getPrimarySortCompression() { - return primarySortCompression; - } - - public void setPrimarySortCompression(ArangoSearchCompression primarySortCompression) { - this.primarySortCompression = primarySortCompression; - } - - /** - * @return An array of objects to describe which document attributes to store in the View index. It can then cover - * search queries, which means the data can be taken from the index directly and accessing the storage engine can be - * avoided. - * @since ArangoDB 3.7 - */ - public Collection getStoredValues() { - return storedValues; - } - - public void addStoredValues(final StoredValue... storedValues) { - this.storedValues.addAll(Arrays.asList(storedValues)); - } - -} diff --git a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java index 55c6d9afe..4c5f3073b 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java @@ -21,7 +21,8 @@ package com.arangodb.entity.arangosearch; import com.arangodb.entity.ViewEntity; -import com.arangodb.entity.ViewType; +import com.arangodb.serde.InternalDeserializers; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.Collection; @@ -30,26 +31,16 @@ * @author Michele Rastelli * @see API Documentation */ -public class ArangoSearchPropertiesEntity extends ViewEntity { +public final class ArangoSearchPropertiesEntity extends ViewEntity { - private final ArangoSearchProperties properties; - - public ArangoSearchPropertiesEntity(final String id, final String name, final ViewType type, - final ArangoSearchProperties properties) { - super(id, name, type); - this.properties = properties; - } - - /** - * @return Wait at least this many milliseconds between committing index data changes and making them visible to - * queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a - * lower value, until commit, will cause the index not to account for them and memory usage would continue - * to grow. For the case where there are a few inserts/updates, a higher value will impact performance and - * waste disk space for each commit call without any added benefits. - */ - public Long getConsolidationIntervalMsec() { - return properties.getConsolidationIntervalMsec(); - } + private Long consolidationIntervalMsec; + private Long commitIntervalMsec; + private Long cleanupIntervalStep; + private ConsolidationPolicy consolidationPolicy; + private Collection primarySort; + private Collection links; + private ArangoSearchCompression primarySortCompression; + private Collection storedValues; /** * @return Wait at least this many milliseconds between committing view data store changes and making documents @@ -65,7 +56,18 @@ public Long getConsolidationIntervalMsec() { * continue to return a repeatable-read state. */ public Long getCommitIntervalMsec() { - return properties.getCommitIntervalMsec(); + return commitIntervalMsec; + } + + /** + * @return Wait at least this many milliseconds between committing index data changes and making them visible to + * queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a + * lower value, until commit, will cause the index not to account for them and memory usage would continue + * to grow. For the case where there are a few inserts/updates, a higher value will impact performance and + * waste disk space for each commit call without any added benefits. + */ + public Long getConsolidationIntervalMsec() { + return consolidationIntervalMsec; } /** @@ -76,25 +78,26 @@ public Long getCommitIntervalMsec() { * performance without any added benefits. */ public Long getCleanupIntervalStep() { - return properties.getCleanupIntervalStep(); + return cleanupIntervalStep; } public ConsolidationPolicy getConsolidationPolicy() { - return properties.getConsolidationPolicy(); + return consolidationPolicy; } /** * @return A list of linked collections */ + @JsonDeserialize(using = InternalDeserializers.CollectionLinksDeserializer.class) public Collection getLinks() { - return properties.getLinks(); + return links; } /** * @return A list of primary sort objects */ public Collection getPrimarySort() { - return properties.getPrimarySort(); + return primarySort; } /** @@ -103,7 +106,7 @@ public Collection getPrimarySort() { * @since ArangoDB 3.7 */ public ArangoSearchCompression getPrimarySortCompression() { - return properties.getPrimarySortCompression(); + return primarySortCompression; } /** @@ -113,7 +116,7 @@ public ArangoSearchCompression getPrimarySortCompression() { * @since ArangoDB 3.7 */ public Collection getStoredValues() { - return properties.getStoredValues(); + return storedValues; } } diff --git a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java index adf57d9da..d358e24d0 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java @@ -20,27 +20,32 @@ package com.arangodb.entity.arangosearch; -import java.util.ArrayList; +import com.arangodb.serde.InternalDeserializers; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import java.util.Arrays; import java.util.Collection; /** * @author Mark Vollmary */ -public class CollectionLink { +public final class CollectionLink { private final String name; - private final Collection analyzers; + private Collection analyzers; private Boolean includeAllFields; private Boolean trackListPositions; private StoreValuesType storeValues; - private final Collection fields; + private Collection fields; private CollectionLink(final String name) { super(); this.name = name; - fields = new ArrayList<>(); - analyzers = new ArrayList<>(); } /** @@ -49,7 +54,8 @@ private CollectionLink(final String name) { * @param name Name of a collection * @return new instance of {@code CollectionLink} */ - public static CollectionLink on(final String name) { + @JsonCreator + public static CollectionLink on(@JsonProperty("name") final String name) { return new CollectionLink(name); } @@ -58,7 +64,7 @@ public static CollectionLink on(final String name) { * @return link */ public CollectionLink analyzers(final String... analyzers) { - this.analyzers.addAll(Arrays.asList(analyzers)); + this.analyzers = Arrays.asList(analyzers); return this; } @@ -95,11 +101,13 @@ public CollectionLink storeValues(final StoreValuesType storeValues) { * @param fields A list of linked fields * @return link */ + @JsonDeserialize(using = InternalDeserializers.FieldLinksDeserializer.class) public CollectionLink fields(final FieldLink... fields) { - this.fields.addAll(Arrays.asList(fields)); + this.fields = Arrays.asList(fields); return this; } + @JsonIgnore public String getName() { return name; } @@ -120,6 +128,7 @@ public StoreValuesType getStoreValues() { return storeValues; } + @JsonSerialize(using = InternalSerializers.FieldLinksSerializer.class) public Collection getFields() { return fields; } diff --git a/src/main/java/com/arangodb/entity/arangosearch/ConsolidationPolicy.java b/src/main/java/com/arangodb/entity/arangosearch/ConsolidationPolicy.java index b0cb50a0a..63bf7483c 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/ConsolidationPolicy.java +++ b/src/main/java/com/arangodb/entity/arangosearch/ConsolidationPolicy.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class ConsolidationPolicy { +public final class ConsolidationPolicy { private ConsolidationType type; private Double threshold; diff --git a/src/main/java/com/arangodb/entity/arangosearch/ConsolidationType.java b/src/main/java/com/arangodb/entity/arangosearch/ConsolidationType.java index 978a6a0d5..9ab2da72a 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/ConsolidationType.java +++ b/src/main/java/com/arangodb/entity/arangosearch/ConsolidationType.java @@ -1,7 +1,13 @@ package com.arangodb.entity.arangosearch; +import com.fasterxml.jackson.annotation.JsonProperty; + public enum ConsolidationType { - BYTES_ACCUM, TIER + @JsonProperty("bytes_accum") + BYTES_ACCUM, + + @JsonProperty("tier") + TIER } \ No newline at end of file diff --git a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java index d6bf26381..cb3a851dc 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java @@ -1,23 +1,26 @@ package com.arangodb.entity.arangosearch; -import java.util.ArrayList; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import java.util.Arrays; import java.util.Collection; -public class FieldLink { +public final class FieldLink { private final String name; - private final Collection analyzers; + private Collection analyzers; private Boolean includeAllFields; private Boolean trackListPositions; private StoreValuesType storeValues; - private final Collection fields; + private Collection fields; private FieldLink(final String name) { super(); this.name = name; - fields = new ArrayList<>(); - analyzers = new ArrayList<>(); } /** @@ -26,7 +29,8 @@ private FieldLink(final String name) { * @param name Name of a field * @return new instance of {@code FieldLink} */ - public static FieldLink on(final String name) { + @JsonCreator + public static FieldLink on(@JsonProperty("name") final String name) { return new FieldLink(name); } @@ -35,7 +39,7 @@ public static FieldLink on(final String name) { * @return link */ public FieldLink analyzers(final String... analyzers) { - this.analyzers.addAll(Arrays.asList(analyzers)); + this.analyzers = Arrays.asList(analyzers); return this; } @@ -73,10 +77,11 @@ public FieldLink storeValues(final StoreValuesType storeValues) { * @return link */ public FieldLink fields(final FieldLink... fields) { - this.fields.addAll(Arrays.asList(fields)); + this.fields = Arrays.asList(fields); return this; } + @JsonIgnore public String getName() { return name; } @@ -97,6 +102,7 @@ public StoreValuesType getStoreValues() { return storeValues; } + @JsonSerialize(using = InternalSerializers.FieldLinksSerializer.class) public Collection getFields() { return fields; } diff --git a/src/main/java/com/arangodb/entity/arangosearch/PrimarySort.java b/src/main/java/com/arangodb/entity/arangosearch/PrimarySort.java index 32c3a34a3..ab0d7c872 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/PrimarySort.java +++ b/src/main/java/com/arangodb/entity/arangosearch/PrimarySort.java @@ -23,7 +23,7 @@ /** * @author Heiko Kernbach */ -public class PrimarySort { +public final class PrimarySort { private final String fieldName; private Boolean ascending; diff --git a/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java b/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java index 3630e903a..23577a4f8 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java +++ b/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java @@ -20,6 +20,8 @@ package com.arangodb.entity.arangosearch; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @author Mark Vollmary */ @@ -28,11 +30,13 @@ public enum StoreValuesType { /** * Do not track values by the view */ + @JsonProperty("none") NONE, /** * Track only value presence, to allow use of the EXISTS() function. */ + @JsonProperty("id") ID } diff --git a/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java b/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java index 5d3c2bd36..d44df7a6d 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java +++ b/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java @@ -21,6 +21,9 @@ package com.arangodb.entity.arangosearch; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.List; /** @@ -28,12 +31,13 @@ * @see API Documentation * @since ArangoDB 3.7 */ -public class StoredValue { +public final class StoredValue { private final List fields; private final ArangoSearchCompression compression; - public StoredValue(List fields, ArangoSearchCompression compression) { + @JsonCreator + public StoredValue(@JsonProperty("fields") List fields, @JsonProperty("compression") ArangoSearchCompression compression) { this.fields = fields; this.compression = compression; } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzer.java index 2677d0de4..4f453cdf2 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzer.java @@ -32,7 +32,7 @@ * @see API Documentation * @since ArangoDB 3.8 */ -public class AQLAnalyzer extends SearchAnalyzer { +public final class AQLAnalyzer extends SearchAnalyzer { public AQLAnalyzer() { setType(AnalyzerType.aql); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzerProperties.java index 6118d2c3b..aaa497dd6 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/AQLAnalyzerProperties.java @@ -27,7 +27,7 @@ /** * @author Michele Rastelli */ -public class AQLAnalyzerProperties { +public final class AQLAnalyzerProperties { private String queryString; private Boolean collapsePositions; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzer.java index e07d820a3..47a588dc0 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzer.java @@ -33,7 +33,7 @@ * @see API Documentation * @since ArangoDB 3.9 */ -public class CollationAnalyzer extends SearchAnalyzer { +public final class CollationAnalyzer extends SearchAnalyzer { public CollationAnalyzer() { setType(AnalyzerType.collation); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzerProperties.java index d056dbaa2..bbfb0581b 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/CollationAnalyzerProperties.java @@ -27,7 +27,7 @@ * @author Michele Rastelli * @since ArangoDB 3.9 */ -public class CollationAnalyzerProperties { +public final class CollationAnalyzerProperties { private String locale; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzer.java index 764096619..78306f0c1 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzer.java @@ -31,7 +31,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class DelimiterAnalyzer extends SearchAnalyzer { +public final class DelimiterAnalyzer extends SearchAnalyzer { public DelimiterAnalyzer() { setType(AnalyzerType.delimiter); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzerProperties.java index c67f05428..21c8ef741 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/DelimiterAnalyzerProperties.java @@ -26,7 +26,7 @@ /** * @author Michele Rastelli */ -public class DelimiterAnalyzerProperties { +public final class DelimiterAnalyzerProperties { private String delimiter; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/EdgeNgram.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/EdgeNgram.java index 018fc2eac..35c4536da 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/EdgeNgram.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/EdgeNgram.java @@ -26,7 +26,7 @@ /** * @author Michele Rastelli */ -public class EdgeNgram { +public final class EdgeNgram { private long min; private long max; private boolean preserveOriginal; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoAnalyzerOptions.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoAnalyzerOptions.java index 5b48d1c69..a6a2f6762 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoAnalyzerOptions.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoAnalyzerOptions.java @@ -27,7 +27,7 @@ /** * @author Michele Rastelli */ -public class GeoAnalyzerOptions { +public final class GeoAnalyzerOptions { private Integer maxCells; private Integer minLevel; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzer.java index a5005b676..ea8fc9a70 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzer.java @@ -33,7 +33,7 @@ * @see API Documentation * @since ArangoDB 3.8 */ -public class GeoJSONAnalyzer extends SearchAnalyzer { +public final class GeoJSONAnalyzer extends SearchAnalyzer { public GeoJSONAnalyzer() { setType(AnalyzerType.geojson); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzerProperties.java index 7c2289666..3ef1cfb7f 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoJSONAnalyzerProperties.java @@ -26,7 +26,7 @@ /** * @author Michele Rastelli */ -public class GeoJSONAnalyzerProperties { +public final class GeoJSONAnalyzerProperties { public enum GeoJSONAnalyzerType { diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzer.java index e4ead1855..af1890582 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzer.java @@ -33,7 +33,7 @@ * @see API Documentation * @since ArangoDB 3.8 */ -public class GeoPointAnalyzer extends SearchAnalyzer { +public final class GeoPointAnalyzer extends SearchAnalyzer { public GeoPointAnalyzer() { setType(AnalyzerType.geopoint); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzerProperties.java index f90953421..a0c148216 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/GeoPointAnalyzerProperties.java @@ -27,7 +27,7 @@ /** * @author Michele Rastelli */ -public class GeoPointAnalyzerProperties { +public final class GeoPointAnalyzerProperties { private String[] latitude; private String[] longitude; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/IdentityAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/IdentityAnalyzer.java index ad096e669..e658ea327 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/IdentityAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/IdentityAnalyzer.java @@ -29,7 +29,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class IdentityAnalyzer extends SearchAnalyzer { +public final class IdentityAnalyzer extends SearchAnalyzer { public IdentityAnalyzer() { setType(AnalyzerType.identity); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzer.java index 7e76429fd..83125fa0f 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzer.java @@ -36,7 +36,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class NGramAnalyzer extends SearchAnalyzer { +public final class NGramAnalyzer extends SearchAnalyzer { public NGramAnalyzer() { setType(AnalyzerType.ngram); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzerProperties.java index 534c38916..90b577225 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NGramAnalyzerProperties.java @@ -34,7 +34,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class NGramAnalyzerProperties { +public final class NGramAnalyzerProperties { private long min; private long max; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzer.java index 4673ccb1b..43ac0a335 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzer.java @@ -31,7 +31,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class NormAnalyzer extends SearchAnalyzer { +public final class NormAnalyzer extends SearchAnalyzer { public NormAnalyzer() { setType(AnalyzerType.norm); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java index cb1bcfbb8..72258ea83 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java @@ -21,20 +21,20 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; /** * @author Michele Rastelli */ -public class NormAnalyzerProperties { +public final class NormAnalyzerProperties { private String locale; private boolean accent; - @SerializedName("case") + @JsonProperty("case") private SearchAnalyzerCase analyzerCase; /** diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzer.java index 6616d3845..9319f38e6 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzer.java @@ -36,7 +36,7 @@ * @see API Documentation * @since ArangoDB 3.8 */ -public class PipelineAnalyzer extends SearchAnalyzer { +public final class PipelineAnalyzer extends SearchAnalyzer { public PipelineAnalyzer() { setType(AnalyzerType.pipeline); diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzerProperties.java index 5cc686d9f..bdcf4a91d 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/PipelineAnalyzerProperties.java @@ -28,7 +28,7 @@ /** * @author Michele Rastelli */ -public class PipelineAnalyzerProperties { +public final class PipelineAnalyzerProperties { private List pipeline = new LinkedList<>(); /** diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java index 2155a39a8..8963a365f 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java @@ -21,9 +21,11 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.entity.Entity; import com.arangodb.entity.arangosearch.AnalyzerFeature; import com.arangodb.entity.arangosearch.AnalyzerType; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import java.util.Collection; import java.util.HashSet; @@ -33,7 +35,23 @@ /** * @author Michele Rastelli */ -public abstract class SearchAnalyzer implements Entity { +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "identity", value = IdentityAnalyzer.class), + @JsonSubTypes.Type(name = "delimiter", value = DelimiterAnalyzer.class), + @JsonSubTypes.Type(name = "stem", value = StemAnalyzer.class), + @JsonSubTypes.Type(name = "norm", value = NormAnalyzer.class), + @JsonSubTypes.Type(name = "ngram", value = NGramAnalyzer.class), + @JsonSubTypes.Type(name = "text", value = TextAnalyzer.class), + @JsonSubTypes.Type(name = "pipeline", value = PipelineAnalyzer.class), + @JsonSubTypes.Type(name = "stopwords", value = StopwordsAnalyzer.class), + @JsonSubTypes.Type(name = "aql", value = AQLAnalyzer.class), + @JsonSubTypes.Type(name = "geojson", value = GeoJSONAnalyzer.class), + @JsonSubTypes.Type(name = "geopoint", value = GeoPointAnalyzer.class), + @JsonSubTypes.Type(name = "segmentation", value = SegmentationAnalyzer.class), + @JsonSubTypes.Type(name = "collation", value = CollationAnalyzer.class) +}) +public abstract class SearchAnalyzer { private String name; private AnalyzerType type; private Collection features; @@ -52,6 +70,7 @@ public void setName(String name) { /** * @return The Analyzer type. */ + @JsonIgnore public AnalyzerType getType() { return type; } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzer.java index 70ce2f4cf..6b2f449b3 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzer.java @@ -35,7 +35,7 @@ * @see API Documentation * @since ArangoDB 3.9 */ -public class SegmentationAnalyzer extends SearchAnalyzer { +public final class SegmentationAnalyzer extends SearchAnalyzer { public SegmentationAnalyzer() { setType(AnalyzerType.segmentation); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java index 221cda81e..a98b39b76 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java @@ -21,7 +21,7 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; @@ -29,12 +29,12 @@ * @author Michele Rastelli * @since ArangoDB 3.9 */ -public class SegmentationAnalyzerProperties { +public final class SegmentationAnalyzerProperties { - @SerializedName("break") + @JsonProperty("break") private BreakMode breakMode; - @SerializedName("case") + @JsonProperty("case") private SearchAnalyzerCase analyzerCase; public BreakMode getBreakMode() { diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzer.java index 6e3166c64..0e4fb9cb0 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzer.java @@ -31,7 +31,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class StemAnalyzer extends SearchAnalyzer { +public final class StemAnalyzer extends SearchAnalyzer { public StemAnalyzer() { setType(AnalyzerType.stem); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzerProperties.java index b58634f6a..600ffa5a1 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StemAnalyzerProperties.java @@ -26,7 +26,7 @@ /** * @author Michele Rastelli */ -public class StemAnalyzerProperties { +public final class StemAnalyzerProperties { private String locale; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzer.java index 264b48d54..c1041e293 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzer.java @@ -32,7 +32,7 @@ * @see API Documentation * @since ArangoDB 3.8 */ -public class StopwordsAnalyzer extends SearchAnalyzer { +public final class StopwordsAnalyzer extends SearchAnalyzer { public StopwordsAnalyzer() { setType(AnalyzerType.stopwords); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzerProperties.java index 8b094e709..b6f570267 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzerProperties.java @@ -21,6 +21,8 @@ package com.arangodb.entity.arangosearch.analyzer; +import com.fasterxml.jackson.annotation.JsonIgnore; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -29,7 +31,7 @@ /** * @author Michele Rastelli */ -public class StopwordsAnalyzerProperties { +public final class StopwordsAnalyzerProperties { private static String stringToHex(String str) { final StringBuilder hex = new StringBuilder(); @@ -57,9 +59,14 @@ public StopwordsAnalyzerProperties() { private final List stopwords; private final boolean hex; + public List getStopwords() { + return stopwords; + } + /** * @return list of verbatim strings that describe the tokens to be discarded. */ + @JsonIgnore public List getStopwordsAsStringList() { if (hex) { return stopwords.stream() @@ -73,6 +80,7 @@ public List getStopwordsAsStringList() { /** * @return list of hex-encoded strings that describe the tokens to be discarded. */ + @JsonIgnore public List getStopwordsAsHexList() { if (hex) { return stopwords; diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzer.java index edc70b858..8bde16668 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzer.java @@ -32,7 +32,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class TextAnalyzer extends SearchAnalyzer { +public final class TextAnalyzer extends SearchAnalyzer { public TextAnalyzer() { setType(AnalyzerType.text); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java index b22f7bc34..38cbebe89 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java @@ -21,7 +21,7 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collections; import java.util.List; @@ -30,7 +30,7 @@ /** * @author Michele Rastelli */ -public class TextAnalyzerProperties { +public final class TextAnalyzerProperties { public TextAnalyzerProperties() { stopwords = Collections.emptyList(); @@ -40,7 +40,7 @@ public TextAnalyzerProperties() { private boolean accent; - @SerializedName("case") + @JsonProperty("case") private SearchAnalyzerCase analyzerCase; private boolean stemming; diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 6dded7789..a97bd4955 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java @@ -25,7 +25,6 @@ import com.arangodb.entity.*; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; -import com.arangodb.velocypack.VPackSlice; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,7 +101,7 @@ public T getDocument(final String key, final Class type, final DocumentRe throws ArangoDBException { DocumentUtil.validateDocumentKey(key); try { - return executor.execute(getDocumentRequest(key, options), type); + return executor.execute(getDocumentRequest(key, options), getDocumentResponseDeserializer(type)); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); @@ -232,7 +231,7 @@ public Boolean documentExists(final String key) { @Override public Boolean documentExists(final String key, final DocumentExistsOptions options) throws ArangoDBException { try { - executor.execute(documentExistsRequest(key, options), VPackSlice.class); + executor.execute(documentExistsRequest(key, options), Void.class); return true; } catch (final ArangoDBException e) { diff --git a/src/main/java/com/arangodb/internal/ArangoCursorExecute.java b/src/main/java/com/arangodb/internal/ArangoCursorExecute.java index 455844113..8e501d66a 100644 --- a/src/main/java/com/arangodb/internal/ArangoCursorExecute.java +++ b/src/main/java/com/arangodb/internal/ArangoCursorExecute.java @@ -21,7 +21,7 @@ package com.arangodb.internal; import com.arangodb.ArangoDBException; -import com.arangodb.entity.CursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import java.util.Map; @@ -30,7 +30,7 @@ */ public interface ArangoCursorExecute { - CursorEntity next(String id, Map meta) throws ArangoDBException; + InternalCursorEntity next(String id, Map meta) throws ArangoDBException; void close(String id, Map meta) throws ArangoDBException; diff --git a/src/main/java/com/arangodb/internal/ArangoDBImpl.java b/src/main/java/com/arangodb/internal/ArangoDBImpl.java index ea980dede..cdefb0d3a 100644 --- a/src/main/java/com/arangodb/internal/ArangoDBImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDBImpl.java @@ -28,8 +28,7 @@ import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.net.HostHandler; import com.arangodb.internal.net.HostResolver; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; import com.arangodb.model.DBCreateOptions; @@ -37,7 +36,7 @@ import com.arangodb.model.UserCreateOptions; import com.arangodb.model.UserUpdateOptions; import com.arangodb.util.ArangoCursorInitializer; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -60,11 +59,11 @@ public class ArangoDBImpl extends InternalArangoDB implement private final HostHandler hostHandler; public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCommunication.Builder httpBuilder, - final ArangoSerializationFactory util, final Protocol protocol, final HostResolver hostResolver, + final InternalSerde util, final Protocol protocol, final HostResolver hostResolver, final HostHandler hostHandler, final ArangoContext context, int responseQueueTimeSamples, final int timeoutMs) { super(new ArangoExecutorSync( - createProtocol(vstBuilder, httpBuilder, util.get(Serializer.INTERNAL), protocol), + createProtocol(vstBuilder, httpBuilder, util, protocol), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, @@ -73,11 +72,11 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom cp = createProtocol( new VstCommunicationSync.Builder(vstBuilder).maxConnections(1), new HttpCommunication.Builder(httpBuilder), - util.get(Serializer.INTERNAL), + util, protocol); this.hostHandler = hostHandler; - hostResolver.init(this.executor(), util()); + hostResolver.init(this.executor(), getSerde()); LOGGER.debug("ArangoDB Client is ready to use"); @@ -86,7 +85,7 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom private static CommunicationProtocol createProtocol( final VstCommunicationSync.Builder vstBuilder, final HttpCommunication.Builder httpBuilder, - final ArangoSerialization util, + final InternalSerde util, final Protocol protocol) { return (protocol == null || Protocol.VST == protocol) ? createVST(vstBuilder, util) @@ -95,13 +94,13 @@ private static CommunicationProtocol createProtocol( private static CommunicationProtocol createVST( final VstCommunicationSync.Builder builder, - final ArangoSerialization util) { + final InternalSerde util) { return new VstProtocol(builder.build(util)); } private static CommunicationProtocol createHTTP( final HttpCommunication.Builder builder, - final ArangoSerialization util) { + final InternalSerde util) { return new HttpProtocol(builder.build(util)); } diff --git a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java index e73fa0fa0..f02e8c516 100644 --- a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java @@ -24,13 +24,14 @@ import com.arangodb.entity.*; import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; import com.arangodb.internal.cursor.ArangoCursorImpl; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; import com.arangodb.model.arangosearch.AnalyzerDeleteOptions; import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; +import com.arangodb.serde.SerdeUtils; import com.arangodb.util.ArangoCursorInitializer; -import com.arangodb.velocypack.Type; import com.arangodb.velocystream.Request; import java.util.Collection; @@ -167,7 +168,7 @@ public ArangoCursor query( final Request request = queryRequest(query, bindVars, options); final HostHandle hostHandle = new HostHandle(); - final CursorEntity result = executor.execute(request, CursorEntity.class, hostHandle); + final InternalCursorEntity result = executor.execute(request, InternalCursorEntity.class, hostHandle); return createCursor(result, type, options, hostHandle); @@ -193,21 +194,21 @@ public ArangoCursor query(final String query, final Class type) throws @Override public ArangoCursor cursor(final String cursorId, final Class type) throws ArangoDBException { final HostHandle hostHandle = new HostHandle(); - final CursorEntity result = executor - .execute(queryNextRequest(cursorId, null, null), CursorEntity.class, hostHandle); + final InternalCursorEntity result = executor + .execute(queryNextRequest(cursorId, null, null), InternalCursorEntity.class, hostHandle); return createCursor(result, type, null, hostHandle); } private ArangoCursor createCursor( - final CursorEntity result, + final InternalCursorEntity result, final Class type, final AqlQueryOptions options, final HostHandle hostHandle) { final ArangoCursorExecute execute = new ArangoCursorExecute() { @Override - public CursorEntity next(final String id, Map meta) { - return executor.execute(queryNextRequest(id, options, meta), CursorEntity.class, hostHandle); + public InternalCursorEntity next(final String id, Map meta) { + return executor.execute(queryNextRequest(id, options, meta), InternalCursorEntity.class, hostHandle); } @Override @@ -262,14 +263,14 @@ public QueryTrackingPropertiesEntity setQueryTrackingProperties(final QueryTrack @Override public Collection getCurrentlyRunningQueries() throws ArangoDBException { - return executor.execute(getCurrentlyRunningQueriesRequest(), new Type>() { - }.getType()); + return executor.execute(getCurrentlyRunningQueriesRequest(), + SerdeUtils.INSTANCE.constructListType(QueryEntity.class)); } @Override public Collection getSlowQueries() throws ArangoDBException { - return executor.execute(getSlowQueriesRequest(), new Type>() { - }.getType()); + return executor.execute(getSlowQueriesRequest(), + SerdeUtils.INSTANCE.constructListType(QueryEntity.class)); } @Override diff --git a/src/main/java/com/arangodb/internal/ArangoExecuteable.java b/src/main/java/com/arangodb/internal/ArangoExecuteable.java index dc58fe914..e56d0bc51 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecuteable.java +++ b/src/main/java/com/arangodb/internal/ArangoExecuteable.java @@ -20,11 +20,11 @@ package com.arangodb.internal; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.DbName; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.util.EncodeUtils; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -33,18 +33,18 @@ /** * @author Mark Vollmary */ -public abstract class ArangoExecuteable { +public abstract class ArangoExecuteable implements ArangoSerdeAccessor { private static final String SLASH = "/"; protected final E executor; - protected final ArangoSerializationFactory util; + protected final InternalSerde serde; protected final ArangoContext context; - protected ArangoExecuteable(final E executor, final ArangoSerializationFactory util, final ArangoContext context) { + protected ArangoExecuteable(final E executor, final InternalSerde serde, final ArangoContext context) { super(); this.executor = executor; - this.util = util; + this.serde = serde; this.context = context; } @@ -52,12 +52,14 @@ protected E executor() { return executor; } - public ArangoSerialization util() { - return util.get(Serializer.INTERNAL); + @Override + public InternalSerde getSerde() { + return serde; } - public ArangoSerialization util(final Serializer serializer) { - return util.get(serializer); + @Override + public ArangoSerde getUserSerde() { + return serde.getUserSerde(); } protected Request request(final DbName dbName, final RequestType requestType, final String... path) { diff --git a/src/main/java/com/arangodb/internal/ArangoExecutor.java b/src/main/java/com/arangodb/internal/ArangoExecutor.java index 1dff75c10..8a0555009 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutor.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutor.java @@ -21,66 +21,32 @@ package com.arangodb.internal; import com.arangodb.QueueTimeMetrics; -import com.arangodb.entity.Entity; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; -import com.arangodb.velocypack.exception.VPackException; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; -import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.Map; /** * @author Mark Vollmary */ public abstract class ArangoExecutor { - @SuppressWarnings("unchecked") protected T createResult(final Type type, final Response response) { - if (type != Void.class && response.getBody() != null) { - if (isInternal(type)) { - return (T) util.get(Serializer.INTERNAL).deserialize(response.getBody(), type); - } else { - return (T) util.get(Serializer.CUSTOM).deserialize(response.getBody(), type); - } - } else { - return null; - } - } - - private boolean isInternal(final Type type) { - if (type instanceof ParameterizedType) { - ParameterizedType pType = ((ParameterizedType) type); - Type rawType = pType.getRawType(); - - if (rawType instanceof Class && ( - Map.class.isAssignableFrom((Class) rawType) || Iterable.class.isAssignableFrom((Class) rawType) - )) { - for (Type arg : pType.getActualTypeArguments()) { - if (!isInternal(arg)) { - return false; - } - } - return true; - } - } - - return type instanceof Class && Entity.class.isAssignableFrom((Class) type); + return serde.deserialize(response.getBody(), type); } private final DocumentCache documentCache; private final QueueTimeMetricsImpl qtMetrics; - private final ArangoSerializationFactory util; + private final InternalSerde serde; private final String timeoutS; - protected ArangoExecutor(final ArangoSerializationFactory util, final DocumentCache documentCache, + protected ArangoExecutor(final InternalSerde serde, final DocumentCache documentCache, final QueueTimeMetricsImpl qtMetrics, final int timeoutMs) { super(); this.documentCache = documentCache; this.qtMetrics = qtMetrics; - this.util = util; + this.serde = serde; timeoutS = timeoutMs >= 1000 ? Integer.toString(timeoutMs / 1000) : null; } @@ -89,7 +55,7 @@ public DocumentCache documentCache() { } public interface ResponseDeserializer { - T deserialize(Response response) throws VPackException; + T deserialize(Response response); } protected final void interceptResponse(Response response) { diff --git a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java index 2f60d2b56..4d9d5875d 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java @@ -24,8 +24,7 @@ import com.arangodb.entity.MetaAware; import com.arangodb.internal.net.CommunicationProtocol; import com.arangodb.internal.net.HostHandle; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.velocypack.exception.VPackException; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -43,7 +42,7 @@ public class ArangoExecutorSync extends ArangoExecutor { private final CommunicationProtocol protocol; - public ArangoExecutorSync(final CommunicationProtocol protocol, final ArangoSerializationFactory util, + public ArangoExecutorSync(final CommunicationProtocol protocol, final InternalSerde util, final DocumentCache documentCache, final QueueTimeMetricsImpl qtMetrics, final int timeoutMs) { super(util, documentCache, qtMetrics, timeoutMs); this.protocol = protocol; @@ -66,22 +65,16 @@ public T execute( final ResponseDeserializer responseDeserializer, final HostHandle hostHandle) throws ArangoDBException { - try { - - final Response response = protocol.execute(interceptRequest(request), hostHandle); - interceptResponse(response); - T deserialize = responseDeserializer.deserialize(response); - - if (deserialize instanceof MetaAware) { - LOG.debug("Response is MetaAware " + deserialize.getClass().getName()); - ((MetaAware) deserialize).setMeta(response.getMeta()); - } + final Response response = protocol.execute(interceptRequest(request), hostHandle); + interceptResponse(response); + T deserialize = responseDeserializer.deserialize(response); - return deserialize; - - } catch (final VPackException e) { - throw new ArangoDBException(e); + if (deserialize instanceof MetaAware) { + LOG.debug("Response is MetaAware {}", deserialize.getClass().getName()); + ((MetaAware) deserialize).setMeta(response.getMeta()); } + + return deserialize; } public void disconnect() { diff --git a/src/main/java/com/arangodb/internal/ArangoResponseField.java b/src/main/java/com/arangodb/internal/ArangoResponseField.java index 846774a3e..5ce43feda 100644 --- a/src/main/java/com/arangodb/internal/ArangoResponseField.java +++ b/src/main/java/com/arangodb/internal/ArangoResponseField.java @@ -29,7 +29,7 @@ private ArangoResponseField() { super(); } - public static final String ERROR = "error"; - public static final String RESULT = "result"; + public static final String ERROR_FIELD_NAME = "error"; + public static final String RESULT_JSON_POINTER = "/result"; } diff --git a/src/main/java/com/arangodb/internal/DocumentCache.java b/src/main/java/com/arangodb/internal/DocumentCache.java index 63254a6be..61bef4676 100644 --- a/src/main/java/com/arangodb/internal/DocumentCache.java +++ b/src/main/java/com/arangodb/internal/DocumentCache.java @@ -92,7 +92,7 @@ private void findAnnotation( for (Annotation annotation : field.getAnnotations()) { if (annotation != null && !field.isSynthetic() && !Modifier.isStatic(field.getModifiers()) - && String.class.isAssignableFrom(field.getType())) { + && String.class.equals(field.getType())) { String value = null; if (annotation instanceof Id) { value = DocumentFields.ID; diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 70b32b23c..3840fd7a2 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -24,16 +24,15 @@ import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.Type; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; +import com.fasterxml.jackson.databind.JsonNode; +import java.lang.reflect.Type; import java.util.*; /** @@ -67,7 +66,7 @@ public abstract class InternalArangoCollection, D protected volatile String name; protected InternalArangoCollection(final D db, final String name) { - super(db.executor, db.util, db.context); + super(db.executor, db.serde, db.context); this.db = db; this.name = name; } @@ -90,25 +89,15 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ? params.getOverwriteMode().getValue() : null); request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - - request.setBody(util(Serializer.CUSTOM).serialize(value)); - + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer> insertDocumentResponseDeserializer( final T value, final DocumentCreateOptions options) { return response -> { - final VPackSlice body = response.getBody(); - final DocumentCreateEntity doc = util().deserialize(body, DocumentCreateEntity.class); - final VPackSlice newDoc = body.get(NEW); - if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); - } - final VPackSlice oldDoc = body.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, value.getClass()); + final DocumentCreateEntity doc = getSerde().deserialize(response.getBody(), type); if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); @@ -129,47 +118,31 @@ protected Request insertDocumentsRequest(final Collection values, final D request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ? params.getOverwriteMode().getValue() : null); request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - - request.setBody(util(Serializer.CUSTOM) - .serialize(values, new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true))); + request.setBody(getSerde().serializeCollectionUserData(values)); return request; } - @SuppressWarnings("unchecked") protected ResponseDeserializer>> insertDocumentsResponseDeserializer( final Collection values, final DocumentCreateOptions params) { return response -> { - Class type = null; - if (Boolean.TRUE == params.getReturnNew()) { - if (!values.isEmpty()) { - type = (Class) values.iterator().next().getClass(); - } - } + Class userDataClass = getCollectionContentClass(values); final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>(); final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); - if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentCreateEntity doc = util().deserialize(next, DocumentCreateEntity.class); - final VPackSlice newDoc = next.get(NEW); - if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, type)); - } - final VPackSlice oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); - } - docs.add(doc); - documentsAndErrors.add(doc); - } + final JsonNode body = getSerde().parse(response.getBody()); + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); + if (isError != null && isError.booleanValue()) { + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, userDataClass); + final DocumentCreateEntity doc = getSerde().deserialize(next, type); + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -180,12 +153,12 @@ protected ResponseDeserializer>> } protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(util().serialize(values)); + return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getSerde().serialize(SerdeUtils.INSTANCE.parseJson(values))); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(util(Serializer.CUSTOM) - .serialize(values, new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true))); + return importDocumentsRequest(options).putQueryParam("type", ImportType.list) + .setBody(getSerde().serializeCollectionUserData(values)); } protected Request importDocumentsRequest(final DocumentImportOptions options) { @@ -210,12 +183,16 @@ protected Request getDocumentRequest(final String key, final DocumentReadOptions return request; } + protected ResponseDeserializer getDocumentResponseDeserializer(final Class type) { + return response -> getSerde().deserializeUserData(response.getBody(), type); + } + protected Request getDocumentsRequest(final Collection keys, final DocumentReadOptions options) { final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions()); final Request request = request(db.dbName(), RequestType.PUT, PATH_API_DOCUMENT, name) .putQueryParam("onlyget", true) .putHeaderParam(ArangoRequestParam.IF_NONE_MATCH, params.getIfNoneMatch()) - .putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()).setBody(util().serialize(keys)) + .putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()).setBody(getSerde().serialize(keys)) .putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); if (params.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); @@ -230,15 +207,16 @@ protected ResponseDeserializer> getDocumentsResponseD final Collection docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = util().deserialize(next, ErrorEntity.class); + final JsonNode body = getSerde().parse(response.getBody()); + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); + if (isError != null && isError.booleanValue()) { + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final T doc = util(Serializer.CUSTOM).deserialize(next, type); + final T doc = getSerde().deserializeUserData(getSerde().serialize(next), type); docs.add(doc); documentsAndErrors.add(doc); } @@ -262,23 +240,15 @@ protected Request replaceDocumentRequest( request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer> replaceDocumentResponseDeserializer( final T value, final DocumentReplaceOptions options) { return response -> { - final VPackSlice body = response.getBody(); - final DocumentUpdateEntity doc = util().deserialize(body, DocumentUpdateEntity.class); - final VPackSlice newDoc = body.get(NEW); - if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); - } - final VPackSlice oldDoc = body.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, value.getClass()); + final DocumentUpdateEntity doc = getSerde().deserialize(response.getBody(), type); if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); @@ -297,46 +267,31 @@ 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(util(Serializer.CUSTOM) - .serialize(values, new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true))); + request.setBody(getSerde().serializeCollectionUserData(values)); return request; } - @SuppressWarnings("unchecked") protected ResponseDeserializer>> replaceDocumentsResponseDeserializer( final Collection values, final DocumentReplaceOptions params) { return response -> { - Class type = null; - if (Boolean.TRUE == params.getReturnNew() || Boolean.TRUE == params.getReturnOld()) { - if (!values.isEmpty()) { - type = (Class) values.iterator().next().getClass(); - } - } + Class userDataClass = getCollectionContentClass(values); final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>(); final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); - if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); - final VPackSlice newDoc = next.get(NEW); - if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, type)); - } - final VPackSlice oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); - } - docs.add(doc); - documentsAndErrors.add(doc); - } + final JsonNode body = getSerde().parse(response.getBody()); + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); + if (isError != null && isError.booleanValue()) { + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, userDataClass); + final DocumentUpdateEntity doc = getSerde().deserialize(next, type); + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -359,24 +314,15 @@ protected Request updateDocumentRequest(final String key, final T value, fin request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(util(Serializer.CUSTOM).serialize(value, new ArangoSerializer.Options() - .serializeNullValues(params.getSerializeNull() == null || params.getSerializeNull()))); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer> updateDocumentResponseDeserializer( final T value, final DocumentUpdateOptions options, final Class returnType) { return response -> { - final VPackSlice body = response.getBody(); - final DocumentUpdateEntity doc = util().deserialize(body, DocumentUpdateEntity.class); - final VPackSlice newDoc = body.get(NEW); - if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, returnType)); - } - final VPackSlice oldDoc = body.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, returnType)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, returnType); + final DocumentUpdateEntity doc = getSerde().deserialize(response.getBody(), type); if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); @@ -398,13 +344,10 @@ protected Request updateDocumentsRequest(final Collection values, final D request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(util(Serializer.CUSTOM).serialize(values, new ArangoSerializer.Options() - .serializeNullValues(params.getSerializeNull() == null || params.getSerializeNull()) - .stringAsJson(true))); + request.setBody(getSerde().serializeCollectionUserData(values)); return request; } - @SuppressWarnings("unchecked") protected ResponseDeserializer>> updateDocumentsResponseDeserializer( final Class returnType) { return response -> { @@ -412,27 +355,19 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); - if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); - final VPackSlice newDoc = next.get(NEW); - if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, returnType)); - } - final VPackSlice oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, returnType)); - } - docs.add(doc); - documentsAndErrors.add(doc); - } + final JsonNode body = getSerde().parse(response.getBody()); + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); + if (isError != null && isError.booleanValue()) { + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, returnType); + final DocumentUpdateEntity doc = getSerde().deserialize(next, type); + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -455,15 +390,10 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp } protected ResponseDeserializer> deleteDocumentResponseDeserializer( - final Class type) { + final Class userDataClass) { return response -> { - final VPackSlice body = response.getBody(); - final DocumentDeleteEntity doc = util().deserialize(body, DocumentDeleteEntity.class); - final VPackSlice oldDoc = body.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); - } - return doc; + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentDeleteEntity.class, userDataClass); + return getSerde().deserialize(response.getBody(), type); }; } @@ -474,34 +404,30 @@ protected Request deleteDocumentsRequest(final Collection keys, final Doc request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(util().serialize(keys)); + request.setBody(getSerde().serialize(keys)); return request; } protected ResponseDeserializer>> deleteDocumentsResponseDeserializer( - final Class type) { + final Class userDataClass) { return response -> { final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>(); final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); - if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { - final ErrorEntity error = util().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentDeleteEntity doc = util().deserialize(next, DocumentDeleteEntity.class); - final VPackSlice oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); - } - docs.add(doc); - documentsAndErrors.add(doc); - } + final JsonNode body = getSerde().parse(response.getBody()); + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); + if (isError != null && isError.booleanValue()) { + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentDeleteEntity.class, userDataClass); + final DocumentDeleteEntity doc = getSerde().deserialize(next, type); + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -530,7 +456,7 @@ protected Request deleteIndexRequest(final String id) { } protected ResponseDeserializer deleteIndexResponseDeserializer() { - return response -> response.getBody().get("id").getAsString(); + return response -> getSerde().deserialize(response.getBody(), "/id", String.class); } private String createIndexId(final String id) { @@ -550,7 +476,7 @@ protected Request createHashIndexRequest(final Iterable fields, final Ha final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); request.setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); return request; } @@ -559,7 +485,7 @@ protected Request createSkiplistIndexRequest(final Iterable fields, fina final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); request.setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); return request; } @@ -567,7 +493,7 @@ protected Request createPersistentIndexRequest( final Iterable fields, final PersistentIndexOptions options) { final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); - request.setBody(util().serialize( + request.setBody(getSerde().serialize( OptionsBuilder.build(options != null ? options : new PersistentIndexOptions(), fields))); return request; } @@ -576,7 +502,7 @@ protected Request createGeoIndexRequest(final Iterable fields, final Geo final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); request.setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); return request; } @@ -584,7 +510,7 @@ protected Request createFulltextIndexRequest(final Iterable fields, fina final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); request.setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); return request; } @@ -592,7 +518,7 @@ protected Request createTtlIndexRequest(final Iterable fields, final Ttl final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); request.setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); return request; } @@ -600,7 +526,7 @@ protected Request createZKDIndexRequest( final Iterable fields, final ZKDIndexOptions options) { final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX); request.putQueryParam(COLLECTION, name); - request.setBody(util().serialize(OptionsBuilder.build(options != null ? options : + request.setBody(getSerde().serialize(OptionsBuilder.build(options != null ? options : new ZKDIndexOptions().fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE), fields))); return request; } @@ -612,8 +538,8 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("indexes"), new Type>() { - }.getType()); + return response -> getSerde().deserialize(response.getBody(), "/indexes", + SerdeUtils.INSTANCE.constructListType(IndexEntity.class)); } protected Request truncateRequest(final CollectionTruncateOptions options) { @@ -644,19 +570,19 @@ protected Request getPropertiesRequest() { protected Request changePropertiesRequest(final CollectionPropertiesOptions options) { final Request request = request(db.dbName(), RequestType.PUT, PATH_API_COLLECTION, name, "properties"); - request.setBody(util().serialize(options != null ? options : new CollectionPropertiesOptions())); + request.setBody(getSerde().serialize(options != null ? options : new CollectionPropertiesOptions())); return request; } protected Request renameRequest(final String newName) { final Request request = request(db.dbName(), RequestType.PUT, PATH_API_COLLECTION, name, "rename"); - request.setBody(util().serialize(OptionsBuilder.build(new CollectionRenameOptions(), newName))); + request.setBody(getSerde().serialize(OptionsBuilder.build(new CollectionRenameOptions(), newName))); return request; } protected Request responsibleShardRequest(final T value) { final Request request = request(db.dbName(), RequestType.PUT, PATH_API_COLLECTION, name, "responsibleShard"); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } @@ -666,7 +592,7 @@ protected Request getRevisionRequest() { protected Request grantAccessRequest(final String user, final Permissions permissions) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, - db.dbName().get(), name).setBody(util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + db.dbName().get(), name).setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { @@ -680,16 +606,18 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> { - final VPackSlice body = response.getBody(); - if (body != null) { - final VPackSlice result = body.get(ArangoResponseField.RESULT); - if (!result.isNone()) { - return util().deserialize(result, Permissions.class); - } - } + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); + } + + private Class getCollectionContentClass(Collection c) { + if (c == null || c.isEmpty()) { return null; - }; + } + Object v = c.iterator().next(); + if (v == null) { + return null; + } + return v.getClass(); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index db5d9135d..862c4d90c 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -23,17 +23,15 @@ import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory; import com.arangodb.model.*; -import com.arangodb.velocypack.Type; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.InternalSerde; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.Map.Entry; /** * @author Mark Vollmary @@ -49,7 +47,7 @@ public abstract class InternalArangoDB extends ArangoE private static final String PATH_ENDPOINTS = "/_api/cluster/endpoints"; private static final String PATH_API_USER = "/_api/user"; - protected InternalArangoDB(final E executor, final ArangoSerializationFactory util, final ArangoContext context) { + protected InternalArangoDB(final E executor, final InternalSerde util, final ArangoContext context) { super(executor, util, context); } @@ -62,22 +60,22 @@ protected Request getServerIdRequest() { } protected ResponseDeserializer getRoleResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("role"), ServerRole.class); + return response -> getSerde().deserialize(response.getBody(), "/role", ServerRole.class); } protected ResponseDeserializer getServerIdResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("id"), String.class); + return response -> getSerde().deserialize(response.getBody(), "/id", String.class); } protected Request createDatabaseRequest(final DBCreateOptions options) { final Request request = request(DbName.SYSTEM, RequestType.POST, InternalArangoDatabase.PATH_API_DATABASE); - request.setBody(util().serialize(options)); + request.setBody(getSerde().serialize(options)); return request; } protected ResponseDeserializer createDatabaseResponseDeserializer() { - return response -> response.getBody().get(ArangoResponseField.RESULT).getAsBoolean(); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); } protected Request getDatabasesRequest(final DbName dbName) { @@ -85,11 +83,8 @@ protected Request getDatabasesRequest(final DbName dbName) { } protected ResponseDeserializer> getDatabaseResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(String.class)); } protected Request getAccessibleDatabasesForRequest(final DbName dbName, final String user) { @@ -98,11 +93,10 @@ protected Request getAccessibleDatabasesForRequest(final DbName dbName, final St protected ResponseDeserializer> getAccessibleDatabasesForResponseDeserializer() { return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); + Iterator names = getSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER).fieldNames(); final Collection dbs = new ArrayList<>(); - for (final Iterator> iterator = result.objectIterator(); iterator - .hasNext(); ) { - dbs.add(iterator.next().getKey()); + while (names.hasNext()) { + dbs.add(names.next()); } return dbs; }; @@ -116,7 +110,7 @@ protected Request createUserRequest( final Request request; request = request(dbName, RequestType.POST, PATH_API_USER); request.setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); return request; } @@ -133,35 +127,32 @@ protected Request getUserRequest(final DbName dbName, final String user) { } protected ResponseDeserializer> getUsersResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(UserEntity.class)); } protected Request updateUserRequest(final DbName dbName, final String user, final UserUpdateOptions options) { final Request request; request = request(dbName, RequestType.PATCH, PATH_API_USER, user); - request.setBody(util().serialize(options != null ? options : new UserUpdateOptions())); + request.setBody(getSerde().serialize(options != null ? options : new UserUpdateOptions())); return request; } protected Request replaceUserRequest(final DbName dbName, final String user, final UserUpdateOptions options) { final Request request; request = request(dbName, RequestType.PUT, PATH_API_USER, user); - request.setBody(util().serialize(options != null ? options : new UserUpdateOptions())); + request.setBody(getSerde().serialize(options != null ? options : new UserUpdateOptions())); return request; } protected Request updateUserDefaultDatabaseAccessRequest(final String user, final Permissions permissions) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, - "*").setBody(util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + "*").setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request updateUserDefaultCollectionAccessRequest(final String user, final Permissions permissions) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, - "*", "*").setBody(util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + "*", "*").setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getLogEntriesRequest(final LogOptions options) { @@ -182,7 +173,7 @@ protected Request getLogLevelRequest() { protected Request setLogLevelRequest(final LogLevelEntity entity) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_ADMIN_LOG_LEVEL) - .setBody(util().serialize(entity)); + .setBody(getSerde().serialize(entity)); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java index 6abc81bfa..9b8821057 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java @@ -23,25 +23,9 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDBException; import com.arangodb.entity.LoadBalancingStrategy; -import com.arangodb.internal.net.Connection; -import com.arangodb.internal.net.ConnectionFactory; -import com.arangodb.internal.net.DirtyReadHostHandler; -import com.arangodb.internal.net.ExtendedHostResolver; -import com.arangodb.internal.net.FallbackHostHandler; -import com.arangodb.internal.net.Host; -import com.arangodb.internal.net.HostDescription; -import com.arangodb.internal.net.HostHandler; -import com.arangodb.internal.net.HostResolver; -import com.arangodb.internal.net.RandomHostHandler; -import com.arangodb.internal.net.RoundRobinHostHandler; -import com.arangodb.internal.net.SimpleHostResolver; +import com.arangodb.internal.net.*; import com.arangodb.internal.util.HostUtils; -import com.arangodb.internal.velocypack.VPackDriverModule; -import com.arangodb.util.ArangoDeserializer; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackParser; +import com.arangodb.serde.ArangoSerde; import org.apache.http.client.HttpRequestRetryHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,23 +78,15 @@ public abstract class InternalArangoDBBuilder { protected Integer maxConnections; protected Long connectionTtl; protected Integer keepAliveInterval; - protected final VPack.Builder vpackBuilder; - protected final VPackParser.Builder vpackParserBuilder; - protected ArangoSerializer serializer; - protected ArangoDeserializer deserializer; protected Boolean acquireHostList; protected Integer acquireHostListInterval; protected LoadBalancingStrategy loadBalancingStrategy; - protected ArangoSerialization customSerializer; + protected ArangoSerde customSerializer; protected Integer responseQueueTimeSamples; public InternalArangoDBBuilder() { super(); - vpackBuilder = new VPack.Builder(); - vpackParserBuilder = new VPackParser.Builder(); - vpackBuilder.registerModule(new VPackDriverModule()); - vpackParserBuilder.registerModule(new VPackDriverModule()); host = new HostDescription(ArangoDefaults.DEFAULT_HOST, ArangoDefaults.DEFAULT_PORT); hosts = new ArrayList<>(); user = ArangoDefaults.DEFAULT_USER; @@ -225,15 +201,7 @@ protected void setResponseQueueTimeSamples(final Integer responseQueueTimeSample this.responseQueueTimeSamples = responseQueueTimeSamples; } - protected void serializer(final ArangoSerializer serializer) { - this.serializer = serializer; - } - - protected void deserializer(final ArangoDeserializer deserializer) { - this.deserializer = deserializer; - } - - protected void setSerializer(final ArangoSerialization serializer) { + protected void setSerializer(final ArangoSerde serializer) { this.customSerializer = serializer; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 879f30987..97d9707af 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -24,16 +24,12 @@ import com.arangodb.entity.*; import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; import com.arangodb.model.arangosearch.AnalyzerDeleteOptions; import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; import com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.Type; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -44,8 +40,7 @@ * @author Mark Vollmary * @author Michele Rastelli */ -public abstract class InternalArangoDatabase, EXECUTOR extends ArangoExecutor> - extends ArangoExecuteable { +public abstract class InternalArangoDatabase, EXECUTOR extends ArangoExecutor> extends ArangoExecuteable { protected static final String PATH_API_DATABASE = "/_api/database"; private static final String PATH_API_VERSION = "/_api/version"; @@ -70,7 +65,7 @@ public abstract class InternalArangoDatabase> getCollectionsResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(CollectionEntity.class)); } protected Request dropRequest() { @@ -128,50 +119,33 @@ protected Request dropRequest() { } protected ResponseDeserializer createDropResponseDeserializer() { - return response -> response.getBody().get(ArangoResponseField.RESULT).getAsBoolean(); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); } protected Request grantAccessRequest(final String user, final Permissions permissions) { - return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, - dbName.get()).setBody(util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get()).setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { - return request(DbName.SYSTEM, RequestType.DELETE, PATH_API_USER, user, ArangoRequestParam.DATABASE, - dbName.get()); + return request(DbName.SYSTEM, RequestType.DELETE, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get()); } protected Request updateUserDefaultCollectionAccessRequest(final String user, final Permissions permissions) { - return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, - dbName.get(), "*").setBody(util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get(), "*").setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getPermissionsRequest(final String user) { - return request(DbName.SYSTEM, RequestType.GET, PATH_API_USER, user, ArangoRequestParam.DATABASE, - dbName.get()); + return request(DbName.SYSTEM, RequestType.GET, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get()); } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> { - final VPackSlice body = response.getBody(); - if (body != null) { - final VPackSlice result = body.get(ArangoResponseField.RESULT); - if (!result.isNone()) { - return util().deserialize(result, Permissions.class); - } - } - return null; - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } - protected Request queryRequest( - final String query, final Map bindVars, final AqlQueryOptions options) { + protected Request queryRequest(final String query, final Map bindVars, final AqlQueryOptions options) { final AqlQueryOptions opt = options != null ? options : new AqlQueryOptions(); final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR) - .setBody(util().serialize(OptionsBuilder - .build(opt, query, bindVars != null ? - util(ArangoSerializationFactory.Serializer.CUSTOM).serialize(bindVars, new ArangoSerializer.Options().serializeNullValues(true)) : - null))); + .setBody(getSerde().serialize(OptionsBuilder.build(opt, query, bindVars))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } @@ -213,26 +187,14 @@ protected Request queryCloseRequest(final String id, final AqlQueryOptions optio return request; } - protected Request explainQueryRequest( - final String query, - final Map bindVars, - final AqlQueryExplainOptions options - ) { - + protected Request explainQueryRequest(final String query, final Map bindVars, final AqlQueryExplainOptions options) { final AqlQueryExplainOptions opt = options != null ? options : new AqlQueryExplainOptions(); - return request(dbName, RequestType.POST, PATH_API_EXPLAIN) - .setBody(util().serialize(OptionsBuilder.build( - opt, - query, - bindVars != null ? util(ArangoSerializationFactory.Serializer.CUSTOM).serialize( - bindVars, - new ArangoSerializer.Options().serializeNullValues(true)) : null))); + .setBody(getSerde().serialize(OptionsBuilder.build(opt, query, bindVars))); } protected Request parseQueryRequest(final String query) { - return request(dbName, RequestType.POST, PATH_API_QUERY) - .setBody(util().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); + return request(dbName, RequestType.POST, PATH_API_QUERY).setBody(getSerde().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); } protected Request clearQueryCacheRequest() { @@ -244,7 +206,7 @@ protected Request getQueryCachePropertiesRequest() { } protected Request setQueryCachePropertiesRequest(final QueryCachePropertiesEntity properties) { - return request(dbName, RequestType.PUT, PATH_API_QUERY_CACHE_PROPERTIES).setBody(util().serialize(properties)); + return request(dbName, RequestType.PUT, PATH_API_QUERY_CACHE_PROPERTIES).setBody(getSerde().serialize(properties)); } protected Request getQueryTrackingPropertiesRequest() { @@ -252,7 +214,7 @@ protected Request getQueryTrackingPropertiesRequest() { } protected Request setQueryTrackingPropertiesRequest(final QueryTrackingPropertiesEntity properties) { - return request(dbName, RequestType.PUT, PATH_API_QUERY_PROPERTIES).setBody(util().serialize(properties)); + return request(dbName, RequestType.PUT, PATH_API_QUERY_PROPERTIES).setBody(getSerde().serialize(properties)); } protected Request getCurrentlyRunningQueriesRequest() { @@ -271,10 +233,8 @@ protected Request killQueryRequest(final String id) { return request(dbName, RequestType.DELETE, PATH_API_QUERY, id); } - protected Request createAqlFunctionRequest( - final String name, final String code, final AqlFunctionCreateOptions options) { - return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(util().serialize( - OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); + protected Request createAqlFunctionRequest(final String name, final String code, final AqlFunctionCreateOptions options) { + return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(getSerde().serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); } protected Request deleteAqlFunctionRequest(final String name, final AqlFunctionDeleteOptions options) { @@ -285,19 +245,7 @@ protected Request deleteAqlFunctionRequest(final String name, final AqlFunctionD } protected ResponseDeserializer deleteAqlFunctionResponseDeserializer() { - return response -> { - // compatibility with ArangoDB < 3.4 - // https://www.arangodb.com/docs/stable/release-notes-upgrading-changes34.html - Integer count = null; - final VPackSlice body = response.getBody(); - if (body.isObject()) { - final VPackSlice deletedCount = body.get("deletedCount"); - if (deletedCount.isInteger()) { - count = deletedCount.getAsInt(); - } - } - return count; - }; + return response -> getSerde().deserialize(response.getBody(), "/deletedCount", Integer.class); } protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { @@ -308,24 +256,16 @@ protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { } protected ResponseDeserializer> getAqlFunctionsResponseDeserializer() { - return response -> { - final VPackSlice body = response.getBody(); - // compatibility with ArangoDB < 3.4 - // https://www.arangodb.com/docs/stable/release-notes-upgrading-changes34.html - final VPackSlice result = body.isArray() ? body : body.get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(AqlFunctionEntity.class)); } - protected Request createGraphRequest( - final String name, final Collection edgeDefinitions, final GraphCreateOptions options) { - return request(dbName, RequestType.POST, InternalArangoGraph.PATH_API_GHARIAL).setBody(util().serialize( - OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); + protected Request createGraphRequest(final String name, final Collection edgeDefinitions, final GraphCreateOptions options) { + return request(dbName, RequestType.POST, InternalArangoGraph.PATH_API_GHARIAL).setBody(getSerde().serialize(OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); } protected ResponseDeserializer createGraphResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("graph"), GraphEntity.class); + return response -> getSerde().deserialize(response.getBody(), "/graph", GraphEntity.class); } protected Request getGraphsRequest() { @@ -333,31 +273,23 @@ protected Request getGraphsRequest() { } protected ResponseDeserializer> getGraphsResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("graphs"), new Type>() { - }.getType()); + return response -> getSerde().deserialize(response.getBody(), "/graphs", + SerdeUtils.INSTANCE.constructListType(GraphEntity.class)); } protected Request transactionRequest(final String action, final TransactionOptions options) { - return request(dbName, RequestType.POST, PATH_API_TRANSACTION).setBody( - util().serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); + return request(dbName, RequestType.POST, PATH_API_TRANSACTION).setBody(getSerde().serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); } protected ResponseDeserializer transactionResponseDeserializer(final Class type) { return response -> { - final VPackSlice body = response.getBody(); - if (body != null) { - final VPackSlice result = body.get(ArangoResponseField.RESULT); - if (!result.isNone() && !result.isNull()) { - return util(Serializer.CUSTOM).deserialize(result, type); - } - } - return null; + byte[] userContent = getSerde().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); + return getSerde().deserializeUserData(userContent, type); }; } protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { - return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION) - .setBody(util().serialize(options != null ? options : new StreamTransactionOptions())); + return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION).setBody(getSerde().serialize(options != null ? options : new StreamTransactionOptions())); } protected Request abortStreamTransactionRequest(String id) { @@ -373,11 +305,8 @@ protected Request getStreamTransactionRequest(String id) { } protected ResponseDeserializer> transactionsResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get("transactions"); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), "/transactions", + SerdeUtils.INSTANCE.constructListType(TransactionEntity.class)); } protected Request commitStreamTransactionRequest(String id) { @@ -385,8 +314,7 @@ protected Request commitStreamTransactionRequest(String id) { } protected ResponseDeserializer streamTransactionResponseDeserializer() { - return response -> util() - .deserialize(response.getBody().get(ArangoResponseField.RESULT), StreamTransactionEntity.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, StreamTransactionEntity.class); } protected Request getInfoRequest() { @@ -394,7 +322,7 @@ protected Request getInfoRequest() { } protected ResponseDeserializer getInfoResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(ArangoResponseField.RESULT), DatabaseEntity.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, DatabaseEntity.class); } protected Request reloadRoutingRequest() { @@ -406,21 +334,16 @@ protected Request getViewsRequest() { } protected ResponseDeserializer> getViewsResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(ViewEntity.class)); } protected Request createViewRequest(final String name, final ViewType type) { - return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW) - .setBody(util().serialize(OptionsBuilder.build(new ViewCreateOptions(), name, type))); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getSerde().serialize(OptionsBuilder.build(new ViewCreateOptions(), name, type))); } protected Request createArangoSearchRequest(final String name, final ArangoSearchCreateOptions options) { - return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(util().serialize( - ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getSerde().serialize(ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); } protected Request getAnalyzerRequest(final String name) { @@ -432,16 +355,12 @@ protected Request getAnalyzersRequest() { } protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(SearchAnalyzer.class)); } protected Request createAnalyzerRequest(final SearchAnalyzer options) { - return request(dbName, RequestType.POST, InternalArangoView.PATH_API_ANALYZER) - .setBody(util().serialize(options)); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_ANALYZER).setBody(getSerde().serialize(options)); } protected Request deleteAnalyzerRequest(final String name, final AnalyzerDeleteOptions options) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java index 44ad70837..01e6b5e68 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -23,12 +23,9 @@ import com.arangodb.entity.EdgeEntity; import com.arangodb.entity.EdgeUpdateEntity; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -42,7 +39,6 @@ public abstract class InternalArangoEdgeCollection extends ArangoExecuteable { private static final String PATH_API_GHARIAL = "/_api/gharial"; - private static final String EDGE = "edge"; private static final String TRANSACTION_ID = "x-arango-trx-id"; @@ -50,7 +46,7 @@ public abstract class InternalArangoEdgeCollection private final String name; protected InternalArangoEdgeCollection(final G graph, final String name) { - super(graph.executor, graph.util, graph.context); + super(graph.executor, graph.serde, graph.context); this.graph = graph; this.name = name; } @@ -64,19 +60,18 @@ public String name() { } protected Request insertEdgeRequest(final T value, final EdgeCreateOptions options) { - final Request request = request(graph.db().dbName(), RequestType.POST, PATH_API_GHARIAL, graph.name(), EDGE, + final Request request = request(graph.db().dbName(), RequestType.POST, PATH_API_GHARIAL, graph.name(), "edge", name); final EdgeCreateOptions params = (options != null ? options : new EdgeCreateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer insertEdgeResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(EDGE); - final EdgeEntity doc = util().deserialize(body, EdgeEntity.class); + final EdgeEntity doc = getSerde().deserialize(response.getBody(), "/edge", EdgeEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -87,7 +82,7 @@ protected ResponseDeserializer insertEdgeResponseDeserializer(fi } protected Request getEdgeRequest(final String key, final GraphDocumentReadOptions options) { - final Request request = request(graph.db().dbName(), RequestType.GET, PATH_API_GHARIAL, graph.name(), EDGE, + final Request request = request(graph.db().dbName(), RequestType.GET, PATH_API_GHARIAL, graph.name(), "edge", DocumentUtil.createDocumentHandle(name, key)); final GraphDocumentReadOptions params = (options != null ? options : new GraphDocumentReadOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); @@ -100,24 +95,23 @@ protected Request getEdgeRequest(final String key, final GraphDocumentReadOption } protected ResponseDeserializer getEdgeResponseDeserializer(final Class type) { - return response -> util(Serializer.CUSTOM).deserialize(response.getBody().get(EDGE), type); + return response -> getSerde().deserializeUserData(getSerde().extract(response.getBody(), "/edge"), type); } protected Request replaceEdgeRequest(final String key, final T value, final EdgeReplaceOptions options) { - final Request request = request(graph.db().dbName(), RequestType.PUT, PATH_API_GHARIAL, graph.name(), EDGE, + final Request request = request(graph.db().dbName(), RequestType.PUT, PATH_API_GHARIAL, graph.name(), "edge", DocumentUtil.createDocumentHandle(name, key)); final EdgeReplaceOptions params = (options != null ? options : new EdgeReplaceOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer replaceEdgeResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(EDGE); - final EdgeUpdateEntity doc = util().deserialize(body, EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getSerde().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -127,22 +121,20 @@ protected ResponseDeserializer replaceEdgeResponseDeserial protected Request updateEdgeRequest(final String key, final T value, final EdgeUpdateOptions options) { final Request request; - request = request(graph.db().dbName(), RequestType.PATCH, PATH_API_GHARIAL, graph.name(), EDGE, + request = request(graph.db().dbName(), RequestType.PATCH, PATH_API_GHARIAL, graph.name(), "edge", DocumentUtil.createDocumentHandle(name, key)); final EdgeUpdateOptions params = (options != null ? options : new EdgeUpdateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody( - util(Serializer.CUSTOM).serialize(value, new ArangoSerializer.Options().serializeNullValues(true))); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer updateEdgeResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(EDGE); - final EdgeUpdateEntity doc = util().deserialize(body, EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getSerde().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -151,7 +143,7 @@ protected ResponseDeserializer updateEdgeResponseDeseriali } protected Request deleteEdgeRequest(final String key, final EdgeDeleteOptions options) { - final Request request = request(graph.db().dbName(), RequestType.DELETE, PATH_API_GHARIAL, graph.name(), EDGE, + final Request request = request(graph.db().dbName(), RequestType.DELETE, PATH_API_GHARIAL, graph.name(), "edge", DocumentUtil.createDocumentHandle(name, key)); final EdgeDeleteOptions params = (options != null ? options : new EdgeDeleteOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index a03e090e6..46e3ff8d1 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoGraph.java +++ b/src/main/java/com/arangodb/internal/InternalArangoGraph.java @@ -25,7 +25,7 @@ import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; import com.arangodb.model.OptionsBuilder; import com.arangodb.model.VertexCollectionCreateOptions; -import com.arangodb.velocypack.Type; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -38,7 +38,7 @@ public abstract class InternalArangoGraph, D exten extends ArangoExecuteable { protected static final String PATH_API_GHARIAL = "/_api/gharial"; - private static final String GRAPH = "graph"; + private static final String GRAPH = "/graph"; private static final String VERTEX = "vertex"; private static final String EDGE = "edge"; @@ -46,7 +46,7 @@ public abstract class InternalArangoGraph, D exten private final String name; protected InternalArangoGraph(final D db, final String name) { - super(db.executor, db.util, db.context); + super(db.executor, db.serde, db.context); this.db = db; this.name = name; } @@ -84,13 +84,13 @@ protected Request getVertexCollectionsRequest() { } protected ResponseDeserializer> getVertexCollectionsResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("collections"), new Type>() { - }.getType()); + return response -> getSerde().deserialize(response.getBody(), "/collections", + SerdeUtils.INSTANCE.constructListType(String.class)); } protected Request addVertexCollectionRequest(final String name, final VertexCollectionCreateOptions options) { final Request request = request(db.dbName(), RequestType.POST, PATH_API_GHARIAL, name(), VERTEX); - request.setBody(util().serialize(OptionsBuilder.build(options, name))); + request.setBody(getSerde().serialize(OptionsBuilder.build(options, name))); return request; } @@ -103,29 +103,29 @@ protected Request getEdgeDefinitionsRequest() { } protected ResponseDeserializer> getEdgeDefinitionsDeserializer() { - return response -> util().deserialize(response.getBody().get("collections"), new Type>() { - }.getType()); + return response -> getSerde().deserialize(response.getBody(), "/collections", + SerdeUtils.INSTANCE.constructListType(String.class)); } protected Request addEdgeDefinitionRequest(final EdgeDefinition definition) { final Request request = request(db.dbName(), RequestType.POST, PATH_API_GHARIAL, name, EDGE); - request.setBody(util().serialize(definition)); + request.setBody(getSerde().serialize(definition)); return request; } protected ResponseDeserializer addEdgeDefinitionResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getSerde().deserialize(response.getBody(), GRAPH, GraphEntity.class); } protected Request replaceEdgeDefinitionRequest(final EdgeDefinition definition) { final Request request = request(db.dbName(), RequestType.PUT, PATH_API_GHARIAL, name, EDGE, definition.getCollection()); - request.setBody(util().serialize(definition)); + request.setBody(getSerde().serialize(definition)); return request; } protected ResponseDeserializer replaceEdgeDefinitionResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getSerde().deserialize(response.getBody(), GRAPH, GraphEntity.class); } protected Request removeEdgeDefinitionRequest(final String definitionName) { @@ -133,7 +133,7 @@ protected Request removeEdgeDefinitionRequest(final String definitionName) { } protected ResponseDeserializer removeEdgeDefinitionResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getSerde().deserialize(response.getBody(), GRAPH, GraphEntity.class); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoRoute.java b/src/main/java/com/arangodb/internal/InternalArangoRoute.java index 9c6a4171a..7e0f11949 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoRoute.java +++ b/src/main/java/com/arangodb/internal/InternalArangoRoute.java @@ -41,7 +41,7 @@ public abstract class InternalArangoRoute, D exten protected Object body; protected InternalArangoRoute(final D db, final String path, final Map headerParam) { - super(db.executor, db.util, db.context); + super(db.executor, db.serde, db.context); this.db = db; this.path = path; this.queryParam = new HashMap<>(); @@ -74,7 +74,7 @@ protected Request createRequest(final RequestType requestType) { request.putQueryParam(param.getKey(), param.getValue()); } if (body != null) { - request.setBody(util().serialize(body)); + request.setBody(getSerde().serialize(body)); } return request; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoSearch.java b/src/main/java/com/arangodb/internal/InternalArangoSearch.java index dac8d35e8..cb836c9de 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoSearch.java +++ b/src/main/java/com/arangodb/internal/InternalArangoSearch.java @@ -40,13 +40,13 @@ protected Request getPropertiesRequest() { protected Request replacePropertiesRequest(final ArangoSearchPropertiesOptions options) { final Request request = request(db.dbName(), RequestType.PUT, PATH_API_VIEW, name, "properties"); - request.setBody(util().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); + request.setBody(getSerde().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); return request; } protected Request updatePropertiesRequest(final ArangoSearchPropertiesOptions options) { final Request request = request(db.dbName(), RequestType.PATCH, PATH_API_VIEW, name, "properties"); - request.setBody(util().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); + request.setBody(getSerde().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); return request; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 0472adbb9..d7c9ebb8d 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -23,12 +23,10 @@ import com.arangodb.entity.VertexEntity; import com.arangodb.entity.VertexUpdateEntity; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -42,7 +40,6 @@ public abstract class InternalArangoVertexCollection { private static final String PATH_API_GHARIAL = "/_api/gharial"; - private static final String VERTEX = "vertex"; private static final String TRANSACTION_ID = "x-arango-trx-id"; @@ -50,7 +47,7 @@ public abstract class InternalArangoVertexCollection Request insertVertexRequest(final T value, final VertexCreateOptions options) { - final Request request = request(graph.db().dbName(), RequestType.POST, PATH_API_GHARIAL, graph.name(), VERTEX, + final Request request = request(graph.db().dbName(), RequestType.POST, PATH_API_GHARIAL, graph.name(), "vertex", name); final VertexCreateOptions params = (options != null ? options : new VertexCreateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer insertVertexResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(VERTEX); - final VertexEntity doc = util().deserialize(body, VertexEntity.class); + final VertexEntity doc = getSerde().deserialize(response.getBody(), "/vertex", VertexEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -91,7 +87,7 @@ protected ResponseDeserializer insertVertexResponseDeserialize } protected Request getVertexRequest(final String key, final GraphDocumentReadOptions options) { - final Request request = request(graph.db().dbName(), RequestType.GET, PATH_API_GHARIAL, graph.name(), VERTEX, + final Request request = request(graph.db().dbName(), RequestType.GET, PATH_API_GHARIAL, graph.name(), "vertex", DocumentUtil.createDocumentHandle(name, key)); final GraphDocumentReadOptions params = (options != null ? options : new GraphDocumentReadOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); @@ -104,24 +100,23 @@ protected Request getVertexRequest(final String key, final GraphDocumentReadOpti } protected ResponseDeserializer getVertexResponseDeserializer(final Class type) { - return response -> util(Serializer.CUSTOM).deserialize(response.getBody().get(VERTEX), type); + return response -> getSerde().deserializeUserData(getSerde().extract(response.getBody(), "/vertex"), type); } protected Request replaceVertexRequest(final String key, final T value, final VertexReplaceOptions options) { - final Request request = request(graph.db().dbName(), RequestType.PUT, PATH_API_GHARIAL, graph.name(), VERTEX, + final Request request = request(graph.db().dbName(), RequestType.PUT, PATH_API_GHARIAL, graph.name(), "vertex", DocumentUtil.createDocumentHandle(name, key)); final VertexReplaceOptions params = (options != null ? options : new VertexReplaceOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer replaceVertexResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(VERTEX); - final VertexUpdateEntity doc = util().deserialize(body, VertexUpdateEntity.class); + final VertexUpdateEntity doc = getSerde().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -131,22 +126,20 @@ protected ResponseDeserializer replaceVertexResponseDese protected Request updateVertexRequest(final String key, final T value, final VertexUpdateOptions options) { final Request request; - request = request(graph.db().dbName(), RequestType.PATCH, PATH_API_GHARIAL, graph.name(), VERTEX, + request = request(graph.db().dbName(), RequestType.PATCH, PATH_API_GHARIAL, graph.name(), "vertex", DocumentUtil.createDocumentHandle(name, key)); final VertexUpdateOptions params = (options != null ? options : new VertexUpdateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody( - util(Serializer.CUSTOM).serialize(value, new ArangoSerializer.Options().serializeNullValues(true))); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer updateVertexResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(VERTEX); - final VertexUpdateEntity doc = util().deserialize(body, VertexUpdateEntity.class); + final VertexUpdateEntity doc = getSerde().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -155,7 +148,7 @@ protected ResponseDeserializer updateVertexResponseDeser } protected Request deleteVertexRequest(final String key, final VertexDeleteOptions options) { - final Request request = request(graph.db().dbName(), RequestType.DELETE, PATH_API_GHARIAL, graph.name(), VERTEX, + final Request request = request(graph.db().dbName(), RequestType.DELETE, PATH_API_GHARIAL, graph.name(), "vertex", DocumentUtil.createDocumentHandle(name, key)); final VertexDeleteOptions params = (options != null ? options : new VertexDeleteOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); diff --git a/src/main/java/com/arangodb/internal/InternalArangoView.java b/src/main/java/com/arangodb/internal/InternalArangoView.java index 1fa76f015..fde7cfa64 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoView.java +++ b/src/main/java/com/arangodb/internal/InternalArangoView.java @@ -39,7 +39,7 @@ public abstract class InternalArangoView, D extend protected volatile String name; protected InternalArangoView(final D db, final String name) { - super(db.executor, db.util, db.context); + super(db.executor, db.serde, db.context); this.db = db; this.name = name; } @@ -58,7 +58,7 @@ protected Request dropRequest() { protected Request renameRequest(final String newName) { final Request request = request(db.dbName(), RequestType.PUT, PATH_API_VIEW, name, "rename"); - request.setBody(util().serialize(OptionsBuilder.build(new ViewRenameOptions(), newName))); + request.setBody(getSerde().serialize(OptionsBuilder.build(new ViewRenameOptions(), newName))); return request; } diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java index 1de76a083..1af8097fb 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java @@ -22,10 +22,10 @@ import com.arangodb.ArangoCursor; import com.arangodb.ArangoIterator; -import com.arangodb.entity.CursorEntity; -import com.arangodb.entity.CursorEntity.Extras; -import com.arangodb.entity.CursorEntity.Stats; -import com.arangodb.entity.CursorEntity.Warning; +import com.arangodb.entity.CursorStats; +import com.arangodb.entity.CursorWarning; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity.Extras; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; @@ -44,7 +44,7 @@ public class ArangoCursorImpl extends AbstractArangoIterable implements Ar private final ArangoCursorExecute execute; public ArangoCursorImpl(final InternalArangoDatabase db, final ArangoCursorExecute execute, - final Class type, final CursorEntity result) { + final Class type, final InternalCursorEntity result) { super(); this.execute = execute; this.type = type; @@ -56,7 +56,7 @@ protected ArangoCursorIterator createIterator( final ArangoCursor cursor, final InternalArangoDatabase db, final ArangoCursorExecute execute, - final CursorEntity result) { + final InternalCursorEntity result) { return new ArangoCursorIterator<>(cursor, execute, db, result); } @@ -76,13 +76,13 @@ public Integer getCount() { } @Override - public Stats getStats() { + public CursorStats getStats() { final Extras extra = iterator.getResult().getExtra(); return extra != null ? extra.getStats() : null; } @Override - public Collection getWarnings() { + public Collection getWarnings() { final Extras extra = iterator.getResult().getExtra(); return extra != null ? extra.getWarnings() : null; } diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java index b67ed820d..f34f3203a 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -22,11 +22,10 @@ import com.arangodb.ArangoCursor; import com.arangodb.ArangoIterator; -import com.arangodb.entity.CursorEntity; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; +import com.fasterxml.jackson.databind.JsonNode; import java.util.Iterator; import java.util.NoSuchElementException; @@ -37,24 +36,24 @@ */ public class ArangoCursorIterator implements ArangoIterator { - private CursorEntity result; - private Iterator arrayIterator; + private InternalCursorEntity result; + private Iterator arrayIterator; private final ArangoCursor cursor; private final InternalArangoDatabase db; private final ArangoCursorExecute execute; protected ArangoCursorIterator(final ArangoCursor cursor, final ArangoCursorExecute execute, - final InternalArangoDatabase db, final CursorEntity result) { + final InternalArangoDatabase db, final InternalCursorEntity result) { super(); this.cursor = cursor; this.execute = execute; this.db = db; this.result = result; - arrayIterator = result.getResult().arrayIterator(); + arrayIterator = result.getResult().iterator(); } - public CursorEntity getResult() { + public InternalCursorEntity getResult() { return result; } @@ -67,16 +66,16 @@ public boolean hasNext() { public T next() { if (!arrayIterator.hasNext() && result.getHasMore()) { result = execute.next(cursor.getId(), result.getMeta()); - arrayIterator = result.getResult().arrayIterator(); + arrayIterator = result.getResult().iterator(); } if (!hasNext()) { throw new NoSuchElementException(); } - return deserialize(arrayIterator.next(), cursor.getType()); + return deserialize(db.getSerde().serialize(arrayIterator.next()), cursor.getType()); } - protected R deserialize(final VPackSlice result, final Class type) { - return db.util(Serializer.CUSTOM).deserialize(result, type); + protected R deserialize(final byte[] result, final Class type) { + return db.getSerde().deserializeUserData(result, type); } @Override diff --git a/src/main/java/com/arangodb/entity/CursorEntity.java b/src/main/java/com/arangodb/internal/cursor/entity/InternalCursorEntity.java similarity index 63% rename from src/main/java/com/arangodb/entity/CursorEntity.java rename to src/main/java/com/arangodb/internal/cursor/entity/InternalCursorEntity.java index 66a9a7010..56f428f67 100644 --- a/src/main/java/com/arangodb/entity/CursorEntity.java +++ b/src/main/java/com/arangodb/internal/cursor/entity/InternalCursorEntity.java @@ -18,9 +18,12 @@ * Copyright holder is ArangoDB GmbH, Cologne, Germany */ -package com.arangodb.entity; +package com.arangodb.internal.cursor.entity; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.entity.CursorStats; +import com.arangodb.entity.CursorWarning; +import com.arangodb.entity.MetaAware; +import com.fasterxml.jackson.databind.JsonNode; import java.util.Collection; import java.util.Collections; @@ -31,14 +34,14 @@ * @see API * Documentation */ -public class CursorEntity implements Entity, MetaAware { +public final class InternalCursorEntity implements MetaAware { private String id; private Integer count; private Extras extra = new Extras(); private Boolean cached; private Boolean hasMore; - private VPackSlice result; + private JsonNode result; private Map meta; @@ -81,9 +84,9 @@ public Boolean getHasMore() { } /** - * @return an vpack-array of result documents (might be empty if query has no results) + * @return an array of result documents (might be empty if query has no results) */ - public VPackSlice getResult() { + public JsonNode getResult() { return result; } @@ -105,75 +108,19 @@ public void setMeta(Map meta) { this.meta = cleanupMeta(meta); } - public static class Warning { + public static final class Extras { + private CursorStats stats; + private Collection warnings = Collections.emptyList(); - private Integer code; - private String message; - - public Integer getCode() { - return code; - } - - public String getMessage() { - return message; - } - - } - - public static class Extras { - private Stats stats; - private Collection warnings = Collections.emptyList(); - - public Stats getStats() { + public CursorStats getStats() { return stats; } - public Collection getWarnings() { + public Collection getWarnings() { return warnings; } } - public static class Stats { - private Long writesExecuted; - private Long writesIgnored; - private Long scannedFull; - private Long scannedIndex; - private Long filtered; - private Long fullCount; - private Double executionTime; - private Long peakMemoryUsage; - - public Long getWritesExecuted() { - return writesExecuted; - } - - public Long getWritesIgnored() { - return writesIgnored; - } - - public Long getScannedFull() { - return scannedFull; - } - - public Long getScannedIndex() { - return scannedIndex; - } - - public Long getFiltered() { - return filtered; - } - - public Long getFullCount() { - return fullCount; - } - - public Double getExecutionTime() { - return executionTime; - } - - public Long getPeakMemoryUsage() { - return peakMemoryUsage; - } - } } + diff --git a/src/main/java/com/arangodb/internal/http/CURLLogger.java b/src/main/java/com/arangodb/internal/http/CURLLogger.java index 941769fe4..062b30bba 100644 --- a/src/main/java/com/arangodb/internal/http/CURLLogger.java +++ b/src/main/java/com/arangodb/internal/http/CURLLogger.java @@ -20,7 +20,7 @@ package com.arangodb.internal.http; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import org.apache.http.auth.Credentials; @@ -44,7 +44,7 @@ public static void log( final Request request, final Credentials credentials, final String jwt, - final ArangoSerialization util) { + final InternalSerde util) { final RequestType requestType = request.getRequestType(); final boolean includeBody = (requestType == RequestType.POST || requestType == RequestType.PUT || requestType == RequestType.PATCH || requestType == RequestType.DELETE) && request.getBody() != null; @@ -73,7 +73,7 @@ public static void log( buffer.append(" '").append(url).append("'"); if (includeBody) { buffer.append("\n"); - buffer.append((String) util.deserialize(request.getBody(), String.class)); + buffer.append(util.toJsonString(request.getBody())); buffer.append("\n"); buffer.append("___EOB___"); } diff --git a/src/main/java/com/arangodb/internal/http/HttpCommunication.java b/src/main/java/com/arangodb/internal/http/HttpCommunication.java index dcb840ce1..284a2b45c 100644 --- a/src/main/java/com/arangodb/internal/http/HttpCommunication.java +++ b/src/main/java/com/arangodb/internal/http/HttpCommunication.java @@ -24,7 +24,7 @@ import com.arangodb.internal.net.*; import com.arangodb.internal.util.HostUtils; import com.arangodb.internal.util.RequestUtils; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -55,7 +55,7 @@ public Builder(final Builder builder) { this(builder.hostHandler); } - public HttpCommunication build(final ArangoSerialization util) { + public HttpCommunication build(final InternalSerde util) { return new HttpCommunication(hostHandler); } } diff --git a/src/main/java/com/arangodb/internal/http/HttpConnection.java b/src/main/java/com/arangodb/internal/http/HttpConnection.java index 7cc380e22..1544839dc 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnection.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnection.java @@ -27,9 +27,7 @@ import com.arangodb.internal.net.HostDescription; import com.arangodb.internal.util.IOUtils; import com.arangodb.internal.util.ResponseUtils; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer.Options; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.apache.http.*; @@ -47,7 +45,6 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; @@ -64,7 +61,6 @@ import javax.net.ssl.SSLContext; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -82,13 +78,10 @@ public class HttpConnection implements Connection { "utf-8"); private static final ContentType CONTENT_TYPE_VPACK = ContentType.create("application/x-velocypack"); - // max safe UTF-8 json string length, so that it can be converted to byte array - private static final int MAX_JSON_LENGTH = (Integer.MAX_VALUE - 8) / 4; - public static class Builder { private String user; private String password; - private ArangoSerialization util; + private InternalSerde util; private Boolean useSsl; private String httpCookieSpec; private Protocol contentType; @@ -109,7 +102,7 @@ public Builder password(final String password) { return this; } - public Builder serializationUtil(final ArangoSerialization util) { + public Builder serializationUtil(final InternalSerde util) { this.util = util; return this; } @@ -170,13 +163,13 @@ public HttpConnection build() { private final String user; private final String password; private volatile String jwt = null; - private final ArangoSerialization util; + private final InternalSerde util; private final Boolean useSsl; private final Protocol contentType; private final HostDescription host; private HttpConnection(final HostDescription host, final Integer timeout, final String user, final String password, - final Boolean useSsl, final SSLContext sslContext, final HostnameVerifier hostnameVerifier, final ArangoSerialization util, final Protocol contentType, + final Boolean useSsl, final SSLContext sslContext, final HostnameVerifier hostnameVerifier, final InternalSerde util, final Protocol contentType, final Long ttl, final String httpCookieSpec, final HttpRequestRetryHandler httpRequestRetryHandler) { super(); this.host = host; @@ -287,19 +280,12 @@ private HttpRequestBase buildHttpRequestBase(final Request request, final String } private HttpRequestBase requestWithBody(final HttpEntityEnclosingRequestBase httpRequest, final Request request) { - final VPackSlice body = request.getBody(); + final byte[] body = request.getBody(); if (body != null) { if (contentType == Protocol.HTTP_VPACK) { - httpRequest.setEntity(new ByteArrayEntity( - Arrays.copyOfRange(body.getBuffer(), body.getStart(), body.getStart() + body.getByteSize()), - CONTENT_TYPE_VPACK)); + httpRequest.setEntity(new ByteArrayEntity(body, CONTENT_TYPE_VPACK)); } else { - String json = body.toString(); - if (json.length() > MAX_JSON_LENGTH) { - LOGGER.warn("Json string length is greater than safe threshold (" + MAX_JSON_LENGTH + "). " + - "This could cause memory allocation errors."); - } - httpRequest.setEntity(new StringEntity(json, CONTENT_TYPE_APPLICATION_JSON_UTF8)); + httpRequest.setEntity(new ByteArrayEntity(body, CONTENT_TYPE_APPLICATION_JSON_UTF8)); } } return httpRequest; @@ -359,17 +345,9 @@ public Response buildResponse(final CloseableHttpResponse httpResponse) response.setResponseCode(httpResponse.getStatusLine().getStatusCode()); final HttpEntity entity = httpResponse.getEntity(); if (entity != null && entity.getContent() != null) { - if (contentType == Protocol.HTTP_VPACK) { - final byte[] content = IOUtils.toByteArray(entity.getContent()); - if (content.length > 0) { - response.setBody(new VPackSlice(content)); - } - } else { - final String content = IOUtils.toString(entity.getContent()); - if (!content.isEmpty()) { - response.setBody( - util.serialize(content, new Options().stringAsJson(true).serializeNullValues(true))); - } + final byte[] content = IOUtils.toByteArray(entity.getContent()); + if (content.length > 0) { + response.setBody(content); } } final Header[] headers = httpResponse.getAllHeaders(); diff --git a/src/main/java/com/arangodb/internal/http/HttpConnectionFactory.java b/src/main/java/com/arangodb/internal/http/HttpConnectionFactory.java index 0461cd098..b0294ad0c 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnectionFactory.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnectionFactory.java @@ -24,7 +24,7 @@ import com.arangodb.internal.net.Connection; import com.arangodb.internal.net.ConnectionFactory; import com.arangodb.internal.net.HostDescription; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import org.apache.http.client.HttpRequestRetryHandler; import javax.net.ssl.HostnameVerifier; @@ -39,7 +39,7 @@ public class HttpConnectionFactory implements ConnectionFactory { public HttpConnectionFactory(final Integer timeout, final String user, final String password, final Boolean useSsl, final SSLContext sslContext, final HostnameVerifier hostnameVerifier, - final ArangoSerialization util, final Protocol protocol, final Long connectionTtl, + final InternalSerde util, final Protocol protocol, final Long connectionTtl, final String httpCookieSpec, final HttpRequestRetryHandler httpRequestRetryHandler) { super(); builder = new HttpConnection.Builder().timeout(timeout).user(user).password(password).useSsl(useSsl) diff --git a/src/main/java/com/arangodb/internal/mapping/ArangoAnnotationIntrospector.java b/src/main/java/com/arangodb/internal/mapping/ArangoAnnotationIntrospector.java deleted file mode 100644 index 6f80f1e01..000000000 --- a/src/main/java/com/arangodb/internal/mapping/ArangoAnnotationIntrospector.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.mapping; - - -import com.arangodb.velocypack.annotations.Expose; -import com.arangodb.velocypack.annotations.SerializedName; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.PropertyName; -import com.fasterxml.jackson.databind.introspect.Annotated; -import com.fasterxml.jackson.databind.introspect.AnnotatedMember; -import com.fasterxml.jackson.databind.introspect.AnnotatedParameter; -import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; - -/** - * @author Michele Rastelli - */ -public class ArangoAnnotationIntrospector extends JacksonAnnotationIntrospector { - - @Override - public JsonProperty.Access findPropertyAccess(Annotated m) { - if (!(m instanceof AnnotatedMember)) { - return super.findPropertyAccess(m); - } - - final Expose expose = m.getAnnotation(Expose.class); - if (expose != null) { - final boolean serialize = expose.serialize(); - final boolean deserialize = expose.deserialize(); - - if (serialize && deserialize) { - return JsonProperty.Access.READ_WRITE; - } else if (serialize) { - return JsonProperty.Access.READ_ONLY; - } else if (deserialize) { - return JsonProperty.Access.WRITE_ONLY; - } - } - - return super.findPropertyAccess(m); - } - - @Override - public boolean hasIgnoreMarker(AnnotatedMember m) { - final Expose expose = m.getAnnotation(Expose.class); - if (expose != null && !expose.serialize() && !expose.deserialize()) { - return true; - } - return super.hasIgnoreMarker(m); - } - - @Override - public PropertyName findNameForSerialization(Annotated a) { - PropertyName name = findPropertyName(a); - if (name != null) { - return name; - } else { - return super.findNameForSerialization(a); - } - } - - @Override - public PropertyName findNameForDeserialization(Annotated a) { - PropertyName name = findPropertyName(a); - if (name != null) { - return name; - } else { - return super.findNameForDeserialization(a); - } - } - - @Override - public String findImplicitPropertyName(AnnotatedMember member) { - String name = findParameterName(member); - if (name != null) { - return name; - } else { - return super.findImplicitPropertyName(member); - } - } - - private String findParameterName(Annotated a) { - if (!(a instanceof AnnotatedParameter)) { - return null; - } - - final SerializedName serializedName = a.getAnnotation(SerializedName.class); - if (serializedName != null) { - return serializedName.value(); - } - - return null; - } - - private PropertyName findPropertyName(Annotated a) { - if (!(a instanceof AnnotatedMember)) { - return null; - } - - final SerializedName serializedName = a.getAnnotation(SerializedName.class); - if (serializedName != null) { - return PropertyName.construct(serializedName.value()); - } - - return null; - } - -} - diff --git a/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java b/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java deleted file mode 100644 index a30d9d0cf..000000000 --- a/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2017 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.mapping; - -import com.arangodb.entity.BaseDocument; -import com.arangodb.entity.BaseEdgeDocument; -import com.arangodb.jackson.dataformat.velocypack.internal.VPackParser; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.internal.util.DateUtil; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; - -import java.io.IOException; -import java.text.ParseException; -import java.util.Map; - -/** - * @author Mark Vollmary - */ -public class VPackDeserializers { - - public static final JsonDeserializer VPACK = new JsonDeserializer() { - @Override - public VPackSlice deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - if (p instanceof VPackParser) { - final VPackSlice vpack = ((VPackParser) p).getVPack(); - // consume each element - if (vpack.isArray() || vpack.isObject()) { - for (int i = 0; i < vpack.size() + 1; i++) { - p.nextToken(); - } - } - return vpack; - } - return new VPackSlice(p.getBinaryValue()); - } - }; - - public static final JsonDeserializer UTIL_DATE = new JsonDeserializer() { - @Override - public java.util.Date deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - try { - return DateUtil.parse(p.getValueAsString()); - } catch (final ParseException e) { - throw new IOException(e); - } - } - }; - - public static final JsonDeserializer SQL_DATE = new JsonDeserializer() { - @Override - public java.sql.Date deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - try { - return new java.sql.Date(DateUtil.parse(p.getValueAsString()).getTime()); - } catch (final ParseException e) { - throw new IOException(e); - } - } - }; - - public static final JsonDeserializer SQL_TIMESTAMP = new JsonDeserializer() { - @Override - public java.sql.Timestamp deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - try { - return new java.sql.Timestamp(DateUtil.parse(p.getValueAsString()).getTime()); - } catch (final ParseException e) { - throw new IOException(e); - } - } - }; - - public static final JsonDeserializer BASE_DOCUMENT = new JsonDeserializer() { - @SuppressWarnings("unchecked") - @Override - public BaseDocument deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - return new BaseDocument(p.readValueAs(Map.class)); - } - }; - - public static final JsonDeserializer BASE_EDGE_DOCUMENT = new JsonDeserializer() { - @SuppressWarnings("unchecked") - @Override - public BaseEdgeDocument deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - return new BaseEdgeDocument(p.readValueAs(Map.class)); - } - }; - -} diff --git a/src/main/java/com/arangodb/internal/mapping/VPackSerializers.java b/src/main/java/com/arangodb/internal/mapping/VPackSerializers.java deleted file mode 100644 index eb4b4ad8f..000000000 --- a/src/main/java/com/arangodb/internal/mapping/VPackSerializers.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2017 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - - -package com.arangodb.internal.mapping; - -import com.arangodb.entity.BaseDocument; -import com.arangodb.entity.BaseEdgeDocument; -import com.arangodb.internal.DocumentFields; -import com.arangodb.jackson.dataformat.velocypack.internal.VPackGenerator; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.internal.util.DateUtil; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - -import java.io.IOException; -import java.sql.Date; -import java.sql.Timestamp; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Mark Vollmary - */ -public class VPackSerializers { - - public static final JsonSerializer VPACK = new JsonSerializer() { - @Override - public void serialize(final VPackSlice value, final JsonGenerator gen, final SerializerProvider serializers) - throws IOException { - if (gen instanceof VPackGenerator) { - ((VPackGenerator) gen).writeVPack(value); - } else { - gen.writeBinary(value.toByteArray()); - } - } - }; - - public static final JsonSerializer UTIL_DATE = new JsonSerializer() { - @Override - public void serialize(final java.util.Date value, final JsonGenerator gen, final SerializerProvider serializers) - throws IOException, JsonProcessingException { - gen.writeString(DateUtil.format(value)); - } - }; - - public static final JsonSerializer SQL_DATE = new JsonSerializer() { - @Override - public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider serializers) - throws IOException, JsonProcessingException { - gen.writeString(DateUtil.format(value)); - } - }; - - public static final JsonSerializer SQL_TIMESTAMP = new JsonSerializer() { - @Override - public void serialize(final Timestamp value, final JsonGenerator gen, final SerializerProvider serializers) - throws IOException, JsonProcessingException { - gen.writeString(DateUtil.format(value)); - } - }; - - public static final JsonSerializer BASE_DOCUMENT = new JsonSerializer() { - @Override - public void serialize(final BaseDocument value, final JsonGenerator gen, final SerializerProvider serializers) - throws IOException { - final Map doc = new HashMap<>(); - doc.putAll(value.getProperties()); - doc.put(DocumentFields.ID, value.getId()); - doc.put(DocumentFields.KEY, value.getKey()); - doc.put(DocumentFields.REV, value.getRevision()); - gen.writeObject(doc); - } - }; - - public static final JsonSerializer BASE_EDGE_DOCUMENT = new JsonSerializer() { - @Override - public void serialize( - final BaseEdgeDocument value, - final JsonGenerator gen, - final SerializerProvider serializers) throws IOException { - final Map doc = new HashMap<>(); - doc.putAll(value.getProperties()); - doc.put(DocumentFields.ID, value.getId()); - doc.put(DocumentFields.KEY, value.getKey()); - doc.put(DocumentFields.REV, value.getRevision()); - doc.put(DocumentFields.FROM, value.getFrom()); - doc.put(DocumentFields.TO, value.getTo()); - gen.writeObject(doc); - } - }; - -} diff --git a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java index eb7dd40e0..5d617c942 100644 --- a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java +++ b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java @@ -24,19 +24,14 @@ import com.arangodb.DbName; import com.arangodb.internal.ArangoExecutorSync; import com.arangodb.internal.util.HostUtils; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.SerdeUtils; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Mark Vollmary @@ -54,7 +49,7 @@ public class ExtendedHostResolver implements HostResolver { private final Integer acquireHostListInterval; private ArangoExecutorSync executor; - private ArangoSerialization arangoSerialization; + private InternalSerde arangoSerialization; public ExtendedHostResolver(final List hosts, final Integer maxConnections, @@ -69,13 +64,12 @@ public ExtendedHostResolver(final List hosts, final Integer maxConnections } @Override - public void init(ArangoExecutorSync executor, ArangoSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { this.executor = executor; this.arangoSerialization = arangoSerialization; } @Override - public HostSet resolve(boolean initial, boolean closeConnections) { if (!initial && isExpired()) { @@ -127,16 +121,12 @@ private Collection resolveFromServer() throws ArangoDBException { response = executor.execute( new Request(DbName.SYSTEM, RequestType.GET, "/_api/cluster/endpoints"), response1 -> { - final VPackSlice field = response1.getBody().get("endpoints"); - Collection endpoints; - if (field.isNone()) { - endpoints = Collections.emptyList(); - } else { - final Collection> tmp = arangoSerialization.deserialize(field, Collection.class); - endpoints = new ArrayList<>(); - for (final Map map : tmp) { - endpoints.add(map.get("endpoint")); - } + final List> tmp = arangoSerialization.deserialize(response1.getBody(), "/endpoints", + SerdeUtils.INSTANCE.constructParametricType(List.class, + SerdeUtils.INSTANCE.constructParametricType(Map.class, String.class, String.class))); + Collection endpoints = new ArrayList<>(); + for (final Map map : tmp) { + endpoints.add(map.get("endpoint")); } return endpoints; }, null); diff --git a/src/main/java/com/arangodb/internal/net/HostResolver.java b/src/main/java/com/arangodb/internal/net/HostResolver.java index 85bdd2038..b05f6e419 100644 --- a/src/main/java/com/arangodb/internal/net/HostResolver.java +++ b/src/main/java/com/arangodb/internal/net/HostResolver.java @@ -21,14 +21,14 @@ package com.arangodb.internal.net; import com.arangodb.internal.ArangoExecutorSync; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; /** * @author Mark Vollmary */ public interface HostResolver { - void init(ArangoExecutorSync executorSync, ArangoSerialization arangoSerialization); + void init(ArangoExecutorSync executorSync, InternalSerde arangoSerialization); HostSet resolve(boolean initial, boolean closeConnections); diff --git a/src/main/java/com/arangodb/internal/net/SimpleHostResolver.java b/src/main/java/com/arangodb/internal/net/SimpleHostResolver.java index e139e3866..23740938d 100644 --- a/src/main/java/com/arangodb/internal/net/SimpleHostResolver.java +++ b/src/main/java/com/arangodb/internal/net/SimpleHostResolver.java @@ -21,7 +21,7 @@ package com.arangodb.internal.net; import com.arangodb.internal.ArangoExecutorSync; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import java.util.List; @@ -38,7 +38,7 @@ public SimpleHostResolver(final List hosts) { } @Override - public void init(ArangoExecutorSync executor, ArangoSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { } diff --git a/src/main/java/com/arangodb/internal/util/ArangoDeserializerImpl.java b/src/main/java/com/arangodb/internal/util/ArangoDeserializerImpl.java deleted file mode 100644 index 79fa9025b..000000000 --- a/src/main/java/com/arangodb/internal/util/ArangoDeserializerImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.util; - -import com.arangodb.ArangoDBException; -import com.arangodb.util.ArangoDeserializer; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackParser; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.exception.VPackException; - -import java.lang.reflect.Type; - -/** - * @author Mark Vollmary - */ -public class ArangoDeserializerImpl implements ArangoDeserializer { - - private final VPack vpacker; - private final VPackParser vpackParser; - - public ArangoDeserializerImpl(final VPack vpacker, final VPackParser vpackParser) { - super(); - this.vpacker = vpacker; - this.vpackParser = vpackParser; - } - - @Override - @SuppressWarnings("unchecked") - public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { - try { - final T doc; - if (type == String.class && !vpack.isString() && !vpack.isNull()) { - doc = (T) vpackParser.toJson(vpack, true); - } else { - doc = vpacker.deserialize(vpack, type); - } - return doc; - } catch (final VPackException e) { - throw new ArangoDBException(e); - } - } -} diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java b/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java deleted file mode 100644 index 035c2dc92..000000000 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2018 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.util; - -import com.arangodb.util.ArangoSerialization; - -/** - * @author Mark Vollmary - */ -public class ArangoSerializationFactory { - - public enum Serializer { - INTERNAL, CUSTOM - } - - private final ArangoSerialization interal; - private final ArangoSerialization custom; - - public ArangoSerializationFactory(final ArangoSerialization interal, final ArangoSerialization custom) { - super(); - this.interal = interal; - this.custom = custom; - } - - public ArangoSerialization get(final Serializer serializer) { - switch (serializer) { - case CUSTOM: - return custom; - case INTERNAL: - default: - return interal; - } - } - -} diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializerImpl.java b/src/main/java/com/arangodb/internal/util/ArangoSerializerImpl.java deleted file mode 100644 index 7561622ce..000000000 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializerImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.util; - -import com.arangodb.ArangoDBException; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPack.SerializeOptions; -import com.arangodb.velocypack.VPackParser; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.exception.VPackException; - -import java.util.Iterator; - -/** - * @author Mark Vollmary - */ -public class ArangoSerializerImpl implements ArangoSerializer { - - private final VPack vpacker; - private final VPack vpackerNull; - private final VPackParser vpackParser; - - public ArangoSerializerImpl(final VPack vpacker, final VPack vpackerNull, final VPackParser vpackParser) { - super(); - this.vpacker = vpacker; - this.vpackerNull = vpackerNull; - this.vpackParser = vpackParser; - } - - @Override - public VPackSlice serialize(final Object entity) throws ArangoDBException { - return serialize(entity, new ArangoSerializer.Options()); - } - - @SuppressWarnings("unchecked") - @Override - public VPackSlice serialize(final Object entity, final Options options) throws ArangoDBException { - if (options.getType() == null) { - options.type(entity.getClass()); - } - try { - final VPackSlice vpack; - final Class type = entity.getClass(); - final boolean serializeNullValues = options.isSerializeNullValues(); - if (String.class.isAssignableFrom(type)) { - vpack = vpackParser.fromJson((String) entity, serializeNullValues); - } else if (options.isStringAsJson() && Iterable.class.isAssignableFrom(type)) { - final Iterator iterator = ((Iterable) entity).iterator(); - if (iterator.hasNext() && String.class.isAssignableFrom(iterator.next().getClass())) { - vpack = vpackParser.fromJson((Iterable) entity, serializeNullValues); - } else { - final VPack vp = serializeNullValues ? vpackerNull : vpacker; - vpack = vp.serialize(entity, - new SerializeOptions().type(options.getType()).additionalFields(options.getAdditionalFields())); - } - } else { - final VPack vp = serializeNullValues ? vpackerNull : vpacker; - vpack = vp.serialize(entity, - new SerializeOptions().type(options.getType()).additionalFields(options.getAdditionalFields())); - } - return vpack; - } catch (final VPackException e) { - throw new ArangoDBException(e); - } - } - -} diff --git a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java deleted file mode 100644 index f77f2ee49..000000000 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.util; - -import com.arangodb.ArangoDBException; -import com.arangodb.util.ArangoDeserializer; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPackSlice; - -import java.lang.reflect.Type; - -/** - * @author Mark Vollmary - */ -public class DefaultArangoSerialization implements ArangoSerialization { - - private final ArangoSerializer serializer; - private final ArangoDeserializer deserializer; - - public DefaultArangoSerialization(final ArangoSerializer serializer, final ArangoDeserializer deserializer) { - super(); - this.serializer = serializer; - this.deserializer = deserializer; - } - - @Override - public VPackSlice serialize(final Object entity) throws ArangoDBException { - return serializer.serialize(entity); - } - - @Override - public VPackSlice serialize(final Object entity, final Options options) throws ArangoDBException { - return serializer.serialize(entity, options); - } - - @Override - public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { - return deserializer.deserialize(vpack, type); - } - -} diff --git a/src/main/java/com/arangodb/internal/util/ResponseUtils.java b/src/main/java/com/arangodb/internal/util/ResponseUtils.java index 0cc5e38cb..ea70a9272 100644 --- a/src/main/java/com/arangodb/internal/util/ResponseUtils.java +++ b/src/main/java/com/arangodb/internal/util/ResponseUtils.java @@ -24,8 +24,7 @@ import com.arangodb.entity.ErrorEntity; import com.arangodb.internal.ArangoErrors; import com.arangodb.internal.net.ArangoDBRedirectException; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.exception.VPackParserException; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Response; import java.util.concurrent.TimeoutException; @@ -43,26 +42,22 @@ private ResponseUtils() { super(); } - public static void checkError(final ArangoSerialization util, final Response response) throws ArangoDBException { - try { - final int responseCode = response.getResponseCode(); - if (responseCode >= ERROR_STATUS) { - if (responseCode == ERROR_INTERNAL && response.getMeta().containsKey(HEADER_ENDPOINT)) { - throw new ArangoDBRedirectException(String.format("Response Code: %s", responseCode), - response.getMeta().get(HEADER_ENDPOINT)); - } else if (response.getBody() != null) { - final ErrorEntity errorEntity = util.deserialize(response.getBody(), ErrorEntity.class); - ArangoDBException e = new ArangoDBException(errorEntity); - if(ArangoErrors.QUEUE_TIME_VIOLATED.equals(e.getErrorNum())){ - throw new ArangoDBException(new TimeoutException().initCause(e)); - } - throw e; - } else { - throw new ArangoDBException(String.format("Response Code: %s", responseCode), responseCode); + public static void checkError(final InternalSerde util, final Response response) throws ArangoDBException { + final int responseCode = response.getResponseCode(); + if (responseCode >= ERROR_STATUS) { + if (responseCode == ERROR_INTERNAL && response.getMeta().containsKey(HEADER_ENDPOINT)) { + throw new ArangoDBRedirectException(String.format("Response Code: %s", responseCode), + response.getMeta().get(HEADER_ENDPOINT)); + } else if (response.getBody() != null) { + final ErrorEntity errorEntity = util.deserialize(response.getBody(), ErrorEntity.class); + ArangoDBException e = new ArangoDBException(errorEntity); + if (ArangoErrors.QUEUE_TIME_VIOLATED.equals(e.getErrorNum())) { + throw new ArangoDBException(new TimeoutException().initCause(e)); } + throw e; + } else { + throw new ArangoDBException(String.format("Response Code: %s", responseCode), responseCode); } - } catch (final VPackParserException e) { - throw new ArangoDBException(e); } } } diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java deleted file mode 100644 index 2e8849214..000000000 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.velocypack; - -import com.arangodb.entity.BaseDocument; -import com.arangodb.entity.BaseEdgeDocument; -import com.arangodb.entity.CollectionStatus; -import com.arangodb.entity.CollectionType; -import com.arangodb.entity.License; -import com.arangodb.entity.LogLevel; -import com.arangodb.entity.Permissions; -import com.arangodb.entity.QueryExecutionState; -import com.arangodb.entity.ReplicationFactor; -import com.arangodb.entity.ViewEntity; -import com.arangodb.entity.ViewType; -import com.arangodb.entity.arangosearch.AnalyzerType; -import com.arangodb.entity.arangosearch.ArangoSearchCompression; -import com.arangodb.entity.arangosearch.ArangoSearchProperties; -import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; -import com.arangodb.entity.arangosearch.CollectionLink; -import com.arangodb.entity.arangosearch.ConsolidationPolicy; -import com.arangodb.entity.arangosearch.ConsolidationType; -import com.arangodb.entity.arangosearch.FieldLink; -import com.arangodb.entity.arangosearch.PrimarySort; -import com.arangodb.entity.arangosearch.StoreValuesType; -import com.arangodb.entity.arangosearch.StoredValue; -import com.arangodb.entity.arangosearch.analyzer.*; -import com.arangodb.model.CollectionSchema; -import com.arangodb.model.ZKDIndexOptions; -import com.arangodb.velocypack.VPackDeserializer; -import com.arangodb.velocypack.VPackParser; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocystream.Response; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.Map.Entry; - -/** - * @author Mark Vollmary - */ -public class VPackDeserializers { - - private static final Logger LOGGER = LoggerFactory.getLogger(VPackDeserializers.class); - private static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; - - public static final VPackDeserializer RESPONSE = (parent, vpack, context) -> { - final Response response = new Response(); - response.setVersion(vpack.get(0).getAsInt()); - response.setType(vpack.get(1).getAsInt()); - response.setResponseCode(vpack.get(2).getAsInt()); - if (vpack.size() > 3) { - response.setMeta(context.deserialize(vpack.get(3), Map.class)); - } - return response; - }; - - public static final VPackDeserializer COLLECTION_TYPE = (parent, vpack, context) -> CollectionType.fromType(vpack.getAsInt()); - - public static final VPackDeserializer COLLECTION_STATUS = (parent, vpack, context) -> CollectionStatus.fromStatus(vpack.getAsInt()); - - @SuppressWarnings("unchecked") - public static final VPackDeserializer BASE_DOCUMENT = (parent, vpack, context) -> new BaseDocument((Map) context.deserialize(vpack, Map.class)); - - public static final VPackDeserializer SEARCH_ANALYZER = (parent, vpack, context) -> { - AnalyzerType type = context.deserialize(vpack.get("type"), AnalyzerType.class); - switch (type) { - case identity: - return context.deserialize(vpack, IdentityAnalyzer.class); - case text: - return context.deserialize(vpack, TextAnalyzer.class); - case ngram: - return context.deserialize(vpack, NGramAnalyzer.class); - case delimiter: - return context.deserialize(vpack, DelimiterAnalyzer.class); - case stem: - return context.deserialize(vpack, StemAnalyzer.class); - case norm: - return context.deserialize(vpack, NormAnalyzer.class); - case pipeline: - return context.deserialize(vpack, PipelineAnalyzer.class); - case stopwords: - return context.deserialize(vpack, StopwordsAnalyzer.class); - case aql: - return context.deserialize(vpack, AQLAnalyzer.class); - case geojson: - return context.deserialize(vpack, GeoJSONAnalyzer.class); - case geopoint: - return context.deserialize(vpack, GeoPointAnalyzer.class); - case segmentation: - return context.deserialize(vpack, SegmentationAnalyzer.class); - case collation: - return context.deserialize(vpack, CollationAnalyzer.class); - default: - throw new IllegalArgumentException("Unknown analyzer type: " + type); - } - }; - - @SuppressWarnings("unchecked") - public static final VPackDeserializer BASE_EDGE_DOCUMENT = (parent, vpack, context) -> new BaseEdgeDocument((Map) context.deserialize(vpack, Map.class)); - - public static final VPackDeserializer DATE_STRING = (parent, vpack, context) -> { - try { - return new SimpleDateFormat(DATE_TIME_FORMAT).parse(vpack.getAsString()); - } catch (final ParseException e) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("got ParseException for date string: " + vpack.getAsString()); - } - } - return null; - }; - - public static final VPackDeserializer LOG_LEVEL = (parent, vpack, context) -> LogLevel.fromLevel(vpack.getAsInt()); - - public static final VPackDeserializer LICENSE = (parent, vpack, context) -> License.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH)); - - public static final VPackDeserializer PERMISSIONS = (parent, vpack, context) -> Permissions.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH)); - - public static final VPackDeserializer QUERY_EXECUTION_STATE = (parent, vpack, context) -> QueryExecutionState.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH).replaceAll(" ", "_")); - - public static final VPackDeserializer REPLICATION_FACTOR = (parent, vpack, context) -> { - final ReplicationFactor replicationFactor = new ReplicationFactor(); - if (vpack.isString() && vpack.getAsString().equals("satellite")) { - replicationFactor.setSatellite(true); - } else { - replicationFactor.setReplicationFactor(vpack.getAsInt()); - } - return replicationFactor; - }; - - public static final VPackDeserializer VIEW_TYPE = (parent, vpack, context) -> "arangosearch".equals(vpack.getAsString()) ? ViewType.ARANGO_SEARCH - : ViewType.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH)); - - public static final VPackDeserializer ARANGO_SEARCH_PROPERTIES = (parent, vpack, context) -> { - final ArangoSearchProperties properties = new ArangoSearchProperties(); - final VPackSlice consolidationIntervalMsec = vpack.get("consolidationIntervalMsec"); - if (consolidationIntervalMsec.isInteger()) { - properties.setConsolidationIntervalMsec(consolidationIntervalMsec.getAsLong()); - } - - final VPackSlice commitIntervalMsec = vpack.get("commitIntervalMsec"); - if (commitIntervalMsec.isInteger()) { - properties.setCommitIntervalMsec(commitIntervalMsec.getAsLong()); - } - - final VPackSlice cleanupIntervalStep = vpack.get("cleanupIntervalStep"); - if (cleanupIntervalStep.isInteger()) { - properties.setCleanupIntervalStep(cleanupIntervalStep.getAsLong()); - } - - final VPackSlice consolidationPolicy = vpack.get("consolidationPolicy"); - if (consolidationPolicy.isObject()) { - properties.setConsolidationPolicy( - context.deserialize(consolidationPolicy, ConsolidationPolicy.class)); - } - - final VPackSlice links = vpack.get("links"); - if (links.isObject()) { - final Iterator> collectionIterator = links.objectIterator(); - for (; collectionIterator.hasNext(); ) { - final Entry entry = collectionIterator.next(); - final VPackSlice value = entry.getValue(); - final CollectionLink link = CollectionLink.on(entry.getKey()); - final VPackSlice analyzers = value.get("analyzers"); - if (analyzers.isArray()) { - final Iterator analyzerIterator = analyzers.arrayIterator(); - for (; analyzerIterator.hasNext(); ) { - link.analyzers(analyzerIterator.next().getAsString()); - } - } - final VPackSlice includeAllFields = value.get("includeAllFields"); - if (includeAllFields.isBoolean()) { - link.includeAllFields(includeAllFields.getAsBoolean()); - } - final VPackSlice trackListPositions = value.get("trackListPositions"); - if (trackListPositions.isBoolean()) { - link.trackListPositions(trackListPositions.getAsBoolean()); - } - final VPackSlice storeValues = value.get("storeValues"); - if (storeValues.isString()) { - link.storeValues(StoreValuesType.valueOf(storeValues.getAsString().toUpperCase(Locale.ENGLISH))); - } - final VPackSlice fields = value.get("fields"); - if (fields.isObject()) { - final Iterator> fieldsIterator = fields.objectIterator(); - for (; fieldsIterator.hasNext(); ) { - link.fields(deserializeField(fieldsIterator.next())); - } - } - properties.addLink(link); - } - } - - final VPackSlice primarySorts = vpack.get("primarySort"); - if (primarySorts.isArray()) { - final Iterator primarySortsIterator = primarySorts.arrayIterator(); - for (; primarySortsIterator.hasNext(); ) { - final VPackSlice entry = primarySortsIterator.next(); - if (entry.isObject()) { - if (entry.get("field").isString() && entry.get("asc").isBoolean()) { - final PrimarySort primarySort = PrimarySort.on(entry.get("field").getAsString()); - primarySort.ascending(entry.get("asc").getAsBoolean()); - properties.addPrimarySort(primarySort); - } - } - } - } - - final VPackSlice primarySortCompression = vpack.get("primarySortCompression"); - if (primarySortCompression.isString()) { - properties.setPrimarySortCompression(ArangoSearchCompression.valueOf(primarySortCompression.getAsString())); - } - - final VPackSlice storedValues = vpack.get("storedValues"); - if (storedValues.isArray()) { - final Iterator storedValueIterator = storedValues.arrayIterator(); - for (; storedValueIterator.hasNext(); ) { - final VPackSlice entry = storedValueIterator.next(); - if (entry.isObject()) { - VPackSlice fields = entry.get("fields"); - VPackSlice compression = entry.get("compression"); - if (fields.isArray() && compression.isString()) { - final Iterator fieldsIterator = fields.arrayIterator(); - List fieldsList = new ArrayList<>(); - fieldsIterator.forEachRemaining(it -> fieldsList.add(it.getAsString())); - properties.addStoredValues(new StoredValue(fieldsList, ArangoSearchCompression.valueOf(compression.getAsString()))); - } - } - } - } - - return properties; - }; - - protected static FieldLink deserializeField(final Entry field) { - final VPackSlice value = field.getValue(); - final FieldLink link = FieldLink.on(field.getKey()); - final VPackSlice analyzers = value.get("analyzers"); - if (analyzers.isArray()) { - final Iterator analyzerIterator = analyzers.arrayIterator(); - for (; analyzerIterator.hasNext(); ) { - link.analyzers(analyzerIterator.next().getAsString()); - } - } - final VPackSlice includeAllFields = value.get("includeAllFields"); - if (includeAllFields.isBoolean()) { - link.includeAllFields(includeAllFields.getAsBoolean()); - } - final VPackSlice trackListPositions = value.get("trackListPositions"); - if (trackListPositions.isBoolean()) { - link.trackListPositions(trackListPositions.getAsBoolean()); - } - final VPackSlice storeValues = value.get("storeValues"); - if (storeValues.isString()) { - link.storeValues(StoreValuesType.valueOf(storeValues.getAsString().toUpperCase(Locale.ENGLISH))); - } - final VPackSlice fields = value.get("fields"); - if (fields.isObject()) { - final Iterator> fieldsIterator = fields.objectIterator(); - for (; fieldsIterator.hasNext(); ) { - link.fields(deserializeField(fieldsIterator.next())); - } - } - return link; - } - - public static final VPackDeserializer ARANGO_SEARCH_PROPERTIES_ENTITY = (parent, vpack, context) -> { - final ViewEntity entity = context.deserialize(vpack, ViewEntity.class); - final ArangoSearchProperties properties = context.deserialize(vpack, ArangoSearchProperties.class); - return new ArangoSearchPropertiesEntity(entity.getId(), - entity.getName(), entity.getType(), properties); - }; - - public static final VPackDeserializer CONSOLIDATE = (parent, vpack, context) -> { - final VPackSlice type = vpack.get("type"); - if (type.isString()) { - final ConsolidationPolicy consolidate = ConsolidationPolicy - .of(ConsolidationType.valueOf(type.getAsString().toUpperCase(Locale.ENGLISH))); - final VPackSlice threshold = vpack.get("threshold"); - if (threshold.isNumber()) { - consolidate.threshold(threshold.getAsDouble()); - } - final VPackSlice segmentThreshold = vpack.get("segmentThreshold"); - if (segmentThreshold.isInteger()) { - consolidate.segmentThreshold(segmentThreshold.getAsLong()); - } - return consolidate; - } - return null; - }; - - public static final VPackDeserializer COLLECTION_VALIDATION = (parent, vpack, context) -> { - VPackParser parser = new VPackParser.Builder().build(); - CollectionSchema collectionValidation = new CollectionSchema(); - collectionValidation.setLevel(CollectionSchema.Level.of(vpack.get("level").getAsString())); - collectionValidation.setRule(parser.toJson(vpack.get("rule"), true)); - collectionValidation.setMessage(vpack.get("message").getAsString()); - return collectionValidation; - }; - - public static final VPackDeserializer ZKD_FIELD_VALUE_TYPES = - (parent, vpack, context) -> ZKDIndexOptions.FieldValueTypes.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH)); - - -} diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java deleted file mode 100644 index ca86c5946..000000000 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.velocypack; - -import com.arangodb.entity.*; -import com.arangodb.entity.arangosearch.ArangoSearchProperties; -import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; -import com.arangodb.entity.arangosearch.ConsolidationPolicy; -import com.arangodb.entity.arangosearch.ConsolidationType; -import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; -import com.arangodb.internal.DocumentFields; -import com.arangodb.internal.velocystream.internal.AuthenticationRequest; -import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; -import com.arangodb.model.CollectionSchema; -import com.arangodb.model.ZKDIndexOptions; -import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions; -import com.arangodb.velocypack.VPackModule; -import com.arangodb.velocypack.VPackParserModule; -import com.arangodb.velocypack.VPackParserSetupContext; -import com.arangodb.velocypack.VPackSetupContext; -import com.arangodb.velocystream.Request; -import com.arangodb.velocystream.Response; - -import java.lang.annotation.Annotation; -import java.util.Date; - -/** - * @author Mark Vollmary - */ -public class VPackDriverModule implements VPackModule, VPackParserModule { - - @Override - public > void setup(final C context) { - context.fieldNamingStrategy(field -> { - for (Annotation annotation : field.getAnnotations()) { - if (annotation instanceof Id) { - return DocumentFields.ID; - } else if (annotation instanceof Key) { - return DocumentFields.KEY; - } else if (annotation instanceof Rev) { - return DocumentFields.REV; - } else if (annotation instanceof From) { - return DocumentFields.FROM; - } else if (annotation instanceof To) { - return DocumentFields.TO; - } - } - return field.getName(); - }); - context.registerSerializer(Request.class, VPackSerializers.REQUEST); - context.registerSerializer(AuthenticationRequest.class, VPackSerializers.AUTH_REQUEST); - context.registerSerializer(JwtAuthenticationRequest.class, VPackSerializers.JWT_AUTH_REQUEST); - context.registerSerializer(CollectionType.class, VPackSerializers.COLLECTION_TYPE); - context.registerSerializer(BaseDocument.class, VPackSerializers.BASE_DOCUMENT); - context.registerSerializer(BaseEdgeDocument.class, VPackSerializers.BASE_EDGE_DOCUMENT); - context.registerSerializer(LogLevel.class, VPackSerializers.LOG_LEVEL); - context.registerSerializer(Permissions.class, VPackSerializers.PERMISSIONS); - context.registerSerializer(ReplicationFactor.class, VPackSerializers.REPLICATION_FACTOR); - context.registerSerializer(ViewType.class, VPackSerializers.VIEW_TYPE); - context.registerSerializer(ArangoSearchPropertiesOptions.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES_OPTIONS); - context.registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES); - context.registerSerializer(ConsolidationType.class, VPackSerializers.CONSOLIDATE_TYPE); - context.registerSerializer(CollectionSchema.class, VPackSerializers.COLLECTION_VALIDATION); - context.registerSerializer(ZKDIndexOptions.FieldValueTypes.class, VPackSerializers.ZKD_FIELD_VALUE_TYPES); - - context.registerDeserializer(Response.class, VPackDeserializers.RESPONSE); - context.registerDeserializer(CollectionType.class, VPackDeserializers.COLLECTION_TYPE); - context.registerDeserializer(CollectionStatus.class, VPackDeserializers.COLLECTION_STATUS); - context.registerDeserializer(BaseDocument.class, VPackDeserializers.BASE_DOCUMENT); - context.registerDeserializer(SearchAnalyzer.class, VPackDeserializers.SEARCH_ANALYZER); - context.registerDeserializer(BaseEdgeDocument.class, VPackDeserializers.BASE_EDGE_DOCUMENT); - context.registerDeserializer(QueryEntity.PROPERTY_STARTED, Date.class, VPackDeserializers.DATE_STRING); - context.registerDeserializer(LogLevel.class, VPackDeserializers.LOG_LEVEL); - context.registerDeserializer(License.class, VPackDeserializers.LICENSE); - context.registerDeserializer(Permissions.class, VPackDeserializers.PERMISSIONS); - context.registerDeserializer(QueryExecutionState.class, VPackDeserializers.QUERY_EXECUTION_STATE); - context.registerDeserializer(ReplicationFactor.class, VPackDeserializers.REPLICATION_FACTOR); - context.registerDeserializer(ViewType.class, VPackDeserializers.VIEW_TYPE); - context.registerDeserializer(ArangoSearchProperties.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES); - context.registerDeserializer(ArangoSearchPropertiesEntity.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY); - context.registerDeserializer(ConsolidationPolicy.class, VPackDeserializers.CONSOLIDATE); - context.registerDeserializer(CollectionSchema.class, VPackDeserializers.COLLECTION_VALIDATION); - context.registerDeserializer(ZKDIndexOptions.FieldValueTypes.class, VPackDeserializers.ZKD_FIELD_VALUE_TYPES); - } - - @Override - public > void setup(final C context) { - - } - -} diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java deleted file mode 100644 index 399c8c8b5..000000000 --- a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.velocypack; - -import com.arangodb.entity.*; -import com.arangodb.entity.arangosearch.*; -import com.arangodb.internal.DocumentFields; -import com.arangodb.internal.velocystream.internal.AuthenticationRequest; -import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; -import com.arangodb.model.CollectionSchema; -import com.arangodb.model.ZKDIndexOptions; -import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions; -import com.arangodb.velocypack.*; -import com.arangodb.velocystream.Request; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; - -/** - * @author Mark Vollmary - */ -public class VPackSerializers { - - public static final VPackSerializer REQUEST = (builder, attribute, value, context) -> { - builder.add(attribute, ValueType.ARRAY); - builder.add(value.getVersion()); - builder.add(value.getType()); - builder.add(value.getDbName().get()); - builder.add(value.getRequestType().getType()); - builder.add(value.getRequest()); - builder.add(ValueType.OBJECT); - for (final Entry entry : value.getQueryParam().entrySet()) { - builder.add(entry.getKey(), entry.getValue()); - } - builder.close(); - builder.add(ValueType.OBJECT); - for (final Entry entry : value.getHeaderParam().entrySet()) { - builder.add(entry.getKey(), entry.getValue()); - } - builder.close(); - builder.close(); - }; - - public static final VPackSerializer AUTH_REQUEST = (builder, attribute, value, context) -> { - builder.add(attribute, ValueType.ARRAY); - builder.add(value.getVersion()); - builder.add(value.getType()); - builder.add(value.getEncryption()); - builder.add(value.getUser()); - builder.add(value.getPassword()); - builder.close(); - }; - - public static final VPackSerializer JWT_AUTH_REQUEST = (builder, attribute, value, context) -> { - builder.add(attribute, ValueType.ARRAY); - builder.add(value.getVersion()); - builder.add(value.getType()); - builder.add(value.getEncryption()); - builder.add(value.getToken()); - builder.close(); - }; - - public static final VPackSerializer COLLECTION_TYPE = (builder, attribute, value, context) -> builder.add(attribute, value.getType()); - - public static final VPackSerializer BASE_DOCUMENT = (builder, attribute, value, context) -> { - final Map doc = new HashMap<>(value.getProperties()); - doc.put(DocumentFields.ID, value.getId()); - doc.put(DocumentFields.KEY, value.getKey()); - doc.put(DocumentFields.REV, value.getRevision()); - context.serialize(builder, attribute, doc); - }; - - public static final VPackSerializer BASE_EDGE_DOCUMENT = (builder, attribute, value, context) -> { - final Map doc = new HashMap<>(value.getProperties()); - doc.put(DocumentFields.ID, value.getId()); - doc.put(DocumentFields.KEY, value.getKey()); - doc.put(DocumentFields.REV, value.getRevision()); - doc.put(DocumentFields.FROM, value.getFrom()); - doc.put(DocumentFields.TO, value.getTo()); - context.serialize(builder, attribute, doc); - }; - - public static final VPackSerializer LOG_LEVEL = (builder, attribute, value, context) -> builder.add(attribute, value.getLevel()); - - public static final VPackSerializer PERMISSIONS = (builder, attribute, value, context) -> builder.add(attribute, value.toString().toLowerCase(Locale.ENGLISH)); - - public static final VPackSerializer REPLICATION_FACTOR = (builder, attribute, value, context) -> { - final Boolean satellite = value.getSatellite(); - if (Boolean.TRUE == satellite) { - builder.add(attribute, "satellite"); - } else if (value.getReplicationFactor() != null) { - builder.add(attribute, value.getReplicationFactor()); - } - }; - - public static final VPackSerializer VIEW_TYPE = (builder, attribute, value, context) -> { - final String type = value == ViewType.ARANGO_SEARCH ? "arangosearch" : value.name().toLowerCase(Locale.ENGLISH); - builder.add(attribute, type); - }; - - public static final VPackSerializer ARANGO_SEARCH_PROPERTIES_OPTIONS = (builder, attribute, value, context) -> { - builder.add(ValueType.OBJECT); - context.serialize(builder, attribute, value.getProperties()); - builder.close(); - }; - - public static final VPackSerializer ARANGO_SEARCH_PROPERTIES = (builder, attribute, value, context) -> { - final Long consolidationIntervalMsec = value.getConsolidationIntervalMsec(); - if (consolidationIntervalMsec != null) { - builder.add("consolidationIntervalMsec", consolidationIntervalMsec); - } - - final Long commitIntervalMsec = value.getCommitIntervalMsec(); - if (commitIntervalMsec != null) { - builder.add("commitIntervalMsec", commitIntervalMsec); - } - - final Long cleanupIntervalStep = value.getCleanupIntervalStep(); - if (cleanupIntervalStep != null) { - builder.add("cleanupIntervalStep", cleanupIntervalStep); - } - context.serialize(builder, "consolidationPolicy", value.getConsolidationPolicy()); - - final Collection links = value.getLinks(); - if (!links.isEmpty()) { - builder.add("links", ValueType.OBJECT); - for (final CollectionLink collectionLink : links) { - builder.add(collectionLink.getName(), ValueType.OBJECT); - final Collection analyzers = collectionLink.getAnalyzers(); - if (!analyzers.isEmpty()) { - builder.add("analyzers", ValueType.ARRAY); - for (final String analyzer : analyzers) { - builder.add(analyzer); - } - builder.close(); - } - final Boolean includeAllFields = collectionLink.getIncludeAllFields(); - if (includeAllFields != null) { - builder.add("includeAllFields", includeAllFields); - } - final Boolean trackListPositions = collectionLink.getTrackListPositions(); - if (trackListPositions != null) { - builder.add("trackListPositions", trackListPositions); - } - final StoreValuesType storeValues = collectionLink.getStoreValues(); - if (storeValues != null) { - builder.add("storeValues", storeValues.name().toLowerCase(Locale.ENGLISH)); - } - serializeFieldLinks(builder, collectionLink.getFields()); - builder.close(); - } - builder.close(); - } - - final Collection primarySorts = value.getPrimarySort(); - if (!primarySorts.isEmpty()) { - builder.add("primarySort", ValueType.ARRAY); // open array - for (final PrimarySort primarySort : primarySorts) { - builder.add(ValueType.OBJECT); // open object - builder.add("field", primarySort.getFieldName()); - builder.add("asc", primarySort.getAscending()); - builder.close(); // close object - } - builder.close(); // close array - } - - final ArangoSearchCompression primarySortCompression = value.getPrimarySortCompression(); - if (primarySortCompression != null) { - builder.add("primarySortCompression", primarySortCompression.getValue()); - } - - final Collection storedValues = value.getStoredValues(); - if (!storedValues.isEmpty()) { - builder.add("storedValues", ValueType.ARRAY); // open array - for (final StoredValue storedValue : storedValues) { - builder.add(ValueType.OBJECT); // open object - builder.add("fields", ValueType.ARRAY); - for (final String field : storedValue.getFields()) { - builder.add(field); - } - builder.close(); - if (storedValue.getCompression() != null) { - builder.add("compression", storedValue.getCompression().getValue()); - } - builder.close(); // close object - } - builder.close(); // close array - } - - }; - - private static void serializeFieldLinks(final VPackBuilder builder, final Collection links) { - if (!links.isEmpty()) { - builder.add("fields", ValueType.OBJECT); - for (final FieldLink fieldLink : links) { - builder.add(fieldLink.getName(), ValueType.OBJECT); - final Collection analyzers = fieldLink.getAnalyzers(); - if (!analyzers.isEmpty()) { - builder.add("analyzers", ValueType.ARRAY); - for (final String analyzer : analyzers) { - builder.add(analyzer); - } - builder.close(); - } - final Boolean includeAllFields = fieldLink.getIncludeAllFields(); - if (includeAllFields != null) { - builder.add("includeAllFields", includeAllFields); - } - final Boolean trackListPositions = fieldLink.getTrackListPositions(); - if (trackListPositions != null) { - builder.add("trackListPositions", trackListPositions); - } - final StoreValuesType storeValues = fieldLink.getStoreValues(); - if (storeValues != null) { - builder.add("storeValues", storeValues.name().toLowerCase(Locale.ENGLISH)); - } - serializeFieldLinks(builder, fieldLink.getFields()); - builder.close(); - } - builder.close(); - } - } - - public static final VPackSerializer CONSOLIDATE_TYPE = (builder, attribute, value, context) -> builder.add(attribute, value.toString().toLowerCase(Locale.ENGLISH)); - - public static final VPackSerializer COLLECTION_VALIDATION = (builder, attribute, value, context) -> { - VPackParser parser = new VPackParser.Builder().build(); - VPackSlice rule = value.getRule() != null ? parser.fromJson(value.getRule(), true) : null; - final Map doc = new HashMap<>(); - doc.put("message", value.getMessage()); - doc.put("level", value.getLevel() != null ? value.getLevel().getValue() : null); - doc.put("rule", rule); - context.serialize(builder, attribute, doc); - }; - - public static final VPackSerializer ZKD_FIELD_VALUE_TYPES = - (builder, attribute, value, context) -> builder.add(attribute, value.name().toLowerCase(Locale.ENGLISH)); - -} diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java index 0cb2faea1..3f6c7267b 100644 --- a/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java +++ b/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java @@ -31,7 +31,7 @@ import com.arangodb.internal.velocystream.internal.Chunk; import com.arangodb.internal.velocystream.internal.Message; import com.arangodb.internal.velocystream.internal.VstConnection; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.exception.VPackParserException; import com.arangodb.velocystream.Request; @@ -56,7 +56,7 @@ public abstract class VstCommunication implements Cl private static final Logger LOGGER = LoggerFactory.getLogger(VstCommunication.class); protected static final AtomicLong mId = new AtomicLong(0L); - protected final ArangoSerialization util; + protected final InternalSerde util; protected final String user; protected final String password; @@ -66,7 +66,7 @@ public abstract class VstCommunication implements Cl protected final HostHandler hostHandler; protected VstCommunication(final Integer timeout, final String user, final String password, final String jwt, - final Boolean useSsl, final SSLContext sslContext, final ArangoSerialization util, + final Boolean useSsl, final SSLContext sslContext, final InternalSerde util, final Integer chunksize, final HostHandler hostHandler) { this.user = user; this.password = password; @@ -158,9 +158,9 @@ protected void checkError(final Response response) throws ArangoDBException { } protected Response createResponse(final Message message) throws VPackParserException { - final Response response = util.deserialize(message.getHead(), Response.class); + final Response response = util.deserialize(message.getHead().toByteArray(), Response.class); if (message.getBody() != null) { - response.setBody(message.getBody()); + response.setBody(message.getBody().toByteArray()); } return response; } diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java index e01e22bc2..84289e60b 100644 --- a/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java +++ b/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java @@ -30,7 +30,7 @@ import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; import com.arangodb.internal.velocystream.internal.Message; import com.arangodb.internal.velocystream.internal.VstConnectionSync; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocypack.exception.VPackParserException; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; @@ -116,7 +116,7 @@ public Builder connectionTtl(final Long connectionTtl) { return this; } - public VstCommunication build(final ArangoSerialization util) { + public VstCommunication build(final InternalSerde util) { return new VstCommunicationSync(hostHandler, timeout, user, password, jwt, useSsl, sslContext, util, chunksize, maxConnections, connectionTtl); } @@ -125,7 +125,7 @@ public VstCommunication build(final ArangoSerializa protected VstCommunicationSync(final HostHandler hostHandler, final Integer timeout, final String user, final String password, final String jwt, final Boolean useSsl, - final SSLContext sslContext, final ArangoSerialization util, + final SSLContext sslContext, final InternalSerde util, final Integer chunksize, final Integer maxConnections, final Long ttl) { super(timeout, user, password, jwt, useSsl, sslContext, util, chunksize, hostHandler); } diff --git a/src/main/java/com/arangodb/internal/velocystream/internal/Message.java b/src/main/java/com/arangodb/internal/velocystream/internal/Message.java index 6ad13259c..5a2e74724 100644 --- a/src/main/java/com/arangodb/internal/velocystream/internal/Message.java +++ b/src/main/java/com/arangodb/internal/velocystream/internal/Message.java @@ -45,11 +45,11 @@ public Message(final long id, final byte[] chunkBuffer) throws BufferUnderflowEx } } - public Message(final long id, final VPackSlice head, final VPackSlice body) { + public Message(final long id, final byte[] head, final byte[] body) { super(); this.id = id; - this.head = head; - this.body = body; + this.head = new VPackSlice(head); + this.body = body != null ? new VPackSlice(body) : null; } public long getId() { diff --git a/src/main/java/com/arangodb/internal/velocystream/internal/VstConnection.java b/src/main/java/com/arangodb/internal/velocystream/internal/VstConnection.java index 266820773..142660a8b 100644 --- a/src/main/java/com/arangodb/internal/velocystream/internal/VstConnection.java +++ b/src/main/java/com/arangodb/internal/velocystream/internal/VstConnection.java @@ -87,7 +87,7 @@ public abstract class VstConnection implements Connection { private final String connectionName; - private final VPackSlice keepAliveRequest = new VPackBuilder() + private final byte[] keepAliveRequest = new VPackBuilder() .add(ValueType.ARRAY) .add(1) .add(1) @@ -99,7 +99,8 @@ public abstract class VstConnection implements Connection { .add(ValueType.OBJECT) .close() .close() - .slice(); + .slice() + .toByteArray(); protected VstConnection(final HostDescription host, final Integer timeout, @@ -130,7 +131,7 @@ protected T sendKeepAlive() { } return write(message, Collections.singleton(new Chunk( id, 0, 1, -1, - 0, keepAliveRequest.getByteSize() + 0, keepAliveRequest.length ))); } diff --git a/src/main/java/com/arangodb/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java deleted file mode 100644 index 132a724b2..000000000 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2017 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.mapping; - -import com.arangodb.ArangoDBException; -import com.arangodb.entity.BaseDocument; -import com.arangodb.entity.BaseEdgeDocument; -import com.arangodb.internal.mapping.ArangoAnnotationIntrospector; -import com.arangodb.internal.mapping.VPackDeserializers; -import com.arangodb.internal.mapping.VPackSerializers; -import com.arangodb.jackson.dataformat.velocypack.VPackMapper; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; -import com.arangodb.velocypack.VPackParser; -import com.arangodb.velocypack.VPackSlice; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.PropertyAccessor; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.module.SimpleModule; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Arrays; -import java.util.Iterator; - -/** - * @author Mark Vollmary - */ -public class ArangoJack implements ArangoSerialization { - - public interface ConfigureFunction { - void configure(ObjectMapper mapper); - } - - private final ObjectMapper vpackMapper; - private final ObjectMapper vpackMapperNull; - private final ObjectMapper jsonMapper; - private final VPackParser vpackParser; - - private static final class ArangoModule extends SimpleModule { - @Override - public void setupModule(SetupContext context) { - super.setupModule(context); - context.insertAnnotationIntrospector(new ArangoAnnotationIntrospector()); - } - } - - static VPackMapper createDefaultMapper() { - final VPackMapper mapper = new VPackMapper(); - mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); - - final SimpleModule module = new ArangoJack.ArangoModule(); - module.addSerializer(VPackSlice.class, VPackSerializers.VPACK); - module.addSerializer(java.util.Date.class, VPackSerializers.UTIL_DATE); - module.addSerializer(java.sql.Date.class, VPackSerializers.SQL_DATE); - module.addSerializer(java.sql.Timestamp.class, VPackSerializers.SQL_TIMESTAMP); - module.addSerializer(BaseDocument.class, VPackSerializers.BASE_DOCUMENT); - module.addSerializer(BaseEdgeDocument.class, VPackSerializers.BASE_EDGE_DOCUMENT); - - module.addDeserializer(VPackSlice.class, VPackDeserializers.VPACK); - module.addDeserializer(java.util.Date.class, VPackDeserializers.UTIL_DATE); - module.addDeserializer(java.sql.Date.class, VPackDeserializers.SQL_DATE); - module.addDeserializer(java.sql.Timestamp.class, VPackDeserializers.SQL_TIMESTAMP); - module.addDeserializer(BaseDocument.class, VPackDeserializers.BASE_DOCUMENT); - module.addDeserializer(BaseEdgeDocument.class, VPackDeserializers.BASE_EDGE_DOCUMENT); - - mapper.registerModule(module); - return mapper; - } - - public ArangoJack() { - this(createDefaultMapper()); - } - - /** - * @param mapper configured VPackMapper to use. A defensive copy is created and used. - */ - public ArangoJack(final VPackMapper mapper) { - super(); - vpackMapper = mapper.copy().setSerializationInclusion(Include.NON_NULL); - vpackMapperNull = mapper.copy().setSerializationInclusion(Include.ALWAYS); - jsonMapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL); - vpackParser = new VPackParser.Builder().build(); - } - - public void configure(final ArangoJack.ConfigureFunction f) { - f.configure(vpackMapper); - f.configure(vpackMapperNull); - f.configure(jsonMapper); - } - - @Override - public VPackSlice serialize(final Object entity) throws ArangoDBException { - return serialize(entity, new ArangoSerializer.Options()); - } - - @SuppressWarnings("unchecked") - @Override - public VPackSlice serialize(final Object entity, final Options options) throws ArangoDBException { - if (options.getType() == null) { - options.type(entity.getClass()); - } - try { - final VPackSlice vpack; - final Class type = entity.getClass(); - final boolean serializeNullValues = options.isSerializeNullValues(); - if (String.class.isAssignableFrom(type)) { - vpack = vpackParser.fromJson((String) entity, serializeNullValues); - } else if (options.isStringAsJson() && Iterable.class.isAssignableFrom(type)) { - final Iterator iterator = Iterable.class.cast(entity).iterator(); - if (iterator.hasNext() && String.class.isAssignableFrom(iterator.next().getClass())) { - vpack = vpackParser.fromJson((Iterable) entity, serializeNullValues); - } else { - final ObjectMapper vp = serializeNullValues ? vpackMapperNull : vpackMapper; - vpack = new VPackSlice(vp.writeValueAsBytes(entity)); - } - } else { - final ObjectMapper vp = serializeNullValues ? vpackMapperNull : vpackMapper; - vpack = new VPackSlice(vp.writeValueAsBytes(entity)); - } - return vpack; - } catch (final JsonProcessingException e) { - throw new ArangoDBException(e); - } - } - - @SuppressWarnings("unchecked") - @Override - public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { - try { - final T doc; - if (type == String.class && !vpack.isString() && !vpack.isNull()) { - final JsonNode node = vpackMapper.readTree( - Arrays.copyOfRange(vpack.getBuffer(), vpack.getStart(), vpack.getStart() + vpack.getByteSize())); - doc = (T) jsonMapper.writeValueAsString(node); - } else { - doc = vpackMapper.readValue(vpack.getBuffer(), vpack.getStart(), vpack.getStart() + vpack.getByteSize(), - (Class) type); - } - return doc; - } catch (final IOException e) { - throw new ArangoDBException(e); - } - } - -} diff --git a/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java b/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java index a1897c491..ebd50373e 100644 --- a/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java +++ b/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class AqlFunctionCreateOptions { +public final class AqlFunctionCreateOptions { private String name; private String code; @@ -39,12 +39,12 @@ public AqlFunctionCreateOptions() { * @param name the fully qualified name of the user functions * @return options */ - protected AqlFunctionCreateOptions name(final String name) { + AqlFunctionCreateOptions name(final String name) { this.name = name; return this; } - protected String getName() { + public String getName() { return name; } @@ -52,12 +52,12 @@ protected String getName() { * @param code a string representation of the function body * @return options */ - protected AqlFunctionCreateOptions code(final String code) { + AqlFunctionCreateOptions code(final String code) { this.code = code; return this; } - protected String getCode() { + public String getCode() { return code; } diff --git a/src/main/java/com/arangodb/model/AqlFunctionDeleteOptions.java b/src/main/java/com/arangodb/model/AqlFunctionDeleteOptions.java index dd3cd2901..f821c7e78 100644 --- a/src/main/java/com/arangodb/model/AqlFunctionDeleteOptions.java +++ b/src/main/java/com/arangodb/model/AqlFunctionDeleteOptions.java @@ -26,7 +26,7 @@ * "https://www.arangodb.com/docs/stable/http/aql-user-functions.html#remove-existing-aql-user-function">API * Documentation */ -public class AqlFunctionDeleteOptions { +public final class AqlFunctionDeleteOptions { private Boolean group; diff --git a/src/main/java/com/arangodb/model/AqlFunctionGetOptions.java b/src/main/java/com/arangodb/model/AqlFunctionGetOptions.java index 2b4713ddb..e5c5dcd95 100644 --- a/src/main/java/com/arangodb/model/AqlFunctionGetOptions.java +++ b/src/main/java/com/arangodb/model/AqlFunctionGetOptions.java @@ -26,7 +26,7 @@ * "https://www.arangodb.com/docs/stable/http/aql-user-functions.html#return-registered-aql-user-functions">API * Documentation */ -public class AqlFunctionGetOptions { +public final class AqlFunctionGetOptions { private String namespace; diff --git a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java index 27b962465..7a1b9b448 100644 --- a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java @@ -20,18 +20,19 @@ package com.arangodb.model; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.UserDataInside; import java.util.Collection; +import java.util.Map; /** * @author Mark Vollmary * @author Michele Rastelli * @see API Documentation */ -public class AqlQueryExplainOptions { +public final class AqlQueryExplainOptions { - private VPackSlice bindVars; + private Map bindVars; private String query; private Options options; @@ -39,7 +40,8 @@ public AqlQueryExplainOptions() { super(); } - protected VPackSlice getBindVars() { + @UserDataInside + public Map getBindVars() { return bindVars; } @@ -47,12 +49,12 @@ protected VPackSlice getBindVars() { * @param bindVars key/value pairs representing the bind parameters * @return options */ - protected AqlQueryExplainOptions bindVars(final VPackSlice bindVars) { + AqlQueryExplainOptions bindVars(final Map bindVars) { this.bindVars = bindVars; return this; } - protected String getQuery() { + public String getQuery() { return query; } @@ -60,7 +62,7 @@ protected String getQuery() { * @param query the query which you want explained * @return options */ - protected AqlQueryExplainOptions query(final String query) { + AqlQueryExplainOptions query(final String query) { this.query = query; return this; } @@ -114,12 +116,12 @@ private Options getOptions() { return options; } - public static class Options { + public static final class Options { private Optimizer optimizer; private Integer maxNumberOfPlans; private Boolean allPlans; - protected Optimizer getOptimizer() { + public Optimizer getOptimizer() { if (optimizer == null) { optimizer = new Optimizer(); } @@ -127,7 +129,7 @@ protected Optimizer getOptimizer() { } } - public static class Optimizer { + public static final class Optimizer { private Collection rules; } } diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 52e344663..9fe1e4a65 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -20,13 +20,11 @@ package com.arangodb.model; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.annotations.Expose; +import com.arangodb.serde.UserDataInside; -import java.io.Serializable; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Map; /** * @author Mark Vollmary @@ -34,20 +32,16 @@ * @see API * Documentation */ -public class AqlQueryOptions implements Serializable { - - private static final long serialVersionUID = 1L; +public final class AqlQueryOptions { private Boolean count; private Integer ttl; private Integer batchSize; private Boolean cache; - private Boolean fillBlockCache; private Long memoryLimit; - private VPackSlice bindVars; + private Map bindVars; private String query; private Options options; - @Expose(serialize = false) private Boolean allowDirtyRead; private String streamTransactionId; @@ -133,7 +127,7 @@ public AqlQueryOptions cache(final Boolean cache) { } public Boolean getFillBlockCache() { - return options != null ? options.fillBlockCache : null; + return getOptions().fillBlockCache; } /** @@ -152,20 +146,21 @@ public AqlQueryOptions fillBlockCache(final Boolean fillBlockCache) { return this; } - protected VPackSlice getBindVars() { + @UserDataInside + public Map getBindVars() { return bindVars; } /** - * @param bindVars key/value pairs representing the bind parameters + * @param bindVarsBytes serialized bind parameters * @return options */ - protected AqlQueryOptions bindVars(final VPackSlice bindVars) { - this.bindVars = bindVars; + AqlQueryOptions bindVars(final Map bindVarsBytes) { + this.bindVars = bindVarsBytes; return this; } - protected String getQuery() { + public String getQuery() { return query; } @@ -173,13 +168,13 @@ protected String getQuery() { * @param query the query which you want parse * @return options */ - protected AqlQueryOptions query(final String query) { + public AqlQueryOptions query(final String query) { this.query = query; return this; } public Boolean getFailOnWarning() { - return options != null ? options.failOnWarning : null; + return getOptions().failOnWarning; } /** @@ -210,7 +205,7 @@ public AqlQueryOptions maxRuntime(final Double timeout) { * profile of the extra return attribute if the query result is not served from the query cache. */ public Boolean getProfile() { - return options != null ? options.profile : null; + return getOptions().profile; } /** @@ -224,7 +219,7 @@ public AqlQueryOptions profile(final Boolean profile) { } public Long getMaxTransactionSize() { - return options != null ? options.maxTransactionSize : null; + return getOptions().maxTransactionSize; } /** @@ -238,7 +233,7 @@ public AqlQueryOptions maxTransactionSize(final Long maxTransactionSize) { } public Long getMaxWarningCount() { - return options != null ? options.maxWarningCount : null; + return getOptions().maxWarningCount; } /** @@ -253,7 +248,7 @@ public AqlQueryOptions maxWarningCount(final Long maxWarningCount) { } public Long getIntermediateCommitCount() { - return options != null ? options.intermediateCommitCount : null; + return getOptions().intermediateCommitCount; } /** @@ -268,7 +263,7 @@ public AqlQueryOptions intermediateCommitCount(final Long intermediateCommitCoun } public Long getIntermediateCommitSize() { - return options != null ? options.intermediateCommitSize : null; + return getOptions().intermediateCommitSize; } /** @@ -283,7 +278,7 @@ public AqlQueryOptions intermediateCommitSize(final Long intermediateCommitSize) } public Double getSatelliteSyncWait() { - return options != null ? options.satelliteSyncWait : null; + return getOptions().satelliteSyncWait; } /** @@ -299,7 +294,7 @@ public AqlQueryOptions satelliteSyncWait(final Double satelliteSyncWait) { } public Boolean getSkipInaccessibleCollections() { - return options != null ? options.skipInaccessibleCollections : null; + return getOptions().skipInaccessibleCollections; } /** @@ -318,7 +313,7 @@ public AqlQueryOptions skipInaccessibleCollections(final Boolean skipInaccessibl } public Boolean getFullCount() { - return options != null ? options.fullCount : null; + return getOptions().fullCount; } /** @@ -339,7 +334,7 @@ public AqlQueryOptions fullCount(final Boolean fullCount) { } public Integer getMaxPlans() { - return options != null ? options.maxPlans : null; + return getOptions().maxPlans; } /** @@ -352,7 +347,7 @@ public AqlQueryOptions maxPlans(final Integer maxPlans) { } public Collection getRules() { - return options != null ? options.optimizer != null ? options.optimizer.rules : null : null; + return getOptions().getOptimizer().rules; } /** @@ -367,7 +362,7 @@ public AqlQueryOptions rules(final Collection rules) { } public Boolean getStream() { - return options != null ? options.stream : null; + return getOptions().stream; } /** @@ -389,7 +384,7 @@ public AqlQueryOptions stream(final Boolean stream) { } public Collection getShardIds() { - return options != null ? options.shardIds : null; + return getOptions().shardIds; } /** @@ -399,20 +394,18 @@ public Collection getShardIds() { * @return options */ public AqlQueryOptions shardIds(final String... shardIds) { - getOptions().getShardIds().addAll(Arrays.asList(shardIds)); + getOptions().shardIds = Arrays.asList(shardIds); return this; } - private Options getOptions() { + public Options getOptions() { if (options == null) { options = new Options(); } return options; } - public static class Options implements Serializable { - - private static final long serialVersionUID = 1L; + public static final class Options { private Boolean failOnWarning; private Boolean profile; @@ -430,24 +423,77 @@ public static class Options implements Serializable { private Double maxRuntime; private Boolean fillBlockCache; - protected Optimizer getOptimizer() { + public Boolean getFailOnWarning() { + return failOnWarning; + } + + public Boolean getProfile() { + return profile; + } + + public Long getMaxTransactionSize() { + return maxTransactionSize; + } + + public Long getMaxWarningCount() { + return maxWarningCount; + } + + public Long getIntermediateCommitCount() { + return intermediateCommitCount; + } + + public Long getIntermediateCommitSize() { + return intermediateCommitSize; + } + + public Double getSatelliteSyncWait() { + return satelliteSyncWait; + } + + public Boolean getSkipInaccessibleCollections() { + return skipInaccessibleCollections; + } + + public Boolean getFullCount() { + return fullCount; + } + + public Integer getMaxPlans() { + return maxPlans; + } + + public Boolean getStream() { + return stream; + } + + public Double getMaxRuntime() { + return maxRuntime; + } + + public Boolean getFillBlockCache() { + return fillBlockCache; + } + + public Optimizer getOptimizer() { if (optimizer == null) { optimizer = new Optimizer(); } return optimizer; } - protected Collection getShardIds() { - if (shardIds == null) { - shardIds = new ArrayList<>(); - } + public Collection getShardIds() { return shardIds; } } - public static class Optimizer { + public static final class Optimizer { private Collection rules; + + public Collection getRules() { + return rules; + } } /** diff --git a/src/main/java/com/arangodb/model/AqlQueryParseOptions.java b/src/main/java/com/arangodb/model/AqlQueryParseOptions.java index b2194779c..a5a4b22b1 100644 --- a/src/main/java/com/arangodb/model/AqlQueryParseOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryParseOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class AqlQueryParseOptions { +public final class AqlQueryParseOptions { private String query; @@ -32,7 +32,7 @@ public AqlQueryParseOptions() { super(); } - protected String getQuery() { + public String getQuery() { return query; } @@ -40,7 +40,7 @@ protected String getQuery() { * @param query the query which you want parse * @return options */ - protected AqlQueryParseOptions query(final String query) { + AqlQueryParseOptions query(final String query) { this.query = query; return this; } diff --git a/src/main/java/com/arangodb/model/CollectionCountOptions.java b/src/main/java/com/arangodb/model/CollectionCountOptions.java index 6030f1db8..edfc64eaa 100644 --- a/src/main/java/com/arangodb/model/CollectionCountOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCountOptions.java @@ -23,7 +23,7 @@ /** * @author Michele Rastelli */ -public class CollectionCountOptions { +public final class CollectionCountOptions { private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index e4c425aa0..fa7ebc9db 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -25,19 +25,22 @@ import com.arangodb.entity.KeyType; import com.arangodb.entity.ReplicationFactor; +import java.util.Arrays; +import java.util.Collection; + /** * @author Mark Vollmary * @see API * Documentation */ -public class CollectionCreateOptions { +public final class CollectionCreateOptions { private String name; - private final ReplicationFactor replicationFactor; + private ReplicationFactor replicationFactor; private Integer writeConcern; private KeyOptions keyOptions; private Boolean waitForSync; - private String[] shardKeys; + private Collection shardKeys; private Integer numberOfShards; private Boolean isSystem; private CollectionType type; @@ -50,10 +53,9 @@ public class CollectionCreateOptions { public CollectionCreateOptions() { super(); - replicationFactor = new ReplicationFactor(); } - protected String getName() { + public String getName() { return name; } @@ -61,13 +63,13 @@ protected String getName() { * @param name The name of the collection * @return options */ - protected CollectionCreateOptions name(final String name) { + CollectionCreateOptions name(final String name) { this.name = name; return this; } - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } /** @@ -80,8 +82,18 @@ public Integer getReplicationFactor() { * reported. * @return options */ - public CollectionCreateOptions replicationFactor(final Integer replicationFactor) { - this.replicationFactor.setReplicationFactor(replicationFactor); + public CollectionCreateOptions replicationFactor(final ReplicationFactor replicationFactor) { + this.replicationFactor = replicationFactor; + return this; + } + + public CollectionCreateOptions replicationFactor(int replicationFactor) { + this.replicationFactor = ReplicationFactor.of(replicationFactor); + return this; + } + + public CollectionCreateOptions satellite() { + this.replicationFactor = ReplicationFactor.ofSatellite(); return this; } @@ -102,20 +114,6 @@ public CollectionCreateOptions writeConcern(final Integer writeConcern) { return this; } - public Boolean getSatellite() { - return replicationFactor.getSatellite(); - } - - /** - * @param satellite If the true the collection is created as a satellite collection. In this case - * {@link #replicationFactor(Integer)} is ignored. - * @return options - */ - public CollectionCreateOptions satellite(final Boolean satellite) { - this.replicationFactor.setSatellite(satellite); - return this; - } - public KeyOptions getKeyOptions() { return keyOptions; } @@ -153,7 +151,7 @@ public CollectionCreateOptions waitForSync(final Boolean waitForSync) { return this; } - public String[] getShardKeys() { + public Collection getShardKeys() { return shardKeys; } @@ -166,7 +164,7 @@ public String[] getShardKeys() { * @return options */ public CollectionCreateOptions shardKeys(final String... shardKeys) { - this.shardKeys = shardKeys; + this.shardKeys = Arrays.asList(shardKeys); return this; } diff --git a/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java b/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java index d4ca9ac8e..c10909e65 100644 --- a/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java +++ b/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class CollectionPropertiesOptions { +public final class CollectionPropertiesOptions { private Boolean waitForSync; private CollectionSchema schema; diff --git a/src/main/java/com/arangodb/model/CollectionRenameOptions.java b/src/main/java/com/arangodb/model/CollectionRenameOptions.java index 1c7896c79..11f531e28 100644 --- a/src/main/java/com/arangodb/model/CollectionRenameOptions.java +++ b/src/main/java/com/arangodb/model/CollectionRenameOptions.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class CollectionRenameOptions { +public final class CollectionRenameOptions { private String name; @@ -39,7 +39,7 @@ public String getName() { * @param name The new name * @return options */ - protected CollectionRenameOptions name(final String name) { + CollectionRenameOptions name(final String name) { this.name = name; return this; } diff --git a/src/main/java/com/arangodb/model/CollectionSchema.java b/src/main/java/com/arangodb/model/CollectionSchema.java index 49b6fea85..40c5c539b 100644 --- a/src/main/java/com/arangodb/model/CollectionSchema.java +++ b/src/main/java/com/arangodb/model/CollectionSchema.java @@ -22,20 +22,18 @@ package com.arangodb.model; +import com.arangodb.serde.InternalDeserializers; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + /** * @author Michele Rastelli * @see API Documentation * @since ArangoDB 3.7 */ -public class CollectionSchema { - - /** - * Value to unset the collection schema on properties update {@link com.arangodb.ArangoCollection#changeProperties(CollectionPropertiesOptions)}. - */ - public static final CollectionSchema NULL_SCHEMA = new CollectionSchema() - .setLevel(null) - .setMessage(null) - .setRule(null); +public final class CollectionSchema { private String rule; private Level level; @@ -44,10 +42,12 @@ public class CollectionSchema { /** * @return JSON Schema description */ + @JsonSerialize(using = InternalSerializers.CollectionSchemaRuleSerializer.class) public String getRule() { return rule; } + @JsonDeserialize(using = InternalDeserializers.CollectionSchemaRuleDeserializer.class) public CollectionSchema setRule(String rule) { this.rule = rule; return this; @@ -82,11 +82,13 @@ public enum Level { /** * The rule is inactive and validation thus turned off. */ + @JsonProperty("none") NONE("none"), /** * Only newly inserted documents are validated. */ + @JsonProperty("new") NEW("new"), /** @@ -95,11 +97,13 @@ public enum Level { * but you want to stop the insertion of more invalid documents and prohibit that valid documents are changed to * invalid documents. */ + @JsonProperty("moderate") MODERATE("moderate"), /** * All new and modified document must strictly pass validation. No exceptions are made (default). */ + @JsonProperty("strict") STRICT("strict"); private final String value; diff --git a/src/main/java/com/arangodb/model/CollectionTruncateOptions.java b/src/main/java/com/arangodb/model/CollectionTruncateOptions.java index dff681273..1b089533e 100644 --- a/src/main/java/com/arangodb/model/CollectionTruncateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionTruncateOptions.java @@ -23,7 +23,7 @@ /** * @author Michele Rastelli */ -public class CollectionTruncateOptions { +public final class CollectionTruncateOptions { private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/CollectionsReadOptions.java b/src/main/java/com/arangodb/model/CollectionsReadOptions.java index cea7750d0..18f3ce42c 100644 --- a/src/main/java/com/arangodb/model/CollectionsReadOptions.java +++ b/src/main/java/com/arangodb/model/CollectionsReadOptions.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class CollectionsReadOptions { +public final class CollectionsReadOptions { private Boolean excludeSystem; diff --git a/src/main/java/com/arangodb/model/DBCreateOptions.java b/src/main/java/com/arangodb/model/DBCreateOptions.java index 1c9d6ed07..9b018c3fa 100644 --- a/src/main/java/com/arangodb/model/DBCreateOptions.java +++ b/src/main/java/com/arangodb/model/DBCreateOptions.java @@ -27,7 +27,7 @@ /** * @author Mark Vollmary */ -public class DBCreateOptions { +public final class DBCreateOptions { private Collection users; private String name; diff --git a/src/main/java/com/arangodb/model/DatabaseOptions.java b/src/main/java/com/arangodb/model/DatabaseOptions.java index 81052c6c5..68cfd83d0 100644 --- a/src/main/java/com/arangodb/model/DatabaseOptions.java +++ b/src/main/java/com/arangodb/model/DatabaseOptions.java @@ -26,29 +26,24 @@ * @author Michele Rastelli * @since ArangoDB 3.6.0 */ -public class DatabaseOptions { +public final class DatabaseOptions { - private final ReplicationFactor replicationFactor; + private ReplicationFactor replicationFactor; private Integer writeConcern; private String sharding; public DatabaseOptions() { super(); - replicationFactor = new ReplicationFactor(); } - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } public Integer getWriteConcern() { return writeConcern; } - public Boolean getSatellite() { - return this.replicationFactor.getSatellite(); - } - public String getSharding() { return sharding; } @@ -58,8 +53,18 @@ public String getSharding() { * @return options * @since ArangoDB 3.6.0 */ - public DatabaseOptions replicationFactor(final Integer replicationFactor) { - this.replicationFactor.setReplicationFactor(replicationFactor); + public DatabaseOptions replicationFactor(final ReplicationFactor replicationFactor) { + this.replicationFactor = replicationFactor; + return this; + } + + public DatabaseOptions replicationFactor(int replicationFactor) { + this.replicationFactor = ReplicationFactor.of(replicationFactor); + return this; + } + + public DatabaseOptions satellite() { + this.replicationFactor = ReplicationFactor.ofSatellite(); return this; } @@ -77,17 +82,6 @@ public DatabaseOptions writeConcern(final Integer writeConcern) { return this; } - /** - * @param satellite whether the collection is a satellite collection. Only in an enterprise cluster setup (else - * returning null). - * @return options - * @since ArangoDB 3.6.0 - */ - public DatabaseOptions satellite(final Boolean satellite) { - this.replicationFactor.setSatellite(satellite); - return this; - } - /** * @param sharding The sharding method to use for new collections in this database. * Valid values are: “”, “flexible”, or “single”. The first two are equivalent. diff --git a/src/main/java/com/arangodb/model/DatabaseUsersOptions.java b/src/main/java/com/arangodb/model/DatabaseUsersOptions.java index edc9175da..63d11e6c8 100644 --- a/src/main/java/com/arangodb/model/DatabaseUsersOptions.java +++ b/src/main/java/com/arangodb/model/DatabaseUsersOptions.java @@ -25,7 +25,7 @@ /** * @author Michele Rastelli */ -public class DatabaseUsersOptions { +public final class DatabaseUsersOptions { private String username; private Map extra; diff --git a/src/main/java/com/arangodb/model/DocumentCreateOptions.java b/src/main/java/com/arangodb/model/DocumentCreateOptions.java index 057a382e7..8d796966a 100644 --- a/src/main/java/com/arangodb/model/DocumentCreateOptions.java +++ b/src/main/java/com/arangodb/model/DocumentCreateOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class DocumentCreateOptions { +public final class DocumentCreateOptions { private Boolean waitForSync; private Boolean returnNew; diff --git a/src/main/java/com/arangodb/model/DocumentDeleteOptions.java b/src/main/java/com/arangodb/model/DocumentDeleteOptions.java index e0e566952..ba59aaf5e 100644 --- a/src/main/java/com/arangodb/model/DocumentDeleteOptions.java +++ b/src/main/java/com/arangodb/model/DocumentDeleteOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class DocumentDeleteOptions { +public final class DocumentDeleteOptions { private Boolean waitForSync; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/DocumentExistsOptions.java b/src/main/java/com/arangodb/model/DocumentExistsOptions.java index a790bf201..ec2a47c45 100644 --- a/src/main/java/com/arangodb/model/DocumentExistsOptions.java +++ b/src/main/java/com/arangodb/model/DocumentExistsOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class DocumentExistsOptions { +public final class DocumentExistsOptions { private String ifNoneMatch; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/DocumentImportOptions.java b/src/main/java/com/arangodb/model/DocumentImportOptions.java index b8a55e3ed..4cd40b71b 100644 --- a/src/main/java/com/arangodb/model/DocumentImportOptions.java +++ b/src/main/java/com/arangodb/model/DocumentImportOptions.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class DocumentImportOptions { +public final class DocumentImportOptions { public enum OnDuplicate { error, update, replace, ignore diff --git a/src/main/java/com/arangodb/model/DocumentReadOptions.java b/src/main/java/com/arangodb/model/DocumentReadOptions.java index b808f6ed4..1041b786c 100644 --- a/src/main/java/com/arangodb/model/DocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/DocumentReadOptions.java @@ -20,20 +20,17 @@ package com.arangodb.model; -import com.arangodb.velocypack.annotations.Expose; - /** * @author Mark Vollmary * @author Michele Rastelli * @see API * Documentation */ -public class DocumentReadOptions { +public final class DocumentReadOptions { private String ifNoneMatch; private String ifMatch; private boolean catchException; - @Expose(serialize = false) private Boolean allowDirtyRead; private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/DocumentReplaceOptions.java b/src/main/java/com/arangodb/model/DocumentReplaceOptions.java index 2646f847d..d32fb56c5 100644 --- a/src/main/java/com/arangodb/model/DocumentReplaceOptions.java +++ b/src/main/java/com/arangodb/model/DocumentReplaceOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class DocumentReplaceOptions { +public final class DocumentReplaceOptions { private Boolean waitForSync; private Boolean ignoreRevs; diff --git a/src/main/java/com/arangodb/model/DocumentUpdateOptions.java b/src/main/java/com/arangodb/model/DocumentUpdateOptions.java index 20d7b8cca..c1d74b837 100644 --- a/src/main/java/com/arangodb/model/DocumentUpdateOptions.java +++ b/src/main/java/com/arangodb/model/DocumentUpdateOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class DocumentUpdateOptions { +public final class DocumentUpdateOptions { private Boolean keepNull; private Boolean mergeObjects; @@ -35,7 +35,6 @@ public class DocumentUpdateOptions { private String ifMatch; private Boolean returnNew; private Boolean returnOld; - private Boolean serializeNull; private Boolean silent; private String streamTransactionId; @@ -142,21 +141,6 @@ public DocumentUpdateOptions returnOld(final Boolean returnOld) { return this; } - public Boolean getSerializeNull() { - return serializeNull; - } - - /** - * @param serializeNull By default, or if this is set to true, all fields of the document which have null values are - * serialized to VelocyPack otherwise they are excluded from serialization. Use this to update single - * fields from a stored document. - * @return options - */ - public DocumentUpdateOptions serializeNull(final Boolean serializeNull) { - this.serializeNull = serializeNull; - return this; - } - public Boolean getSilent() { return silent; } diff --git a/src/main/java/com/arangodb/model/EdgeCreateOptions.java b/src/main/java/com/arangodb/model/EdgeCreateOptions.java index 3f335cfb1..7e340bc25 100644 --- a/src/main/java/com/arangodb/model/EdgeCreateOptions.java +++ b/src/main/java/com/arangodb/model/EdgeCreateOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class EdgeCreateOptions { +public final class EdgeCreateOptions { private Boolean waitForSync; private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/EdgeDeleteOptions.java b/src/main/java/com/arangodb/model/EdgeDeleteOptions.java index 30d13c117..a82d68ec1 100644 --- a/src/main/java/com/arangodb/model/EdgeDeleteOptions.java +++ b/src/main/java/com/arangodb/model/EdgeDeleteOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class EdgeDeleteOptions { +public final class EdgeDeleteOptions { private Boolean waitForSync; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/EdgeReplaceOptions.java b/src/main/java/com/arangodb/model/EdgeReplaceOptions.java index 81f021ea0..e30b64ffc 100644 --- a/src/main/java/com/arangodb/model/EdgeReplaceOptions.java +++ b/src/main/java/com/arangodb/model/EdgeReplaceOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class EdgeReplaceOptions { +public final class EdgeReplaceOptions { private Boolean waitForSync; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/EdgeUpdateOptions.java b/src/main/java/com/arangodb/model/EdgeUpdateOptions.java index cb95ddd85..2ff7611fe 100644 --- a/src/main/java/com/arangodb/model/EdgeUpdateOptions.java +++ b/src/main/java/com/arangodb/model/EdgeUpdateOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class EdgeUpdateOptions { +public final class EdgeUpdateOptions { private Boolean keepNull; private Boolean waitForSync; diff --git a/src/main/java/com/arangodb/model/FulltextIndexOptions.java b/src/main/java/com/arangodb/model/FulltextIndexOptions.java index 9bf8f82a5..89bb478e3 100644 --- a/src/main/java/com/arangodb/model/FulltextIndexOptions.java +++ b/src/main/java/com/arangodb/model/FulltextIndexOptions.java @@ -27,7 +27,7 @@ * @see API * Documentation */ -public class FulltextIndexOptions extends IndexOptions { +public final class FulltextIndexOptions extends IndexOptions { private Iterable fields; private final IndexType type = IndexType.fulltext; @@ -38,11 +38,11 @@ public FulltextIndexOptions() { } @Override - protected FulltextIndexOptions getThis() { + FulltextIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -50,12 +50,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected FulltextIndexOptions fields(final Iterable fields) { + FulltextIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/GeoIndexOptions.java b/src/main/java/com/arangodb/model/GeoIndexOptions.java index 691ed0ec2..3b2fb9446 100644 --- a/src/main/java/com/arangodb/model/GeoIndexOptions.java +++ b/src/main/java/com/arangodb/model/GeoIndexOptions.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class GeoIndexOptions extends IndexOptions { +public final class GeoIndexOptions extends IndexOptions { private Iterable fields; private final IndexType type = IndexType.geo; @@ -37,11 +37,11 @@ public GeoIndexOptions() { } @Override - protected GeoIndexOptions getThis() { + GeoIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -49,12 +49,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected GeoIndexOptions fields(final Iterable fields) { + GeoIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index 6d75fb4e1..83cb05363 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -30,7 +30,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class GraphCreateOptions { +public final class GraphCreateOptions { private String name; private Collection edgeDefinitions; @@ -42,7 +42,7 @@ public GraphCreateOptions() { super(); } - protected String getName() { + public String getName() { return name; } @@ -50,7 +50,7 @@ protected String getName() { * @param name Name of the graph * @return options */ - protected GraphCreateOptions name(final String name) { + GraphCreateOptions name(final String name) { this.name = name; return this; } @@ -63,7 +63,7 @@ public Collection getEdgeDefinitions() { * @param edgeDefinitions An array of definitions for the edge * @return options */ - protected GraphCreateOptions edgeDefinitions(final Collection edgeDefinitions) { + GraphCreateOptions edgeDefinitions(final Collection edgeDefinitions) { this.edgeDefinitions = edgeDefinitions; return this; } @@ -109,8 +109,8 @@ public GraphCreateOptions isDisjoint(final Boolean isDisjoint) { return this; } - public Integer getReplicationFactor() { - return getOptions().replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return getOptions().replicationFactor; } /** @@ -123,23 +123,18 @@ public Integer getReplicationFactor() { * reported. * @return options */ - public GraphCreateOptions replicationFactor(final Integer replicationFactor) { - getOptions().replicationFactor.setReplicationFactor(replicationFactor); + public GraphCreateOptions replicationFactor(final ReplicationFactor replicationFactor) { + getOptions().setReplicationFactor(replicationFactor); return this; } - public Boolean getSatellite() { - return getOptions().replicationFactor.getSatellite(); + public GraphCreateOptions replicationFactor(int replicationFactor) { + getOptions().setReplicationFactor(ReplicationFactor.of(replicationFactor)); + return this; } - /** - * @param satellite If the true the graph is created as a satellite graph. In this case - * {@link #replicationFactor(Integer)} is ignored. - * @return options - * @since ArangoDB 3.7 - */ - public GraphCreateOptions satellite(final Boolean satellite) { - getOptions().replicationFactor.setSatellite(satellite); + public GraphCreateOptions satellite() { + getOptions().setReplicationFactor(ReplicationFactor.ofSatellite()); return this; } @@ -203,14 +198,14 @@ public GraphCreateOptions satellites(final String... satellites) { return this; } - private SmartOptions getOptions() { + public SmartOptions getOptions() { if (options == null) { options = new SmartOptions(); } return options; } - public static class SmartOptions { + public static final class SmartOptions { private ReplicationFactor replicationFactor; private Integer writeConcern; private Integer numberOfShards; @@ -220,23 +215,14 @@ public static class SmartOptions { public SmartOptions() { super(); - replicationFactor = new ReplicationFactor(); - } - - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); - } - - public void setReplicationFactor(final Integer replicationFactor) { - this.replicationFactor.setReplicationFactor(replicationFactor); } - public Boolean getSatellite() { - return replicationFactor.getSatellite(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } - public void setSatellite(final Boolean satellite) { - replicationFactor.setSatellite(satellite); + public void setReplicationFactor(final ReplicationFactor replicationFactor) { + this.replicationFactor = replicationFactor; } public Integer getWriteConcern() { diff --git a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java index 1e661f64d..7277b10df 100644 --- a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java @@ -20,17 +20,14 @@ package com.arangodb.model; -import com.arangodb.velocypack.annotations.Expose; - /** * @author Mark Vollmary */ -public class GraphDocumentReadOptions { +public final class GraphDocumentReadOptions { private String ifNoneMatch; private String ifMatch; private boolean catchException; - @Expose(serialize = false) private Boolean allowDirtyRead; private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 3af784ebb..1192f601c 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -29,7 +29,7 @@ * index. */ @Deprecated -public class HashIndexOptions extends IndexOptions { +public final class HashIndexOptions extends IndexOptions { private Iterable fields; private final IndexType type = IndexType.hash; @@ -43,11 +43,11 @@ public HashIndexOptions() { } @Override - protected HashIndexOptions getThis() { + HashIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -55,12 +55,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected HashIndexOptions fields(final Iterable fields) { + HashIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/IndexOptions.java b/src/main/java/com/arangodb/model/IndexOptions.java index 1132e1c8e..afd7240c1 100644 --- a/src/main/java/com/arangodb/model/IndexOptions.java +++ b/src/main/java/com/arangodb/model/IndexOptions.java @@ -23,7 +23,7 @@ /** * @author Heiko Kernbach *

- * This class is used for all index similarities + * This final class is used for all index similarities */ public abstract class IndexOptions { @@ -34,7 +34,7 @@ public IndexOptions() { super(); } - protected abstract T getThis(); + abstract T getThis(); /** * @param inBackground create the the index in the background @@ -59,7 +59,7 @@ public T name(final String name) { return getThis(); } - protected String getName() { + public String getName() { return name; } } diff --git a/src/main/java/com/arangodb/model/LogOptions.java b/src/main/java/com/arangodb/model/LogOptions.java index 9a37cdf08..944305f3e 100644 --- a/src/main/java/com/arangodb/model/LogOptions.java +++ b/src/main/java/com/arangodb/model/LogOptions.java @@ -28,7 +28,7 @@ * "https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#read-global-logs-from-the-server">API * Documentation */ -public class LogOptions { +public final class LogOptions { public static final String PROPERTY_UPTO = "upto"; public static final String PROPERTY_LEVEL = "level"; diff --git a/src/main/java/com/arangodb/model/OptionsBuilder.java b/src/main/java/com/arangodb/model/OptionsBuilder.java index ab99ad37f..f62a45d19 100644 --- a/src/main/java/com/arangodb/model/OptionsBuilder.java +++ b/src/main/java/com/arangodb/model/OptionsBuilder.java @@ -23,15 +23,15 @@ import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.Permissions; import com.arangodb.entity.ViewType; -import com.arangodb.velocypack.VPackSlice; import java.util.Collection; +import java.util.Map; /** * @author Mark Vollmary * @author Michele Rastelli */ -public class OptionsBuilder { +public final class OptionsBuilder { private OptionsBuilder() { super(); @@ -83,14 +83,14 @@ public static CollectionCreateOptions build(final CollectionCreateOptions option return options.name(name); } - public static AqlQueryOptions build(final AqlQueryOptions options, final String query, final VPackSlice bindVars) { + public static AqlQueryOptions build(final AqlQueryOptions options, final String query, final Map bindVars) { return options.query(query).bindVars(bindVars); } public static AqlQueryExplainOptions build( final AqlQueryExplainOptions options, final String query, - final VPackSlice bindVars) { + final Map bindVars) { return options.query(query).bindVars(bindVars); } diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index c9ba08c34..598054551 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -27,10 +27,10 @@ * @see API * Documentation */ -public class PersistentIndexOptions extends IndexOptions { +public final class PersistentIndexOptions extends IndexOptions { private Iterable fields; - protected final IndexType type = IndexType.persistent; + private final IndexType type = IndexType.persistent; private Boolean unique; private Boolean sparse; private Boolean deduplicate; @@ -41,11 +41,11 @@ public PersistentIndexOptions() { } @Override - protected PersistentIndexOptions getThis() { + PersistentIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -53,12 +53,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected PersistentIndexOptions fields(final Iterable fields) { + PersistentIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/QueueTimeSample.java b/src/main/java/com/arangodb/model/QueueTimeSample.java index 841221761..bfc1f2496 100644 --- a/src/main/java/com/arangodb/model/QueueTimeSample.java +++ b/src/main/java/com/arangodb/model/QueueTimeSample.java @@ -10,7 +10,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class QueueTimeSample { +public final class QueueTimeSample { /** * Unix-timestamp in milliseconds, recorded at client side. */ diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index 15f3dcdfe..1ab9babb5 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -29,7 +29,7 @@ * persistent index. */ @Deprecated -public class SkiplistIndexOptions extends IndexOptions { +public final class SkiplistIndexOptions extends IndexOptions { private Iterable fields; private final IndexType type = IndexType.skiplist; @@ -43,11 +43,11 @@ public SkiplistIndexOptions() { } @Override - protected SkiplistIndexOptions getThis() { + SkiplistIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -55,12 +55,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected SkiplistIndexOptions fields(final Iterable fields) { + SkiplistIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/StreamTransactionOptions.java b/src/main/java/com/arangodb/model/StreamTransactionOptions.java index 98f8b451d..9bcf5000e 100644 --- a/src/main/java/com/arangodb/model/StreamTransactionOptions.java +++ b/src/main/java/com/arangodb/model/StreamTransactionOptions.java @@ -26,7 +26,7 @@ * @see API Documentation * @since ArangoDB 3.5.0 */ -public class StreamTransactionOptions { +public final class StreamTransactionOptions { private final TransactionCollectionOptions collections; private Integer lockTimeout; @@ -39,6 +39,10 @@ public StreamTransactionOptions() { collections = new TransactionCollectionOptions(); } + public TransactionCollectionOptions getCollections() { + return collections; + } + public Integer getLockTimeout() { return lockTimeout; } diff --git a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java index d11d14220..ce1d4e466 100644 --- a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java @@ -27,7 +27,7 @@ * @author Mark Vollmary * @author Michele Rastelli */ -public class TransactionCollectionOptions { +public final class TransactionCollectionOptions { private Collection read; private Collection write; diff --git a/src/main/java/com/arangodb/model/TransactionOptions.java b/src/main/java/com/arangodb/model/TransactionOptions.java index e1226a1bd..19b5b2599 100644 --- a/src/main/java/com/arangodb/model/TransactionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class TransactionOptions { +public final class TransactionOptions { private String action; private Object params; @@ -40,7 +40,11 @@ public TransactionOptions() { collections = new TransactionCollectionOptions(); } - protected String getAction() { + public TransactionCollectionOptions getCollections() { + return collections; + } + + public String getAction() { return action; } @@ -48,7 +52,7 @@ protected String getAction() { * @param action the actual transaction operations to be executed, in the form of stringified JavaScript code * @return options */ - protected TransactionOptions action(final String action) { + TransactionOptions action(final String action) { this.action = action; return this; } diff --git a/src/main/java/com/arangodb/model/TtlIndexOptions.java b/src/main/java/com/arangodb/model/TtlIndexOptions.java index 59ee57e82..c599a614e 100644 --- a/src/main/java/com/arangodb/model/TtlIndexOptions.java +++ b/src/main/java/com/arangodb/model/TtlIndexOptions.java @@ -26,7 +26,7 @@ * @author Heiko Kernbach * @see API Documentation */ -public class TtlIndexOptions extends IndexOptions { +public final class TtlIndexOptions extends IndexOptions { private Iterable fields; private final IndexType type = IndexType.ttl; @@ -37,11 +37,11 @@ public TtlIndexOptions() { } @Override - protected TtlIndexOptions getThis() { + TtlIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -49,12 +49,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected TtlIndexOptions fields(final Iterable fields) { + TtlIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } @@ -67,7 +67,7 @@ public TtlIndexOptions expireAfter(final Integer expireAfter) { return this; } - protected Integer getExpireAfter() { + public Integer getExpireAfter() { return expireAfter; } diff --git a/src/main/java/com/arangodb/model/UserAccessOptions.java b/src/main/java/com/arangodb/model/UserAccessOptions.java index 85f86bc66..19c597ab7 100644 --- a/src/main/java/com/arangodb/model/UserAccessOptions.java +++ b/src/main/java/com/arangodb/model/UserAccessOptions.java @@ -25,7 +25,7 @@ /** * @author Mark Vollmary */ -public class UserAccessOptions { +public final class UserAccessOptions { private Permissions grant; @@ -33,11 +33,11 @@ public UserAccessOptions() { super(); } - protected Permissions getGrant() { + public Permissions getGrant() { return grant; } - protected UserAccessOptions grant(final Permissions grant) { + UserAccessOptions grant(final Permissions grant) { this.grant = grant; return this; } diff --git a/src/main/java/com/arangodb/model/UserCreateOptions.java b/src/main/java/com/arangodb/model/UserCreateOptions.java index 2ac216259..4279e60d6 100644 --- a/src/main/java/com/arangodb/model/UserCreateOptions.java +++ b/src/main/java/com/arangodb/model/UserCreateOptions.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class UserCreateOptions { +public final class UserCreateOptions { private String user; private String passwd; @@ -37,7 +37,7 @@ public UserCreateOptions() { super(); } - protected String getUser() { + public String getUser() { return user; } @@ -45,12 +45,12 @@ protected String getUser() { * @param user The name of the user * @return options */ - protected UserCreateOptions user(final String user) { + UserCreateOptions user(final String user) { this.user = user; return this; } - protected String getPasswd() { + public String getPasswd() { return passwd; } @@ -58,7 +58,7 @@ protected String getPasswd() { * @param passwd The user password * @return options */ - protected UserCreateOptions passwd(final String passwd) { + UserCreateOptions passwd(final String passwd) { this.passwd = passwd; return this; } diff --git a/src/main/java/com/arangodb/model/UserUpdateOptions.java b/src/main/java/com/arangodb/model/UserUpdateOptions.java index eec7fa2f4..09c3786c8 100644 --- a/src/main/java/com/arangodb/model/UserUpdateOptions.java +++ b/src/main/java/com/arangodb/model/UserUpdateOptions.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class UserUpdateOptions { +public final class UserUpdateOptions { private String passwd; private Boolean active; diff --git a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java index b79b8ed41..86fa34067 100644 --- a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java @@ -26,16 +26,16 @@ /** * @author Mark Vollmary */ -public class VertexCollectionCreateOptions { +public final class VertexCollectionCreateOptions { private String collection; - private Options options; + private final Options options = new Options(); public VertexCollectionCreateOptions() { super(); } - protected String getCollection() { + public String getCollection() { return collection; } @@ -43,11 +43,15 @@ protected String getCollection() { * @param collection The name of the collection * @return options */ - protected VertexCollectionCreateOptions collection(final String collection) { + VertexCollectionCreateOptions collection(final String collection) { this.collection = collection; return this; } + public Options getOptions() { + return options; + } + public Collection getSatellites() { return options.satellites; } @@ -60,13 +64,16 @@ public Collection getSatellites() { * @since ArangoDB 3.9.0 */ public VertexCollectionCreateOptions satellites(final String... satellites) { - options = new Options(); options.satellites = Arrays.asList(satellites); return this; } - public static class Options { + public static final class Options { private Collection satellites; + + public Collection getSatellites() { + return satellites; + } } } diff --git a/src/main/java/com/arangodb/model/VertexCreateOptions.java b/src/main/java/com/arangodb/model/VertexCreateOptions.java index d998aa590..156476a93 100644 --- a/src/main/java/com/arangodb/model/VertexCreateOptions.java +++ b/src/main/java/com/arangodb/model/VertexCreateOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class VertexCreateOptions { +public final class VertexCreateOptions { private Boolean waitForSync; private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/VertexDeleteOptions.java b/src/main/java/com/arangodb/model/VertexDeleteOptions.java index d52f58347..e43c6d016 100644 --- a/src/main/java/com/arangodb/model/VertexDeleteOptions.java +++ b/src/main/java/com/arangodb/model/VertexDeleteOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class VertexDeleteOptions { +public final class VertexDeleteOptions { private Boolean waitForSync; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/VertexReplaceOptions.java b/src/main/java/com/arangodb/model/VertexReplaceOptions.java index 5957b7235..9111f11e0 100644 --- a/src/main/java/com/arangodb/model/VertexReplaceOptions.java +++ b/src/main/java/com/arangodb/model/VertexReplaceOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class VertexReplaceOptions { +public final class VertexReplaceOptions { private Boolean waitForSync; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/VertexUpdateOptions.java b/src/main/java/com/arangodb/model/VertexUpdateOptions.java index 1e0478692..a66e9b450 100644 --- a/src/main/java/com/arangodb/model/VertexUpdateOptions.java +++ b/src/main/java/com/arangodb/model/VertexUpdateOptions.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class VertexUpdateOptions { +public final class VertexUpdateOptions { private Boolean keepNull; private Boolean waitForSync; diff --git a/src/main/java/com/arangodb/model/ViewCreateOptions.java b/src/main/java/com/arangodb/model/ViewCreateOptions.java index b2287a6de..8c11dd343 100644 --- a/src/main/java/com/arangodb/model/ViewCreateOptions.java +++ b/src/main/java/com/arangodb/model/ViewCreateOptions.java @@ -25,7 +25,7 @@ /** * @author Mark Vollmary */ -public class ViewCreateOptions { +public final class ViewCreateOptions { @SuppressWarnings("unused") private String name; @@ -36,14 +36,22 @@ public ViewCreateOptions() { super(); } - protected ViewCreateOptions name(final String name) { + ViewCreateOptions name(final String name) { this.name = name; return this; } - protected ViewCreateOptions type(final ViewType type) { + ViewCreateOptions type(final ViewType type) { this.type = type; return this; } + public String getName() { + return name; + } + + public ViewType getType() { + return type; + } + } diff --git a/src/main/java/com/arangodb/model/ViewRenameOptions.java b/src/main/java/com/arangodb/model/ViewRenameOptions.java index d67c5bf54..2f0ed5faf 100644 --- a/src/main/java/com/arangodb/model/ViewRenameOptions.java +++ b/src/main/java/com/arangodb/model/ViewRenameOptions.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class ViewRenameOptions { +public final class ViewRenameOptions { private String name; @@ -39,7 +39,7 @@ public String getName() { * @param name The new name * @return options */ - protected ViewRenameOptions name(final String name) { + ViewRenameOptions name(final String name) { this.name = name; return this; } diff --git a/src/main/java/com/arangodb/model/ZKDIndexOptions.java b/src/main/java/com/arangodb/model/ZKDIndexOptions.java index 4e570a9ad..aad739d86 100644 --- a/src/main/java/com/arangodb/model/ZKDIndexOptions.java +++ b/src/main/java/com/arangodb/model/ZKDIndexOptions.java @@ -21,16 +21,17 @@ package com.arangodb.model; import com.arangodb.entity.IndexType; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Michele Rastelli * @see API Documentation * @since ArangoDB 3.9 */ -public class ZKDIndexOptions extends IndexOptions { +public final class ZKDIndexOptions extends IndexOptions { private Iterable fields; - protected final IndexType type = IndexType.zkd; + final IndexType type = IndexType.zkd; private Boolean unique; private FieldValueTypes fieldValueTypes; @@ -39,11 +40,11 @@ public ZKDIndexOptions() { } @Override - protected ZKDIndexOptions getThis() { + ZKDIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -51,12 +52,12 @@ protected Iterable getFields() { * @param fields A list of attribute paths * @return options */ - protected ZKDIndexOptions fields(final Iterable fields) { + ZKDIndexOptions fields(final Iterable fields) { this.fields = fields; return this; } - protected IndexType getType() { + public IndexType getType() { return type; } @@ -87,6 +88,7 @@ public ZKDIndexOptions fieldValueTypes(final FieldValueTypes fieldValueTypes) { } public enum FieldValueTypes { + @JsonProperty("double") DOUBLE } diff --git a/src/main/java/com/arangodb/model/arangosearch/AnalyzerDeleteOptions.java b/src/main/java/com/arangodb/model/arangosearch/AnalyzerDeleteOptions.java index 62be6902c..776d3def1 100644 --- a/src/main/java/com/arangodb/model/arangosearch/AnalyzerDeleteOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/AnalyzerDeleteOptions.java @@ -23,7 +23,7 @@ /** * @author Michele Rastelli */ -public class AnalyzerDeleteOptions { +public final class AnalyzerDeleteOptions { private Boolean force; diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java index 2fcfe376b..5d810507a 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java @@ -22,25 +22,36 @@ import com.arangodb.entity.ViewType; import com.arangodb.entity.arangosearch.*; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.util.Arrays; +import java.util.Collection; /** * @author Mark Vollmary */ -public class ArangoSearchCreateOptions { +public final class ArangoSearchCreateOptions { @SuppressWarnings("unused") private String name; @SuppressWarnings("unused") private final ViewType type; - private final ArangoSearchProperties properties; + private Long consolidationIntervalMsec; + private Long commitIntervalMsec; + private Long cleanupIntervalStep; + private ConsolidationPolicy consolidationPolicy; + private Collection links; + private Collection primarySorts; + private ArangoSearchCompression primarySortCompression; + private Collection storedValues; public ArangoSearchCreateOptions() { super(); type = ViewType.ARANGO_SEARCH; - properties = new ArangoSearchProperties(); } - protected ArangoSearchCreateOptions name(final String name) { + ArangoSearchCreateOptions name(final String name) { this.name = name; return this; } @@ -54,7 +65,7 @@ protected ArangoSearchCreateOptions name(final String name) { * @return options */ public ArangoSearchCreateOptions consolidationIntervalMsec(final Long consolidationIntervalMsec) { - properties.setConsolidationIntervalMsec(consolidationIntervalMsec); + this.consolidationIntervalMsec = consolidationIntervalMsec; return this; } @@ -73,7 +84,7 @@ public ArangoSearchCreateOptions consolidationIntervalMsec(final Long consolidat * @return options */ public ArangoSearchCreateOptions commitIntervalMsec(final Long commitIntervalMsec) { - properties.setCommitIntervalMsec(commitIntervalMsec); + this.commitIntervalMsec = commitIntervalMsec; return this; } @@ -86,7 +97,7 @@ public ArangoSearchCreateOptions commitIntervalMsec(final Long commitIntervalMse * @return options */ public ArangoSearchCreateOptions cleanupIntervalStep(final Long cleanupIntervalStep) { - properties.setCleanupIntervalStep(cleanupIntervalStep); + this.cleanupIntervalStep = cleanupIntervalStep; return this; } @@ -95,7 +106,7 @@ public ArangoSearchCreateOptions cleanupIntervalStep(final Long cleanupIntervalS * @return options */ public ArangoSearchCreateOptions consolidationPolicy(final ConsolidationPolicy consolidationPolicy) { - properties.setConsolidationPolicy(consolidationPolicy); + this.consolidationPolicy = consolidationPolicy; return this; } @@ -104,7 +115,7 @@ public ArangoSearchCreateOptions consolidationPolicy(final ConsolidationPolicy c * @return options */ public ArangoSearchCreateOptions link(final CollectionLink... links) { - properties.addLink(links); + this.links = Arrays.asList(links); return this; } @@ -113,7 +124,7 @@ public ArangoSearchCreateOptions link(final CollectionLink... links) { * @return options */ public ArangoSearchCreateOptions primarySort(final PrimarySort... primarySorts) { - properties.addPrimarySort(primarySorts); + this.primarySorts = Arrays.asList(primarySorts); return this; } @@ -122,7 +133,7 @@ public ArangoSearchCreateOptions primarySort(final PrimarySort... primarySorts) * @return options */ public ArangoSearchCreateOptions primarySortCompression(final ArangoSearchCompression primarySortCompression) { - properties.setPrimarySortCompression(primarySortCompression); + this.primarySortCompression = primarySortCompression; return this; } @@ -130,8 +141,49 @@ public ArangoSearchCreateOptions primarySortCompression(final ArangoSearchCompre * @return options */ public ArangoSearchCreateOptions storedValues(final StoredValue... storedValues) { - properties.addStoredValues(storedValues); + this.storedValues = Arrays.asList(storedValues); return this; } + public String getName() { + return name; + } + + public ViewType getType() { + return type; + } + + public Long getConsolidationIntervalMsec() { + return consolidationIntervalMsec; + } + + public Long getCommitIntervalMsec() { + return commitIntervalMsec; + } + + public Long getCleanupIntervalStep() { + return cleanupIntervalStep; + } + + public ConsolidationPolicy getConsolidationPolicy() { + return consolidationPolicy; + } + + @JsonSerialize(using = InternalSerializers.CollectionLinksSerializer.class) + public Collection getLinks() { + return links; + } + + public Collection getPrimarySorts() { + return primarySorts; + } + + public ArangoSearchCompression getPrimarySortCompression() { + return primarySortCompression; + } + + public Collection getStoredValues() { + return storedValues; + } + } diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java index a874e6d30..7be061b87 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java @@ -20,26 +20,25 @@ package com.arangodb.model.arangosearch; -import com.arangodb.entity.arangosearch.ArangoSearchProperties; import com.arangodb.entity.arangosearch.CollectionLink; import com.arangodb.entity.arangosearch.ConsolidationPolicy; import com.arangodb.entity.arangosearch.PrimarySort; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.util.Arrays; +import java.util.Collection; /** * @author Mark Vollmary */ -public class ArangoSearchPropertiesOptions { - - private final ArangoSearchProperties properties; +public final class ArangoSearchPropertiesOptions { - public ArangoSearchPropertiesOptions() { - super(); - properties = new ArangoSearchProperties(); - } - - public ArangoSearchProperties getProperties() { - return properties; - } + private Long consolidationIntervalMsec; + private Long cleanupIntervalStep; + private ConsolidationPolicy consolidationPolicy; + private Collection links; + private Collection primarySorts; /** * @param consolidationIntervalMsec Wait at least this many milliseconds between committing index data changes and making them visible to @@ -50,7 +49,7 @@ public ArangoSearchProperties getProperties() { * @return options */ public ArangoSearchPropertiesOptions consolidationIntervalMsec(final Long consolidationIntervalMsec) { - properties.setConsolidationIntervalMsec(consolidationIntervalMsec); + this.consolidationIntervalMsec = consolidationIntervalMsec; return this; } @@ -63,7 +62,7 @@ public ArangoSearchPropertiesOptions consolidationIntervalMsec(final Long consol * @return options */ public ArangoSearchPropertiesOptions cleanupIntervalStep(final Long cleanupIntervalStep) { - properties.setCleanupIntervalStep(cleanupIntervalStep); + this.cleanupIntervalStep = cleanupIntervalStep; return this; } @@ -72,7 +71,7 @@ public ArangoSearchPropertiesOptions cleanupIntervalStep(final Long cleanupInter * @return options */ public ArangoSearchPropertiesOptions consolidationPolicy(final ConsolidationPolicy consolidationPolicy) { - properties.setConsolidationPolicy(consolidationPolicy); + this.consolidationPolicy = consolidationPolicy; return this; } @@ -81,7 +80,7 @@ public ArangoSearchPropertiesOptions consolidationPolicy(final ConsolidationPoli * @return options */ public ArangoSearchPropertiesOptions link(final CollectionLink... links) { - properties.addLink(links); + this.links = Arrays.asList(links); return this; } @@ -90,8 +89,28 @@ public ArangoSearchPropertiesOptions link(final CollectionLink... links) { * @return options */ public ArangoSearchPropertiesOptions primarySort(final PrimarySort... primarySorts) { - properties.addPrimarySort(primarySorts); + this.primarySorts = Arrays.asList(primarySorts); return this; } + public Long getConsolidationIntervalMsec() { + return consolidationIntervalMsec; + } + + public Long getCleanupIntervalStep() { + return cleanupIntervalStep; + } + + public ConsolidationPolicy getConsolidationPolicy() { + return consolidationPolicy; + } + + @JsonSerialize(using = InternalSerializers.CollectionLinksSerializer.class) + public Collection getLinks() { + return links; + } + + public Collection getPrimarySorts() { + return primarySorts; + } } diff --git a/src/main/java/com/arangodb/serde/ArangoSerde.java b/src/main/java/com/arangodb/serde/ArangoSerde.java new file mode 100644 index 000000000..f09e1d2f6 --- /dev/null +++ b/src/main/java/com/arangodb/serde/ArangoSerde.java @@ -0,0 +1,52 @@ +package com.arangodb.serde; + +import java.lang.reflect.Type; +import java.util.function.Consumer; + +/** + * Contract for serialization/deserialization of user data. + * Implementations of this interface could be used for customizing serialization/deserialization of user related data + * using serialization/deserialization libraries like: + * - serialization libraries for specific JVM languages (e.g. Scala, Kotlin, ...) + * - serialization libraries already in use in frameworks (e.g. JSON-B, Micronaut Serialization, ...) + * - high performance serialization libraries (e.g. supporting compile-time data binding code generation) + * - low-level libraries without support to data binding + *

+ * To create a custom serde based on Jackson, existing {@link JacksonSerde} can be reused and instantiated providing a + * custom configured ObjectMapper ({@link JacksonSerde#create(com.fasterxml.jackson.databind.ObjectMapper)}) or configured + * after creation through {@link JacksonSerde#configure(Consumer)}. + */ +public interface ArangoSerde { + + /** + * Serializes the object into the target data type. For data type {@link DataType#JSON}, the serialized JSON string + * must be encoded into a byte array using the UTF-8 charset. + * + * @param value object to serialize + * @return serialized byte array + */ + byte[] serialize(Object value); + + /** + * Deserializes the content and binds it to the target data type. + * For data type {@link DataType#JSON}, the byte array is the JSON string encoded using the UTF-8 charset. + * + * @param content byte array to deserialize + * @param clazz class of target data type + * @return deserialized object + */ + default T deserialize(byte[] content, Class clazz) { + return deserialize(content, (Type) clazz); + } + + /** + * Deserializes the content and binds it to the target data type. + * For data type {@link DataType#JSON}, the byte array is the JSON string encoded using the UTF-8 charset. + * + * @param content byte array to deserialize + * @param type target data type + * @return deserialized object + */ + T deserialize(byte[] content, Type type); + +} diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/serde/DataType.java similarity index 60% rename from src/main/java/com/arangodb/util/ArangoSerialization.java rename to src/main/java/com/arangodb/serde/DataType.java index 2396d51b2..59fc96bcf 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/serde/DataType.java @@ -1,28 +1,38 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.util; - -/** - * @author Mark Vollmary - */ -public interface ArangoSerialization extends ArangoSerializer, ArangoDeserializer { - -} +/* + * DISCLAIMER + * + * Copyright 2016 ArangoDB GmbH, Cologne, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright holder is ArangoDB GmbH, Cologne, Germany + */ +package com.arangodb.serde; + +import com.arangodb.Protocol; + +public enum DataType { + JSON, VPACK; + + public static DataType of(Protocol protocol) { + switch (protocol) { + case HTTP_JSON: + return DataType.JSON; + case HTTP_VPACK: + case VST: + return DataType.VPACK; + default: + throw new IllegalArgumentException("Unexpected value: " + protocol); + } + } +} diff --git a/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java b/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java new file mode 100644 index 000000000..cfaa5b417 --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java @@ -0,0 +1,55 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.databind.introspect.Annotated; +import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; + +class InternalAnnotationIntrospector extends JacksonAnnotationIntrospector { + + private final UserDataSerializer userDataSerializer; + private final UserDataDeserializer userDataDeserializer; + + InternalAnnotationIntrospector( + final UserDataSerializer userDataSerializer, + final UserDataDeserializer userDataDeserializer + ) { + this.userDataSerializer = userDataSerializer; + this.userDataDeserializer = userDataDeserializer; + } + + @Override + public Object findSerializer(Annotated a) { + if (a.getAnnotation(UserData.class) != null) { + return userDataSerializer; + } else { + return super.findSerializer(a); + } + } + + @Override + public Object findContentSerializer(Annotated a) { + if (a.getAnnotation(UserDataInside.class) != null) { + return userDataSerializer; + } else { + return super.findContentSerializer(a); + } + } + + @Override + public Object findDeserializer(Annotated a) { + if (a.getAnnotation(UserData.class) != null) { + return userDataDeserializer; + } else { + return super.findDeserializer(a); + } + } + + @Override + public Object findContentDeserializer(Annotated a) { + if (a.getAnnotation(UserDataInside.class) != null) { + return userDataDeserializer; + } else { + return super.findContentDeserializer(a); + } + } + +} diff --git a/src/main/java/com/arangodb/serde/InternalDeserializers.java b/src/main/java/com/arangodb/serde/InternalDeserializers.java new file mode 100644 index 000000000..f571b5f5b --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -0,0 +1,142 @@ +package com.arangodb.serde; + +import com.arangodb.entity.CollectionStatus; +import com.arangodb.entity.CollectionType; +import com.arangodb.entity.ReplicationFactor; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.FieldLink; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.arangodb.velocystream.Response; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.*; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +public final class InternalDeserializers { + + private static T readTreeAsValue(JsonParser p, DeserializationContext ctxt, JsonNode n, Class targetType) throws IOException { + try (TreeTraversingParser t = new TreeTraversingParser(n, p.getCodec())) { + t.nextToken(); + return ctxt.readValue(t, targetType); + } + } + + public static class CollectionLinksDeserializer extends JsonDeserializer> { + + @Override + public Collection deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Collection out = new ArrayList<>(); + ObjectNode tree = p.readValueAsTree(); + Iterator> it = tree.fields(); + while (it.hasNext()) { + Map.Entry e = it.next(); + ObjectNode v = (ObjectNode) e.getValue(); + v.put("name", e.getKey()); + out.add(readTreeAsValue(p, ctxt, v, CollectionLink.class)); + } + return out; + } + } + + public static class FieldLinksDeserializer extends JsonDeserializer { + + @Override + public FieldLink[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Collection out = new ArrayList<>(); + ObjectNode tree = p.readValueAsTree(); + Iterator> it = tree.fields(); + while (it.hasNext()) { + Map.Entry e = it.next(); + ObjectNode v = (ObjectNode) e.getValue(); + v.put("name", e.getKey()); + out.add(readTreeAsValue(p, ctxt, v, FieldLink.class)); + } + return out.toArray(new FieldLink[0]); + } + } + + public static class CollectionSchemaRuleDeserializer extends JsonDeserializer { + @Override + public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + return SerdeUtils.INSTANCE.writeJson(p.readValueAsTree()); + } + } + + + private InternalDeserializers() { + } + + static final JsonDeserializer RAW_JSON_DESERIALIZER = new JsonDeserializer() { + @Override + public RawJson deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + // TODO: find a way to access raw bytes directly + return RawJson.of(SerdeUtils.INSTANCE.writeJson(p.readValueAsTree())); + } + }; + + static final JsonDeserializer RAW_BYTES_DESERIALIZER = new JsonDeserializer() { + @Override + public RawBytes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + // TODO: find a way to access raw bytes directly + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try (JsonGenerator g = p.getCodec().getFactory().createGenerator(os)) { + g.writeTree(p.readValueAsTree()); + } + return RawBytes.of(os.toByteArray()); + } + }; + + static final JsonDeserializer COLLECTION_STATUS = new JsonDeserializer() { + @Override + public CollectionStatus deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { + return CollectionStatus.fromStatus(p.getIntValue()); + } + }; + + static final JsonDeserializer COLLECTION_TYPE = new JsonDeserializer() { + @Override + public CollectionType deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { + return CollectionType.fromType(p.getIntValue()); + } + }; + + static final JsonDeserializer REPLICATION_FACTOR = new JsonDeserializer() { + @Override + public ReplicationFactor deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { + TreeNode node = p.readValueAsTree(); + if (node instanceof NumericNode) { + return ReplicationFactor.of(((NumericNode) node).intValue()); + } else if (node instanceof TextNode && "satellite".equals(((TextNode) node).textValue())) { + return ReplicationFactor.ofSatellite(); + } else throw new IllegalArgumentException(); + } + }; + + static final JsonDeserializer RESPONSE = new JsonDeserializer() { + @Override + public Response deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { + final Response response = new Response(); + Iterator it = ((ArrayNode) p.readValueAsTree()).iterator(); + response.setVersion(it.next().intValue()); + response.setType(it.next().intValue()); + response.setResponseCode(it.next().intValue()); + if (it.hasNext()) { + response.setMeta(readTreeAsValue(p, ctxt, it.next(), Map.class)); + } + return response; + } + }; + + +} diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java new file mode 100644 index 000000000..407590d7a --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -0,0 +1,45 @@ +package com.arangodb.serde; + +import com.arangodb.entity.CollectionStatus; +import com.arangodb.entity.CollectionType; +import com.arangodb.entity.ReplicationFactor; +import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.arangodb.velocystream.Request; +import com.arangodb.velocystream.Response; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import java.util.function.Supplier; + +enum InternalModule implements Supplier { + INSTANCE; + + private final SimpleModule module; + + InternalModule() { + module = new SimpleModule(); + + module.addSerializer(RawJson.class, InternalSerializers.RAW_JSON_SERIALIZER); + module.addSerializer(RawBytes.class, InternalSerializers.RAW_BYTES_SERIALIZER); + module.addSerializer(AuthenticationRequest.class, InternalSerializers.AUTHENTICATION_REQUEST); + module.addSerializer(JwtAuthenticationRequest.class, InternalSerializers.JWT_AUTHENTICATION_REQUEST); + module.addSerializer(Request.class, InternalSerializers.REQUEST); + module.addSerializer(CollectionType.class, InternalSerializers.COLLECTION_TYPE); + + module.addDeserializer(RawJson.class, InternalDeserializers.RAW_JSON_DESERIALIZER); + module.addDeserializer(RawBytes.class, InternalDeserializers.RAW_BYTES_DESERIALIZER); + module.addDeserializer(CollectionStatus.class, InternalDeserializers.COLLECTION_STATUS); + module.addDeserializer(CollectionType.class, InternalDeserializers.COLLECTION_TYPE); + module.addDeserializer(ReplicationFactor.class, InternalDeserializers.REPLICATION_FACTOR); + module.addDeserializer(Response.class, InternalDeserializers.RESPONSE); + } + + @Override + public Module get() { + return module; + } + +} diff --git a/src/main/java/com/arangodb/serde/InternalParameterizedType.java b/src/main/java/com/arangodb/serde/InternalParameterizedType.java new file mode 100644 index 000000000..40086b74f --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalParameterizedType.java @@ -0,0 +1,31 @@ +package com.arangodb.serde; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +class InternalParameterizedType implements ParameterizedType { + + private final Class rawType; + private final Type[] actualRawArguments; + + InternalParameterizedType(final Class rawType, final Type[] actualRawArguments) { + this.rawType = rawType; + this.actualRawArguments = actualRawArguments; + } + + @Override + public Type getRawType() { + return rawType; + } + + @Override + public Type[] getActualTypeArguments() { + return actualRawArguments; + } + + @Override + public Type getOwnerType() { + return null; + } + +} diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java new file mode 100644 index 000000000..2fcafb358 --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -0,0 +1,159 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.databind.JsonNode; + +import java.lang.reflect.Type; +import java.util.Collection; + +public interface InternalSerde extends JacksonSerde { + + /** + * Creates a new InternalSerde with default settings for the specified data type. + * + * @param dataType serialization target data type + * @return the created InternalSerde + */ + static InternalSerde of(final DataType dataType, ArangoSerde userSerde) { + return new InternalSerdeImpl(MapperProvider.of(dataType), userSerde); + } + + /** + * Used for logging and debugging. + * + * @param content byte array + * @return JSON string + */ + String toJsonString(byte[] content); + + /** + * Extract the nested content pointed by the json pointer. + * Used for extracting nested user data. + * + * @param content byte array + * @param jsonPointer location of data to be extracted + * @return byte array + */ + byte[] extract(byte[] content, String jsonPointer); + + /** + * Deserializes the parsed json node and binds it to the target data type. + * + * @param node parsed json node + * @param clazz class of target data type + * @return deserialized object + */ + default T deserialize(JsonNode node, Class clazz) { + return deserialize(node, (Type) clazz); + } + + /** + * Deserializes the parsed json node and binds it to the target data type. + * + * @param node parsed json node + * @param type target data type + * @return deserialized object + */ + T deserialize(JsonNode node, Type type); + + /** + * Parses the content. + * + * @param content VPack or byte encoded JSON string + * @return root of the parsed tree + */ + JsonNode parse(byte[] content); + + /** + * Parses the content at json pointer. + * + * @param content VPack or byte encoded JSON string + * @param jsonPointer location of data to be parsed + * @return root of the parsed tree + */ + JsonNode parse(byte[] content, String jsonPointer); + + /** + * Deserializes the content at json pointer and binds it to the target data type. + * For data type {@link DataType#JSON}, the byte array is the JSON string encoded using the UTF-8 charset. + * + * @param content byte array to deserialize + * @param jsonPointer location of data to be deserialized + * @param clazz class of target data type + * @return deserialized object + */ + default T deserialize(byte[] content, String jsonPointer, Class clazz) { + return deserialize(content, jsonPointer, (Type) clazz); + } + + /** + * Deserializes the content at json pointer and binds it to the target data type. + * For data type {@link DataType#JSON}, the byte array is the JSON string encoded using the UTF-8 charset. + * + * @param content byte array to deserialize + * @param jsonPointer location of data to be deserialized + * @param type target data type + * @return deserialized object + */ + default T deserialize(byte[] content, String jsonPointer, Type type) { + return deserialize(parse(content, jsonPointer), type); + } + + /** + * Serializes the object into the target data type, using the user serde. + * + * @param value object to serialize + * @return serialized byte array + */ + byte[] serializeUserData(Object value); + + /** + * Serializes each element in the collection using the user serde. + * + * @param value objects to serialize + * @return serialized byte array + */ + byte[] serializeCollectionUserData(Collection value); + + /** + * Deserializes the content and binds it to the target data type, using the user serde. + * + * @param content byte array to deserialize + * @param clazz class of target data type + * @return deserialized object + */ + T deserializeUserData(byte[] content, Class clazz); + + /** + * Deserializes the content and binds it to the target data type, using the user serde. + * + * @param content byte array to deserialize + * @param type target data type + * @return deserialized object + */ + T deserializeUserData(byte[] content, Type type); + + /** + * Deserializes the parsed json node and binds it to the target data type, using the user serde. + * + * @param node parsed json node + * @param clazz class of target data type + * @return deserialized object + */ + default T deserializeUserData(JsonNode node, Class clazz) { + return deserializeUserData(node, (Type) clazz); + } + + /** + * Deserializes the parsed json node and binds it to the target data type, using the user serde. + * + * @param node parsed json node + * @param type target data type + * @return deserialized object + */ + T deserializeUserData(JsonNode node, Type type); + + /** + * @return the user serde + */ + ArangoSerde getUserSerde(); +} diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java new file mode 100644 index 000000000..2922c6544 --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -0,0 +1,145 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDBException; +import com.arangodb.entity.BaseDocument; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +final class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { + + private final ArangoSerde userSerde; + + static { + SerdeUtils.INSTANCE.checkSupportedJacksonVersion(); + } + + InternalSerdeImpl(final ObjectMapper mapper, final ArangoSerde userSerde) { + super(mapper); + this.userSerde = userSerde; + mapper.registerModule(InternalModule.INSTANCE.get()); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.setAnnotationIntrospector(new InternalAnnotationIntrospector( + new UserDataSerializer(this), + new UserDataDeserializer(this) + )); + } + + @Override + public String toJsonString(final byte[] content) { + try { + return SerdeUtils.INSTANCE.writeJson(mapper.readTree(content)); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + + @Override + public byte[] extract(final byte[] content, final String jsonPointer) { + try { + JsonNode target = parse(content).at(jsonPointer); + return mapper.writeValueAsBytes(target); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + + @Override + public JsonNode parse(byte[] content) { + try { + return mapper.readTree(content); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + + @Override + public JsonNode parse(byte[] content, String jsonPointer) { + try { + return mapper.readTree(content).at(jsonPointer); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + + @Override + public byte[] serializeUserData(Object value) { + Class clazz = value.getClass(); + if ( RawJson.class.equals(clazz) || + RawBytes.class.equals(clazz) || + JsonNode.class.isAssignableFrom(clazz) || + BaseDocument.class.isAssignableFrom(clazz) + ) { + return serialize(value); + } else { + return userSerde.serialize(value); + } + } + + @Override + public byte[] serializeCollectionUserData(Collection value) { + List jsonNodeCollection = value.stream() + .map(this::serializeUserData) + .map(this::parse) + .collect(Collectors.toList()); + return serialize(jsonNodeCollection); + } + + @Override + public T deserializeUserData(byte[] content, Class clazz) { + if ( RawJson.class.isAssignableFrom(clazz) || + RawBytes.class.isAssignableFrom(clazz) || + JsonNode.class.isAssignableFrom(clazz) || + BaseDocument.class.isAssignableFrom(clazz) + ) { + return deserialize(content, clazz); + } else { + return userSerde.deserialize(content, clazz); + } + } + + @Override + public T deserializeUserData(byte[] content, Type type) { + if (type instanceof Class) { + return deserializeUserData(content, (Class) type); + } else { + return userSerde.deserialize(content, type); + } + } + + @Override + public T deserializeUserData(JsonNode node, Type type) { + return deserializeUserData(serialize(node), type); + } + + @Override + public ArangoSerde getUserSerde() { + return userSerde; + } + + @Override + public T deserialize(final JsonNode node, final Type type) { + try { + return mapper.readerFor(mapper.constructType(type)).readValue(node); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + + @Override + public T deserialize(final byte[] content, final Type type) { + if (content == null) { + return null; + } + return super.deserialize(content, type); + } + +} diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java new file mode 100644 index 000000000..454b1a4bc --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -0,0 +1,128 @@ +package com.arangodb.serde; + +import com.arangodb.entity.CollectionType; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.FieldLink; +import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.arangodb.velocystream.Request; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public final class InternalSerializers { + + public static class CollectionSchemaRuleSerializer extends JsonSerializer { + @Override + public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeTree(SerdeUtils.INSTANCE.parseJson(value)); + } + } + + public static class FieldLinksSerializer extends JsonSerializer> { + @Override + public void serialize(Collection value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + Map mapLikeValue = new HashMap<>(); + for (FieldLink fl : value) { + mapLikeValue.put(fl.getName(), fl); + } + gen.writeObject(mapLikeValue); + } + } + + public static class CollectionLinksSerializer extends JsonSerializer> { + @Override + public void serialize(Collection value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + Map mapLikeValue = new HashMap<>(); + for (CollectionLink cl : value) { + mapLikeValue.put(cl.getName(), cl); + } + gen.writeObject(mapLikeValue); + } + } + + private InternalSerializers() { + } + + static final JsonSerializer RAW_JSON_SERIALIZER = new JsonSerializer() { + @Override + public void serialize(RawJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeTree(SerdeUtils.INSTANCE.parseJson(value.getValue())); + } + }; + + static final JsonSerializer RAW_BYTES_SERIALIZER = new JsonSerializer() { + @Override + public void serialize(RawBytes value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + // TODO: find a way to append raw bytes directly + // see https://github.com/FasterXML/jackson-dataformats-binary/issues/331 + try (JsonParser parser = gen.getCodec().getFactory().createParser(value.getValue())) { + gen.writeTree(parser.readValueAsTree()); + } + } + }; + + static final JsonSerializer AUTHENTICATION_REQUEST = new JsonSerializer() { + @Override + public void serialize(AuthenticationRequest value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartArray(); + gen.writeNumber(value.getVersion()); + gen.writeNumber(value.getType()); + gen.writeString(value.getEncryption()); + gen.writeString(value.getUser()); + gen.writeString(value.getPassword()); + gen.writeEndArray(); + } + }; + + static final JsonSerializer JWT_AUTHENTICATION_REQUEST = new JsonSerializer() { + @Override + public void serialize(JwtAuthenticationRequest value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartArray(); + gen.writeNumber(value.getVersion()); + gen.writeNumber(value.getType()); + gen.writeString(value.getEncryption()); + gen.writeString(value.getToken()); + gen.writeEndArray(); + } + }; + + static final JsonSerializer REQUEST = new JsonSerializer() { + @Override + public void serialize(Request value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartArray(); + gen.writeNumber(value.getVersion()); + gen.writeNumber(value.getType()); + gen.writeString(value.getDbName().get()); + gen.writeNumber(value.getRequestType().getType()); + gen.writeString(value.getRequest()); + gen.writeStartObject(); + for (final Map.Entry entry : value.getQueryParam().entrySet()) { + gen.writeStringField(entry.getKey(), entry.getValue()); + } + gen.writeEndObject(); + gen.writeStartObject(); + for (final Map.Entry entry : value.getHeaderParam().entrySet()) { + gen.writeStringField(entry.getKey(), entry.getValue()); + } + gen.writeEndObject(); + gen.writeEndArray(); + } + }; + + static final JsonSerializer COLLECTION_TYPE = new JsonSerializer() { + @Override + public void serialize(CollectionType value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeNumber(value.getType()); + } + }; + +} diff --git a/src/main/java/com/arangodb/serde/JacksonSerde.java b/src/main/java/com/arangodb/serde/JacksonSerde.java new file mode 100644 index 000000000..122601dcf --- /dev/null +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -0,0 +1,38 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.function.Consumer; + +/** + * User data serde based on Jackson Databind. + */ +public interface JacksonSerde extends ArangoSerde { + + /** + * Creates a new JacksonSerde with default settings for the specified data type. + * + * @param dataType serialization target data type + * @return the created JacksonSerde + */ + static JacksonSerde of(final DataType dataType) { + return create(MapperProvider.of(dataType)); + } + + /** + * Creates a new JacksonSerde using the provided ObjectMapper. + * + * @param mapper Jackson ObjectMapper to use + * @return the created JacksonSerde + */ + static JacksonSerde create(final ObjectMapper mapper) { + return new JacksonSerdeImpl(mapper); + } + + /** + * Allows configuring the underlying Jackson ObjectMapper + * @param configureFunction function to configure the Jackson ObjectMapper + */ + void configure(final Consumer configureFunction); + +} diff --git a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java new file mode 100644 index 000000000..11f56ab1f --- /dev/null +++ b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java @@ -0,0 +1,44 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDBException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.function.Consumer; + +class JacksonSerdeImpl implements JacksonSerde { + + protected final ObjectMapper mapper; + + JacksonSerdeImpl(final ObjectMapper mapper) { + this.mapper = mapper; + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + @Override + public byte[] serialize(final Object value) { + try { + return mapper.writeValueAsBytes(value); + } catch (JsonProcessingException e) { + throw new ArangoDBException(e); + } + } + + @Override + public T deserialize(final byte[] content, final Type type) { + try { + return mapper.readerFor(mapper.constructType(type)).readValue(content); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + + @Override + public void configure(Consumer configureFunction) { + configureFunction.accept(mapper); + } + +} diff --git a/src/main/java/com/arangodb/serde/JsonMapperProvider.java b/src/main/java/com/arangodb/serde/JsonMapperProvider.java new file mode 100644 index 000000000..033deef2f --- /dev/null +++ b/src/main/java/com/arangodb/serde/JsonMapperProvider.java @@ -0,0 +1,12 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.databind.ObjectMapper; + +enum JsonMapperProvider implements MapperProvider { + INSTANCE; + + @Override + public ObjectMapper get() { + return new ObjectMapper(); + } +} diff --git a/src/main/java/com/arangodb/serde/JsonbSerde.java b/src/main/java/com/arangodb/serde/JsonbSerde.java new file mode 100644 index 000000000..c6dac0dcc --- /dev/null +++ b/src/main/java/com/arangodb/serde/JsonbSerde.java @@ -0,0 +1,29 @@ +package com.arangodb.serde; + +import jakarta.json.bind.JsonbConfig; + +/** + * User data serde based on Jakarta JSON Binding (JSON-B). + */ +public interface JsonbSerde extends ArangoSerde { + + /** + * Creates a new JsonbSerde with default settings. + * + * @return the created JsonbSerde + */ + static JsonbSerde create() { + return new JsonbSerdeImpl(); + } + + /** + * Creates a new JsonbSerde using the provided . + * + * @param config JsonbConfig to use + * @return the created JsonbSerde + */ + static JsonbSerde of(final JsonbConfig config) { + return new JsonbSerdeImpl(config); + } + +} diff --git a/src/main/java/com/arangodb/serde/JsonbSerdeImpl.java b/src/main/java/com/arangodb/serde/JsonbSerdeImpl.java new file mode 100644 index 000000000..17993ca2b --- /dev/null +++ b/src/main/java/com/arangodb/serde/JsonbSerdeImpl.java @@ -0,0 +1,32 @@ +package com.arangodb.serde; + +import jakarta.json.bind.Jsonb; +import jakarta.json.bind.JsonbBuilder; +import jakarta.json.bind.JsonbConfig; + +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; + +class JsonbSerdeImpl implements JsonbSerde { + + private final Jsonb jsonb; + + JsonbSerdeImpl() { + jsonb = JsonbBuilder.create(); + } + + JsonbSerdeImpl(final JsonbConfig config) { + jsonb = JsonbBuilder.create(config); + } + + @Override + public byte[] serialize(Object value) { + return jsonb.toJson(value).getBytes(StandardCharsets.UTF_8); + } + + @Override + public T deserialize(byte[] content, Type type) { + return jsonb.fromJson(new String(content, StandardCharsets.UTF_8), type); + } + +} diff --git a/src/main/java/com/arangodb/serde/MapperProvider.java b/src/main/java/com/arangodb/serde/MapperProvider.java new file mode 100644 index 000000000..be5759a54 --- /dev/null +++ b/src/main/java/com/arangodb/serde/MapperProvider.java @@ -0,0 +1,17 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.function.Supplier; + +interface MapperProvider extends Supplier { + static ObjectMapper of(final DataType dataType) { + if (dataType == DataType.JSON) { + return JsonMapperProvider.INSTANCE.get(); + } else if (dataType == DataType.VPACK) { + return VPackMapperProvider.INSTANCE.get(); + } else { + throw new IllegalArgumentException("Unexpected value: " + dataType); + } + } +} diff --git a/src/main/java/com/arangodb/serde/SerdeUtils.java b/src/main/java/com/arangodb/serde/SerdeUtils.java new file mode 100644 index 000000000..87eb13d3d --- /dev/null +++ b/src/main/java/com/arangodb/serde/SerdeUtils.java @@ -0,0 +1,89 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDBException; +import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +public enum SerdeUtils { + INSTANCE; + + private final ObjectMapper jsonMapper = new ObjectMapper(); + + /** + * Parse a JSON string. + * + * @param json JSON string to parse + * @return root of the parsed tree + */ + public JsonNode parseJson(final String json) { + try { + return jsonMapper.readTree(json); + } catch (JsonProcessingException e) { + throw new ArangoDBException(e); + } + } + + /** + * @param data JsonNode + * @return JSON string + */ + public String writeJson(final JsonNode data) { + try { + return jsonMapper.writeValueAsString(data); + } catch (JsonProcessingException e) { + throw new ArangoDBException(e); + } + } + + public Type constructListType(Class clazz) { + return TypeFactory.defaultInstance().constructCollectionType(List.class, clazz); + } + + public Type constructMapType(Class keyClazz, Class valueClazz) { + return TypeFactory.defaultInstance().constructMapType(Map.class, keyClazz, valueClazz); + } + + public Type constructParametricType(Class rawType, Type... rawArgs) { + if (rawArgs == null || rawArgs.length == 0 || rawArgs[0] == null) { + return rawType; + } else { + return new InternalParameterizedType(rawType, rawArgs); + } + } + + public Type convertToType(final JavaType javaType) { + List args = new ArrayList<>(); + for (JavaType it : javaType.getBindings().getTypeParameters()) { + Type type = convertToType(it); + args.add(type); + } + return constructParametricType(javaType.getRawClass(), args.toArray(new Type[0])); + } + + void checkSupportedJacksonVersion() { + Arrays.asList( + com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION, + com.fasterxml.jackson.core.json.PackageVersion.VERSION + ).forEach(version -> { + int major = version.getMajorVersion(); + int minor = version.getMinorVersion(); + if (major != 2 || minor < 10 || minor > 13) { + Logger.getLogger(VPackMapper.class.getName()) + .log(Level.WARNING, "Unsupported Jackson version: {0}", version); + } + }); + } + +} diff --git a/src/main/java/com/arangodb/serde/UserData.java b/src/main/java/com/arangodb/serde/UserData.java new file mode 100644 index 000000000..8e53d2048 --- /dev/null +++ b/src/main/java/com/arangodb/serde/UserData.java @@ -0,0 +1,14 @@ +package com.arangodb.serde; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marker annotation for fields that need to be serialized/deserialized using the user serde. + */ +@Target({ElementType.METHOD, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface UserData { +} diff --git a/src/main/java/com/arangodb/serde/UserDataDeserializer.java b/src/main/java/com/arangodb/serde/UserDataDeserializer.java new file mode 100644 index 000000000..5be515eb5 --- /dev/null +++ b/src/main/java/com/arangodb/serde/UserDataDeserializer.java @@ -0,0 +1,42 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.deser.ContextualDeserializer; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; + +import java.io.IOException; +import java.lang.reflect.Type; + +class UserDataDeserializer extends JsonDeserializer implements ContextualDeserializer { + private final Type targetType; + private final InternalSerde serde; + + UserDataDeserializer(final InternalSerde serde) { + targetType = null; + this.serde = serde; + } + + private UserDataDeserializer(final JavaType targetType, final InternalSerde serde) { + this.targetType = SerdeUtils.INSTANCE.convertToType(targetType); + this.serde = serde; + } + + @Override + public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + return serde.deserializeUserData(p.readValueAsTree(), targetType); + } + + @Override + public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException { + return deserialize(p, ctxt); + } + + @Override + public JsonDeserializer createContextual(DeserializationContext ctxt, BeanProperty property) { + return new UserDataDeserializer(ctxt.getContextualType(), serde); + } +} diff --git a/src/main/java/com/arangodb/serde/UserDataInside.java b/src/main/java/com/arangodb/serde/UserDataInside.java new file mode 100644 index 000000000..6e03165f5 --- /dev/null +++ b/src/main/java/com/arangodb/serde/UserDataInside.java @@ -0,0 +1,19 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marker annotation for collections or map fields whose values need to be serialized/deserialized using the user serde. + */ +@Target({ElementType.METHOD, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@JsonInclude(value = JsonInclude.Include.NON_NULL) +@JacksonAnnotationsInside +public @interface UserDataInside { +} diff --git a/src/main/java/com/arangodb/serde/UserDataSerializer.java b/src/main/java/com/arangodb/serde/UserDataSerializer.java new file mode 100644 index 000000000..9f3067db9 --- /dev/null +++ b/src/main/java/com/arangodb/serde/UserDataSerializer.java @@ -0,0 +1,25 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; + +class UserDataSerializer extends JsonSerializer { + private final InternalSerde serde; + + UserDataSerializer(InternalSerde serde) { + this.serde = serde; + } + + @Override + public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + // TODO: find a way to append raw bytes directly + // see https://github.com/FasterXML/jackson-dataformats-binary/issues/331 + try (JsonParser parser = gen.getCodec().getFactory().createParser(serde.serializeUserData(value))) { + gen.writeTree(parser.readValueAsTree()); + } + } +} diff --git a/src/main/java/com/arangodb/serde/VPackMapperProvider.java b/src/main/java/com/arangodb/serde/VPackMapperProvider.java new file mode 100644 index 000000000..95f4e1a7d --- /dev/null +++ b/src/main/java/com/arangodb/serde/VPackMapperProvider.java @@ -0,0 +1,13 @@ +package com.arangodb.serde; + +import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.fasterxml.jackson.databind.ObjectMapper; + +enum VPackMapperProvider implements MapperProvider { + INSTANCE; + + @Override + public ObjectMapper get() { + return new VPackMapper(); + } +} diff --git a/src/main/java/com/arangodb/util/ArangoCursorInitializer.java b/src/main/java/com/arangodb/util/ArangoCursorInitializer.java index bc2da8378..6344bf2d3 100644 --- a/src/main/java/com/arangodb/util/ArangoCursorInitializer.java +++ b/src/main/java/com/arangodb/util/ArangoCursorInitializer.java @@ -21,7 +21,7 @@ package com.arangodb.util; import com.arangodb.ArangoCursor; -import com.arangodb.entity.CursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; @@ -34,6 +34,6 @@ ArangoCursor createInstance( final InternalArangoDatabase db, final ArangoCursorExecute execute, final Class type, - final CursorEntity result); + final InternalCursorEntity result); } diff --git a/src/main/java/com/arangodb/util/ArangoDeserializer.java b/src/main/java/com/arangodb/util/ArangoDeserializer.java deleted file mode 100644 index 55601faff..000000000 --- a/src/main/java/com/arangodb/util/ArangoDeserializer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.util; - -import com.arangodb.ArangoDBException; -import com.arangodb.velocypack.VPackSlice; - -import java.lang.reflect.Type; - -/** - * @author Mark Vollmary - */ -public interface ArangoDeserializer { - - /** - * Deserialize a given VelocyPack to an instance of a given type - * - * @param vpack The VelocyPack to deserialize - * @param type The target type to deserialize to. Use String for raw JSON. - * @return The deserialized VelocyPack - * @throws ArangoDBException - */ - T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException; - -} diff --git a/src/main/java/com/arangodb/util/ArangoSerializer.java b/src/main/java/com/arangodb/util/ArangoSerializer.java deleted file mode 100644 index ee327d234..000000000 --- a/src/main/java/com/arangodb/util/ArangoSerializer.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.util; - -import com.arangodb.ArangoDBException; -import com.arangodb.velocypack.VPackSlice; - -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.Map; - -/** - * @author Mark Vollmary - */ -public interface ArangoSerializer { - - class Options { - private Type type; - private boolean serializeNullValues; - private Map additionalFields; - private boolean stringAsJson; - - public Options() { - super(); - serializeNullValues = false; - stringAsJson = false; - additionalFields = Collections.emptyMap(); - } - - /** - * @param type The source type of the Object. - * @return options - */ - public Options type(final Type type) { - this.type = type; - return this; - } - - /** - * @param serializeNullValues Whether or not null values should be excluded from serialization. - * @return options - */ - public Options serializeNullValues(final boolean serializeNullValues) { - this.serializeNullValues = serializeNullValues; - return this; - } - - /** - * @param additionalFields Additional Key/Value pairs to include in the created VelocyPack. - * @return options - */ - public Options additionalFields(final Map additionalFields) { - this.additionalFields = additionalFields; - return this; - } - - /** - * @param stringAsJson Wheter or not String should be interpreted as json - * @return options - */ - public Options stringAsJson(final boolean stringAsJson) { - this.stringAsJson = stringAsJson; - return this; - } - - public Type getType() { - return type; - } - - public boolean isSerializeNullValues() { - return serializeNullValues; - } - - public Map getAdditionalFields() { - return additionalFields; - } - - public boolean isStringAsJson() { - return stringAsJson; - } - - } - - /** - * Serialize a given Object to VelocyPack - * - * @param entity The Object to serialize. If it is from type String, it will be handled as a JSON. - * @return The serialized VelocyPack - * @throws ArangoDBException - */ - VPackSlice serialize(final Object entity) throws ArangoDBException; - - /** - * Serialize a given Object to VelocyPack - * - * @param entity The Object to serialize. If it is from type String, it will be handled as a JSON. - * @param options Additional options - * @return the serialized VelocyPack - * @throws ArangoDBException - */ - VPackSlice serialize(final Object entity, final Options options) throws ArangoDBException; - -} diff --git a/src/main/java/com/arangodb/util/RawBytes.java b/src/main/java/com/arangodb/util/RawBytes.java new file mode 100644 index 000000000..249713075 --- /dev/null +++ b/src/main/java/com/arangodb/util/RawBytes.java @@ -0,0 +1,47 @@ +package com.arangodb.util; + +import java.util.Arrays; + +/** + * Helper class used to encapsulate raw value serialized as byte array. + * It can be used: + * - in serialization to append an already serialized raw value as is + * - in deserialization as target wrapper type for the raw value + *

+ * No validation is performed, the user is responsible for providing a valid byte array for the used content type. + *

+ * The raw value byte array can represent either: + * - a valid VPack + * - a valid JSON UTF-8 encoded string + *

+ * The driver's {@link com.arangodb.serde.InternalSerde} supports serializing and deserializing to and from + * {@code RawBytes}. + */ +public class RawBytes { + private final byte[] value; + + public static RawBytes of(final byte[] value) { + return new RawBytes(value); + } + + protected RawBytes(final byte[] value) { + this.value = value; + } + + public byte[] getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RawBytes rawBytes = (RawBytes) o; + return Arrays.equals(getValue(), rawBytes.getValue()); + } + + @Override + public int hashCode() { + return Arrays.hashCode(getValue()); + } +} diff --git a/src/main/java/com/arangodb/util/RawJson.java b/src/main/java/com/arangodb/util/RawJson.java new file mode 100644 index 000000000..8aec5b9a3 --- /dev/null +++ b/src/main/java/com/arangodb/util/RawJson.java @@ -0,0 +1,41 @@ +package com.arangodb.util; + +import java.util.Objects; + +/** + * Helper class used to encapsulate raw JSON string. + * It can be used: + * - in serialization to append a raw JSON node + * - in deserialization as target wrapper type for the raw JSON string + *

+ * The driver's {@link com.arangodb.serde.InternalSerde} supports serializing and deserializing to and from + * {@code RawJson}. + */ +public class RawJson { + private final String value; + + public static RawJson of(final String value) { + return new RawJson(value); + } + + protected RawJson(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RawJson rawJson = (RawJson) o; + return Objects.equals(getValue(), rawJson.getValue()); + } + + @Override + public int hashCode() { + return Objects.hash(getValue()); + } +} diff --git a/src/main/java/com/arangodb/velocystream/Request.java b/src/main/java/com/arangodb/velocystream/Request.java index cfa9eead7..678808e59 100644 --- a/src/main/java/com/arangodb/velocystream/Request.java +++ b/src/main/java/com/arangodb/velocystream/Request.java @@ -21,8 +21,6 @@ package com.arangodb.velocystream; import com.arangodb.DbName; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.annotations.Expose; import java.util.HashMap; import java.util.Map; @@ -39,8 +37,7 @@ public class Request { private final String request; private final Map queryParam; private final Map headerParam; - @Expose(serialize = false) - private VPackSlice body; + private byte[] body; public Request(final DbName dbName, final RequestType requestType, final String path) { super(); @@ -104,11 +101,11 @@ public Request putHeaderParam(final String key, final String value) { return this; } - public VPackSlice getBody() { + public byte[] getBody() { return body; } - public Request setBody(final VPackSlice body) { + public Request setBody(final byte[] body) { this.body = body; return this; } diff --git a/src/main/java/com/arangodb/velocystream/Response.java b/src/main/java/com/arangodb/velocystream/Response.java index 9e3811793..1f7b164bd 100644 --- a/src/main/java/com/arangodb/velocystream/Response.java +++ b/src/main/java/com/arangodb/velocystream/Response.java @@ -20,9 +20,6 @@ package com.arangodb.velocystream; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.annotations.Expose; - import java.util.HashMap; import java.util.Map; @@ -35,8 +32,7 @@ public class Response { private int type = 2; private int responseCode; private Map meta; - @Expose(deserialize = false) - private VPackSlice body = null; + private byte[] body = null; public Response() { super(); @@ -75,11 +71,11 @@ public void setMeta(final Map meta) { this.meta = meta; } - public VPackSlice getBody() { + public byte[] getBody() { return body; } - public void setBody(final VPackSlice body) { + public void setBody(final byte[] body) { this.body = body; } diff --git a/src/main/resources/META-INF/native-image/com.arangodb/arangodb-java-driver/reflect-config.json b/src/main/resources/META-INF/native-image/com.arangodb/arangodb-java-driver/reflect-config.json index eac1dd6cd..09cda49c3 100644 --- a/src/main/resources/META-INF/native-image/com.arangodb/arangodb-java-driver/reflect-config.json +++ b/src/main/resources/META-INF/native-image/com.arangodb/arangodb-java-driver/reflect-config.json @@ -1,1492 +1,1172 @@ [ + { + "name": "com.arangodb.serde.InternalSerializers$CollectionSchemaRuleSerializer", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.serde.InternalSerializers$FieldLinksSerializer", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.serde.InternalSerializers$CollectionLinksSerializer", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.serde.InternalDeserializers$CollectionLinksDeserializer", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.serde.InternalDeserializers$FieldLinksDeserializer", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.serde.InternalDeserializers$CollectionSchemaRuleDeserializer", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, { "name": "com.arangodb.entity.DocumentCreateEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ReplicationFactor$SatelliteReplicationFactor", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.GeoPointAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.GeoJSONAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.CursorEntity", + "name": "com.arangodb.entity.Rev", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.TraversalEntity", + "name": "com.arangodb.entity.MetaAware", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.IndexEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.VertexEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlExecutionExplainEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlParseEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.EdgeDefinition", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.CollectionEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.entity.CursorEntity$Stats", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.MultiDocumentEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.StopwordsAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionVariable", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.StopwordsAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.CollectionPropertiesEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.EdgeUpdateEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.QueryCachePropertiesEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.DocumentUpdateEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.CursorStats", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.AQLAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.GraphEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.GeoJSONAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlFunctionEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.PrimarySort", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.DatabaseEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.EdgeEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.ViewEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.EdgeNgram", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionNode", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.BaseDocument", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.TransactionEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.ArangoDBEngine", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.UserEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.entity.LogEntity", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.ErrorEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.arangosearch.analyzer.NormAnalyzer", + "name": "com.arangodb.entity.arangosearch.analyzer.DelimiterAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.arangosearch.analyzer.DelimiterAnalyzerProperties", + "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionStats", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.CursorEntity$Warning", + "name": "com.arangodb.entity.arangosearch.analyzer.NormAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionStats", + "name": "com.arangodb.entity.arangosearch.FieldLink", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.arangosearch.analyzer.GeoAnalyzerOptions", + "name": "com.arangodb.entity.To", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.arangosearch.analyzer.NGramAnalyzer", + "name": "com.arangodb.entity.arangosearch.analyzer.GeoAnalyzerOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlParseEntity$AstNode", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.arangosearch.ArangoSearchProperties", + "name": "com.arangodb.entity.arangosearch.analyzer.NGramAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.ShardEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionCollection", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.PipelineAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ReplicationFactor$NumericReplicationFactor", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.Key", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.TextAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.SegmentationAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.DocumentDeleteEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.EdgeDefinition$Options", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.entity.arangosearch.AnalyzerEntity", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.ArangoDBVersion", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.AQLAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.SegmentationAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.BaseEdgeDocument", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.ConsolidationPolicy", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.VertexUpdateEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.NormAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.KeyOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionPlan", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.LogLevelEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.ReplicationFactor", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.Id", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.DelimiterAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.DocumentEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.NGramAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.CursorWarning", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.StemAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.IdentityAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.StreamTransactionEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.LogEntriesEntity", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.GeoPointAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.LogEntriesEntity", + "name": "com.arangodb.entity.QueryEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.PathEntity", + "name": "com.arangodb.entity.arangosearch.CollectionLink", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "com.arangodb.entity.QueryEntity", + "name": "com.arangodb.entity.arangosearch.StoredValue", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.DocumentImportEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.PipelineAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.CollationAnalyzerProperties", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.entity.MinReplicationFactor", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.StemAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.QueryTrackingPropertiesEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.CollectionRevisionEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.entity.CursorEntity$Extras", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.LogEntriesEntity$Message", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name": "java.lang.Object", + "name": "com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.CollationAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.TextAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.From", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.entity.AqlExecutionExplainEntity$ExecutionExpression", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ServerRole", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.analyzer.SegmentationAnalyzerProperties$BreakMode", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.AnalyzerFeature", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ReplicationFactor$SatelliteReplicationFactor", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ArangoDBEngine$StorageEngineName", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.StreamTransactionStatus", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.QueryExecutionState", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.LogLevel", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.QueryCachePropertiesEntity$CacheMode", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.LogLevelEntity$LogLevel", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.StoreValuesType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.LoadBalancingStrategy", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.IndexType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.ArangoSearchCompression", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.License", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.CollectionStatus", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.analyzer.SearchAnalyzerCase", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.analyzer.StreamType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.analyzer.AQLAnalyzerProperties$ReturnType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.CollectionType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.KeyType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ViewType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ServerMode", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.AnalyzerType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.analyzer.GeoJSONAnalyzerProperties$GeoJSONAnalyzerType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.ShardingStrategy", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.arangosearch.ConsolidationType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.entity.Permissions", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.GeoIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.TtlIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentReadOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryOptions$Optimizer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DBCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.VertexCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlFunctionDeleteOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.arangosearch.AnalyzerDeleteOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.FulltextIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.UserUpdateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.StreamTransactionOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.model.TraversalOptions$Uniqueness", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentReplaceOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DatabaseUsersOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.ViewRenameOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryExplainOptions$Options", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.ViewCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.VertexCollectionCreateOptions$Options", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryParseOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.UserAccessOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.HashIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.EdgeUpdateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.VertexCollectionCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.arangosearch.ArangoSearchCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.VertexDeleteOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.EdgeCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.GraphCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionsReadOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.TransactionOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionTruncateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.PersistentIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.SkiplistIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.ZKDIndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionSchema", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentImportOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentDeleteOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryOptions$Options", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.EdgeReplaceOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.VertexReplaceOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentUpdateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.GraphDocumentReadOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.VertexUpdateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.OptionsBuilder", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.TransactionCollectionOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.LogOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.UserCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionPropertiesOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DatabaseOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.arangodb.model.TraversalOptions", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.GraphCreateOptions$SmartOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionCountOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.EdgeDeleteOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.IndexOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.CollectionRenameOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.DocumentExistsOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlFunctionGetOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "java.lang.Object", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlFunctionCreateOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryExplainOptions$Optimizer", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.model.AqlQueryExplainOptions", "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.QueueTimeSample", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.DocumentImportOptions$OnDuplicate", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.OverwriteMode", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.ImportType", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.LogOptions$SortOrder", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.CollectionSchema$Level", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.model.ZKDIndexOptions$FieldValueTypes", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.internal.cursor.entity.InternalCursorEntity", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.internal.cursor.entity.InternalCursorEntity$Extras", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true } ] diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index d332312e9..ad980df47 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -38,7 +38,9 @@ import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeAll; @@ -91,8 +93,7 @@ static void init() { @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocument(ArangoCollection collection) { - final DocumentCreateEntity doc = collection - .insertDocument(new BaseDocument(), null); + final DocumentCreateEntity doc = collection.insertDocument(new BaseDocument(), null); assertThat(doc).isNotNull(); assertThat(doc.getId()).isNotNull(); assertThat(doc.getKey()).isNotNull(); @@ -111,8 +112,7 @@ void insertDocumentWithArrayWithNullValues(ArangoCollection collection) { BaseDocument doc = new BaseDocument(); doc.addAttribute("arr", arr); - final DocumentCreateEntity insertedDoc = collection - .insertDocument(doc, new DocumentCreateOptions().returnNew(true)); + final DocumentCreateEntity insertedDoc = collection.insertDocument(doc, new DocumentCreateOptions().returnNew(true)); assertThat(insertedDoc).isNotNull(); assertThat(insertedDoc.getId()).isNotNull(); assertThat(insertedDoc.getKey()).isNotNull(); @@ -130,8 +130,7 @@ void insertDocumentWithNullValues(ArangoCollection collection) { BaseDocument doc = new BaseDocument(); doc.addAttribute("null", null); - final DocumentCreateEntity insertedDoc = collection - .insertDocument(doc, new DocumentCreateOptions().returnNew(true)); + final DocumentCreateEntity insertedDoc = collection.insertDocument(doc, new DocumentCreateOptions().returnNew(true)); assertThat(insertedDoc).isNotNull(); assertThat(insertedDoc.getId()).isNotNull(); assertThat(insertedDoc.getKey()).isNotNull(); @@ -144,8 +143,7 @@ void insertDocumentWithNullValues(ArangoCollection collection) { @MethodSource("cols") void insertDocumentUpdateRev(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); assertThat(doc.getRevision()).isEqualTo(createResult.getRev()); } @@ -153,14 +151,14 @@ void insertDocumentUpdateRev(ArangoCollection collection) { @MethodSource("cols") void insertDocumentReturnNew(ArangoCollection collection) { final DocumentCreateOptions options = new DocumentCreateOptions().returnNew(true); - final DocumentCreateEntity doc = collection - .insertDocument(new BaseDocument(), options); + final DocumentCreateEntity doc = collection.insertDocument(new BaseDocument(), options); assertThat(doc).isNotNull(); assertThat(doc.getId()).isNotNull(); assertThat(doc.getKey()).isNotNull(); assertThat(doc.getRev()).isNotNull(); assertThat(doc.getNew()).isNotNull(); } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentOverwriteModeIgnore(ArangoCollection collection) { @@ -173,8 +171,7 @@ void insertDocumentOverwriteModeIgnore(ArangoCollection collection) { final BaseDocument doc2 = new BaseDocument(key); doc2.addAttribute("bar", "b"); - final DocumentCreateEntity insertIgnore = collection - .insertDocument(doc2, new DocumentCreateOptions().overwriteMode(OverwriteMode.ignore)); + final DocumentCreateEntity insertIgnore = collection.insertDocument(doc2, new DocumentCreateOptions().overwriteMode(OverwriteMode.ignore)); assertThat(insertIgnore).isNotNull(); assertThat(insertIgnore.getRev()).isEqualTo(meta.getRev()); @@ -191,8 +188,7 @@ void insertDocumentOverwriteModeConflict(ArangoCollection collection) { collection.insertDocument(doc); final BaseDocument doc2 = new BaseDocument(key); - Throwable thrown = catchThrowable(() -> - collection.insertDocument(doc2, new DocumentCreateOptions().overwriteMode(OverwriteMode.conflict))); + Throwable thrown = catchThrowable(() -> collection.insertDocument(doc2, new DocumentCreateOptions().overwriteMode(OverwriteMode.conflict))); assertThat(thrown).isInstanceOf(ArangoDBException.class); ArangoDBException e = (ArangoDBException) thrown; assertThat(e.getResponseCode()).isEqualTo(409); @@ -211,8 +207,7 @@ void insertDocumentOverwriteModeReplace(ArangoCollection collection) { final BaseDocument doc2 = new BaseDocument(key); doc2.addAttribute("bar", "b"); - final DocumentCreateEntity repsert = collection - .insertDocument(doc2, new DocumentCreateOptions().overwriteMode(OverwriteMode.replace).returnNew(true)); + final DocumentCreateEntity repsert = collection.insertDocument(doc2, new DocumentCreateOptions().overwriteMode(OverwriteMode.replace).returnNew(true)); assertThat(repsert).isNotNull(); assertThat(repsert.getRev()).isNotEqualTo(meta.getRev()); @@ -230,8 +225,7 @@ void insertDocumentOverwriteModeUpdate(ArangoCollection collection) { final DocumentCreateEntity meta = collection.insertDocument(doc); doc.addAttribute("bar", "b"); - final DocumentCreateEntity updated = collection - .insertDocument(doc, new DocumentCreateOptions().overwriteMode(OverwriteMode.update).returnNew(true)); + final DocumentCreateEntity updated = collection.insertDocument(doc, new DocumentCreateOptions().overwriteMode(OverwriteMode.update).returnNew(true)); assertThat(updated).isNotNull(); assertThat(updated.getRev()).isNotEqualTo(meta.getRev()); @@ -251,11 +245,7 @@ void insertDocumentOverwriteModeUpdateMergeObjectsFalse(ArangoCollection collect Map fieldB = Collections.singletonMap("b", "b"); doc.addAttribute("foo", fieldB); - final DocumentCreateEntity updated = collection - .insertDocument(doc, new DocumentCreateOptions() - .overwriteMode(OverwriteMode.update) - .mergeObjects(false) - .returnNew(true)); + final DocumentCreateEntity updated = collection.insertDocument(doc, new DocumentCreateOptions().overwriteMode(OverwriteMode.update).mergeObjects(false).returnNew(true)); assertThat(updated).isNotNull(); assertThat(updated.getRev()).isNotEqualTo(meta.getRev()); @@ -266,8 +256,7 @@ void insertDocumentOverwriteModeUpdateMergeObjectsFalse(ArangoCollection collect @MethodSource("cols") void insertDocumentWaitForSync(ArangoCollection collection) { final DocumentCreateOptions options = new DocumentCreateOptions().waitForSync(true); - final DocumentCreateEntity doc = collection - .insertDocument(new BaseDocument(), options); + final DocumentCreateEntity doc = collection.insertDocument(new BaseDocument(), options); assertThat(doc).isNotNull(); assertThat(doc.getId()).isNotNull(); assertThat(doc.getKey()).isNotNull(); @@ -279,20 +268,38 @@ void insertDocumentWaitForSync(ArangoCollection collection) { @MethodSource("cols") void insertDocumentAsJson(ArangoCollection collection) { String key = "doc-" + UUID.randomUUID(); - final DocumentCreateEntity doc = collection - .insertDocument("{\"_key\":\"" + key + "\",\"a\":\"test\"}", null); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\",\"a\":\"test\"}"); + final DocumentCreateEntity doc = collection.insertDocument(rawJson); assertThat(doc).isNotNull(); assertThat(doc.getId()).isEqualTo(collection.name() + "/" + key); assertThat(doc.getKey()).isEqualTo(key); assertThat(doc.getRev()).isNotNull(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void insertDocumentAsBytes(ArangoCollection collection) { + String key = "doc-" + UUID.randomUUID(); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("a", "test"); + byte[] bytes = collection.getSerde().serializeUserData(doc); + RawBytes rawJson = RawBytes.of(bytes); + final DocumentCreateEntity createEntity = collection.insertDocument(rawJson, new DocumentCreateOptions().returnNew(true)); + assertThat(createEntity).isNotNull(); + assertThat(createEntity.getId()).isEqualTo(collection.name() + "/" + key); + assertThat(createEntity.getKey()).isEqualTo(key); + assertThat(createEntity.getRev()).isNotNull(); + assertThat(createEntity.getNew()).isNotNull().isInstanceOf(RawBytes.class); + Map newDoc = collection.getSerde().deserializeUserData(createEntity.getNew().getValue(), Map.class); + assertThat(newDoc).containsAllEntriesOf(doc); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity meta = collection - .insertDocument(new BaseDocument(), new DocumentCreateOptions().silent(true)); + final DocumentCreateEntity meta = collection.insertDocument(new BaseDocument(), new DocumentCreateOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); assertThat(meta.getKey()).isNull(); @@ -306,8 +313,7 @@ void insertDocumentSilentDontTouchInstance(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); final String key = "testkey-" + UUID.randomUUID(); doc.setKey(key); - final DocumentCreateEntity meta = collection - .insertDocument(doc, new DocumentCreateOptions().silent(true)); + final DocumentCreateEntity meta = collection.insertDocument(doc, new DocumentCreateOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getKey()).isNull(); assertThat(doc.getKey()).isEqualTo(key); @@ -317,9 +323,7 @@ void insertDocumentSilentDontTouchInstance(ArangoCollection collection) { @MethodSource("cols") void insertDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final MultiDocumentEntity> info = collection - .insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument()), - new DocumentCreateOptions().silent(true)); + final MultiDocumentEntity> info = collection.insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument()), new DocumentCreateOptions().silent(true)); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); assertThat(info.getDocumentsAndErrors()).isEmpty(); @@ -329,11 +333,9 @@ void insertDocumentsSilent(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocument(ArangoCollection collection) { - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument(), null); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument(), null); assertThat(createResult.getKey()).isNotNull(); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getId()).isEqualTo(COLLECTION_NAME + "/" + createResult.getKey()); } @@ -341,12 +343,10 @@ void getDocument(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentIfMatch(ArangoCollection collection) { - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument(), null); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument(), null); assertThat(createResult.getKey()).isNotNull(); final DocumentReadOptions options = new DocumentReadOptions().ifMatch(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, options); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, options); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getId()).isEqualTo(COLLECTION_NAME + "/" + createResult.getKey()); } @@ -354,24 +354,20 @@ void getDocumentIfMatch(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentIfMatchFail(ArangoCollection collection) { - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument(), null); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument(), null); assertThat(createResult.getKey()).isNotNull(); final DocumentReadOptions options = new DocumentReadOptions().ifMatch("no"); - final BaseDocument document = collection - .getDocument(createResult.getKey(), BaseDocument.class, options); + final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, options); assertThat(document).isNull(); } @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentIfNoneMatch(ArangoCollection collection) { - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument(), null); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument(), null); assertThat(createResult.getKey()).isNotNull(); final DocumentReadOptions options = new DocumentReadOptions().ifNoneMatch("no"); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, options); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, options); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getId()).isEqualTo(COLLECTION_NAME + "/" + createResult.getKey()); } @@ -379,12 +375,10 @@ void getDocumentIfNoneMatch(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentIfNoneMatchFail(ArangoCollection collection) { - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument(), null); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument(), null); assertThat(createResult.getKey()).isNotNull(); final DocumentReadOptions options = new DocumentReadOptions().ifNoneMatch(createResult.getRev()); - final BaseDocument document = collection - .getDocument(createResult.getKey(), BaseDocument.class, options); + final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, options); assertThat(document).isNull(); } @@ -392,11 +386,10 @@ void getDocumentIfNoneMatchFail(ArangoCollection collection) { @MethodSource("cols") void getDocumentAsJson(ArangoCollection collection) { String key = rnd(); - collection.insertDocument("{\"_key\":\"" + key + "\",\"a\":\"test\"}", null); - final String readResult = collection.getDocument(key, String.class, null); - assertThat(readResult) - .contains("\"_key\":\"" + key + "\"") - .contains("\"_id\":\"" + COLLECTION_NAME + "/" + key + "\""); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\",\"a\":\"test\"}"); + collection.insertDocument(rawJson); + final RawJson readResult = collection.getDocument(key, RawJson.class); + assertThat(readResult.getValue()).contains("\"_key\":\"" + key + "\"").contains("\"_id\":\"" + COLLECTION_NAME + "/" + key + "\""); } @ParameterizedTest(name = "{index}") @@ -409,8 +402,7 @@ void getDocumentNotFound(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentNotFoundOptionsDefault(ArangoCollection collection) { - final BaseDocument document = collection - .getDocument("no", BaseDocument.class, new DocumentReadOptions()); + final BaseDocument document = collection.getDocument("no", BaseDocument.class, new DocumentReadOptions()); assertThat(document).isNull(); } @@ -424,8 +416,7 @@ void getDocumentNotFoundOptionsNull(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentNotFoundThrowException(ArangoCollection collection) { - Throwable thrown = catchThrowable(() -> - collection.getDocument("no", BaseDocument.class, new DocumentReadOptions().catchException(false))); + Throwable thrown = catchThrowable(() -> collection.getDocument("no", BaseDocument.class, new DocumentReadOptions().catchException(false))); assertThat(thrown).isInstanceOf(ArangoDBException.class); } @@ -442,8 +433,7 @@ void getDocumentDirtyRead(ArangoCollection collection) throws InterruptedExcepti final BaseDocument doc = new BaseDocument(); collection.insertDocument(doc, new DocumentCreateOptions()); Thread.sleep(2000); - final VPackSlice document = collection - .getDocument(doc.getKey(), VPackSlice.class, new DocumentReadOptions().allowDirtyRead(true)); + final RawJson document = collection.getDocument(doc.getKey(), RawJson.class, new DocumentReadOptions().allowDirtyRead(true)); assertThat(document).isNotNull(); } @@ -455,8 +445,7 @@ void getDocuments(ArangoCollection collection) { values.add(new BaseDocument("2")); values.add(new BaseDocument("3")); collection.insertDocuments(values); - final MultiDocumentEntity documents = collection - .getDocuments(Arrays.asList("1", "2", "3"), BaseDocument.class); + final MultiDocumentEntity documents = collection.getDocuments(Arrays.asList("1", "2", "3"), BaseDocument.class); assertThat(documents).isNotNull(); assertThat(documents.getDocuments()).hasSize(3); for (final BaseDocument document : documents.getDocuments()) { @@ -468,24 +457,16 @@ void getDocuments(ArangoCollection collection) { @MethodSource("cols") void getDocumentsWithCustomShardingKey(ArangoCollection c) { ArangoCollection collection = c.db().collection("customShardingKeyCollection"); - if (collection.exists()) - collection.drop(); + if (collection.exists()) collection.drop(); - collection.create(new CollectionCreateOptions() - .shardKeys("customField") - .numberOfShards(10) - ); + collection.create(new CollectionCreateOptions().shardKeys("customField").numberOfShards(10)); - List values = IntStream.range(0, 10) - .mapToObj(String::valueOf).map(key -> new BaseDocument()) - .peek(it -> it.addAttribute("customField", rnd())) - .collect(Collectors.toList()); + List values = IntStream.range(0, 10).mapToObj(String::valueOf).map(key -> new BaseDocument()).peek(it -> it.addAttribute("customField", rnd())).collect(Collectors.toList()); MultiDocumentEntity> inserted = collection.insertDocuments(values); List insertedKeys = inserted.getDocuments().stream().map(DocumentEntity::getKey).collect(Collectors.toList()); - final Collection documents = collection - .getDocuments(insertedKeys, BaseDocument.class).getDocuments(); + final Collection documents = collection.getDocuments(insertedKeys, BaseDocument.class).getDocuments(); assertThat(documents).hasSize(10); } @@ -498,9 +479,7 @@ void getDocumentsDirtyRead(ArangoCollection collection) { values.add(new BaseDocument("2")); values.add(new BaseDocument("3")); collection.insertDocuments(values); - final MultiDocumentEntity documents = collection - .getDocuments(Arrays.asList("1", "2", "3"), BaseDocument.class, - new DocumentReadOptions().allowDirtyRead(true)); + final MultiDocumentEntity documents = collection.getDocuments(Arrays.asList("1", "2", "3"), BaseDocument.class, new DocumentReadOptions().allowDirtyRead(true)); assertThat(documents).isNotNull(); assertThat(documents.getDocuments()).hasSize(3); for (final BaseDocument document : documents.getDocuments()) { @@ -511,8 +490,7 @@ void getDocumentsDirtyRead(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentsNotFound(ArangoCollection collection) { - final MultiDocumentEntity readResult = collection - .getDocuments(Collections.singleton("no"), BaseDocument.class); + final MultiDocumentEntity readResult = collection.getDocuments(Collections.singleton("no"), BaseDocument.class); assertThat(readResult).isNotNull(); assertThat(readResult.getDocuments()).isEmpty(); assertThat(readResult.getErrors()).hasSize(1); @@ -521,8 +499,7 @@ void getDocumentsNotFound(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void getDocumentsWrongKey(ArangoCollection collection) { - final MultiDocumentEntity readResult = collection - .getDocuments(Collections.singleton("no/no"), BaseDocument.class); + final MultiDocumentEntity readResult = collection.getDocuments(Collections.singleton("no/no"), BaseDocument.class); assertThat(readResult).isNotNull(); assertThat(readResult.getDocuments()).isEmpty(); assertThat(readResult.getErrors()).hasSize(1); @@ -534,13 +511,11 @@ void updateDocument(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); doc.addAttribute("c", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", "test1"); doc.addAttribute("b", "test"); doc.updateAttribute("c", null); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, null); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, null); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getNew()).isNull(); @@ -548,8 +523,7 @@ void updateDocument(ArangoCollection collection) { assertThat(updateResult.getRev()).isNotEqualTo(updateResult.getOldRev()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getAttribute("a")).isNotNull(); assertThat(String.valueOf(readResult.getAttribute("a"))).isEqualTo("test1"); @@ -567,8 +541,7 @@ void updateDocumentWithDifferentReturnType(ArangoCollection collection) { doc.addAttribute("a", "test"); collection.insertDocument(doc); - final DocumentUpdateEntity updateResult = collection - .updateDocument(key, Collections.singletonMap("b", "test"), new DocumentUpdateOptions().returnNew(true), BaseDocument.class); + final DocumentUpdateEntity updateResult = collection.updateDocument(key, Collections.singletonMap("b", "test"), new DocumentUpdateOptions().returnNew(true), BaseDocument.class); assertThat(updateResult).isNotNull(); assertThat(updateResult.getKey()).isEqualTo(key); BaseDocument updated = updateResult.getNew(); @@ -581,11 +554,9 @@ void updateDocumentWithDifferentReturnType(ArangoCollection collection) { @MethodSource("cols") void updateDocumentUpdateRev(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); assertThat(doc.getRevision()).isEqualTo(createResult.getRev()); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, null); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, null); assertThat(doc.getRevision()).isEqualTo(updateResult.getRev()); } @@ -595,21 +566,18 @@ void updateDocumentIfMatch(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); doc.addAttribute("c", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", "test1"); doc.addAttribute("b", "test"); doc.updateAttribute("c", null); final DocumentUpdateOptions options = new DocumentUpdateOptions().ifMatch(createResult.getRev()); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getRev()).isNotEqualTo(updateResult.getOldRev()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getAttribute("a")).isNotNull(); assertThat(String.valueOf(readResult.getAttribute("a"))).isEqualTo("test1"); @@ -625,8 +593,7 @@ void updateDocumentIfMatchFail(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); doc.addAttribute("c", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", "test1"); doc.addAttribute("b", "test"); doc.updateAttribute("c", null); @@ -641,13 +608,11 @@ void updateDocumentIfMatchFail(ArangoCollection collection) { void updateDocumentReturnNew(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", "test1"); doc.addAttribute("b", "test"); final DocumentUpdateOptions options = new DocumentUpdateOptions().returnNew(true); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); @@ -665,13 +630,11 @@ void updateDocumentReturnNew(ArangoCollection collection) { void updateDocumentReturnOld(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", "test1"); doc.addAttribute("b", "test"); final DocumentUpdateOptions options = new DocumentUpdateOptions().returnOld(true); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); @@ -688,19 +651,16 @@ void updateDocumentReturnOld(ArangoCollection collection) { void updateDocumentKeepNullTrue(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", null); final DocumentUpdateOptions options = new DocumentUpdateOptions().keepNull(true); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getRev()).isNotEqualTo(updateResult.getOldRev()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getProperties()).containsKey("a"); } @@ -710,28 +670,48 @@ void updateDocumentKeepNullTrue(ArangoCollection collection) { void updateDocumentKeepNullFalse(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", null); final DocumentUpdateOptions options = new DocumentUpdateOptions().keepNull(false); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getRev()).isNotEqualTo(updateResult.getOldRev()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getId()).isEqualTo(createResult.getId()); assertThat(readResult.getRevision()).isNotNull(); assertThat(readResult.getProperties().keySet()).doesNotContain("a"); } - static class TestUpdateEntity { + public static class TestUpdateEntity { @SuppressWarnings("unused") private String a, b; + + public String getA() { + return a; + } + + public String getB() { + return b; + } + } + + public static class TestUpdateEntitySerializeNullFalse { + @SuppressWarnings("unused") + private String a, b; + + @JsonInclude(JsonInclude.Include.NON_NULL) + public String getA() { + return a; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public String getB() { + return b; + } } @ParameterizedTest(name = "{index}") @@ -743,13 +723,11 @@ void updateDocumentSerializeNullTrue(ArangoCollection collection) { final DocumentCreateEntity createResult = collection.insertDocument(doc); final TestUpdateEntity patchDoc = new TestUpdateEntity(); patchDoc.a = "bar"; - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), patchDoc); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); assertThat(updateResult).isNotNull(); assertThat(updateResult.getKey()).isEqualTo(createResult.getKey()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getProperties()).containsKey("a"); assertThat(readResult.getAttribute("a")).isEqualTo("bar"); @@ -758,19 +736,17 @@ void updateDocumentSerializeNullTrue(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void updateDocumentSerializeNullFalse(ArangoCollection collection) { - final TestUpdateEntity doc = new TestUpdateEntity(); + final TestUpdateEntitySerializeNullFalse doc = new TestUpdateEntitySerializeNullFalse(); doc.a = "foo"; doc.b = "foo"; - final DocumentCreateEntity createResult = collection.insertDocument(doc); - final TestUpdateEntity patchDoc = new TestUpdateEntity(); + final DocumentCreateEntity createResult = collection.insertDocument(doc); + final TestUpdateEntitySerializeNullFalse patchDoc = new TestUpdateEntitySerializeNullFalse(); patchDoc.a = "bar"; - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), patchDoc, new DocumentUpdateOptions().serializeNull(false)); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); assertThat(updateResult).isNotNull(); assertThat(updateResult.getKey()).isEqualTo(createResult.getKey()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getProperties()).containsKeys("a", "b"); assertThat(readResult.getAttribute("a")).isEqualTo("bar"); @@ -785,21 +761,18 @@ void updateDocumentMergeObjectsTrue(ArangoCollection collection) { final Map a = new HashMap<>(); a.put("a", "test"); doc.addAttribute("a", a); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); a.clear(); a.put("b", "test"); doc.updateAttribute("a", a); final DocumentUpdateOptions options = new DocumentUpdateOptions().mergeObjects(true); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getRev()).isNotEqualTo(updateResult.getOldRev()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); final Object aResult = readResult.getAttribute("a"); assertThat(aResult).isInstanceOf(Map.class); @@ -815,21 +788,18 @@ void updateDocumentMergeObjectsFalse(ArangoCollection collection) { final Map a = new HashMap<>(); a.put("a", "test"); doc.addAttribute("a", a); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); a.clear(); a.put("b", "test"); doc.updateAttribute("a", a); final DocumentUpdateOptions options = new DocumentUpdateOptions().mergeObjects(false); - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), doc, options); assertThat(updateResult).isNotNull(); assertThat(updateResult.getId()).isEqualTo(createResult.getId()); assertThat(updateResult.getRev()).isNotEqualTo(updateResult.getOldRev()); assertThat(updateResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); final Object aResult = readResult.getAttribute("a"); assertThat(aResult).isInstanceOf(Map.class); @@ -843,8 +813,7 @@ void updateDocumentMergeObjectsFalse(ArangoCollection collection) { void updateDocumentIgnoreRevsFalse(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("a", "test1"); doc.setRevision("no"); @@ -857,10 +826,8 @@ void updateDocumentIgnoreRevsFalse(ArangoCollection collection) { @MethodSource("cols") void updateDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument()); - final DocumentUpdateEntity meta = collection - .updateDocument(createResult.getKey(), new BaseDocument(), new DocumentUpdateOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentUpdateEntity meta = collection.updateDocument(createResult.getKey(), new BaseDocument(), new DocumentUpdateOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); assertThat(meta.getKey()).isNull(); @@ -871,11 +838,8 @@ void updateDocumentSilent(ArangoCollection collection) { @MethodSource("cols") void updateDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument()); - final MultiDocumentEntity> info = collection - .updateDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), - new DocumentUpdateOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = collection.updateDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), new DocumentUpdateOptions().silent(true)); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); assertThat(info.getDocumentsAndErrors()).isEmpty(); @@ -901,15 +865,13 @@ void updateNonExistingDocument(ArangoCollection collection) { void updateDocumentPreconditionFailed(ArangoCollection collection) { final BaseDocument doc = new BaseDocument("test-" + rnd()); doc.addAttribute("foo", "a"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.updateAttribute("foo", "b"); collection.updateDocument(doc.getKey(), doc, null); doc.updateAttribute("foo", "c"); - Throwable thrown = catchThrowable(() -> - collection.updateDocument(doc.getKey(), doc, new DocumentUpdateOptions().ifMatch(createResult.getRev()))); + Throwable thrown = catchThrowable(() -> collection.updateDocument(doc.getKey(), doc, new DocumentUpdateOptions().ifMatch(createResult.getRev()))); assertThat(thrown).isInstanceOf(ArangoDBException.class); ArangoDBException e = (ArangoDBException) thrown; assertThat(e.getResponseCode()).isEqualTo(412); @@ -923,12 +885,10 @@ void updateDocumentPreconditionFailed(ArangoCollection collection) { void replaceDocument(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.getProperties().clear(); doc.addAttribute("b", "test"); - final DocumentUpdateEntity replaceResult = collection - .replaceDocument(createResult.getKey(), doc, null); + final DocumentUpdateEntity replaceResult = collection.replaceDocument(createResult.getKey(), doc, null); assertThat(replaceResult).isNotNull(); assertThat(replaceResult.getId()).isEqualTo(createResult.getId()); assertThat(replaceResult.getNew()).isNull(); @@ -936,8 +896,7 @@ void replaceDocument(ArangoCollection collection) { assertThat(replaceResult.getRev()).isNotEqualTo(replaceResult.getOldRev()); assertThat(replaceResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getRevision()).isEqualTo(replaceResult.getRev()); assertThat(readResult.getProperties().keySet()).doesNotContain("a"); @@ -949,11 +908,9 @@ void replaceDocument(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentUpdateRev(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); assertThat(doc.getRevision()).isEqualTo(createResult.getRev()); - final DocumentUpdateEntity replaceResult = collection - .replaceDocument(createResult.getKey(), doc, null); + final DocumentUpdateEntity replaceResult = collection.replaceDocument(createResult.getKey(), doc, null); assertThat(doc.getRevision()).isEqualTo(replaceResult.getRev()); } @@ -962,20 +919,17 @@ void replaceDocumentUpdateRev(ArangoCollection collection) { void replaceDocumentIfMatch(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.getProperties().clear(); doc.addAttribute("b", "test"); final DocumentReplaceOptions options = new DocumentReplaceOptions().ifMatch(createResult.getRev()); - final DocumentUpdateEntity replaceResult = collection - .replaceDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity replaceResult = collection.replaceDocument(createResult.getKey(), doc, options); assertThat(replaceResult).isNotNull(); assertThat(replaceResult.getId()).isEqualTo(createResult.getId()); assertThat(replaceResult.getRev()).isNotEqualTo(replaceResult.getOldRev()); assertThat(replaceResult.getOldRev()).isEqualTo(createResult.getRev()); - final BaseDocument readResult = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(createResult.getKey()); assertThat(readResult.getRevision()).isEqualTo(replaceResult.getRev()); assertThat(readResult.getProperties().keySet()).doesNotContain("a"); @@ -988,8 +942,7 @@ void replaceDocumentIfMatch(ArangoCollection collection) { void replaceDocumentIfMatchFail(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.getProperties().clear(); doc.addAttribute("b", "test"); @@ -1004,8 +957,7 @@ void replaceDocumentIfMatchFail(ArangoCollection collection) { void replaceDocumentIgnoreRevsFalse(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.getProperties().clear(); doc.addAttribute("b", "test"); doc.setRevision("no"); @@ -1020,13 +972,11 @@ void replaceDocumentIgnoreRevsFalse(ArangoCollection collection) { void replaceDocumentReturnNew(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.getProperties().clear(); doc.addAttribute("b", "test"); final DocumentReplaceOptions options = new DocumentReplaceOptions().returnNew(true); - final DocumentUpdateEntity replaceResult = collection - .replaceDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity replaceResult = collection.replaceDocument(createResult.getKey(), doc, options); assertThat(replaceResult).isNotNull(); assertThat(replaceResult.getId()).isEqualTo(createResult.getId()); assertThat(replaceResult.getOldRev()).isEqualTo(createResult.getRev()); @@ -1043,13 +993,11 @@ void replaceDocumentReturnNew(ArangoCollection collection) { void replaceDocumentReturnOld(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); doc.getProperties().clear(); doc.addAttribute("b", "test"); final DocumentReplaceOptions options = new DocumentReplaceOptions().returnOld(true); - final DocumentUpdateEntity replaceResult = collection - .replaceDocument(createResult.getKey(), doc, options); + final DocumentUpdateEntity replaceResult = collection.replaceDocument(createResult.getKey(), doc, options); assertThat(replaceResult).isNotNull(); assertThat(replaceResult.getId()).isEqualTo(createResult.getId()); assertThat(replaceResult.getOldRev()).isEqualTo(createResult.getRev()); @@ -1065,10 +1013,8 @@ void replaceDocumentReturnOld(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument()); - final DocumentUpdateEntity meta = collection - .replaceDocument(createResult.getKey(), new BaseDocument(), new DocumentReplaceOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentUpdateEntity meta = collection.replaceDocument(createResult.getKey(), new BaseDocument(), new DocumentReplaceOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); assertThat(meta.getKey()).isNull(); @@ -1083,8 +1029,7 @@ void replaceDocumentSilentDontTouchInstance(ArangoCollection collection) { final DocumentCreateEntity createResult = collection.insertDocument(doc); final String revision = doc.getRevision(); assertThat(revision).isNotNull(); - final DocumentUpdateEntity meta = collection - .replaceDocument(createResult.getKey(), doc, new DocumentReplaceOptions().silent(true)); + final DocumentUpdateEntity meta = collection.replaceDocument(createResult.getKey(), doc, new DocumentReplaceOptions().silent(true)); assertThat(meta.getRev()).isNull(); assertThat(doc.getRevision()).isEqualTo(revision); } @@ -1093,11 +1038,8 @@ void replaceDocumentSilentDontTouchInstance(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument()); - final MultiDocumentEntity> info = collection - .replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), - new DocumentReplaceOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())), new DocumentReplaceOptions().silent(true)); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); assertThat(info.getDocumentsAndErrors()).isEmpty(); @@ -1108,11 +1050,9 @@ void replaceDocumentsSilent(ArangoCollection collection) { @MethodSource("cols") void deleteDocument(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); collection.deleteDocument(createResult.getKey(), null, null); - final BaseDocument document = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(document).isNull(); } @@ -1121,11 +1061,9 @@ void deleteDocument(ArangoCollection collection) { void deleteDocumentReturnOld(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); final DocumentDeleteOptions options = new DocumentDeleteOptions().returnOld(true); - final DocumentDeleteEntity deleteResult = collection - .deleteDocument(createResult.getKey(), BaseDocument.class, options); + final DocumentDeleteEntity deleteResult = collection.deleteDocument(createResult.getKey(), BaseDocument.class, options); assertThat(deleteResult.getOld()).isNotNull(); assertThat(deleteResult.getOld()).isInstanceOf(BaseDocument.class); assertThat(deleteResult.getOld().getAttribute("a")).isNotNull(); @@ -1136,12 +1074,10 @@ void deleteDocumentReturnOld(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentIfMatch(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch(createResult.getRev()); collection.deleteDocument(createResult.getKey(), null, options); - final BaseDocument document = collection - .getDocument(createResult.getKey(), BaseDocument.class, null); + final BaseDocument document = collection.getDocument(createResult.getKey(), BaseDocument.class, null); assertThat(document).isNull(); } @@ -1149,8 +1085,7 @@ void deleteDocumentIfMatch(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentIfMatchFail(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); - final DocumentCreateEntity createResult = collection - .insertDocument(doc, null); + final DocumentCreateEntity createResult = collection.insertDocument(doc, null); final DocumentDeleteOptions options = new DocumentDeleteOptions().ifMatch("no"); Throwable thrown = catchThrowable(() -> collection.deleteDocument(createResult.getKey(), null, options)); assertThat(thrown).isInstanceOf(ArangoDBException.class); @@ -1160,10 +1095,8 @@ void deleteDocumentIfMatchFail(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument()); - final DocumentDeleteEntity meta = collection - .deleteDocument(createResult.getKey(), BaseDocument.class, new DocumentDeleteOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final DocumentDeleteEntity meta = collection.deleteDocument(createResult.getKey(), BaseDocument.class, new DocumentDeleteOptions().silent(true)); assertThat(meta).isNotNull(); assertThat(meta.getId()).isNull(); assertThat(meta.getKey()).isNull(); @@ -1174,11 +1107,8 @@ void deleteDocumentSilent(ArangoCollection collection) { @MethodSource("cols") void deleteDocumentsSilent(ArangoCollection collection) { assumeTrue(isSingleServer()); - final DocumentCreateEntity createResult = collection - .insertDocument(new BaseDocument()); - final MultiDocumentEntity> info = collection - .deleteDocuments(Collections.singletonList(createResult.getKey()), BaseDocument.class, - new DocumentDeleteOptions().silent(true)); + final DocumentCreateEntity createResult = collection.insertDocument(new BaseDocument()); + final MultiDocumentEntity> info = collection.deleteDocuments(Collections.singletonList(createResult.getKey()), BaseDocument.class, new DocumentDeleteOptions().silent(true)); assertThat(info).isNotNull(); assertThat(info.getDocuments()).isEmpty(); assertThat(info.getDocumentsAndErrors()).isEmpty(); @@ -1505,9 +1435,7 @@ void createZKDIndexWithOptions(ArangoCollection collection) { collection.truncate(); String name = "ZKDIndex-" + rnd(); - final ZKDIndexOptions options = new ZKDIndexOptions() - .name(name) - .fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE); + final ZKDIndexOptions options = new ZKDIndexOptions().name(name).fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE); String f1 = "field-" + rnd(); String f2 = "field-" + rnd(); @@ -1693,10 +1621,7 @@ void getIndexes(ArangoCollection collection) { String f1 = "field-" + rnd(); final Collection fields = Collections.singletonList(f1); collection.ensureHashIndex(fields, null); - long matchingIndexes = collection.getIndexes().stream() - .filter(i -> i.getType() == IndexType.hash) - .filter(i -> i.getFields().contains(f1)) - .count(); + long matchingIndexes = collection.getIndexes().stream().filter(i -> i.getType() == IndexType.hash).filter(i -> i.getFields().contains(f1)).count(); assertThat(matchingIndexes).isEqualTo(1L); } @@ -1722,14 +1647,12 @@ void exists(ArangoCollection collection) { void truncate(ArangoCollection collection) { final BaseDocument doc = new BaseDocument(); collection.insertDocument(doc, null); - final BaseDocument readResult = collection - .getDocument(doc.getKey(), BaseDocument.class, null); + final BaseDocument readResult = collection.getDocument(doc.getKey(), BaseDocument.class, null); assertThat(readResult.getKey()).isEqualTo(doc.getKey()); final CollectionEntity truncateResult = collection.truncate(); assertThat(truncateResult).isNotNull(); assertThat(truncateResult.getId()).isNotNull(); - final BaseDocument document = collection - .getDocument(doc.getKey(), BaseDocument.class, null); + final BaseDocument document = collection.getDocument(doc.getKey(), BaseDocument.class, null); assertThat(document).isNull(); } @@ -1737,19 +1660,20 @@ void truncate(ArangoCollection collection) { @MethodSource("cols") void getCount(ArangoCollection collection) { Long initialCount = collection.count().getCount(); - collection.insertDocument("{}", null); + collection.insertDocument(RawJson.of("{}")); final CollectionPropertiesEntity count = collection.count(); assertThat(count.getCount()).isEqualTo(initialCount + 1L); } @ParameterizedTest(name = "{index}") @MethodSource("cols") - void documentExists(ArangoCollection collection) throws JsonProcessingException { + void documentExists(ArangoCollection collection) { final Boolean existsNot = collection.documentExists(rnd(), null); assertThat(existsNot).isFalse(); String key = rnd(); - collection.insertDocument(mapper.writeValueAsString(Collections.singletonMap("_key", key)), null); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); + collection.insertDocument(rawJson); final Boolean exists = collection.documentExists(key, null); assertThat(exists).isTrue(); } @@ -1763,9 +1687,10 @@ void documentExistsThrowExcpetion(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") - void documentExistsIfMatch(ArangoCollection collection) throws JsonProcessingException { + void documentExistsIfMatch(ArangoCollection collection) { String key = rnd(); - final DocumentCreateEntity createResult = collection.insertDocument(mapper.writeValueAsString(Collections.singletonMap("_key", key)), null); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); + final DocumentCreateEntity createResult = collection.insertDocument(rawJson); final DocumentExistsOptions options = new DocumentExistsOptions().ifMatch(createResult.getRev()); final Boolean exists = collection.documentExists(key, options); assertThat(exists).isTrue(); @@ -1773,9 +1698,10 @@ void documentExistsIfMatch(ArangoCollection collection) throws JsonProcessingExc @ParameterizedTest(name = "{index}") @MethodSource("cols") - void documentExistsIfMatchFail(ArangoCollection collection) throws JsonProcessingException { + void documentExistsIfMatchFail(ArangoCollection collection) { String key = rnd(); - collection.insertDocument(mapper.writeValueAsString(Collections.singletonMap("_key", key)), null); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); + collection.insertDocument(rawJson); final DocumentExistsOptions options = new DocumentExistsOptions().ifMatch("no"); final Boolean exists = collection.documentExists(key, options); assertThat(exists).isFalse(); @@ -1783,9 +1709,10 @@ void documentExistsIfMatchFail(ArangoCollection collection) throws JsonProcessin @ParameterizedTest(name = "{index}") @MethodSource("cols") - void documentExistsIfNoneMatch(ArangoCollection collection) throws JsonProcessingException { + void documentExistsIfNoneMatch(ArangoCollection collection) { String key = rnd(); - collection.insertDocument(mapper.writeValueAsString(Collections.singletonMap("_key", key)), null); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); + collection.insertDocument(rawJson); final DocumentExistsOptions options = new DocumentExistsOptions().ifNoneMatch("no"); final Boolean exists = collection.documentExists(key, options); assertThat(exists).isTrue(); @@ -1793,9 +1720,10 @@ void documentExistsIfNoneMatch(ArangoCollection collection) throws JsonProcessin @ParameterizedTest(name = "{index}") @MethodSource("cols") - void documentExistsIfNoneMatchFail(ArangoCollection collection) throws JsonProcessingException { + void documentExistsIfNoneMatchFail(ArangoCollection collection) { String key = rnd(); - final DocumentCreateEntity createResult = collection.insertDocument(mapper.writeValueAsString(Collections.singletonMap("_key", key)), null); + RawJson rawJson = RawJson.of("{\"_key\":\"" + key + "\"}"); + final DocumentCreateEntity createResult = collection.insertDocument(rawJson); final DocumentExistsOptions options = new DocumentExistsOptions().ifNoneMatch(createResult.getRev()); final Boolean exists = collection.documentExists(key, options); assertThat(exists).isFalse(); @@ -1804,14 +1732,9 @@ void documentExistsIfNoneMatchFail(ArangoCollection collection) throws JsonProce @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocuments(ArangoCollection collection) { - final Collection values = Arrays.asList( - new BaseDocument(), - new BaseDocument(), - new BaseDocument() - ); + final Collection values = Arrays.asList(new BaseDocument(), new BaseDocument(), new BaseDocument()); - final MultiDocumentEntity> docs = collection - .insertDocuments(values, null); + final MultiDocumentEntity> docs = collection.insertDocuments(values, null); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1835,9 +1758,7 @@ void insertDocumentsOverwriteModeUpdate(ArangoCollection collection) { doc1.addAttribute("bar", "b"); doc2.addAttribute("bar", "b"); - final MultiDocumentEntity> repsert = collection - .insertDocuments(Arrays.asList(doc1, doc2), - new DocumentCreateOptions().overwriteMode(OverwriteMode.update).returnNew(true)); + final MultiDocumentEntity> repsert = collection.insertDocuments(Arrays.asList(doc1, doc2), new DocumentCreateOptions().overwriteMode(OverwriteMode.update).returnNew(true)); assertThat(repsert).isNotNull(); assertThat(repsert.getDocuments()).hasSize(2); assertThat(repsert.getErrors()).isEmpty(); @@ -1852,12 +1773,11 @@ void insertDocumentsOverwriteModeUpdate(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentsJson(ArangoCollection collection) { - final Collection values = new ArrayList<>(); - values.add("{}"); - values.add("{}"); - values.add("{}"); - final MultiDocumentEntity> docs = collection - .insertDocuments(values); + final Collection values = new ArrayList<>(); + values.add(RawJson.of("{}")); + values.add(RawJson.of("{}")); + values.add(RawJson.of("{}")); + final MultiDocumentEntity> docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1870,8 +1790,7 @@ void insertDocumentsJson(ArangoCollection collection) { void insertDocumentsOne(ArangoCollection collection) { final Collection values = new ArrayList<>(); values.add(new BaseDocument()); - final MultiDocumentEntity> docs = collection - .insertDocuments(values, null); + final MultiDocumentEntity> docs = collection.insertDocuments(values, null); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(1); @@ -1883,8 +1802,7 @@ void insertDocumentsOne(ArangoCollection collection) { @MethodSource("cols") void insertDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - final MultiDocumentEntity> docs = collection - .insertDocuments(values, null); + final MultiDocumentEntity> docs = collection.insertDocuments(values, null); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).isEmpty(); @@ -1900,8 +1818,7 @@ void insertDocumentsReturnNew(ArangoCollection collection) { values.add(new BaseDocument()); values.add(new BaseDocument()); final DocumentCreateOptions options = new DocumentCreateOptions().returnNew(true); - final MultiDocumentEntity> docs = collection - .insertDocuments(values, options); + final MultiDocumentEntity> docs = collection.insertDocuments(values, options); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1920,14 +1837,9 @@ void insertDocumentsReturnNew(ArangoCollection collection) { void insertDocumentsFail(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final MultiDocumentEntity> docs = collection - .insertDocuments(values); + final MultiDocumentEntity> docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(2); @@ -1939,11 +1851,7 @@ void insertDocumentsFail(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void importDocuments(ArangoCollection collection) { - final Collection values = Arrays.asList( - new BaseDocument(), - new BaseDocument(), - new BaseDocument() - ); + final Collection values = Arrays.asList(new BaseDocument(), new BaseDocument(), new BaseDocument()); final DocumentImportEntity docs = collection.importDocuments(values); assertThat(docs).isNotNull(); @@ -1958,10 +1866,10 @@ void importDocuments(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void importDocumentsJsonList(ArangoCollection collection) { - final Collection values = Arrays.asList( - "{}", - "{}", - "{}" + final Collection values = Arrays.asList( + RawJson.of("{}"), + RawJson.of("{}"), + RawJson.of("{}") ); final DocumentImportEntity docs = collection.importDocuments(values); @@ -1980,11 +1888,7 @@ void importDocumentsDuplicateDefaultError(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); final DocumentImportEntity docs = collection.importDocuments(values); assertThat(docs).isNotNull(); @@ -2002,14 +1906,9 @@ void importDocumentsDuplicateError(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final DocumentImportEntity docs = collection - .importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.error)); + final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.error)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2025,14 +1924,9 @@ void importDocumentsDuplicateIgnore(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final DocumentImportEntity docs = collection - .importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.ignore)); + final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.ignore)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2048,14 +1942,9 @@ void importDocumentsDuplicateReplace(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final DocumentImportEntity docs = collection - .importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.replace)); + final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.replace)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2071,14 +1960,9 @@ void importDocumentsDuplicateUpdate(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final DocumentImportEntity docs = collection - .importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.update)); + final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().onDuplicate(OnDuplicate.update)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2094,11 +1978,7 @@ void importDocumentsCompleteFail(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); Throwable thrown = catchThrowable(() -> collection.importDocuments(values, new DocumentImportOptions().complete(true))); assertThat(thrown).isInstanceOf(ArangoDBException.class); @@ -2112,14 +1992,9 @@ void importDocumentsDetails(ArangoCollection collection) { String k1 = rnd(); String k2 = rnd(); - final Collection values = Arrays.asList( - new BaseDocument(k1), - new BaseDocument(k2), - new BaseDocument(k2) - ); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); - final DocumentImportEntity docs = collection - .importDocuments(values, new DocumentImportOptions().details(true)); + final DocumentImportEntity docs = collection.importDocuments(values, new DocumentImportOptions().details(true)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2159,17 +2034,13 @@ void importDocumentsOverwriteTrue(ArangoCollection collection) { @MethodSource("edges") void importDocumentsFromToPrefix(ArangoCollection edgeCollection) { final Collection values = new ArrayList<>(); - final String[] keys = { - rnd(), - rnd() - }; + final String[] keys = {rnd(), rnd()}; for (String s : keys) { values.add(new BaseEdgeDocument(s, "from", "to")); } assertThat(values).hasSize(keys.length); - final DocumentImportEntity importResult = edgeCollection - .importDocuments(values, new DocumentImportOptions().fromPrefix("foo").toPrefix("bar")); + final DocumentImportEntity importResult = edgeCollection.importDocuments(values, new DocumentImportOptions().fromPrefix("foo").toPrefix("bar")); assertThat(importResult).isNotNull(); assertThat(importResult.getCreated()).isEqualTo(values.size()); for (String key : keys) { @@ -2183,10 +2054,7 @@ void importDocumentsFromToPrefix(ArangoCollection edgeCollection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void importDocumentsJson(ArangoCollection collection) throws JsonProcessingException { - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", rnd()), - Collections.singletonMap("_key", rnd()) - )); + final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", rnd()), Collections.singletonMap("_key", rnd()))); final DocumentImportEntity docs = collection.importDocuments(values); assertThat(docs).isNotNull(); @@ -2204,11 +2072,7 @@ void importDocumentsJsonDuplicateDefaultError(ArangoCollection collection) throw String k1 = rnd(); String k2 = rnd(); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", k1), - Collections.singletonMap("_key", k2), - Collections.singletonMap("_key", k2) - )); + 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); assertThat(docs).isNotNull(); @@ -2226,14 +2090,9 @@ void importDocumentsJsonDuplicateError(ArangoCollection collection) throws JsonP String k1 = rnd(); String k2 = rnd(); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", k1), - Collections.singletonMap("_key", k2), - Collections.singletonMap("_key", k2) - )); + 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(values, new DocumentImportOptions().onDuplicate(OnDuplicate.error)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2249,13 +2108,8 @@ void importDocumentsJsonDuplicateIgnore(ArangoCollection collection) throws Json String k1 = rnd(); 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 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)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2271,14 +2125,9 @@ void importDocumentsJsonDuplicateReplace(ArangoCollection collection) throws Jso String k1 = rnd(); String k2 = rnd(); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", k1), - Collections.singletonMap("_key", k2), - Collections.singletonMap("_key", k2) - )); + 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(values, new DocumentImportOptions().onDuplicate(OnDuplicate.replace)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2294,14 +2143,9 @@ void importDocumentsJsonDuplicateUpdate(ArangoCollection collection) throws Json String k1 = rnd(); String k2 = rnd(); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", k1), - Collections.singletonMap("_key", k2), - Collections.singletonMap("_key", k2) - )); + 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(values, new DocumentImportOptions().onDuplicate(OnDuplicate.update)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2327,14 +2171,9 @@ void importDocumentsJsonDetails(ArangoCollection collection) throws JsonProcessi String k1 = rnd(); String k2 = rnd(); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", k1), - Collections.singletonMap("_key", k2), - Collections.singletonMap("_key", k2) - )); + 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(values, new DocumentImportOptions().details(true)); assertThat(docs).isNotNull(); assertThat(docs.getCreated()).isEqualTo(2); assertThat(docs.getEmpty()).isZero(); @@ -2351,10 +2190,7 @@ void importDocumentsJsonOverwriteFalse(ArangoCollection collection) throws JsonP collection.insertDocument(new BaseDocument()); Long initialCount = collection.count().getCount(); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", rnd()), - Collections.singletonMap("_key", rnd()) - )); + final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", rnd()), Collections.singletonMap("_key", rnd()))); collection.importDocuments(values, new DocumentImportOptions().overwrite(false)); assertThat(collection.count().getCount()).isEqualTo(initialCount + 2L); } @@ -2364,10 +2200,7 @@ void importDocumentsJsonOverwriteFalse(ArangoCollection collection) throws JsonP void importDocumentsJsonOverwriteTrue(ArangoCollection collection) throws JsonProcessingException { collection.insertDocument(new BaseDocument()); - final String values = mapper.writeValueAsString(Arrays.asList( - Collections.singletonMap("_key", rnd()), - Collections.singletonMap("_key", rnd()) - )); + final String values = mapper.writeValueAsString(Arrays.asList(Collections.singletonMap("_key", rnd()), Collections.singletonMap("_key", rnd()))); collection.importDocuments(values, new DocumentImportOptions().overwrite(true)); assertThat(collection.count().getCount()).isEqualTo(2L); } @@ -2380,21 +2213,9 @@ void importDocumentsJsonFromToPrefix(ArangoCollection edgeCollection) throws Jso final String[] keys = {k1, k2}; - 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 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")); assertThat(importResult).isNotNull(); assertThat(importResult.getCreated()).isEqualTo(2); for (String key : keys) { @@ -2423,8 +2244,7 @@ void deleteDocumentsByKey(ArangoCollection collection) { final Collection keys = new ArrayList<>(); keys.add("1"); keys.add("2"); - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(keys, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(2); for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { @@ -2448,8 +2268,7 @@ void deleteDocumentsByDocuments(ArangoCollection collection) { values.add(e); } collection.insertDocuments(values, null); - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(values, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(2); for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { @@ -2470,8 +2289,7 @@ void deleteDocumentsByKeyOne(ArangoCollection collection) { collection.insertDocuments(values, null); final Collection keys = new ArrayList<>(); keys.add("1"); - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(keys, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(1); for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { @@ -2490,8 +2308,7 @@ void deleteDocumentsByDocumentOne(ArangoCollection collection) { values.add(e); } collection.insertDocuments(values, null); - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(values, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).hasSize(1); for (final DocumentDeleteEntity i : deleteResult.getDocuments()) { @@ -2506,8 +2323,7 @@ void deleteDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); collection.insertDocuments(values, null); final Collection keys = new ArrayList<>(); - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(keys, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).isEmpty(); assertThat(deleteResult.getErrors()).isEmpty(); @@ -2518,13 +2334,9 @@ void deleteDocumentsEmpty(ArangoCollection collection) { void deleteDocumentsByKeyNotExisting(ArangoCollection collection) { final Collection values = new ArrayList<>(); collection.insertDocuments(values, null); - final Collection keys = Arrays.asList( - rnd(), - rnd() - ); + final Collection keys = Arrays.asList(rnd(), rnd()); - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(keys, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(keys, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).isEmpty(); assertThat(deleteResult.getErrors()).hasSize(2); @@ -2544,8 +2356,7 @@ void deleteDocumentsByDocumentsNotExisting(ArangoCollection collection) { e.setKey("2"); values.add(e); } - final MultiDocumentEntity> deleteResult = collection - .deleteDocuments(values, null, null); + final MultiDocumentEntity> deleteResult = collection.deleteDocuments(values, null, null); assertThat(deleteResult).isNotNull(); assertThat(deleteResult.getDocuments()).isEmpty(); assertThat(deleteResult.getErrors()).hasSize(2); @@ -2554,15 +2365,11 @@ void deleteDocumentsByDocumentsNotExisting(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void updateDocuments(ArangoCollection collection) { - final Collection values = Arrays.asList( - new BaseDocument(rnd()), - new BaseDocument(rnd()) - ); + final Collection values = Arrays.asList(new BaseDocument(rnd()), new BaseDocument(rnd())); collection.insertDocuments(values, null); values.forEach(it -> it.addAttribute("a", "test")); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(values, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(values, null); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2571,32 +2378,22 @@ void updateDocuments(ArangoCollection collection) { @MethodSource("cols") void updateDocumentsWithDifferentReturnType(ArangoCollection collection) { List keys = IntStream.range(0, 3).mapToObj(it -> "key-" + UUID.randomUUID()).collect(Collectors.toList()); - List docs = keys.stream() - .map(BaseDocument::new) - .peek(it -> it.addAttribute("a", "test")) - .collect(Collectors.toList()); + List docs = keys.stream().map(BaseDocument::new).peek(it -> it.addAttribute("a", "test")).collect(Collectors.toList()); collection.insertDocuments(docs); - List> modifiedDocs = docs.stream() - .peek(it -> it.addAttribute("b", "test")) - .map(it -> { - Map map = new HashMap<>(); - map.put("_key", it.getKey()); - map.put("a", it.getAttribute("a")); - map.put("b", it.getAttribute("b")); - return map; - }) - .collect(Collectors.toList()); - - final MultiDocumentEntity> updateResult = collection - .updateDocuments(modifiedDocs, new DocumentUpdateOptions().returnNew(true), BaseDocument.class); + List> modifiedDocs = docs.stream().peek(it -> it.addAttribute("b", "test")).map(it -> { + Map map = new HashMap<>(); + map.put("_key", it.getKey()); + map.put("a", it.getAttribute("a")); + map.put("b", it.getAttribute("b")); + return map; + }).collect(Collectors.toList()); + + final MultiDocumentEntity> updateResult = collection.updateDocuments(modifiedDocs, new DocumentUpdateOptions().returnNew(true), BaseDocument.class); assertThat(updateResult.getDocuments()).hasSize(3); assertThat(updateResult.getErrors()).isEmpty(); - assertThat(updateResult.getDocuments().stream()) - .map(DocumentUpdateEntity::getNew) - .allMatch(it -> it.getAttribute("a").equals("test")) - .allMatch(it -> it.getAttribute("b").equals("test")); + assertThat(updateResult.getDocuments().stream()).map(DocumentUpdateEntity::getNew).allMatch(it -> it.getAttribute("a").equals("test")).allMatch(it -> it.getAttribute("b").equals("test")); } @ParameterizedTest(name = "{index}") @@ -2613,8 +2410,7 @@ void updateDocumentsOne(ArangoCollection collection) { final BaseDocument first = values.iterator().next(); first.addAttribute("a", "test"); updatedValues.add(first); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(updatedValues, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2623,8 +2419,7 @@ void updateDocumentsOne(ArangoCollection collection) { @MethodSource("cols") void updateDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(values, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(values, null); assertThat(updateResult.getDocuments()).isEmpty(); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2643,8 +2438,7 @@ void updateDocumentsWithoutKey(ArangoCollection collection) { updatedValues.add(i); } updatedValues.add(new BaseDocument()); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(updatedValues, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).hasSize(1); } @@ -2652,16 +2446,15 @@ void updateDocumentsWithoutKey(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void updateDocumentsJson(ArangoCollection collection) { - final Collection values = new ArrayList<>(); - values.add("{\"_key\":\"1\"}"); - values.add("{\"_key\":\"2\"}"); + final Collection values = new ArrayList<>(); + values.add(RawJson.of("{\"_key\":\"1\"}")); + values.add(RawJson.of("{\"_key\":\"2\"}")); collection.insertDocuments(values); - final Collection updatedValues = new ArrayList<>(); - updatedValues.add("{\"_key\":\"1\", \"foo\":\"bar\"}"); - updatedValues.add("{\"_key\":\"2\", \"foo\":\"bar\"}"); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(updatedValues); + final Collection updatedValues = new ArrayList<>(); + updatedValues.add(RawJson.of("{\"_key\":\"1\", \"foo\":\"bar\"}")); + updatedValues.add(RawJson.of("{\"_key\":\"2\", \"foo\":\"bar\"}")); + final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2680,8 +2473,7 @@ void replaceDocuments(ArangoCollection collection) { i.addAttribute("a", "test"); updatedValues.add(i); } - final MultiDocumentEntity> updateResult = collection - .replaceDocuments(updatedValues, null); + final MultiDocumentEntity> updateResult = collection.replaceDocuments(updatedValues, null); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2700,8 +2492,7 @@ void replaceDocumentsOne(ArangoCollection collection) { final BaseDocument first = values.iterator().next(); first.addAttribute("a", "test"); updatedValues.add(first); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(updatedValues, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2710,8 +2501,7 @@ void replaceDocumentsOne(ArangoCollection collection) { @MethodSource("cols") void replaceDocumentsEmpty(ArangoCollection collection) { final Collection values = new ArrayList<>(); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(values, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(values, null); assertThat(updateResult.getDocuments()).isEmpty(); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2730,8 +2520,7 @@ void replaceDocumentsWithoutKey(ArangoCollection collection) { updatedValues.add(i); } updatedValues.add(new BaseDocument()); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(updatedValues, null); + final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues, null); assertThat(updateResult.getDocuments()).hasSize(1); assertThat(updateResult.getErrors()).hasSize(1); } @@ -2739,19 +2528,19 @@ void replaceDocumentsWithoutKey(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void replaceDocumentsJson(ArangoCollection collection) { - final Collection values = new ArrayList<>(); - values.add("{\"_key\":\"1\"}"); - values.add("{\"_key\":\"2\"}"); + final Collection values = new ArrayList<>(); + values.add(RawJson.of("{\"_key\":\"1\"}")); + values.add(RawJson.of("{\"_key\":\"2\"}")); collection.insertDocuments(values); - final Collection updatedValues = new ArrayList<>(); - updatedValues.add("{\"_key\":\"1\", \"foo\":\"bar\"}"); - updatedValues.add("{\"_key\":\"2\", \"foo\":\"bar\"}"); - final MultiDocumentEntity> updateResult = collection - .replaceDocuments(updatedValues); + final Collection updatedValues = new ArrayList<>(); + updatedValues.add(RawJson.of("{\"_key\":\"1\", \"foo\":\"bar\"}")); + updatedValues.add(RawJson.of("{\"_key\":\"2\", \"foo\":\"bar\"}")); + final MultiDocumentEntity> updateResult = collection.replaceDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void getInfo(ArangoCollection collection) { @@ -2776,23 +2565,10 @@ void changeProperties(ArangoCollection collection) { assertThat(properties.getSchema()).isNull(); } - String schemaRule = ("{ " + - " \"properties\": {" + - " \"number\": {" + - " \"type\": \"number\"" + - " }" + - " }" + - " }") - .replaceAll("\\s", ""); + String schemaRule = ("{ " + " \"properties\": {" + " \"number\": {" + " \"type\": \"number\"" + " }" + " }" + " }").replaceAll("\\s", ""); String schemaMessage = "The document has problems!"; - CollectionPropertiesOptions updatedOptions = new CollectionPropertiesOptions() - .waitForSync(!properties.getWaitForSync()) - .schema(new CollectionSchema() - .setLevel(CollectionSchema.Level.NEW) - .setMessage(schemaMessage) - .setRule(schemaRule) - ); + CollectionPropertiesOptions updatedOptions = new CollectionPropertiesOptions().waitForSync(!properties.getWaitForSync()).schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule)); final CollectionPropertiesEntity changedProperties = collection.changeProperties(updatedOptions); assertThat(changedProperties.getWaitForSync()).isNotNull(); @@ -2806,9 +2582,7 @@ void changeProperties(ArangoCollection collection) { // revert changes CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions() - .waitForSync(properties.getWaitForSync()) - .schema(CollectionSchema.NULL_SCHEMA) - ); + .waitForSync(properties.getWaitForSync()).schema(new CollectionSchema())); if (isAtLeastVersion(3, 7)) { assertThat(revertedProperties.getSchema()).isNull(); } diff --git a/src/test/java/com/arangodb/ArangoCursorTest.java b/src/test/java/com/arangodb/ArangoCursorTest.java index 41d9d5d99..a1988b132 100644 --- a/src/test/java/com/arangodb/ArangoCursorTest.java +++ b/src/test/java/com/arangodb/ArangoCursorTest.java @@ -21,7 +21,7 @@ package com.arangodb; import com.arangodb.model.AqlQueryOptions; -import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -46,17 +46,17 @@ static void init() { @ParameterizedTest(name = "{index}") @MethodSource("dbs") void firstStream(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - final Optional first = cursor.stream().findFirst(); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + final Optional first = cursor.stream().findFirst(); assertThat(first).isPresent(); - assertThat(first.get().isInteger()).isTrue(); - assertThat(first.get().getAsLong()).isZero(); + assertThat(first.get().isInt()).isTrue(); + assertThat(first.get().asLong()).isZero(); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void next(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", new AqlQueryOptions().batchSize(5), VPackSlice.class); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", new AqlQueryOptions().batchSize(5), JsonNode.class); while (cursor.hasNext()) { cursor.next(); } @@ -65,16 +65,16 @@ void next(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") void mapFilterCountStream(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - final long count = cursor.stream().map(VPackSlice::getAsLong).filter(t -> t < 50).count(); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + final long count = cursor.stream().map(JsonNode::asLong).filter(t -> t < 50).count(); assertThat(count).isEqualTo(50L); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void mapFilterCollectIntoSetStream(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - final Set target = cursor.stream().map(VPackSlice::getAsLong).filter(t -> t < 50).collect(Collectors.toSet()); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + final Set target = cursor.stream().map(JsonNode::asLong).filter(t -> t < 50).collect(Collectors.toSet()); assertThat(target) .isNotNull() .hasSize(50); @@ -84,47 +84,47 @@ void mapFilterCollectIntoSetStream(ArangoDatabase db) { @MethodSource("dbs") void forEach(ArangoDatabase db) { final AtomicLong i = new AtomicLong(0L); - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - cursor.forEach(t -> assertThat(t.getAsLong()).isEqualTo(i.getAndIncrement())); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + cursor.forEach(t -> assertThat(t.asLong()).isEqualTo(i.getAndIncrement())); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void mapForeachStream(ArangoDatabase db) { final AtomicLong i = new AtomicLong(0L); - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - cursor.stream().map(VPackSlice::getAsLong).forEach(t -> assertThat(t).isEqualTo(i.getAndIncrement())); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + cursor.stream().map(JsonNode::asLong).forEach(t -> assertThat(t).isEqualTo(i.getAndIncrement())); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void mapFilterForEachStream(ArangoDatabase db) { final AtomicLong i = new AtomicLong(0L); - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - cursor.stream().map(VPackSlice::getAsLong).filter(t -> t < 50).forEach(t -> assertThat(t).isEqualTo(i.getAndIncrement())); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + cursor.stream().map(JsonNode::asLong).filter(t -> t < 50).forEach(t -> assertThat(t).isEqualTo(i.getAndIncrement())); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void anyMatchStream(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - final boolean match = cursor.stream().anyMatch(t -> t.getAsLong() == 50L); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + final boolean match = cursor.stream().anyMatch(t -> t.asLong() == 50L); assertThat(match).isTrue(); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void noneMatchStream(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - final boolean match = cursor.stream().noneMatch(t -> t.getAsLong() == 100L); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + final boolean match = cursor.stream().noneMatch(t -> t.asLong() == 100L); assertThat(match).isTrue(); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void allMatchStream(ArangoDatabase db) { - final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); - final boolean match = cursor.stream().allMatch(t -> t.getAsLong() < 100L); + final ArangoCursor cursor = db.query("FOR i IN 0..99 RETURN i", JsonNode.class); + final boolean match = cursor.stream().allMatch(t -> t.asLong() < 100L); assertThat(match).isTrue(); } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 76d991e6a..c51a12272 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -21,16 +21,15 @@ package com.arangodb; import com.arangodb.entity.*; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.*; import com.arangodb.model.LogOptions.SortOrder; import com.arangodb.util.TestUtils; -import com.arangodb.velocypack.exception.VPackException; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.arangodb.velocystream.Response; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -146,10 +145,9 @@ void createDatabaseWithOptions(ArangoDB arangoDB) { assertThat(resultCreate).isTrue(); DatabaseEntity info = arangoDB.db(dbName).getInfo(); - assertThat(info.getReplicationFactor()).isEqualTo(2); + assertThat(info.getReplicationFactor().getValue()).isEqualTo(2); assertThat(info.getWriteConcern()).isEqualTo(2); assertThat(info.getSharding()).isEmpty(); - assertThat(info.getSatellite()).isNull(); final Boolean resultDelete = arangoDB.db(dbName).drop(); assertThat(resultDelete).isTrue(); @@ -167,15 +165,14 @@ void createDatabaseWithOptionsSatellite(ArangoDB arangoDB) { .name(dbName) .options(new DatabaseOptions() .writeConcern(2) - .satellite(true) + .satellite() .sharding("") ) ); assertThat(resultCreate).isTrue(); DatabaseEntity info = arangoDB.db(dbName).getInfo(); - assertThat(info.getReplicationFactor()).isNull(); - assertThat(info.getSatellite()).isTrue(); + assertThat(info.getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); assertThat(info.getWriteConcern()).isEqualTo(2); assertThat(info.getSharding()).isEmpty(); @@ -215,7 +212,7 @@ void createDatabaseWithUsers(ArangoDB arangoDB) throws InterruptedException { Thread.sleep(1_000); ArangoDB arangoDBTestUser = new ArangoDB.Builder() - .serializer(new ArangoJack()) + .user("testUser") .password("testPasswd") .build(); @@ -377,7 +374,7 @@ void updateUserDefaultCollectionAccess(ArangoDB arangoDB) { @Test void authenticationFailPassword() { - final ArangoDB arangoDB = new ArangoDB.Builder().password("no").jwt(null).serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().password("no").jwt(null).build(); Throwable thrown = catchThrowable(arangoDB::getVersion); assertThat(thrown).isInstanceOf(ArangoDBException.class); assertThat(((ArangoDBException) thrown).getResponseCode()).isEqualTo(401); @@ -386,7 +383,7 @@ void authenticationFailPassword() { @ParameterizedTest(name = "{index}") @MethodSource("arangos") void authenticationFailUser() { - final ArangoDB arangoDB = new ArangoDB.Builder().user("no").jwt(null).serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().user("no").jwt(null).build(); Throwable thrown = catchThrowable(arangoDB::getVersion); assertThat(thrown).isInstanceOf(ArangoDBException.class); assertThat(((ArangoDBException) thrown).getResponseCode()).isEqualTo(401); @@ -394,9 +391,9 @@ void authenticationFailUser() { @ParameterizedTest(name = "{index}") @MethodSource("arangos") - void execute(ArangoDB arangoDB) throws VPackException { + void execute(ArangoDB arangoDB) { final Response response = arangoDB.execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")); - assertThat(response.getBody().get("version").isString()).isTrue(); + assertThat(arangoDB.getSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") @@ -557,7 +554,7 @@ void arangoDBException(ArangoDB arangoDB) { @ParameterizedTest(name = "{index}") @MethodSource("arangos") void fallbackHost() { - final ArangoDB arangoDB = new ArangoDB.Builder().host("not-accessible", 8529).host("127.0.0.1", 8529).serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().host("not-accessible", 8529).host("127.0.0.1", 8529).build(); final ArangoDBVersion version = arangoDB.getVersion(); assertThat(version).isNotNull(); } @@ -591,6 +588,7 @@ void accessMultipleDatabases(ArangoDB arangoDB) { @ParameterizedTest(name = "{index}") @MethodSource("arangos") + @Disabled("Manual execution only") void queueTime(ArangoDB arangoDB) throws InterruptedException, ExecutionException { List> futures = IntStream.range(0, 80) .mapToObj(i -> CompletableFuture.runAsync( diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 35073c24b..a63eefd24 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -22,14 +22,15 @@ import com.arangodb.entity.*; import com.arangodb.entity.AqlExecutionExplainEntity.ExecutionPlan; -import com.arangodb.entity.CursorEntity.Warning; import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.model.*; import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.ValueType; -import com.arangodb.velocypack.exception.VPackException; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -115,8 +116,7 @@ void createCollectionWithReplicationFactor(ArangoDatabase db) { assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); CollectionPropertiesEntity props = db.collection(name).getProperties(); - assertThat(props.getReplicationFactor()).isEqualTo(2); - assertThat(props.getSatellite()).isNull(); + assertThat(props.getReplicationFactor().getValue()).isEqualTo(2); } @ParameterizedTest(name = "{index}") @@ -131,9 +131,8 @@ void createCollectionWithWriteConcern(ArangoDatabase db) { assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); CollectionPropertiesEntity props = db.collection(name).getProperties(); - assertThat(props.getReplicationFactor()).isEqualTo(2); + assertThat(props.getReplicationFactor().getValue()).isEqualTo(2); assertThat(props.getWriteConcern()).isEqualTo(2); - assertThat(props.getSatellite()).isNull(); } @ParameterizedTest(name = "{index}") @@ -144,13 +143,12 @@ void createSatelliteCollection(ArangoDatabase db) { String name = "collection-" + rnd(); final CollectionEntity result = db - .createCollection(name, new CollectionCreateOptions().satellite(true)); + .createCollection(name, new CollectionCreateOptions().satellite()); assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); CollectionPropertiesEntity props = db.collection(name).getProperties(); - assertThat(props.getReplicationFactor()).isNull(); - assertThat(props.getSatellite()).isTrue(); + assertThat(props.getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); } @ParameterizedTest(name = "{index}") @@ -538,6 +536,14 @@ void query(ArangoDatabase db) { } } + @ParameterizedTest(name = "{index}") + @MethodSource("dbs") + void queryWithNullBindVar(ArangoDatabase db) { + final ArangoCursor cursor = db.query("return @foo", Collections.singletonMap("foo", null), null, Object.class); + assertThat(cursor.hasNext()).isTrue(); + assertThat(cursor.next()).isNull(); + } + @ParameterizedTest(name = "{index}") @MethodSource("dbs") void queryForEach(ArangoDatabase db) { @@ -754,7 +760,7 @@ void queryWithMaxWarningCount(ArangoDatabase db) { assertThat(cursorWithWarnings.getWarnings()).hasSize(1); final ArangoCursor cursorWithLimitedWarnings = db .query("RETURN 1 / 0", null, new AqlQueryOptions().maxWarningCount(0L), String.class); - final Collection warnings = cursorWithLimitedWarnings.getWarnings(); + final Collection warnings = cursorWithLimitedWarnings.getWarnings(); assertThat(warnings).isNullOrEmpty(); } @@ -829,6 +835,19 @@ void queryWithBindVars(ArangoDatabase db) { } } + @ParameterizedTest(name = "{index}") + @MethodSource("dbs") + void queryWithRawBindVars(ArangoDatabase db) { + final Map bindVars = new HashMap<>(); + bindVars.put("foo", RawJson.of("\"fooValue\"")); + bindVars.put("bar", RawBytes.of(db.getSerde().serializeUserData(11))); + + final JsonNode res = db.query("RETURN {foo: @foo, bar: @bar}", bindVars, null,JsonNode.class).next(); + + assertThat(res.get("foo").textValue()).isEqualTo("fooValue"); + assertThat(res.get("bar").intValue()).isEqualTo(11); + } + @ParameterizedTest(name = "{index}") @MethodSource("arangos") void queryWithWarning(ArangoDB arangoDB) { @@ -842,9 +861,9 @@ void queryWithWarning(ArangoDB arangoDB) { @MethodSource("dbs") void queryStream(ArangoDatabase db) { if (isAtLeastVersion(3, 4)) { - final ArangoCursor cursor = db + final ArangoCursor cursor = db .query("FOR i IN 1..2 RETURN i", null, new AqlQueryOptions().stream(true).count(true), - VPackSlice.class); + Void.class); assertThat((Object) cursor).isNotNull(); assertThat(cursor.getCount()).isNull(); } @@ -909,6 +928,22 @@ void explainQuery(ArangoDatabase db) { assertThat(plan.getNodes()).isNotEmpty(); } + @ParameterizedTest(name = "{index}") + @MethodSource("dbs") + void explainQueryWithBindVars(ArangoDatabase db) { + final AqlExecutionExplainEntity explain = db.explainQuery("for i in 1..1 return @value", + Collections.singletonMap("value", 11), null); + assertThat(explain).isNotNull(); + assertThat(explain.getPlan()).isNotNull(); + assertThat(explain.getPlans()).isNull(); + final ExecutionPlan plan = explain.getPlan(); + assertThat(plan.getCollections()).isEmpty(); + assertThat(plan.getEstimatedCost()).isPositive(); + assertThat(plan.getEstimatedNrItems()).isPositive(); + assertThat(plan.getVariables()).hasSize(3); + assertThat(plan.getNodes()).isNotEmpty(); + } + @ParameterizedTest(name = "{index}") @MethodSource("dbs") void explainQueryWithIndexNode(ArangoDatabase db) { @@ -1079,14 +1114,14 @@ void createGraphSatellite(ArangoDatabase db) { assumeTrue(isEnterprise()); String name = "graph-" + rnd(); - final GraphEntity result = db.createGraph(name, null, new GraphCreateOptions().satellite(true)); - assertThat(result.getSatellite()).isTrue(); + final GraphEntity result = db.createGraph(name, null, new GraphCreateOptions().satellite()); + assertThat(result.getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); GraphEntity info = db.graph(name).getInfo(); - assertThat(info.getSatellite()).isTrue(); + assertThat(info.getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); GraphEntity graph = db.getGraphs().stream().filter(g -> name.equals(g.getName())).findFirst().get(); - assertThat(graph.getSatellite()).isTrue(); + assertThat(graph.getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); } @ParameterizedTest(name = "{index}") @@ -1102,7 +1137,7 @@ void createGraphReplicationFaktor(ArangoDatabase db) { assertThat(result).isNotNull(); for (final String collection : Arrays.asList(edgeCollection, fromCollection, toCollection)) { final CollectionPropertiesEntity properties = db.collection(collection).getProperties(); - assertThat(properties.getReplicationFactor()).isEqualTo(2); + assertThat(properties.getReplicationFactor().getValue()).isEqualTo(2); } } @@ -1139,8 +1174,8 @@ void getGraphs(ArangoDatabase db) { @MethodSource("dbs") void transactionString(ArangoDatabase db) { final TransactionOptions options = new TransactionOptions().params("test"); - final String result = db.transaction("function (params) {return params;}", String.class, options); - assertThat(result).isEqualTo("test"); + final RawJson result = db.transaction("function (params) {return params;}", RawJson.class, options); + assertThat(result.getValue()).isEqualTo("\"test\""); } @ParameterizedTest(name = "{index}") @@ -1153,32 +1188,31 @@ void transactionNumber(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionVPack(ArangoDatabase db) throws VPackException { - final TransactionOptions options = new TransactionOptions().params(new VPackBuilder().add("test").slice()); - final VPackSlice result = db.transaction("function (params) {return params;}", VPackSlice.class, options); - assertThat(result.isString()).isTrue(); - assertThat(result.getAsString()).isEqualTo("test"); + void transactionVPack(ArangoDatabase db) { + final TransactionOptions options = new TransactionOptions().params(JsonNodeFactory.instance.textNode("test")); + final JsonNode result = db.transaction("function (params) {return params;}", JsonNode.class, options); + assertThat(result.isTextual()).isTrue(); + assertThat(result.asText()).isEqualTo("test"); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionVPackObject(ArangoDatabase db) throws VPackException { - final VPackSlice params = new VPackBuilder().add(ValueType.OBJECT).add("foo", "hello").add("bar", "world") - .close().slice(); + void transactionJsonObject(ArangoDatabase db) { + ObjectNode params = JsonNodeFactory.instance.objectNode().put("foo", "hello").put("bar", "world"); final TransactionOptions options = new TransactionOptions().params(params); - final String result = db - .transaction("function (params) { return params['foo'] + ' ' + params['bar'];}", String.class, options); - assertThat(result).isEqualTo("hello world"); + final RawJson result = db + .transaction("function (params) { return params['foo'] + ' ' + params['bar'];}", RawJson.class, options); + assertThat(result.getValue()).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionVPackArray(ArangoDatabase db) throws VPackException { - final VPackSlice params = new VPackBuilder().add(ValueType.ARRAY).add("hello").add("world").close().slice(); + void transactionJsonArray(ArangoDatabase db) { + ArrayNode params = JsonNodeFactory.instance.arrayNode().add("hello").add("world"); final TransactionOptions options = new TransactionOptions().params(params); - final String result = db - .transaction("function (params) { return params[0] + ' ' + params[1];}", String.class, options); - assertThat(result).isEqualTo("hello world"); + final RawJson result = db + .transaction("function (params) { return params[0] + ' ' + params[1];}", RawJson.class, options); + assertThat(result.getValue()).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1186,9 +1220,9 @@ void transactionVPackArray(ArangoDatabase db) throws VPackException { void transactionMap(ArangoDatabase db) { final Map params = new MapBuilder().put("foo", "hello").put("bar", "world").get(); final TransactionOptions options = new TransactionOptions().params(params); - final String result = db - .transaction("function (params) { return params['foo'] + ' ' + params['bar'];}", String.class, options); - assertThat(result).isEqualTo("hello world"); + final RawJson result = db + .transaction("function (params) { return params['foo'] + ' ' + params['bar'];}", RawJson.class, options); + assertThat(result.getValue()).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1196,9 +1230,9 @@ void transactionMap(ArangoDatabase db) { void transactionArray(ArangoDatabase db) { final String[] params = new String[]{"hello", "world"}; final TransactionOptions options = new TransactionOptions().params(params); - final String result = db - .transaction("function (params) { return params[0] + ' ' + params[1];}", String.class, options); - assertThat(result).isEqualTo("hello world"); + final RawJson result = db + .transaction("function (params) { return params[0] + ' ' + params[1];}", RawJson.class, options); + assertThat(result.getValue()).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1208,9 +1242,9 @@ void transactionCollection(ArangoDatabase db) { params.add("hello"); params.add("world"); final TransactionOptions options = new TransactionOptions().params(params); - final String result = db - .transaction("function (params) { return params[0] + ' ' + params[1];}", String.class, options); - assertThat(result).isEqualTo("hello world"); + final RawJson result = db + .transaction("function (params) { return params[0] + ' ' + params[1];}", RawJson.class, options); + assertThat(result.getValue()).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1223,7 +1257,7 @@ void transactionInsertJson(ArangoDatabase db) { + "var db = require('internal').db;" + "db." + CNAME1 + ".save(JSON.parse(params));" + "}", Void.class, options); - assertThat(db.collection(CNAME1).getDocument(key, String.class)).isNotNull(); + assertThat(db.collection(CNAME1).getDocument(key, RawJson.class)).isNotNull(); } @ParameterizedTest(name = "{index}") @@ -1237,13 +1271,13 @@ void transactionExclusiveWrite(ArangoDatabase db) { + "var db = require('internal').db;" + "db." + CNAME1 + ".save(JSON.parse(params));" + "}", Void.class, options); - assertThat(db.collection(CNAME1).getDocument(key, String.class)).isNotNull(); + assertThat(db.collection(CNAME1).getDocument(key, RawJson.class)).isNotNull(); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") void transactionEmpty(ArangoDatabase db) { - db.transaction("function () {}", null, null); + db.transaction("function () {}", Void.class, null); } @ParameterizedTest(name = "{index}") @@ -1253,20 +1287,24 @@ void transactionAllowImplicit(ArangoDatabase db) { + "return {'a':db." + CNAME1 + ".all().toArray()[0], 'b':db." + CNAME2 + ".all().toArray()[0]};" + "}"; final TransactionOptions options = new TransactionOptions().readCollections(CNAME1); - db.transaction(action, VPackSlice.class, options); + db.transaction(action, JsonNode.class, options); options.allowImplicit(false); - Throwable thrown = catchThrowable(() -> db.transaction(action, VPackSlice.class, options)); + Throwable thrown = catchThrowable(() -> db.transaction(action, JsonNode.class, options)); assertThat(thrown) .isInstanceOf(ArangoDBException.class) .extracting(it -> ((ArangoDBException) it).getResponseCode()) .isEqualTo(400); } - static class TransactionTestEntity { + public static class TransactionTestEntity { private String value; - TransactionTestEntity() { - super(); + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; } } @@ -1315,7 +1353,7 @@ void shouldIncludeExceptionMessage(ArangoDatabase db) { final String exceptionMessage = "My error context"; final String action = "function (params) {" + "throw '" + exceptionMessage + "';" + "}"; try { - db.transaction(action, VPackSlice.class, null); + db.transaction(action, Void.class, null); fail(); } catch (final ArangoDBException e) { assertThat(e.getErrorMessage()).isEqualTo(exceptionMessage); diff --git a/src/test/java/com/arangodb/ArangoGraphTest.java b/src/test/java/com/arangodb/ArangoGraphTest.java index 93aa505ce..9314d5dd1 100644 --- a/src/test/java/com/arangodb/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/ArangoGraphTest.java @@ -23,6 +23,7 @@ import com.arangodb.entity.CollectionPropertiesEntity; import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.GraphEntity; +import com.arangodb.entity.ReplicationFactor; import com.arangodb.model.GraphCreateOptions; import com.arangodb.model.VertexCollectionCreateOptions; import org.junit.jupiter.api.BeforeAll; @@ -96,7 +97,7 @@ void createWithReplicationAndWriteConcern(ArangoDatabase db) { assertThat(graph).isNotNull(); assertThat(graph.getName()).isEqualTo(GRAPH_NAME + "_1"); assertThat(graph.getWriteConcern()).isEqualTo(2); - assertThat(graph.getReplicationFactor()).isEqualTo(2); + assertThat(graph.getReplicationFactor().getValue()).isEqualTo(2); db.graph(GRAPH_NAME + "_1").drop(); } @@ -128,7 +129,7 @@ void getInfo(ArangoGraph graph) { if (isCluster()) { for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2, VERTEX_COL_1, VERTEX_COL_2}) { final CollectionPropertiesEntity properties = graph.db().collection(collection).getProperties(); - assertThat(properties.getReplicationFactor()).isEqualTo(REPLICATION_FACTOR); + assertThat(properties.getReplicationFactor().getValue()).isEqualTo(REPLICATION_FACTOR); assertThat(properties.getNumberOfShards()).isEqualTo(NUMBER_OF_SHARDS); } } @@ -165,12 +166,12 @@ void addSatelliteVertexCollection(ArangoDatabase db) { String v1Name = "vertex-" + rnd(); ArangoGraph g = db.graph(GRAPH_NAME + rnd()); - g.create(Collections.emptyList(), new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")); + g.create(null, new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")); g.addVertexCollection(v1Name, new VertexCollectionCreateOptions().satellites(v1Name)); Collection vertexCollections = g.getVertexCollections(); assertThat(vertexCollections).contains(v1Name); - assertThat(db.collection(v1Name).getProperties().getSatellite()).isTrue(); + assertThat(db.collection(v1Name).getProperties().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); // revert g.drop(); @@ -208,7 +209,7 @@ void addEdgeDefinition(ArangoGraph graph) { } if (isCluster()) { final CollectionPropertiesEntity properties = graph.db().collection(EDGE_COL_3).getProperties(); - assertThat(properties.getReplicationFactor()).isEqualTo(REPLICATION_FACTOR); + assertThat(properties.getReplicationFactor().getValue()).isEqualTo(REPLICATION_FACTOR); assertThat(properties.getNumberOfShards()).isEqualTo(NUMBER_OF_SHARDS); } @@ -229,7 +230,7 @@ void addSatelliteEdgeDefinition(ArangoDatabase db) { EdgeDefinition ed = new EdgeDefinition().collection(eName).from(v1Name).to(v2Name).satellites(v1Name); ArangoGraph g = db.graph(GRAPH_NAME + rnd()); - g.create(Collections.emptyList(), new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")); + g.create(null, new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")); g.addEdgeDefinition(ed); final GraphEntity ge = g.getInfo(); assertThat(ge).isNotNull(); @@ -240,7 +241,7 @@ void addSatelliteEdgeDefinition(ArangoDatabase db) { assertThat(e.getFrom()).contains(v1Name); assertThat(e.getTo()).contains(v2Name); - assertThat(db.collection(v1Name).getProperties().getSatellite()).isTrue(); + assertThat(db.collection(v1Name).getProperties().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); // revert g.drop(); @@ -326,9 +327,9 @@ void hybridSmartGraph(ArangoDatabase db) { assertThat(g.getSmartGraphAttribute()).isEqualTo("test"); assertThat(g.getNumberOfShards()).isEqualTo(2); - assertThat(db.collection(eName).getProperties().getSatellite()).isTrue(); - assertThat(db.collection(v1Name).getProperties().getSatellite()).isTrue(); - assertThat(db.collection(v2Name).getProperties().getReplicationFactor()).isEqualTo(2); + assertThat(db.collection(eName).getProperties().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); + assertThat(db.collection(v1Name).getProperties().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); + assertThat(db.collection(v2Name).getProperties().getReplicationFactor().getValue()).isEqualTo(2); } @ParameterizedTest(name = "{index}") @@ -376,8 +377,8 @@ void hybridDisjointSmartGraph(ArangoDatabase db) { assertThat(g.getSmartGraphAttribute()).isEqualTo("test"); assertThat(g.getNumberOfShards()).isEqualTo(2); - assertThat(db.collection(v1Name).getProperties().getSatellite()).isTrue(); - assertThat(db.collection(v2Name).getProperties().getReplicationFactor()).isEqualTo(2); + assertThat(db.collection(v1Name).getProperties().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); + assertThat(db.collection(v2Name).getProperties().getReplicationFactor().getValue()).isEqualTo(2); } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/ArangoRouteTest.java b/src/test/java/com/arangodb/ArangoRouteTest.java index 6bcd38f41..613b8e3b8 100644 --- a/src/test/java/com/arangodb/ArangoRouteTest.java +++ b/src/test/java/com/arangodb/ArangoRouteTest.java @@ -47,7 +47,7 @@ static void init() { @MethodSource("dbs") void get(ArangoDatabase db) { final Response res = db.route("/_api/version").get(); - assertThat(res.getBody().get("version").isString()).isTrue(); + assertThat(db.arango().getSerde().parse(res.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/ArangoSearchTest.java b/src/test/java/com/arangodb/ArangoSearchTest.java index cfbf8a477..59242b3a7 100644 --- a/src/test/java/com/arangodb/ArangoSearchTest.java +++ b/src/test/java/com/arangodb/ArangoSearchTest.java @@ -595,9 +595,9 @@ void stopwordsAnalyzer(ArangoDatabase db) { createGetAndDeleteTypedAnalyzer(db, analyzer); db.createSearchAnalyzer(analyzer); - String res = db.query("RETURN FLATTEN(TOKENS(SPLIT('the fox and the dog and a theater', ' '), @aName))", - Collections.singletonMap("aName", name), String.class).next(); - assertThat(res).isEqualTo("[\"fox\",\"dog\",\"a\",\"theater\"]"); + Collection res = db.query("RETURN FLATTEN(TOKENS(SPLIT('the fox and the dog and a theater', ' '), @aName))", + Collections.singletonMap("aName", name), Collection.class).next(); + assertThat(res).containsExactly("fox", "dog", "a", "theater"); db.deleteSearchAnalyzer(name); } diff --git a/src/test/java/com/arangodb/ArangoSslTest.java b/src/test/java/com/arangodb/ArangoSslTest.java index 613f1632c..b2693dae9 100644 --- a/src/test/java/com/arangodb/ArangoSslTest.java +++ b/src/test/java/com/arangodb/ArangoSslTest.java @@ -21,7 +21,6 @@ package com.arangodb; import com.arangodb.entity.ArangoDBVersion; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; @@ -71,7 +70,7 @@ void connect() throws Exception { final ArangoDB arangoDB = new ArangoDB.Builder() .loadProperties(ArangoSslTest.class.getResourceAsStream("/arangodb-ssl.properties")).useSsl(true) - .sslContext(sc).serializer(new ArangoJack()).build(); + .sslContext(sc).build(); final ArangoDBVersion version = arangoDB.getVersion(); assertThat(version).isNotNull(); } @@ -80,7 +79,7 @@ void connect() throws Exception { void connectWithoutValidSslContext() { final ArangoDB arangoDB = new ArangoDB.Builder() .loadProperties(ArangoSslTest.class.getResourceAsStream("/arangodb-ssl.properties")).useSsl(true) - .serializer(new ArangoJack()).build(); + .build(); Throwable thrown = catchThrowable(arangoDB::getVersion); assertThat(thrown).isInstanceOf(ArangoDBException.class); ArangoDBException ex = (ArangoDBException) thrown; diff --git a/src/test/java/com/arangodb/ArangoVertexCollectionTest.java b/src/test/java/com/arangodb/ArangoVertexCollectionTest.java index 84283f19f..ed202b7dc 100644 --- a/src/test/java/com/arangodb/ArangoVertexCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoVertexCollectionTest.java @@ -24,6 +24,7 @@ import com.arangodb.entity.VertexEntity; import com.arangodb.entity.VertexUpdateEntity; import com.arangodb.model.*; +import com.arangodb.util.RawJson; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -95,10 +96,10 @@ void insertVertexViolatingUniqueConstraint(ArangoVertexCollection vertices) { collection .ensureSkiplistIndex(Collections.singletonList("field"), new SkiplistIndexOptions().unique(true).sparse(true)); - VertexEntity inserted = vertices.insertVertex("{\"field\": 99}", null); + VertexEntity inserted = vertices.insertVertex(RawJson.of("{\"field\": 99}")); try { - vertices.insertVertex("{\"field\": 99}", null); + vertices.insertVertex(RawJson.of("{\"field\": 99}")); } catch (ArangoDBException e) { assertThat(e.getResponseCode()).isEqualTo(409); assertThat(e.getErrorNum()).isEqualTo(1210); diff --git a/src/test/java/com/arangodb/BaseDocumentTest.java b/src/test/java/com/arangodb/BaseDocumentTest.java deleted file mode 100644 index 8bb1ed0c4..000000000 --- a/src/test/java/com/arangodb/BaseDocumentTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb; - -import com.arangodb.entity.BaseDocument; -import com.arangodb.internal.velocypack.VPackDriverModule; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPack.Builder; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.ValueType; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - - -/** - * @author Mark Vollmary - * @author Michele Rastelli - */ -class BaseDocumentTest { - - @Test - void serialize() { - BaseDocument entity = new BaseDocument(); - entity.setKey("test"); - entity.setRevision("test"); - entity.addAttribute("a", "a"); - - Builder builder = new VPack.Builder(); - builder.registerModule(new VPackDriverModule()); - VPack vpacker = builder.build(); - - VPackSlice vpack = vpacker.serialize(entity); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.size()).isEqualTo(3); - - VPackSlice key = vpack.get("_key"); - assertThat(key.isString()).isTrue(); - assertThat(key.getAsString()).isEqualTo("test"); - - VPackSlice rev = vpack.get("_rev"); - assertThat(rev.isString()).isTrue(); - assertThat(rev.getAsString()).isEqualTo("test"); - - VPackSlice a = vpack.get("a"); - assertThat(a.isString()).isTrue(); - assertThat(a.getAsString()).isEqualTo("a"); - } - - @Test - void deserialize() { - VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("_id", "test/test"); - builder.add("_key", "test"); - builder.add("_rev", "test"); - builder.add("a", "a"); - builder.close(); - - VPack.Builder vbuilder = new VPack.Builder(); - vbuilder.registerModule(new VPackDriverModule()); - VPack vpacker = vbuilder.build(); - - BaseDocument entity = vpacker.deserialize(builder.slice(), BaseDocument.class); - assertThat(entity.getId()).isNotNull(); - assertThat(entity.getId()).isEqualTo("test/test"); - assertThat(entity.getKey()).isNotNull(); - assertThat(entity.getKey()).isEqualTo("test"); - assertThat(entity.getRevision()).isNotNull(); - assertThat(entity.getRevision()).isEqualTo("test"); - assertThat(entity.getProperties()).hasSize(1); - assertThat(String.valueOf(entity.getAttribute("a"))).isEqualTo("a"); - } - -} diff --git a/src/test/java/com/arangodb/BaseJunit5.java b/src/test/java/com/arangodb/BaseJunit5.java index f6e9390ee..506bba0ef 100644 --- a/src/test/java/com/arangodb/BaseJunit5.java +++ b/src/test/java/com/arangodb/BaseJunit5.java @@ -1,9 +1,9 @@ package com.arangodb; import com.arangodb.entity.*; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.CollectionCreateOptions; import com.arangodb.model.GraphCreateOptions; +import com.arangodb.serde.JsonbSerde; import com.arangodb.util.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -13,18 +13,17 @@ import java.util.Collection; import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; import java.util.stream.Stream; class BaseJunit5 { protected static final DbName TEST_DB = DbName.of("java_driver_test_db"); - private static final List adbs = Arrays.stream(Protocol.values()) - .map(p -> new ArangoDB.Builder() - .useProtocol(p) - .serializer(new ArangoJack()) - .build()) - .collect(Collectors.toList()); + private static final List adbs = Arrays.asList( + new ArangoDB.Builder().useProtocol(Protocol.VST).build(), + new ArangoDB.Builder().useProtocol(Protocol.HTTP_VPACK).build(), + new ArangoDB.Builder().useProtocol(Protocol.HTTP_JSON).build(), + new ArangoDB.Builder().useProtocol(Protocol.HTTP_JSON).serializer(JsonbSerde.create()).build() + ); protected static Stream dbsStream() { return adbs.stream().map(adb -> adb.db(TEST_DB)); diff --git a/src/test/java/com/arangodb/ConcurrencyTests.java b/src/test/java/com/arangodb/ConcurrencyTests.java index 16c26ac08..2140a0f07 100644 --- a/src/test/java/com/arangodb/ConcurrencyTests.java +++ b/src/test/java/com/arangodb/ConcurrencyTests.java @@ -1,6 +1,5 @@ package com.arangodb; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -18,7 +17,7 @@ class ConcurrencyTests { @EnumSource(Protocol.class) void concurrentPendingRequests(Protocol protocol) throws ExecutionException, InterruptedException { ExecutorService es = Executors.newFixedThreadPool(10); - ArangoDB adb = new ArangoDB.Builder().useProtocol(protocol).serializer(new ArangoJack()).build(); + ArangoDB adb = new ArangoDB.Builder().useProtocol(protocol).build(); List> futures = IntStream.range(0, 10) .mapToObj(__ -> CompletableFuture.runAsync(() -> adb.db().query("RETURN SLEEP(1)", Void.class), es)) .collect(Collectors.toList()); diff --git a/src/test/java/com/arangodb/DocumentTest.java b/src/test/java/com/arangodb/DocumentTest.java index 327f07bb8..e9f471d41 100644 --- a/src/test/java/com/arangodb/DocumentTest.java +++ b/src/test/java/com/arangodb/DocumentTest.java @@ -22,6 +22,7 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; +import com.arangodb.util.RawJson; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -59,7 +60,7 @@ static void init() { @MethodSource("cols") void insertAsJson(ArangoCollection collection) { //@formatter:off - final String json = + final RawJson json = RawJson.of( "{" + "\"article\": {" + "\"artist\": \"PREGARDIEN/RHEINISCHE KANTOREI/DAS\"," @@ -79,9 +80,10 @@ void insertAsJson(ArangoCollection collection) { + "\"status\": \"RMV\"," + "\"lastUpdate\": \"2016-11-01 00:00\"" + "}" - + "}"; + + "}" + ); //@formatter:on - final DocumentCreateEntity createResult = collection.insertDocument(json); + final DocumentCreateEntity createResult = collection.insertDocument(json); final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class); assertThat(doc).isNotNull(); final Object article = doc.getAttribute("article"); diff --git a/src/test/java/com/arangodb/JwtAuthTest.java b/src/test/java/com/arangodb/JwtAuthTest.java index 6c0c3029f..71bf4da0e 100644 --- a/src/test/java/com/arangodb/JwtAuthTest.java +++ b/src/test/java/com/arangodb/JwtAuthTest.java @@ -1,7 +1,6 @@ package com.arangodb; -import com.arangodb.mapping.ArangoJack; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.arangodb.velocystream.Response; @@ -25,7 +24,7 @@ class JwtAuthTest { @BeforeAll static void init() { - ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + ArangoDB arangoDB = new ArangoDB.Builder().build(); jwt = getJwt(arangoDB); arangoDB.shutdown(); } @@ -76,14 +75,14 @@ void updateJwt(Protocol protocol) { private ArangoDB.Builder getBuilder(Protocol protocol) { return new ArangoDB.Builder() .useProtocol(protocol) - .serializer(new ArangoJack()) + .jwt(null) // unset credentials from properties file .user(null) // unset credentials from properties file .password(null); // unset credentials from properties file } private static String getJwt(ArangoDB arangoDB) { - ArangoSerialization serde = arangoDB.util(); + InternalSerde serde = arangoDB.getSerde(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/StreamTransactionTest.java b/src/test/java/com/arangodb/StreamTransactionTest.java index 4330b13fd..9ed7d9284 100644 --- a/src/test/java/com/arangodb/StreamTransactionTest.java +++ b/src/test/java/com/arangodb/StreamTransactionTest.java @@ -756,7 +756,7 @@ void getStreamTransactions(ArangoDatabase db) { assertThat(gotTxs).hasSameSizeAs(createdIds); assertThat(gotTxs.stream() - .allMatch(it -> it.getStatus() == StreamTransactionStatus.running)).isTrue(); + .allMatch(it -> it.getState() == StreamTransactionStatus.running)).isTrue(); db.abortStreamTransaction(tx1.getId()); db.abortStreamTransaction(tx2.getId()); diff --git a/src/test/java/com/arangodb/async/ArangoCollectionTest.java b/src/test/java/com/arangodb/async/ArangoCollectionTest.java index d7dfbdec2..015a7a170 100644 --- a/src/test/java/com/arangodb/async/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoCollectionTest.java @@ -24,6 +24,7 @@ import com.arangodb.entity.*; import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; +import com.arangodb.util.RawJson; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -120,7 +121,7 @@ void insertDocumentWaitForSync() throws InterruptedException, ExecutionException @Test void insertDocumentAsJson() throws InterruptedException, ExecutionException { db.collection(COLLECTION_NAME) - .insertDocument("{\"_key\":\"docRaw\",\"a\":\"test\"}", null) + .insertDocument(RawJson.of("{\"_key\":\"docRaw\",\"a\":\"test\"}"), null) .whenComplete((doc, ex) -> { assertThat(doc).isNotNull(); assertThat(doc.getId()).isNotNull(); @@ -195,11 +196,11 @@ void getDocumentIfNoneMatchFail() throws InterruptedException, ExecutionExceptio @Test void getDocumentAsJson() throws InterruptedException, ExecutionException { - db.collection(COLLECTION_NAME).insertDocument("{\"_key\":\"docRaw\",\"a\":\"test\"}", null).get(); - db.collection(COLLECTION_NAME).getDocument("docRaw", String.class, null) + db.collection(COLLECTION_NAME).insertDocument(RawJson.of("{\"_key\":\"docRaw\",\"a\":\"test\"}")).get(); + db.collection(COLLECTION_NAME).getDocument("docRaw", RawJson.class) .whenComplete((readResult, ex) -> { - assertThat(readResult.contains("\"_key\":\"docRaw\"")).isEqualTo(true); - assertThat(readResult.contains("\"_id\":\"db_collection_test/docRaw\"")).isEqualTo(true); + assertThat(readResult.getValue().contains("\"_key\":\"docRaw\"")).isEqualTo(true); + assertThat(readResult.getValue().contains("\"_id\":\"db_collection_test/docRaw\"")).isEqualTo(true); }) .get(); } @@ -1250,7 +1251,7 @@ void getCount() throws InterruptedException, ExecutionException { }) .get(); - db.collection(COLLECTION_NAME).insertDocument("{}", null).get(); + db.collection(COLLECTION_NAME).insertDocument(RawJson.of("{}"), null).get(); db.collection(COLLECTION_NAME).count() .whenComplete((count, ex) -> assertThat(count.getCount()).isEqualTo(1L)) @@ -1263,7 +1264,7 @@ void documentExists() throws InterruptedException, ExecutionException { .whenComplete((existsNot, ex) -> assertThat(existsNot).isEqualTo(false)) .get(); - db.collection(COLLECTION_NAME).insertDocument("{\"_key\":\"abc\"}", null).get(); + db.collection(COLLECTION_NAME).insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); db.collection(COLLECTION_NAME).documentExists("abc", null) .whenComplete((exists, ex) -> assertThat(exists).isEqualTo(true)) @@ -1272,8 +1273,8 @@ void documentExists() throws InterruptedException, ExecutionException { @Test void documentExistsIfMatch() throws InterruptedException, ExecutionException { - final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) - .insertDocument("{\"_key\":\"abc\"}", null).get(); + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + .insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); final DocumentExistsOptions options = new DocumentExistsOptions().ifMatch(createResult.getRev()); db.collection(COLLECTION_NAME).documentExists("abc", options) .whenComplete((exists, ex) -> assertThat(exists).isEqualTo(true)) @@ -1282,7 +1283,7 @@ void documentExistsIfMatch() throws InterruptedException, ExecutionException { @Test void documentExistsIfMatchFail() throws InterruptedException, ExecutionException { - db.collection(COLLECTION_NAME).insertDocument("{\"_key\":\"abc\"}", null).get(); + db.collection(COLLECTION_NAME).insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); final DocumentExistsOptions options = new DocumentExistsOptions().ifMatch("no"); db.collection(COLLECTION_NAME).documentExists("abc", options) .whenComplete((exists, ex) -> assertThat(exists).isEqualTo(false)) @@ -1291,7 +1292,7 @@ void documentExistsIfMatchFail() throws InterruptedException, ExecutionException @Test void documentExistsIfNoneMatch() throws InterruptedException, ExecutionException { - db.collection(COLLECTION_NAME).insertDocument("{\"_key\":\"abc\"}", null).get(); + db.collection(COLLECTION_NAME).insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); final DocumentExistsOptions options = new DocumentExistsOptions().ifNoneMatch("no"); db.collection(COLLECTION_NAME).documentExists("abc", options) .whenComplete((exists, ex) -> assertThat(exists).isEqualTo(true)) @@ -1300,8 +1301,8 @@ void documentExistsIfNoneMatch() throws InterruptedException, ExecutionException @Test void documentExistsIfNoneMatchFail() throws InterruptedException, ExecutionException { - final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) - .insertDocument("{\"_key\":\"abc\"}", null).get(); + final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME) + .insertDocument(RawJson.of("{\"_key\":\"abc\"}")).get(); final DocumentExistsOptions options = new DocumentExistsOptions().ifNoneMatch(createResult.getRev()); db.collection(COLLECTION_NAME).documentExists("abc", options) .whenComplete((exists, ex) -> assertThat(exists).isEqualTo(false)) diff --git a/src/test/java/com/arangodb/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 6b7f7321c..2169914d4 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -22,12 +22,11 @@ import com.arangodb.*; import com.arangodb.entity.*; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.*; import com.arangodb.util.TestUtils; -import com.arangodb.velocypack.exception.VPackException; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -55,8 +54,8 @@ class ArangoDBTest { private static final String PW = "machts der hund"; private static Boolean extendedNames; - private final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); - private final ArangoDB arangoDBSync = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + private final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build(); + private final ArangoDB arangoDBSync = new ArangoDB.Builder().build(); private boolean isEnterprise() { return arangoDBSync.getVersion().getLicense() == License.ENTERPRISE; @@ -75,7 +74,7 @@ private boolean isLessThanVersion(final int major, final int minor) { } private boolean supportsExtendedNames() { - final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().build(); if (extendedNames == null) { try { ArangoDatabase testDb = arangoDB.db(DbName.of("test-" + TestUtils.generateRandomDbName(20, true))); @@ -168,10 +167,9 @@ void createDatabaseWithOptions() throws ExecutionException, InterruptedException assertThat(resultCreate).isTrue(); DatabaseEntity info = arangoDB.db(dbName).getInfo().get(); - assertThat(info.getReplicationFactor()).isEqualTo(2); + assertThat(info.getReplicationFactor().getValue()).isEqualTo(2); assertThat(info.getWriteConcern()).isEqualTo(2); assertThat(info.getSharding()).isEmpty(); - assertThat(info.getSatellite()).isNull(); final Boolean resultDelete = arangoDB.db(dbName).drop().get(); assertThat(resultDelete).isTrue(); @@ -188,15 +186,14 @@ void createDatabaseWithOptionsSatellite() throws ExecutionException, Interrupted .name(dbName) .options(new DatabaseOptions() .writeConcern(2) - .satellite(true) + .satellite() .sharding("") ) ).get(); assertThat(resultCreate).isTrue(); DatabaseEntity info = arangoDB.db(dbName).getInfo().get(); - assertThat(info.getReplicationFactor()).isNull(); - assertThat(info.getSatellite()).isTrue(); + assertThat(info.getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); assertThat(info.getWriteConcern()).isEqualTo(2); assertThat(info.getSharding()).isEmpty(); @@ -416,7 +413,7 @@ void updateUserDefaultCollectionAccess() throws InterruptedException, ExecutionE @Test void authenticationFailPassword() throws InterruptedException { - final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().password("no").jwt(null).serializer(new ArangoJack()).build(); + final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().password("no").jwt(null).build(); try { arangoDB.getVersion().get(); fail(); @@ -427,7 +424,7 @@ void authenticationFailPassword() throws InterruptedException { @Test void authenticationFailUser() throws InterruptedException { - final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().user("no").jwt(null).serializer(new ArangoJack()).build(); + final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().user("no").jwt(null).build(); try { arangoDB.getVersion().get(); fail(); @@ -437,24 +434,24 @@ void authenticationFailUser() throws InterruptedException { } @Test - void execute() throws VPackException, InterruptedException, ExecutionException { + void execute() throws InterruptedException, ExecutionException { arangoDB .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(response.getBody().get("version").isString()).isTrue(); + assertThat(arangoDB.getSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } @Test - void execute_acquireHostList_enabled() throws VPackException, InterruptedException, ExecutionException { - final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().acquireHostList(true).serializer(new ArangoJack()).build(); + void execute_acquireHostList_enabled() throws InterruptedException, ExecutionException { + final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().acquireHostList(true).build(); arangoDB .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(response.getBody().get("version").isString()).isTrue(); + assertThat(arangoDB.getSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } @@ -501,6 +498,7 @@ void setLogLevel() throws InterruptedException, ExecutionException { } @Test + @Disabled("Manual execution only") void queueTime() throws InterruptedException, ExecutionException { List>> reqs = IntStream.range(0, 80) .mapToObj(__ -> arangoDB.db().query("RETURN SLEEP(1)", Void.class)) diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index b58e1e6ef..565185563 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -27,9 +27,9 @@ import com.arangodb.entity.AqlParseEntity.AstNode; import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.model.*; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.exception.VPackException; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -117,7 +117,7 @@ void createCollectionWithReplicationFactor() throws InterruptedException, Execut .createCollection(COLLECTION_NAME, new CollectionCreateOptions().replicationFactor(2)).get(); assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); - assertThat(db.collection(COLLECTION_NAME).getProperties().get().getReplicationFactor()).isEqualTo(2); + assertThat(db.collection(COLLECTION_NAME).getProperties().get().getReplicationFactor().getValue()).isEqualTo(2); db.collection(COLLECTION_NAME).drop().get(); } @@ -130,9 +130,8 @@ void createCollectionWithWriteConcern() throws ExecutionException, InterruptedEx new CollectionCreateOptions().replicationFactor(2).writeConcern(2)).get(); assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); - assertThat(db.collection(COLLECTION_NAME).getProperties().get().getReplicationFactor()).isEqualTo(2); + assertThat(db.collection(COLLECTION_NAME).getProperties().get().getReplicationFactor().getValue()).isEqualTo(2); assertThat(db.collection(COLLECTION_NAME).getProperties().get().getWriteConcern()).isEqualTo(2); - assertThat(db.collection(COLLECTION_NAME).getProperties().get().getSatellite()).isNull(); db.collection(COLLECTION_NAME).drop(); } @@ -876,8 +875,8 @@ void getGraphs() throws InterruptedException, ExecutionException { @Test void transactionString() throws InterruptedException, ExecutionException { final TransactionOptions options = new TransactionOptions().params("test"); - db.transaction("function (params) {return params;}", String.class, options) - .whenComplete((result, ex) -> assertThat(result).isEqualTo("test")) + db.transaction("function (params) {return params;}", RawJson.class, options) + .whenComplete((result, ex) -> assertThat(result.getValue()).isEqualTo("\"test\"")) .get(); } @@ -890,23 +889,23 @@ void transactionNumber() throws InterruptedException, ExecutionException { } @Test - void transactionVPack() throws VPackException, InterruptedException, ExecutionException { - final TransactionOptions options = new TransactionOptions().params(new VPackBuilder().add("test").slice()); - db.transaction("function (params) {return params;}", VPackSlice.class, options) + void transactionJsonNode() throws InterruptedException, ExecutionException { + final TransactionOptions options = new TransactionOptions().params(JsonNodeFactory.instance.textNode("test")); + db.transaction("function (params) {return params;}", JsonNode.class, options) .whenComplete((result, ex) -> { - assertThat(result.isString()).isEqualTo(true); - assertThat(result.getAsString()).isEqualTo("test"); + assertThat(result.isTextual()).isEqualTo(true); + assertThat(result.asText()).isEqualTo("test"); }) .get(); } @Test void transactionEmpty() throws InterruptedException, ExecutionException { - db.transaction("function () {}", null, null).get(); + db.transaction("function () {}", Void.class, null).get(); } @Test - void transactionallowImplicit() throws InterruptedException, ExecutionException { + void transactionAllowImplicit() throws InterruptedException, ExecutionException { try { db.createCollection("someCollection", null).get(); db.createCollection("someOtherCollection", null).get(); @@ -914,10 +913,10 @@ void transactionallowImplicit() throws InterruptedException, ExecutionException + "return {'a':db.someCollection.all().toArray()[0], 'b':db.someOtherCollection.all().toArray()[0]};" + "}"; final TransactionOptions options = new TransactionOptions().readCollections("someCollection"); - db.transaction(action, VPackSlice.class, options).get(); + db.transaction(action, Void.class, options).get(); try { options.allowImplicit(false); - db.transaction(action, VPackSlice.class, options).get(); + db.transaction(action, Void.class, options).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause()).isInstanceOf(ArangoDBException.class); @@ -986,7 +985,7 @@ void shouldIncludeExceptionMessage() throws InterruptedException, ExecutionExcep final String exceptionMessage = "My error context"; final String action = "function (params) {" + "throw '" + exceptionMessage + "';" + "}"; try { - db.transaction(action, VPackSlice.class, null).get(); + db.transaction(action, Void.class, null).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause()).isInstanceOf(ArangoDBException.class); @@ -1009,12 +1008,15 @@ void reloadRouting() throws InterruptedException, ExecutionException { db.reloadRouting().get(); } - @SuppressWarnings({"WeakerAccess", "unused"}) - static class TransactionTestEntity { + public static class TransactionTestEntity { private String value; - TransactionTestEntity() { + public TransactionTestEntity() { super(); } + + public String getValue() { + return value; + } } } diff --git a/src/test/java/com/arangodb/async/ArangoGraphTest.java b/src/test/java/com/arangodb/async/ArangoGraphTest.java index 9513d4fec..1e7407aa4 100644 --- a/src/test/java/com/arangodb/async/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/async/ArangoGraphTest.java @@ -20,10 +20,7 @@ package com.arangodb.async; -import com.arangodb.entity.CollectionPropertiesEntity; -import com.arangodb.entity.EdgeDefinition; -import com.arangodb.entity.GraphEntity; -import com.arangodb.entity.ServerRole; +import com.arangodb.entity.*; import com.arangodb.model.GraphCreateOptions; import com.arangodb.model.VertexCollectionCreateOptions; import org.junit.jupiter.api.AfterEach; @@ -102,7 +99,7 @@ void createWithReplicationAndWriteConcern() throws ExecutionException, Interrupt assertThat(graph).isNotNull(); assertThat(graph.getName()).isEqualTo(GRAPH_NAME + "_1"); assertThat(graph.getWriteConcern()).isEqualTo(2); - assertThat(graph.getReplicationFactor()).isEqualTo(2); + assertThat(graph.getReplicationFactor().getValue()).isEqualTo(2); db.graph(GRAPH_NAME + "_1").drop(); } @@ -133,12 +130,12 @@ void getInfo() throws InterruptedException, ExecutionException { if (isCluster()) { for (final String collection : new String[]{VERTEX_COL_1, VERTEX_COL_2}) { final CollectionPropertiesEntity properties = db.collection(collection).getProperties().get(); - assertThat(properties.getReplicationFactor()).isEqualTo(REPLICATION_FACTOR); + assertThat(properties.getReplicationFactor().getValue()).isEqualTo(REPLICATION_FACTOR); assertThat(properties.getNumberOfShards()).isEqualTo(NUMBER_OF_SHARDS); } for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2}) { final CollectionPropertiesEntity properties = db.collection(collection).getProperties().get(); - assertThat(properties.getReplicationFactor()).isEqualTo(REPLICATION_FACTOR); + assertThat(properties.getReplicationFactor().getValue()).isEqualTo(REPLICATION_FACTOR); } } } @@ -169,12 +166,12 @@ void addSatelliteVertexCollection() throws ExecutionException, InterruptedExcept String v1Name = "vertex-" + rnd(); ArangoGraphAsync g = db.graph(GRAPH_NAME + rnd()); - g.createGraph(Collections.emptyList(), new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")).get(); + g.createGraph(null, new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")).get(); g.addVertexCollection(v1Name, new VertexCollectionCreateOptions().satellites(v1Name)).get(); Collection vertexCollections = g.getVertexCollections().get(); assertThat(vertexCollections).contains(v1Name); - assertThat(db.collection(v1Name).getProperties().get().getSatellite()).isTrue(); + assertThat(db.collection(v1Name).getProperties().get().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); // revert g.drop().get(); @@ -211,7 +208,7 @@ void addEdgeDefinition() throws InterruptedException, ExecutionException { } if (isCluster()) { final CollectionPropertiesEntity properties = db.collection(EDGE_COL_3).getProperties().get(); - assertThat(properties.getReplicationFactor()).isEqualTo(REPLICATION_FACTOR); + assertThat(properties.getReplicationFactor().getValue()).isEqualTo(REPLICATION_FACTOR); assertThat(properties.getNumberOfShards()).isEqualTo(NUMBER_OF_SHARDS); } setup(); @@ -229,7 +226,7 @@ void addSatelliteEdgeDefinition() throws ExecutionException, InterruptedExceptio EdgeDefinition ed = new EdgeDefinition().collection(eName).from(v1Name).to(v2Name).satellites(v1Name); ArangoGraphAsync g = db.graph(GRAPH_NAME + rnd()); - g.createGraph(Collections.emptyList(), new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")).get(); + g.createGraph(null, new GraphCreateOptions().isSmart(true).smartGraphAttribute("test")).get(); g.addEdgeDefinition(ed).get(); final GraphEntity ge = g.getInfo().get(); assertThat(ge).isNotNull(); @@ -240,7 +237,7 @@ void addSatelliteEdgeDefinition() throws ExecutionException, InterruptedExceptio assertThat(e.getFrom()).contains(v1Name); assertThat(e.getTo()).contains(v2Name); - assertThat(db.collection(v1Name).getProperties().get().getSatellite()).isTrue(); + assertThat(db.collection(v1Name).getProperties().get().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); // revert g.drop().get(); @@ -327,9 +324,9 @@ void hybridSmartGraph() throws ExecutionException, InterruptedException { assertThat(g.getSmartGraphAttribute()).isEqualTo("test"); assertThat(g.getNumberOfShards()).isEqualTo(2); - assertThat(db.collection(eName).getProperties().get().getSatellite()).isTrue(); - assertThat(db.collection(v1Name).getProperties().get().getSatellite()).isTrue(); - assertThat(db.collection(v2Name).getProperties().get().getReplicationFactor()).isEqualTo(2); + assertThat(db.collection(eName).getProperties().get().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); + assertThat(db.collection(v1Name).getProperties().get().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); + assertThat(db.collection(v2Name).getProperties().get().getReplicationFactor().getValue()).isEqualTo(2); } @Test @@ -355,8 +352,8 @@ void hybridDisjointSmartGraph() throws ExecutionException, InterruptedException assertThat(g.getSmartGraphAttribute()).isEqualTo("test"); assertThat(g.getNumberOfShards()).isEqualTo(2); - assertThat(db.collection(v1Name).getProperties().get().getSatellite()).isTrue(); - assertThat(db.collection(v2Name).getProperties().get().getReplicationFactor()).isEqualTo(2); + assertThat(db.collection(v1Name).getProperties().get().getReplicationFactor()).isEqualTo(ReplicationFactor.ofSatellite()); + assertThat(db.collection(v2Name).getProperties().get().getReplicationFactor().getValue()).isEqualTo(2); } @Test diff --git a/src/test/java/com/arangodb/async/BaseTest.java b/src/test/java/com/arangodb/async/BaseTest.java index db4f312aa..d0c318744 100644 --- a/src/test/java/com/arangodb/async/BaseTest.java +++ b/src/test/java/com/arangodb/async/BaseTest.java @@ -24,7 +24,6 @@ import com.arangodb.DbName; import com.arangodb.entity.License; import com.arangodb.entity.ServerRole; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -44,7 +43,7 @@ public abstract class BaseTest { @BeforeAll static void init() throws InterruptedException, ExecutionException { if (arangoDB == null) { - arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDBAsync.Builder().build(); } if (arangoDB.db(TEST_DB).exists().get()) { diff --git a/src/test/java/com/arangodb/async/CommunicationTest.java b/src/test/java/com/arangodb/async/CommunicationTest.java index 744aa0087..ecbfd3a42 100644 --- a/src/test/java/com/arangodb/async/CommunicationTest.java +++ b/src/test/java/com/arangodb/async/CommunicationTest.java @@ -20,7 +20,6 @@ package com.arangodb.async; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -38,7 +37,7 @@ class CommunicationTest { @Test @Disabled void disconnect() { - final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build(); final CompletableFuture> result = arangoDB.db().query("return sleep(1)", null, null, null); arangoDB.shutdown(); diff --git a/src/test/java/com/arangodb/async/ConcurrencyTest.java b/src/test/java/com/arangodb/async/ConcurrencyTest.java index 46c6bd552..f0643c2ca 100644 --- a/src/test/java/com/arangodb/async/ConcurrencyTest.java +++ b/src/test/java/com/arangodb/async/ConcurrencyTest.java @@ -23,7 +23,6 @@ import com.arangodb.async.internal.ArangoExecutorAsync; import com.arangodb.entity.ArangoDBVersion; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -47,7 +46,7 @@ class ConcurrencyTest { @BeforeEach void initialize() { - arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDBAsync.Builder().build(); } /** diff --git a/src/test/java/com/arangodb/async/ConcurrencyTests.java b/src/test/java/com/arangodb/async/ConcurrencyTests.java index edbad7c81..3219a5f50 100644 --- a/src/test/java/com/arangodb/async/ConcurrencyTests.java +++ b/src/test/java/com/arangodb/async/ConcurrencyTests.java @@ -2,7 +2,6 @@ -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.Test; import java.util.List; @@ -15,7 +14,7 @@ class ConcurrencyTests { @Test void concurrentPendingRequests() throws ExecutionException, InterruptedException { - ArangoDBAsync adb = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + ArangoDBAsync adb = new ArangoDBAsync.Builder().build(); List>> reqs = IntStream.range(0, 10) .mapToObj(__ -> adb.db().query("RETURN SLEEP(1)", Void.class)) .collect(Collectors.toList()); diff --git a/src/test/java/com/arangodb/async/JwtAuthTest.java b/src/test/java/com/arangodb/async/JwtAuthTest.java index c9d0f40d1..13ac28bc6 100644 --- a/src/test/java/com/arangodb/async/JwtAuthTest.java +++ b/src/test/java/com/arangodb/async/JwtAuthTest.java @@ -3,8 +3,7 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDBException; import com.arangodb.DbName; -import com.arangodb.mapping.ArangoJack; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.arangodb.velocystream.Response; @@ -28,7 +27,7 @@ class JwtAuthTest { @BeforeAll static void init() { - ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + ArangoDB arangoDB = new ArangoDB.Builder().build(); jwt = getJwt(arangoDB); arangoDB.shutdown(); } @@ -83,14 +82,14 @@ void updateJwt() throws ExecutionException, InterruptedException { private ArangoDBAsync.Builder getBuilder() { return new ArangoDBAsync.Builder() - .serializer(new ArangoJack()) + .jwt(null) // unset credentials from properties file .user(null) // unset credentials from properties file .password(null); // unset credentials from properties file } private static String getJwt(ArangoDB arangoDB) { - ArangoSerialization serde = arangoDB.util(); + InternalSerde serde = arangoDB.getSerde(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/async/StreamTransactionTest.java b/src/test/java/com/arangodb/async/StreamTransactionTest.java index 9925a110e..5f6690095 100644 --- a/src/test/java/com/arangodb/async/StreamTransactionTest.java +++ b/src/test/java/com/arangodb/async/StreamTransactionTest.java @@ -350,7 +350,7 @@ void getStreamTransactions() throws ExecutionException, InterruptedException { assertThat(gotTxs).hasSameSizeAs(createdIds); assertThat(gotTxs.stream() - .allMatch(it -> it.getStatus() == StreamTransactionStatus.running)).isTrue(); + .allMatch(it -> it.getState() == StreamTransactionStatus.running)).isTrue(); db.abortStreamTransaction(tx1.getId()).get(); db.abortStreamTransaction(tx2.getId()).get(); diff --git a/src/test/java/com/arangodb/async/debug/ConsolidationIntervalMsecTest.java b/src/test/java/com/arangodb/async/debug/ConsolidationIntervalMsecTest.java index 14f5b7ab3..d6c8ebccd 100644 --- a/src/test/java/com/arangodb/async/debug/ConsolidationIntervalMsecTest.java +++ b/src/test/java/com/arangodb/async/debug/ConsolidationIntervalMsecTest.java @@ -29,7 +29,6 @@ import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; import com.arangodb.entity.arangosearch.CollectionLink; import com.arangodb.entity.arangosearch.FieldLink; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; import org.junit.jupiter.api.Test; @@ -50,7 +49,6 @@ void consolidationIntervalMsec() throws ExecutionException, InterruptedException assumeTrue(isAtLeastVersion(3, 4)); ArangoDBAsync arango = new ArangoDBAsync.Builder() - .serializer(new ArangoJack()) .user("root") .password("test") .build(); diff --git a/src/test/java/com/arangodb/async/example/ExampleBase.java b/src/test/java/com/arangodb/async/example/ExampleBase.java index 9ae6e510a..22ca7f7a8 100644 --- a/src/test/java/com/arangodb/async/example/ExampleBase.java +++ b/src/test/java/com/arangodb/async/example/ExampleBase.java @@ -24,7 +24,6 @@ import com.arangodb.async.ArangoCollectionAsync; import com.arangodb.async.ArangoDBAsync; import com.arangodb.async.ArangoDatabaseAsync; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -43,7 +42,7 @@ public class ExampleBase { @BeforeAll static void setUp() throws InterruptedException, ExecutionException { - arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDBAsync.Builder().build(); if (arangoDB.db(DB_NAME).exists().get()) { arangoDB.db(DB_NAME).drop().get(); } diff --git a/src/test/java/com/arangodb/async/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java b/src/test/java/com/arangodb/async/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java index a5ab9ab14..b5e9b1f15 100644 --- a/src/test/java/com/arangodb/async/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java +++ b/src/test/java/com/arangodb/async/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java @@ -22,11 +22,12 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; -import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -55,29 +56,29 @@ private static void createExamples() throws InterruptedException, ExecutionExcep } @Test - void aqlWithLimitQueryAsVPackObject() throws InterruptedException, ExecutionException { + void aqlWithLimitQueryAsJsonObject() throws InterruptedException, ExecutionException { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); - db.query(query, bindVars, null, VPackSlice.class) - .whenComplete((cursor, ex) -> cursor.forEachRemaining(vpack -> { - assertThat(vpack.get("name").getAsString()).isIn("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"); - assertThat(vpack.get("gender").getAsString()).isEqualTo(Gender.FEMALE.name()); - assertThat(vpack.get("age").getAsInt()).isIn(21, 23, 25, 27, 29); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); + db.query(query, bindVars, null, ObjectNode.class) + .whenComplete((cursor, ex) -> cursor.forEachRemaining(node -> { + assertThat(node.get("name").asText()).isIn("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"); + assertThat(node.get("gender").asText()).isEqualTo(Gender.FEMALE.name()); + assertThat(node.get("age").asInt()).isIn(21, 23, 25, 27, 29); })) .get(); } @Test - void aqlWithLimitQueryAsVPackArray() throws InterruptedException, ExecutionException { + void aqlWithLimitQueryAsArrayNode() throws InterruptedException, ExecutionException { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); - db.query(query, bindVars, null, VPackSlice.class) - .whenComplete((cursor, ex) -> cursor.forEachRemaining(vpack -> { - assertThat(vpack.get(0).getAsString()).isIn("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"); - assertThat(vpack.get(1).getAsString()).isEqualTo(Gender.FEMALE.name()); - assertThat(vpack.get(2).getAsInt()).isIn(21, 23, 25, 27, 29); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); + db.query(query, bindVars, null, ArrayNode.class) + .whenComplete((cursor, ex) -> cursor.forEachRemaining(arrNode -> { + assertThat(arrNode.get(0).asText()).isIn("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"); + assertThat(arrNode.get(1).asText()).isEqualTo(Gender.FEMALE.name()); + assertThat(arrNode.get(2).asInt()).isIn(21, 23, 25, 27, 29); })) .get(); } @@ -86,7 +87,7 @@ void aqlWithLimitQueryAsVPackArray() throws InterruptedException, ExecutionExcep void aqlWithLimitQueryAsMap() throws InterruptedException, ExecutionException { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); db.query(query, bindVars, null, Map.class) .whenComplete((cursor, ex) -> cursor.forEachRemaining(map -> { assertThat(map.get("name")).isNotNull(); @@ -103,7 +104,7 @@ void aqlWithLimitQueryAsMap() throws InterruptedException, ExecutionException { void aqlWithLimitQueryAsList() throws InterruptedException, ExecutionException { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); db.query(query, bindVars, null, List.class) .whenComplete((cursor, ex) -> cursor.forEachRemaining(list -> { assertThat(list.get(0)).isNotNull(); diff --git a/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java index 0e7ae4c72..835017668 100644 --- a/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java @@ -23,7 +23,8 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -71,22 +72,23 @@ void getAsBaseDocument() throws InterruptedException, ExecutionException { @Test void getAsVPack() throws InterruptedException, ExecutionException { - collection.getDocument(key, VPackSlice.class) + collection.getDocument(key, JsonNode.class) .whenComplete((doc, ex) -> { assertThat(doc).isNotNull(); - assertThat(doc.get("foo").isString()).isEqualTo(true); - assertThat(doc.get("foo").getAsString()).isEqualTo("bar"); + assertThat(doc.get("foo").isTextual()).isEqualTo(true); + assertThat(doc.get("foo").asText()).isEqualTo("bar"); }) .get(); } @Test void getAsJson() throws InterruptedException, ExecutionException { - collection.getDocument(key, String.class) + collection.getDocument(key, RawJson.class) .whenComplete((doc, ex) -> { - assertThat(doc).isNotNull(); - assertThat(doc.contains("foo")).isEqualTo(true); - assertThat(doc.contains("bar")).isEqualTo(true); + assertThat(doc.getValue()) + .isNotNull() + .contains("foo") + .contains("bar"); }) .get(); } diff --git a/src/test/java/com/arangodb/async/example/document/InsertDocumentExampleTest.java b/src/test/java/com/arangodb/async/example/document/InsertDocumentExampleTest.java index abaedab49..be3a2a1da 100644 --- a/src/test/java/com/arangodb/async/example/document/InsertDocumentExampleTest.java +++ b/src/test/java/com/arangodb/async/example/document/InsertDocumentExampleTest.java @@ -22,11 +22,11 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.ValueType; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; - import java.util.concurrent.ExecutionException; import static org.assertj.core.api.Assertions.assertThat; @@ -54,17 +54,18 @@ void insertBaseDocument() throws ExecutionException, InterruptedException { } @Test - void insertVPack() throws ExecutionException, InterruptedException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT).add("foo", "bar").close(); - collection.insertDocument(builder.slice()) + void insertJsonNode() throws ExecutionException, InterruptedException { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode node = mapper.createObjectNode(); + node.put("foo", "bar"); + collection.insertDocument(node) .whenComplete((doc, ex) -> assertThat(doc.getKey()).isNotNull()) .get(); } @Test void insertJson() throws ExecutionException, InterruptedException { - collection.insertDocument("{\"foo\":\"bar\"}") + collection.insertDocument(RawJson.of("{\"foo\":\"bar\"}")) .whenComplete((doc, ex) -> assertThat(doc.getKey()).isNotNull()) .get(); } diff --git a/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java index d0e293a62..88bbfb425 100644 --- a/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java @@ -29,8 +29,9 @@ import com.arangodb.entity.BaseEdgeDocument; import com.arangodb.entity.CollectionType; import com.arangodb.entity.DocumentCreateEntity; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.CollectionCreateOptions; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -55,7 +56,7 @@ class AQLActorsAndMoviesExampleTest { @BeforeAll static void setUp() throws InterruptedException, ExecutionException { - arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDBAsync.Builder().build(); if (arangoDB.db(TEST_DB).exists().get()) { arangoDB.db(TEST_DB).drop().get(); } @@ -484,11 +485,9 @@ public static class Actor { private String actor; private Integer movies; - public Actor() { - super(); - } - public Actor(final String actor, final Integer movies) { + @JsonCreator + public Actor(@JsonProperty("actor") final String actor, @JsonProperty("movies") final Integer movies) { super(); this.actor = actor; this.movies = movies; @@ -531,14 +530,11 @@ public boolean equals(final Object obj) { @SuppressWarnings("WeakerAccess") public static class Movie { - private String movie; - private Integer actors; - - public Movie() { - super(); - } + private final String movie; + private final Integer actors; - public Movie(final String movie, final Integer actors) { + @JsonCreator + public Movie(@JsonProperty("movie") final String movie, @JsonProperty("actors") final Integer actors) { super(); this.movie = movie; this.actors = actors; diff --git a/src/test/java/com/arangodb/async/example/graph/BaseGraphTest.java b/src/test/java/com/arangodb/async/example/graph/BaseGraphTest.java index 5496496f5..7e3c7a190 100644 --- a/src/test/java/com/arangodb/async/example/graph/BaseGraphTest.java +++ b/src/test/java/com/arangodb/async/example/graph/BaseGraphTest.java @@ -25,7 +25,6 @@ import com.arangodb.async.ArangoDatabaseAsync; import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.VertexEntity; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -48,7 +47,7 @@ public abstract class BaseGraphTest { @BeforeAll static void init() throws InterruptedException, ExecutionException { if (arangoDB == null) { - arangoDB = new ArangoDBAsync.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDBAsync.Builder().build(); } if (arangoDB.db(TEST_DB).exists().get()) { arangoDB.db(TEST_DB).drop().get(); diff --git a/src/test/java/com/arangodb/async/example/ssl/SslExampleTest.java b/src/test/java/com/arangodb/async/example/ssl/SslExampleTest.java index 68d19f0d6..4c55a0ceb 100644 --- a/src/test/java/com/arangodb/async/example/ssl/SslExampleTest.java +++ b/src/test/java/com/arangodb/async/example/ssl/SslExampleTest.java @@ -22,7 +22,6 @@ import com.arangodb.async.ArangoDBAsync; import com.arangodb.entity.ArangoDBVersion; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; @@ -69,7 +68,7 @@ void connect() throws Exception { final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder() .loadProperties(SslExampleTest.class.getResourceAsStream("/arangodb-ssl.properties")).useSsl(true) - .sslContext(sc).serializer(new ArangoJack()).build(); + .sslContext(sc).build(); final ArangoDBVersion version = arangoDB.getVersion().get(); assertThat(version).isNotNull(); } diff --git a/src/test/java/com/arangodb/async/example/velocypack/VPackExampleTest.java b/src/test/java/com/arangodb/async/example/velocypack/VPackExampleTest.java deleted file mode 100644 index a2a91781b..000000000 --- a/src/test/java/com/arangodb/async/example/velocypack/VPackExampleTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.async.example.velocypack; - -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.ValueType; -import com.arangodb.velocypack.exception.VPackException; -import org.junit.jupiter.api.Test; - - -import java.util.Iterator; -import java.util.Map.Entry; - -import static org.assertj.core.api.Assertions.assertThat; - - -/** - * @author Mark Vollmary - */ -class VPackExampleTest { - - @Test - void buildObject() throws VPackException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT);// object start - builder.add("foo", 1); // add field "foo" with value 1 - builder.add("bar", 2); // add field "bar" with value 2 - builder.close();// object end - - final VPackSlice slice = builder.slice(); // create slice - assertThat(slice.isObject()).isTrue(); - assertThat(slice.size()).isEqualTo(2); // number of fields - - final VPackSlice foo = slice.get("foo"); // get field "foo" - assertThat(foo.isInteger()).isTrue(); - assertThat(foo.getAsInt()).isEqualTo(1); - - final VPackSlice bar = slice.get("bar"); // get field "bar" - assertThat(bar.isInteger()).isTrue(); - assertThat(bar.getAsInt()).isEqualTo(2); - - // iterate over the fields - for (final Iterator> iterator = slice.objectIterator(); iterator.hasNext(); ) { - final Entry field = iterator.next(); - assertThat(field.getValue().isInteger()).isTrue(); - } - } - - @Test - void buildArray() throws VPackException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.ARRAY); // array start - builder.add(1);// add value 1 - builder.add(2);// add value 2 - builder.add(3);// add value 3 - builder.close(); // array end - - final VPackSlice slice = builder.slice();// create slice - assertThat(slice.isArray()).isTrue(); - assertThat(slice.size()).isEqualTo(3);// number of values - - // iterate over values - for (int i = 0; i < slice.size(); i++) { - final VPackSlice value = slice.get(i); - assertThat(value.isInteger()).isTrue(); - assertThat(value.getAsInt()).isEqualTo(i + 1); - } - - // iterate over values with Iterator - for (final Iterator iterator = slice.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice value = iterator.next(); - assertThat(value.isInteger()).isTrue(); - } - } - - @Test - void buildObjectInObject() throws VPackException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT);// object start - builder.add("foo", ValueType.OBJECT); // add object in field "foo" - builder.add("bar", 2); // add field "bar" with value 2 to object "foo" - builder.close();// object "foo" end - builder.close();// object end - - final VPackSlice slice = builder.slice(); // create slice - assertThat(slice.isObject()).isTrue(); - - final VPackSlice foo = slice.get("foo"); - assertThat(foo.isObject()).isTrue(); - - final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo" - assertThat(bar.isInteger()).isTrue(); - } - -} diff --git a/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java index 90022a845..16816ec0b 100644 --- a/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java @@ -25,9 +25,9 @@ import com.arangodb.async.ArangoCollectionAsync; import com.arangodb.async.ArangoDBAsync; import com.arangodb.async.ArangoDatabaseAsync; -import com.arangodb.entity.BaseDocument; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; +import com.arangodb.serde.DataType; +import com.arangodb.serde.JacksonSerde; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,6 +36,7 @@ import java.math.BigInteger; import java.util.Collections; import java.util.HashMap; +import java.util.Map; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -56,12 +57,12 @@ class CustomSerdeTest { @BeforeEach void init() throws ExecutionException, InterruptedException { - ArangoJack arangoJack = new ArangoJack(); - arangoJack.configure((mapper) -> { + JacksonSerde serde = JacksonSerde.of(DataType.VPACK); + serde.configure((mapper) -> { mapper.configure(WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true); mapper.configure(USE_BIG_INTEGER_FOR_INTS, true); }); - ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().serializer(arangoJack).build(); + ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().serializer(serde).build(); DbName TEST_DB = DbName.of("custom-serde-test"); db = arangoDB.db(TEST_DB); @@ -84,86 +85,90 @@ void shutdown() throws ExecutionException, InterruptedException { void aqlSerialization() throws ExecutionException, InterruptedException { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); HashMap params = new HashMap<>(); params.put("doc", doc); params.put("@collection", COLLECTION_NAME); - BaseDocument result = db.query( + Map result = db.query( "INSERT @doc INTO @@collection RETURN NEW", params, - BaseDocument.class + Map.class ).get().next(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void aqlDeserialization() throws ExecutionException, InterruptedException { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); collection.insertDocument(doc, null).get(); - final BaseDocument result = db.query( + final Map result = db.query( "RETURN DOCUMENT(@docId)", Collections.singletonMap("docId", COLLECTION_NAME + "/" + key), - BaseDocument.class + Map.class ).get().next(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void insertDocument() throws ExecutionException, InterruptedException { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); - BaseDocument result = collection.insertDocument( + Map result = collection.insertDocument( doc, new DocumentCreateOptions().returnNew(true) ).get().getNew(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void getDocument() throws ExecutionException, InterruptedException { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); collection.insertDocument(doc, null).get(); - final BaseDocument result = db.collection(COLLECTION_NAME).getDocument( + final Map result = db.collection(COLLECTION_NAME).getDocument( key, - BaseDocument.class, + Map.class, null).get(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } } diff --git a/src/test/java/com/arangodb/example/ExampleBase.java b/src/test/java/com/arangodb/example/ExampleBase.java index b4bd582e6..6267026d5 100644 --- a/src/test/java/com/arangodb/example/ExampleBase.java +++ b/src/test/java/com/arangodb/example/ExampleBase.java @@ -20,11 +20,7 @@ package com.arangodb.example; -import com.arangodb.ArangoCollection; -import com.arangodb.ArangoDB; -import com.arangodb.ArangoDatabase; -import com.arangodb.DbName; -import com.arangodb.mapping.ArangoJack; +import com.arangodb.*; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -42,7 +38,7 @@ public class ExampleBase { @BeforeAll static void setUp() { - arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDB.Builder().build(); DbName dbName = DbName.of(DB_NAME); if (arangoDB.db(dbName).exists()) arangoDB.db(dbName).drop(); diff --git a/src/test/java/com/arangodb/example/FirstProject.java b/src/test/java/com/arangodb/example/FirstProject.java index 63bcf034e..ca1db29d4 100644 --- a/src/test/java/com/arangodb/example/FirstProject.java +++ b/src/test/java/com/arangodb/example/FirstProject.java @@ -3,16 +3,15 @@ import com.arangodb.*; import com.arangodb.entity.BaseDocument; import com.arangodb.entity.CollectionEntity; -import com.arangodb.mapping.ArangoJack; -import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; +import java.util.Collections; import java.util.Map; public class FirstProject { public static void main(final String[] args) { - final ArangoDB arangoDB = new ArangoDB.Builder().user("root").serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().user("root").build(); // create database final DbName dbName = DbName.of("mydb"); @@ -55,13 +54,13 @@ public static void main(final String[] args) { System.err.println("Failed to get document: myKey; " + e.getMessage()); } - // read a document as VPack + // read a document as JsonNode try { - final VPackSlice myDocument = arangoDB.db(dbName).collection(collectionName).getDocument("myKey", - VPackSlice.class); - System.out.println("Key: " + myDocument.get("_key").getAsString()); - System.out.println("Attribute a: " + myDocument.get("a").getAsString()); - System.out.println("Attribute b: " + myDocument.get("b").getAsInt()); + final JsonNode myDocument = arangoDB.db(dbName).collection(collectionName).getDocument("myKey", + JsonNode.class); + System.out.println("Key: " + myDocument.get("_key").textValue()); + System.out.println("Attribute a: " + myDocument.get("a").textValue()); + System.out.println("Attribute b: " + myDocument.get("b").textValue()); } catch (final ArangoDBException e) { System.err.println("Failed to get document: myKey; " + e.getMessage()); } @@ -105,7 +104,7 @@ public static void main(final String[] args) { // execute AQL queries try { final String query = "FOR t IN firstCollection FILTER t.name == @name RETURN t"; - final Map bindVars = new MapBuilder().put("name", "Homer").get(); + final Map bindVars = Collections.singletonMap("name", "Homer"); final ArangoCursor cursor = arangoDB.db(dbName).query(query, bindVars, null, BaseDocument.class); for (; cursor.hasNext(); ) { @@ -119,7 +118,7 @@ public static void main(final String[] args) { try { final String query = "FOR t IN firstCollection FILTER t.name == @name " + "REMOVE t IN firstCollection LET removed = OLD RETURN removed"; - final Map bindVars = new MapBuilder().put("name", "Homer").get(); + final Map bindVars = Collections.singletonMap("name", "Homer"); final ArangoCursor cursor = arangoDB.db(dbName).query(query, bindVars, null, BaseDocument.class); for (; cursor.hasNext(); ) { diff --git a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java index 1a46d3a15..f820cdd09 100644 --- a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java +++ b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java @@ -23,11 +23,12 @@ import com.arangodb.ArangoCursor; import com.arangodb.entity.BaseDocument; import com.arangodb.example.ExampleBase; -import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -59,34 +60,34 @@ private static void createExamples() { } @Test - void aqlWithLimitQueryAsVPackObject() { + void aqlWithLimitQueryAsJsonObject() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); - final ArangoCursor cursor = db.query(query, bindVars, null, VPackSlice.class); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); + final ArangoCursor cursor = db.query(query, bindVars, null, ObjectNode.class); assertThat((Object) cursor).isNotNull(); while (cursor.hasNext()) { - final VPackSlice vpack = cursor.next(); - assertThat(vpack.get("name").getAsString()) + final ObjectNode vpack = cursor.next(); + assertThat(vpack.get("name").asText()) .isIn("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"); - assertThat(vpack.get("gender").getAsString()).isEqualTo(Gender.FEMALE.name()); - assertThat(vpack.get("age").getAsInt()).isIn(21, 23, 25, 27, 29); + assertThat(vpack.get("gender").asText()).isEqualTo(Gender.FEMALE.name()); + assertThat(vpack.get("age").asInt()).isIn(21, 23, 25, 27, 29); } } @Test - void aqlWithLimitQueryAsVPackArray() { + void aqlWithLimitQueryAsJsonArray() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); - final ArangoCursor cursor = db.query(query, bindVars, null, VPackSlice.class); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); + final ArangoCursor cursor = db.query(query, bindVars, null, ArrayNode.class); assertThat((Object) cursor).isNotNull(); while (cursor.hasNext()) { - final VPackSlice vpack = cursor.next(); - assertThat(vpack.get(0).getAsString()) + final ArrayNode arrNode = cursor.next(); + assertThat(arrNode.get(0).asText()) .isIn("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"); - assertThat(vpack.get(1).getAsString()).isEqualTo(Gender.FEMALE.name()); - assertThat(vpack.get(2).getAsInt()).isIn(21, 23, 25, 27, 29); + assertThat(arrNode.get(1).asText()).isEqualTo(Gender.FEMALE.name()); + assertThat(arrNode.get(2).asInt()).isIn(21, 23, 25, 27, 29); } } @@ -95,7 +96,7 @@ void aqlWithLimitQueryAsVPackArray() { void aqlWithLimitQueryAsMap() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); final ArangoCursor cursor = db.query(query, bindVars, null, Map.class); assertThat((Object) cursor).isNotNull(); while (cursor.hasNext()) { @@ -115,7 +116,7 @@ void aqlWithLimitQueryAsMap() { void aqlWithLimitQueryAsList() { final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]"; - final Map bindVars = new MapBuilder().put("gender", Gender.FEMALE).get(); + final Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); final ArangoCursor cursor = db.query(query, bindVars, null, List.class); assertThat((Object) cursor).isNotNull(); while (cursor.hasNext()) { diff --git a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java index 10df2972e..51cd6f9f3 100644 --- a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java @@ -23,7 +23,9 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -72,19 +74,27 @@ void getAsMap() { } @Test - void getAsVPack() { - final VPackSlice doc = collection.getDocument(key, VPackSlice.class); + void getAsJsonNode() { + final JsonNode doc = collection.getDocument(key, JsonNode.class); assertThat(doc).isNotNull(); - assertThat(doc.get("foo").isString()).isTrue(); - assertThat(doc.get("foo").getAsString()).isEqualTo("bar"); + assertThat(doc.get("foo").isTextual()).isTrue(); + assertThat(doc.get("foo").asText()).isEqualTo("bar"); } @Test void getAsJson() { - final String doc = collection.getDocument(key, String.class); - assertThat(doc).isNotNull(); - assertThat(doc).contains("foo"); - assertThat(doc).contains("bar"); + final RawJson doc = collection.getDocument(key, RawJson.class); + assertThat(doc.getValue()).isNotNull() + .contains("foo") + .contains("bar"); + } + + @Test + void getAsBytes() { + final RawBytes doc = collection.getDocument(key, RawBytes.class); + assertThat(doc.getValue()).isNotNull(); + Map mapDoc = collection.getSerde().deserializeUserData(doc.getValue(), Map.class); + assertThat(mapDoc).containsEntry("foo", "bar"); } } diff --git a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java index 016d7f2c3..e12949537 100644 --- a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java @@ -23,9 +23,10 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.ValueType; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -51,16 +52,17 @@ void insertBaseDocument() { } @Test - void insertVPack() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT).add("foo", "bar").close(); - final DocumentCreateEntity doc = collection.insertDocument(builder.slice()); + void insertJsonNode() { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode node = mapper.createObjectNode(); + node.put("foo", "bar"); + final DocumentCreateEntity doc = collection.insertDocument(node); assertThat(doc.getKey()).isNotNull(); } @Test void insertJson() { - final DocumentCreateEntity doc = collection.insertDocument("{\"foo\":\"bar\"}"); + final DocumentCreateEntity doc = collection.insertDocument(RawJson.of("{\"foo\":\"bar\"}")); assertThat(doc.getKey()).isNotNull(); } diff --git a/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java index f5283c5aa..0bd9b57a3 100644 --- a/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java @@ -25,8 +25,9 @@ import com.arangodb.entity.BaseEdgeDocument; import com.arangodb.entity.CollectionType; import com.arangodb.entity.DocumentCreateEntity; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.CollectionCreateOptions; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -47,7 +48,7 @@ class AQLActorsAndMoviesExampleTest { @BeforeAll static void setUp() { - arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDB.Builder().build(); if (arangoDB.db(TEST_DB).exists()) arangoDB.db(TEST_DB).drop(); arangoDB.createDatabase(TEST_DB); @@ -219,14 +220,11 @@ void theNumberOfMoviesActedInBetween2005and2010byActor() { } public static class Actor { - private String actor; - private Integer movies; + private final String actor; + private final Integer movies; - public Actor() { - super(); - } - - Actor(final String actor, final Integer movies) { + @JsonCreator + Actor(@JsonProperty("actor") final String actor, @JsonProperty("movies") final Integer movies) { super(); this.actor = actor; this.movies = movies; @@ -268,14 +266,11 @@ public boolean equals(final Object obj) { } public static class Movie { - private String movie; - private Integer actors; - - public Movie() { - super(); - } + private final String movie; + private final Integer actors; - Movie(final String movie, final Integer actors) { + @JsonCreator + public Movie(@JsonProperty("movie") final String movie, @JsonProperty("actors") final Integer actors) { super(); this.movie = movie; this.actors = actors; diff --git a/src/test/java/com/arangodb/example/graph/BaseGraphTest.java b/src/test/java/com/arangodb/example/graph/BaseGraphTest.java index f74c4ed42..2a7baa2f1 100644 --- a/src/test/java/com/arangodb/example/graph/BaseGraphTest.java +++ b/src/test/java/com/arangodb/example/graph/BaseGraphTest.java @@ -26,7 +26,6 @@ import com.arangodb.DbName; import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.VertexEntity; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -48,7 +47,7 @@ abstract class BaseGraphTest { @BeforeAll static void init() { if (arangoDB == null) { - arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDB.Builder().build(); } if (arangoDB.db(TEST_DB).exists()) arangoDB.db(TEST_DB).drop(); diff --git a/src/test/java/com/arangodb/example/ssl/SslExampleTest.java b/src/test/java/com/arangodb/example/ssl/SslExampleTest.java index a21384bdd..b2b2ed2bb 100644 --- a/src/test/java/com/arangodb/example/ssl/SslExampleTest.java +++ b/src/test/java/com/arangodb/example/ssl/SslExampleTest.java @@ -23,7 +23,6 @@ import com.arangodb.ArangoDB; import com.arangodb.Protocol; import com.arangodb.entity.ArangoDBVersion; -import com.arangodb.mapping.ArangoJack; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; @@ -57,7 +56,7 @@ class SslExampleTest { @Test void connect() throws Exception { final ArangoDB arangoDB = new ArangoDB.Builder() - .serializer(new ArangoJack()) + .host("localhost", 8529) .password("test") .useSsl(true) @@ -72,7 +71,7 @@ void connect() throws Exception { @Test void noopHostnameVerifier() throws Exception { final ArangoDB arangoDB = new ArangoDB.Builder() - .serializer(new ArangoJack()) + .host("127.0.0.1", 8529) .password("test") .useSsl(true) diff --git a/src/test/java/com/arangodb/example/velocypack/VPackExampleTest.java b/src/test/java/com/arangodb/example/velocypack/VPackExampleTest.java deleted file mode 100644 index dd1d1e421..000000000 --- a/src/test/java/com/arangodb/example/velocypack/VPackExampleTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.example.velocypack; - -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.ValueType; -import com.arangodb.velocypack.exception.VPackException; -import org.junit.jupiter.api.Test; - -import java.util.Iterator; -import java.util.Map.Entry; - -import static org.assertj.core.api.Assertions.assertThat; - - -/** - * @author Mark Vollmary - */ -class VPackExampleTest { - - @Test - void buildObject() throws VPackException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT);// object start - builder.add("foo", 1); // add field "foo" with value 1 - builder.add("bar", 2); // add field "bar" with value 2 - builder.close();// object end - - final VPackSlice slice = builder.slice(); // create slice - assertThat(slice.isObject()).isTrue(); - assertThat(slice.size()).isEqualTo(2); // number of fields - - final VPackSlice foo = slice.get("foo"); // get field "foo" - assertThat(foo.isInteger()).isTrue(); - assertThat(foo.getAsInt()).isEqualTo(1); - - final VPackSlice bar = slice.get("bar"); // get field "bar" - assertThat(bar.isInteger()).isTrue(); - assertThat(bar.getAsInt()).isEqualTo(2); - - // iterate over the fields - for (final Iterator> iterator = slice.objectIterator(); iterator.hasNext(); ) { - final Entry field = iterator.next(); - assertThat(field.getValue().isInteger()).isTrue(); - } - } - - @Test - void buildArray() throws VPackException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.ARRAY); // array start - builder.add(1);// add value 1 - builder.add(2);// add value 2 - builder.add(3);// add value 3 - builder.close(); // array end - - final VPackSlice slice = builder.slice();// create slice - assertThat(slice.isArray()).isTrue(); - assertThat(slice.size()).isEqualTo(3);// number of values - - // iterate over values - for (int i = 0; i < slice.size(); i++) { - final VPackSlice value = slice.get(i); - assertThat(value.isInteger()).isTrue(); - assertThat(value.getAsInt()).isEqualTo(i + 1); - } - - // iterate over values with Iterator - for (final Iterator iterator = slice.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice value = iterator.next(); - assertThat(value.isInteger()).isTrue(); - } - } - - @Test - void buildObjectInObject() throws VPackException { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT);// object start - builder.add("foo", ValueType.OBJECT); // add object in field "foo" - builder.add("bar", 2); // add field "bar" with value 2 to object "foo" - builder.close();// object "foo" end - builder.close();// object end - - final VPackSlice slice = builder.slice(); // create slice - assertThat(slice.isObject()).isTrue(); - - final VPackSlice foo = slice.get("foo"); - assertThat(foo.isObject()).isTrue(); - - final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo" - assertThat(bar.isInteger()).isTrue(); - } - -} diff --git a/src/test/java/com/arangodb/internal/HostHandlerTest.java b/src/test/java/com/arangodb/internal/HostHandlerTest.java index 56b09ca5d..2aeecec55 100644 --- a/src/test/java/com/arangodb/internal/HostHandlerTest.java +++ b/src/test/java/com/arangodb/internal/HostHandlerTest.java @@ -23,7 +23,7 @@ import com.arangodb.ArangoDBException; import com.arangodb.ArangoDBMultipleException; import com.arangodb.internal.net.*; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.InternalSerde; import org.junit.jupiter.api.Test; import java.util.List; @@ -73,7 +73,7 @@ public HostSet resolve(final boolean initial, final boolean closeConnections) { } @Override - public void init(ArangoExecutorSync executor, ArangoSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { } @@ -92,7 +92,7 @@ public HostSet resolve(final boolean initial, final boolean closeConnections) { } @Override - public void init(ArangoExecutorSync executor, ArangoSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { } diff --git a/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java b/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java deleted file mode 100644 index 5c3880ba6..000000000 --- a/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.internal.velocypack; - -import com.arangodb.entity.ViewType; -import com.arangodb.entity.arangosearch.ArangoSearchCompression; -import com.arangodb.entity.arangosearch.ArangoSearchProperties; -import com.arangodb.entity.arangosearch.StoredValue; -import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackSlice; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; - -class VPackSerializersTest { - - private VPack vpack; - - @BeforeEach - void init() { - vpack = new VPack.Builder() - .registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES) - .build(); - } - - @Test - void serializeArangoSearchProperties() { - final ArangoSearchCreateOptions opts = new ArangoSearchCreateOptions() - .storedValues(new StoredValue(Collections.singletonList("dummy"), ArangoSearchCompression.lz4)); - - final VPackSlice slice = vpack.serialize(opts); - - assertThat(slice.isObject()).isTrue(); - assertThat(slice.get("type").isString()).isTrue(); - assertThat(slice.get("type").getAsString()).isEqualTo(ViewType.ARANGO_SEARCH.name()); - assertThat(slice.get("storedValues")).isNotNull(); - assertThat(slice.get("storedValues").isArray()).isTrue(); - assertThat(slice.get("storedValues").size()).isEqualTo(1); - assertThat(slice.get("storedValues").get(0).isObject()).isTrue(); - assertThat(slice.get("storedValues").get(0).get("fields").isArray()).isTrue(); - assertThat(slice.get("storedValues").get(0).get("fields").size()).isEqualTo(1); - assertThat(slice.get("storedValues").get(0).get("fields").get(0).isString()).isTrue(); - assertThat(slice.get("storedValues").get(0).get("fields").get(0).getAsString()).isEqualTo("dummy"); - assertThat(slice.get("storedValues").get(0).get("compression").isString()).isTrue(); - assertThat(slice.get("storedValues").get(0).get("compression").getAsString()).isEqualTo(ArangoSearchCompression.lz4.name()); - } - - @Test - void serializeArangoSearchPropertiesWithDefaultCompression() { - final ArangoSearchCreateOptions opts = new ArangoSearchCreateOptions() - .storedValues(new StoredValue(Collections.singletonList("dummy"))); - - final VPackSlice slice = vpack.serialize(opts); - - assertThat(slice.get("storedValues").get(0).get("compression").isNone()).isTrue(); - } -} diff --git a/src/test/java/com/arangodb/internal/velocystream/CommunicationTest.java b/src/test/java/com/arangodb/internal/velocystream/CommunicationTest.java index 0778c58ed..c9034cf9c 100644 --- a/src/test/java/com/arangodb/internal/velocystream/CommunicationTest.java +++ b/src/test/java/com/arangodb/internal/velocystream/CommunicationTest.java @@ -23,7 +23,6 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDatabase; import com.arangodb.entity.ArangoDBVersion; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.Test; import java.util.Collection; @@ -42,14 +41,14 @@ class CommunicationTest { @Test void chunkSizeSmall() { - final ArangoDB arangoDB = new ArangoDB.Builder().chunksize(20).serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().chunksize(20).build(); final ArangoDBVersion version = arangoDB.getVersion(); assertThat(version).isNotNull(); } @Test void multiThread() throws Exception { - final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().build(); arangoDB.getUsers(); // authentication and active-failover connection redirect to master final Collection result = new ConcurrentLinkedQueue<>(); @@ -75,7 +74,7 @@ void multiThread() throws Exception { @Test void multiThreadSameDatabases() throws Exception { - final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().build(); arangoDB.getUsers(); // authentication and active-failover connection redirect to master final ArangoDatabase db = arangoDB.db(); @@ -98,14 +97,14 @@ void multiThreadSameDatabases() throws Exception { @Test void minOneConnection() { - final ArangoDB arangoDB = new ArangoDB.Builder().maxConnections(0).serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().maxConnections(0).build(); final ArangoDBVersion version = arangoDB.getVersion(); assertThat(version).isNotNull(); } @Test void defaultMaxConnection() { - final ArangoDB arangoDB = new ArangoDB.Builder().maxConnections(null).serializer(new ArangoJack()).build(); + final ArangoDB arangoDB = new ArangoDB.Builder().maxConnections(null).build(); final ArangoDBVersion version = arangoDB.getVersion(); assertThat(version).isNotNull(); } diff --git a/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java b/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java deleted file mode 100644 index eed9a8052..000000000 --- a/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java +++ /dev/null @@ -1,3302 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - - -package com.arangodb.mapping; - -import com.arangodb.velocypack.*; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.Map.Entry; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Mark Vollmary - */ -class VPackSerializeDeserializeTest { - - private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");// ISO 8601 - - static { - DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); - } - - private final ObjectMapper mapper = ArangoJack.createDefaultMapper(); - - public static class TestEntityBoolean { - private boolean a = true; - private boolean b = false; - private Boolean c = Boolean.TRUE; - private Boolean d = Boolean.FALSE; - - public boolean isA() { - return a; - } - - public void setA(final boolean a) { - this.a = a; - } - - public boolean isB() { - return b; - } - - public void setB(final boolean b) { - this.b = b; - } - - public Boolean getC() { - return c; - } - - public void setC(final Boolean c) { - this.c = c; - } - - public Boolean getD() { - return d; - } - - public void setD(final Boolean d) { - this.d = d; - } - } - - @Test - void fromBoolean() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityBoolean())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice a = vpack.get("a"); - assertThat(a.isBoolean()).isTrue(); - assertThat(a.getAsBoolean()).isTrue(); - } - { - final VPackSlice b = vpack.get("b"); - assertThat(b.isBoolean()).isTrue(); - assertThat(b.getAsBoolean()).isFalse(); - } - { - final VPackSlice c = vpack.get("c"); - assertThat(c.isBoolean()).isTrue(); - assertThat(c.getAsBoolean()).isTrue(); - } - { - final VPackSlice d = vpack.get("d"); - assertThat(d.isBoolean()).isTrue(); - assertThat(d.getAsBoolean()).isFalse(); - } - } - - @Test - void toBoolean() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("a", false); - builder.add("b", true); - builder.add("c", Boolean.FALSE); - builder.add("d", Boolean.TRUE); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityBoolean entity = mapper.readValue(vpack.getBuffer(), TestEntityBoolean.class); - assertThat(entity).isNotNull(); - assertThat(entity.a).isFalse(); - assertThat(entity.b).isTrue(); - assertThat(entity.c).isInstanceOf(Boolean.class).isFalse(); - assertThat(entity.d).isInstanceOf(Boolean.class).isTrue(); - } - - public static class TestEntityString { - private String s = "test"; - private Character c1 = 't'; - private char c2 = 't'; - - public String getS() { - return s; - } - - public void setS(final String s) { - this.s = s; - } - - public Character getC1() { - return c1; - } - - public void setC1(final Character c1) { - this.c1 = c1; - } - - public char getC2() { - return c2; - } - - public void setC2(final char c2) { - this.c2 = c2; - } - } - - @Test - void fromStrings() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityString())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice s = vpack.get("s"); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo("test"); - } - { - final VPackSlice c1 = vpack.get("c1"); - assertThat(c1.isString()).isTrue(); - assertThat(c1.getAsChar()).isEqualTo('t'); - } - { - final VPackSlice c2 = vpack.get("c2"); - assertThat(c2.isString()).isTrue(); - assertThat(c2.getAsChar()).isEqualTo('t'); - } - } - - @Test - void toStrings() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("s", "abc"); - builder.add("c1", 'd'); - builder.add("c2", 'd'); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityString entity = mapper.readValue(vpack.getBuffer(), TestEntityString.class); - assertThat(entity).isNotNull(); - assertThat(entity.s).isEqualTo("abc"); - assertThat(entity.c1).isEqualTo(new Character('d')); - } - - public static class TestEntityInteger { - private int i1 = 1; - private Integer i2 = 1; - - public int getI1() { - return i1; - } - - public void setI1(final int i1) { - this.i1 = i1; - } - - public Integer getI2() { - return i2; - } - - public void setI2(final Integer i2) { - this.i2 = i2; - } - } - - @Test - void fromInteger() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityInteger())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice i1 = vpack.get("i1"); - assertThat(i1.isInteger()).isTrue(); - assertThat(i1.getAsInt()).isEqualTo(1); - } - { - final VPackSlice i2 = vpack.get("i2"); - assertThat(i2.isInteger()).isTrue(); - assertThat(i2.getAsInt()).isEqualTo(1); - } - } - - @Test - void fromNegativeInteger() throws JsonProcessingException { - final TestEntityInteger entity = new TestEntityInteger(); - entity.i1 = -50; - entity.i2 = -50; - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice i1 = vpack.get("i1"); - assertThat(i1.isInteger()).isTrue(); - assertThat(i1.getAsInt()).isEqualTo(-50); - } - { - final VPackSlice i2 = vpack.get("i2"); - assertThat(i2.isInteger()).isTrue(); - assertThat(i2.getAsInt()).isEqualTo(-50); - } - } - - @Test - void toInteger() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("i1", 2); - builder.add("i2", 3); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityInteger entity = mapper.readValue(vpack.getBuffer(), TestEntityInteger.class); - assertThat(entity).isNotNull(); - assertThat(entity.i1).isEqualTo(2); - assertThat(entity.i2).isEqualTo(Integer.valueOf(3)); - } - - @Test - void toNegativeInteger() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("i1", -50); - builder.add("i2", -50); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityInteger entity = mapper.readValue(vpack.getBuffer(), TestEntityInteger.class); - assertThat(entity).isNotNull(); - assertThat(entity.i1).isEqualTo(-50); - assertThat(entity.i2).isEqualTo(Integer.valueOf(-50)); - } - - public static class TestEntityLong { - private long l1 = 1; - private Long l2 = 1L; - - public long getL1() { - return l1; - } - - public void setL1(final long l1) { - this.l1 = l1; - } - - public Long getL2() { - return l2; - } - - public void setL2(final Long l2) { - this.l2 = l2; - } - } - - @Test - void fromLong() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityLong())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice l1 = vpack.get("l1"); - assertThat(l1.isInteger()).isTrue(); - assertThat(l1.getAsLong()).isEqualTo(1L); - } - { - final VPackSlice l2 = vpack.get("l2"); - assertThat(l2.isInteger()).isTrue(); - assertThat(l2.getAsLong()).isEqualTo(1L); - } - } - - @Test - void fromNegativeLong() throws JsonProcessingException { - final TestEntityLong entity = new TestEntityLong(); - entity.l1 = -100L; - entity.l2 = -300L; - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice l1 = vpack.get("l1"); - assertThat(l1.isInteger()).isTrue(); - assertThat(l1.getAsLong()).isEqualTo(-100L); - } - { - final VPackSlice l2 = vpack.get("l2"); - assertThat(l2.isInteger()).isTrue(); - assertThat(l2.getAsLong()).isEqualTo(-300); - } - } - - @Test - void toLong() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("l1", 2); - builder.add("l2", 3); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityLong entity = mapper.readValue(vpack.getBuffer(), TestEntityLong.class); - assertThat(entity).isNotNull(); - assertThat(entity.l1).isEqualTo(2); - assertThat(entity.l2).isEqualTo(Long.valueOf(3)); - } - - @Test - void toNegativeLong() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("l1", -100L); - builder.add("l2", -300L); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityLong entity = mapper.readValue(vpack.getBuffer(), TestEntityLong.class); - assertThat(entity).isNotNull(); - assertThat(entity.l1).isEqualTo(-100L); - assertThat(entity.l2).isEqualTo(Long.valueOf(-300)); - } - - @Test - void negativeLong() { - final TestEntityLong entity = new TestEntityLong(); - entity.l1 = -100L; - entity.l2 = -300L; - final VPack vp = new VPack.Builder().build(); - final TestEntityLong out = vp.deserialize(vp.serialize(entity), TestEntityLong.class); - assertThat(out.l1).isEqualTo(entity.l1); - assertThat(out.l2).isEqualTo(entity.l2); - } - - @Test - void intToLong() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("l1", 100); - builder.add("l2", 300); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityLong entity = mapper.readValue(vpack.getBuffer(), TestEntityLong.class); - assertThat(entity).isNotNull(); - assertThat(entity.l1).isEqualTo(100); - assertThat(entity.l2).isEqualTo(Long.valueOf(300)); - } - - @Test - void negativeIntToLong() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("l1", -100); - builder.add("l2", -300); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityLong entity = mapper.readValue(vpack.getBuffer(), TestEntityLong.class); - assertThat(entity).isNotNull(); - assertThat(entity.l1).isEqualTo(-100L); - assertThat(entity.l2).isEqualTo(Long.valueOf(-300)); - } - - @Test - void negativeLongToInt() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("i1", -100L); - builder.add("i2", -300L); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityInteger entity = mapper.readValue(vpack.getBuffer(), TestEntityInteger.class); - assertThat(entity).isNotNull(); - assertThat(entity.i1).isEqualTo(-100); - assertThat(entity.i2).isEqualTo(Integer.valueOf(-300)); - } - - @Test - void negativeLongToShort() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("s1", -100L); - builder.add("s2", -300L); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityShort entity = mapper.readValue(vpack.getBuffer(), TestEntityShort.class); - assertThat(entity).isNotNull(); - assertThat(entity.s1).isEqualTo((short) -100); - assertThat(entity.s2).isEqualTo(Short.valueOf((short) -300)); - } - - @Test - void negativeShortToLong() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("l1", (short) -100); - builder.add("l2", (short) -300); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityLong entity = mapper.readValue(vpack.getBuffer(), TestEntityLong.class); - assertThat(entity).isNotNull(); - assertThat(entity.l1).isEqualTo(-100L); - assertThat(entity.l2).isEqualTo(Long.valueOf(-300)); - } - - public static class TestEntityFloat { - private float f1 = 1; - private Float f2 = 1F; - - public float getF1() { - return f1; - } - - public void setF1(final float f1) { - this.f1 = f1; - } - - public Float getF2() { - return f2; - } - - public void setF2(final Float f2) { - this.f2 = f2; - } - } - - @Test - void fromFloat() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityFloat())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice f1 = vpack.get("f1"); - assertThat(f1.isDouble()).isTrue(); - assertThat(f1.getAsFloat()).isEqualTo(1.0F); - } - { - final VPackSlice f2 = vpack.get("f2"); - assertThat(f2.isDouble()).isTrue(); - assertThat(f2.getAsFloat()).isEqualTo(1.0F); - } - } - - @Test - void toFloat() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("f1", 2F); - builder.add("f2", 3F); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityFloat entity = mapper.readValue(vpack.getBuffer(), TestEntityFloat.class); - assertThat(entity).isNotNull(); - assertThat(entity.f1).isEqualTo(2F); - assertThat(entity.f2).isEqualTo(new Float(3)); - } - - public static class TestEntityShort { - private short s1 = 1; - private Short s2 = 1; - - public short getS1() { - return s1; - } - - public void setS1(final short s1) { - this.s1 = s1; - } - - public Short getS2() { - return s2; - } - - public void setS2(final Short s2) { - this.s2 = s2; - } - } - - @Test - void fromShort() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityShort())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice s1 = vpack.get("s1"); - assertThat(s1.isInteger()).isTrue(); - assertThat(s1.getAsShort()).isEqualTo((short) 1); - } - { - final VPackSlice s2 = vpack.get("s2"); - assertThat(s2.isInteger()).isTrue(); - assertThat(s2.getAsShort()).isEqualTo((short) 1); - } - } - - @Test - void toShort() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("s1", 2); - builder.add("s2", 3); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityShort entity = mapper.readValue(vpack.getBuffer(), TestEntityShort.class); - assertThat(entity).isNotNull(); - assertThat(entity.s1).isEqualTo((short) 2); - assertThat(entity.s2).isEqualTo(Short.valueOf((short) 3)); - } - - public static class TestEntityByte { - private byte b1 = 1; // short integer path - private Byte b2 = 100; // integer path - - public byte getB1() { - return b1; - } - - public void setB1(final byte b1) { - this.b1 = b1; - } - - public Byte getB2() { - return b2; - } - - public void setB2(final Byte b2) { - this.b2 = b2; - } - } - - @Test - void fromByte() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityByte())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice b1 = vpack.get("b1"); - assertThat(b1.isInteger()).isTrue(); - assertThat(b1.getAsByte()).isEqualTo((byte) 1); - } - { - final VPackSlice b2 = vpack.get("b2"); - assertThat(b2.isInteger()).isTrue(); - assertThat(b2.getAsByte()).isEqualTo((byte) 100); - } - } - - @Test - void toByte() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("b1", 30); // integer path - builder.add("b2", 4); // short integer path - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityByte entity = mapper.readValue(vpack.getBuffer(), TestEntityByte.class); - assertThat(entity).isNotNull(); - assertThat(entity.b1).isEqualTo((byte) 30); - assertThat(entity.b2).isEqualTo(Byte.valueOf((byte) 4)); - } - - public static class TestEntityDouble { - private Double d1 = 1.5; - private double d2 = 1.5; - - public Double getD1() { - return d1; - } - - public void setD1(final Double d1) { - this.d1 = d1; - } - - public double getD2() { - return d2; - } - - public void setD2(final double d2) { - this.d2 = d2; - } - } - - @Test - void fromDouble() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityDouble())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice d1 = vpack.get("d1"); - assertThat(d1.isDouble()).isTrue(); - assertThat(d1.getAsDouble()).isEqualTo(1.5); - } - { - final VPackSlice d2 = vpack.get("d2"); - assertThat(d2.isDouble()).isTrue(); - assertThat(d2.getAsDouble()).isEqualTo(1.5); - } - } - - @Test - void toDouble() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("d1", 2.25); - builder.add("d2", 3.75); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityDouble entity = mapper.readValue(vpack.getBuffer(), TestEntityDouble.class); - assertThat(entity).isNotNull(); - assertThat(entity.d1).isEqualTo(2.25); - assertThat(entity.d2).isEqualTo(3.75); - } - - public static class TestEntityBigNumber { - private static final BigInteger BI = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - private static final BigDecimal BD = BigDecimal.valueOf(Double.MAX_VALUE).add(BigDecimal.ONE); - - private BigInteger bi = BI; - private BigDecimal bd = BD; - - public BigInteger getBi() { - return bi; - } - - public void setBi(final BigInteger bi) { - this.bi = bi; - } - - public BigDecimal getBd() { - return bd; - } - - public void setBd(final BigDecimal bd) { - this.bd = bd; - } - } - - @Test - void fromBigNumbers() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityBigNumber())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice bi = vpack.get("bi"); - assertThat(bi.isString()).isTrue(); - assertThat(bi.getAsBigInteger()).isEqualTo(TestEntityBigNumber.BI); - } - { - final VPackSlice bd = vpack.get("bd"); - assertThat(bd.isString()).isTrue(); - assertThat(bd.getAsBigDecimal()).isEqualTo(TestEntityBigNumber.BD); - } - } - - @Test - void toBigNumbers() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("bi", BigInteger.valueOf(2)); - builder.add("bd", BigDecimal.valueOf(3.75)); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityBigNumber entity = mapper.readValue(vpack.getBuffer(), TestEntityBigNumber.class); - assertThat(entity).isNotNull(); - assertThat(entity.bi).isEqualTo(BigInteger.valueOf(2)); - assertThat(entity.bd).isEqualTo(BigDecimal.valueOf(3.75)); - } - - @Test - void bigDecimal() { - final BigDecimal fromDouble = BigDecimal.valueOf(-710.01); - final BigDecimal fromString = new BigDecimal("-710.01"); - assertThat(fromDouble).isEqualTo(fromString); - assertThat(new VPackBuilder().add(fromDouble).slice().getAsBigDecimal()).isEqualTo(fromDouble); - assertThat(new VPackBuilder().add(fromString).slice().getAsBigDecimal()).isEqualTo(fromDouble); - } - - public static class TestEntityArray { - private String[] a1 = {"a", "b", "cd"}; - private int[] a2 = {1, 2, 3, 4, 5}; - private boolean[] a3 = {true, true, false}; - private TestEnum[] a4 = TestEnum.values(); - - public String[] getA1() { - return a1; - } - - public void setA1(final String[] a1) { - this.a1 = a1; - } - - public int[] getA2() { - return a2; - } - - public void setA2(final int[] a2) { - this.a2 = a2; - } - - public boolean[] getA3() { - return a3; - } - - public void setA3(final boolean[] a3) { - this.a3 = a3; - } - - public TestEnum[] getA4() { - return a4; - } - - public void setA4(final TestEnum[] a4) { - this.a4 = a4; - } - - } - - @Test - void fromArray() throws JsonProcessingException { - final TestEntityArray entity = new TestEntityArray(); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice a1 = vpack.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.getLength()).isEqualTo(entity.a1.length); - for (int i = 0; i < a1.getLength(); i++) { - assertThat(a1.get(i).getAsString()).isEqualTo(entity.a1[i]); - } - } - { - final VPackSlice a2 = vpack.get("a2"); - assertThat(a2.isArray()).isTrue(); - assertThat(a2.getLength()).isEqualTo(entity.a2.length); - for (int i = 0; i < a2.getLength(); i++) { - assertThat(a2.get(i).getAsInt()).isEqualTo(entity.a2[i]); - } - } - { - final VPackSlice a3 = vpack.get("a3"); - assertThat(a3.isArray()).isTrue(); - assertThat(a3.getLength()).isEqualTo(entity.a3.length); - for (int i = 0; i < a3.getLength(); i++) { - assertThat(a3.get(i).getAsBoolean()).isEqualTo(entity.a3[i]); - } - } - { - final VPackSlice a4 = vpack.get("a4"); - assertThat(a4.isArray()).isTrue(); - assertThat(a4.getLength()).isEqualTo(entity.a4.length); - for (int i = 0; i < a4.getLength(); i++) { - assertThat(TestEnum.valueOf(a4.get(i).getAsString())).isEqualTo(entity.a4[i]); - } - } - } - - @Test - void toArray() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("a1", ValueType.ARRAY); - builder.add("a"); - builder.add("b"); - builder.add("c"); - builder.close(); - } - { - builder.add("a2", ValueType.ARRAY); - builder.add(1); - builder.add(2); - builder.add(3); - builder.add(4); - builder.close(); - } - { - builder.add("a3", ValueType.ARRAY); - builder.add(false); - builder.add(true); - builder.close(); - } - { - builder.add("a4", ValueType.ARRAY); - builder.add(TestEnum.A.name()); - builder.add(TestEnum.B.name()); - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityArray entity = mapper.readValue(vpack.getBuffer(), TestEntityArray.class); - assertThat(entity).isNotNull(); - { - assertThat(entity.a1).hasSize(3); - assertThat(entity.a1[0]).isEqualTo("a"); - assertThat(entity.a1[1]).isEqualTo("b"); - assertThat(entity.a1[2]).isEqualTo("c"); - } - { - assertThat(entity.a2).hasSize(4); - assertThat(entity.a2[0]).isEqualTo(1); - assertThat(entity.a2[1]).isEqualTo(2); - assertThat(entity.a2[2]).isEqualTo(3); - assertThat(entity.a2[3]).isEqualTo(4); - } - { - assertThat(entity.a3).hasSize(2); - assertThat(entity.a3[0]).isFalse(); - assertThat(entity.a3[1]).isTrue(); - } - { - assertThat(entity.a4).hasSize(2); - assertThat(entity.a4[0]).isEqualTo(TestEnum.A); - assertThat(entity.a4[1]).isEqualTo(TestEnum.B); - } - } - - @Test - void fromArrayWithNull() throws JsonProcessingException { - final TestEntityArray entity = new TestEntityArray(); - entity.a1 = new String[]{"foo", null}; - - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - - final VPackSlice a1 = vpack.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.size()).isEqualTo(2); - assertThat(a1.get(0).isString()).isTrue(); - assertThat(a1.get(0).getAsString()).isEqualTo("foo"); - assertThat(a1.get(1).isNull()).isTrue(); - } - - protected enum TestEnum { - A, B, C - } - - public static class TestEntityEnum { - private TestEnum e1 = TestEnum.A; - - public TestEnum getE1() { - return e1; - } - - public void setE1(final TestEnum e1) { - this.e1 = e1; - } - } - - @Test - void fromEnum() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityEnum())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice e1 = vpack.get("e1"); - assertThat(e1.isString()).isTrue(); - assertThat(TestEnum.valueOf(e1.getAsString())).isEqualTo(TestEnum.A); - } - } - - @Test - void toEnum() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("e1", TestEnum.B.name()); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityEnum entity = mapper.readValue(vpack.getBuffer(), TestEntityEnum.class); - assertThat(entity).isNotNull(); - assertThat(entity.e1).isEqualTo(TestEnum.B); - } - - public static class TestEntityObject { - private TestEntityLong o1 = new TestEntityLong(); - private TestEntityArray o2 = new TestEntityArray(); - - public TestEntityLong getO1() { - return o1; - } - - public void setO1(final TestEntityLong o1) { - this.o1 = o1; - } - - public TestEntityArray getO2() { - return o2; - } - - public void setO2(final TestEntityArray o2) { - this.o2 = o2; - } - } - - @Test - void fromObject() throws JsonProcessingException { - final TestEntityObject entity = new TestEntityObject(); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice o1 = vpack.get("o1"); - assertThat(o1.isObject()).isTrue(); - { - final VPackSlice l1 = o1.get("l1"); - assertThat(l1.isInteger()).isTrue(); - assertThat(l1.getAsLong()).isEqualTo(1L); - } - { - final VPackSlice l2 = o1.get("l2"); - assertThat(l2.isInteger()).isTrue(); - assertThat(l2.getAsLong()).isEqualTo(1L); - } - } - { - final VPackSlice o2 = vpack.get("o2"); - assertThat(o2.isObject()).isTrue(); - { - final VPackSlice a1 = o2.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.getLength()).isEqualTo(entity.o2.a1.length); - for (int i = 0; i < a1.getLength(); i++) { - assertThat(a1.get(i).getAsString()).isEqualTo(entity.o2.a1[i]); - } - } - { - final VPackSlice a2 = o2.get("a2"); - assertThat(a2.isArray()).isTrue(); - assertThat(a2.getLength()).isEqualTo(entity.o2.a2.length); - for (int i = 0; i < a2.getLength(); i++) { - assertThat(a2.get(i).getAsInt()).isEqualTo(entity.o2.a2[i]); - } - } - { - final VPackSlice a3 = o2.get("a3"); - assertThat(a3.isArray()).isTrue(); - assertThat(a3.getLength()).isEqualTo(entity.o2.a3.length); - for (int i = 0; i < a3.getLength(); i++) { - assertThat(a3.get(i).getAsBoolean()).isEqualTo(entity.o2.a3[i]); - } - } - { - final VPackSlice a4 = o2.get("a4"); - assertThat(a4.isArray()).isTrue(); - assertThat(a4.getLength()).isEqualTo(entity.o2.a4.length); - for (int i = 0; i < a4.getLength(); i++) { - assertThat(TestEnum.valueOf(a4.get(i).getAsString())).isEqualTo(entity.o2.a4[i]); - } - } - } - } - - @Test - void toObject() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("o1", ValueType.OBJECT); - builder.add("l1", 5L); - builder.add("l2", 5L); - builder.close(); - } - { - builder.add("o2", ValueType.OBJECT); - { - builder.add("a1", ValueType.ARRAY); - builder.add("a"); - builder.add("b"); - builder.add("c"); - builder.close(); - } - { - builder.add("a2", ValueType.ARRAY); - builder.add(1); - builder.add(2); - builder.add(3); - builder.add(4); - builder.close(); - } - { - builder.add("a3", ValueType.ARRAY); - builder.add(false); - builder.add(true); - builder.close(); - } - { - builder.add("a4", ValueType.ARRAY); - builder.add(TestEnum.A.name()); - builder.add(TestEnum.B.name()); - builder.close(); - } - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityObject entity = mapper.readValue(vpack.getBuffer(), TestEntityObject.class); - assertThat(entity).isNotNull(); - { - assertThat(entity.o1.l1).isEqualTo(5L); - assertThat(entity.o1.l2).isEqualTo(Long.valueOf(5)); - } - { - assertThat(entity.o2.a1).hasSize(3); - assertThat(entity.o2.a1[0]).isEqualTo("a"); - assertThat(entity.o2.a1[1]).isEqualTo("b"); - assertThat(entity.o2.a1[2]).isEqualTo("c"); - } - { - assertThat(entity.o2.a2).hasSize(4); - assertThat(entity.o2.a2[0]).isEqualTo(1); - assertThat(entity.o2.a2[1]).isEqualTo(2); - assertThat(entity.o2.a2[2]).isEqualTo(3); - assertThat(entity.o2.a2[3]).isEqualTo(4); - } - { - assertThat(entity.o2.a3).hasSize(2); - assertThat(entity.o2.a3[0]).isFalse(); - assertThat(entity.o2.a3[1]).isTrue(); - } - { - assertThat(entity.o2.a4).hasSize(2); - assertThat(entity.o2.a4[0]).isEqualTo(TestEnum.A); - assertThat(entity.o2.a4[1]).isEqualTo(TestEnum.B); - } - } - - public static class TestEntityArrayInArray { - private long[][] a1; - - public long[][] getA1() { - return a1; - } - - public void setA1(final long[][] a1) { - this.a1 = a1; - } - } - - @Test - void fromArrayInArray() throws JsonProcessingException { - final TestEntityArrayInArray entity = new TestEntityArrayInArray(); - entity.a1 = new long[][]{{1, 2, 3}, {4, 5, 6}}; - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice a1 = vpack.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.getLength()).isEqualTo(entity.a1.length); - for (int i = 0; i < a1.getLength(); i++) { - final VPackSlice at = a1.get(i); - assertThat(at.isArray()).isTrue(); - assertThat(at.getLength()).isEqualTo(entity.a1[i].length); - for (int j = 0; j < at.getLength(); j++) { - final VPackSlice atat = at.get(j); - assertThat(atat.isInteger()).isTrue(); - assertThat(atat.getAsLong()).isEqualTo(entity.a1[i][j]); - } - } - } - } - - @Test - void toArrayInArray() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("a1", ValueType.ARRAY); - { - builder.add(ValueType.ARRAY); - builder.add(1); - builder.add(2); - builder.add(3); - builder.close(); - } - { - builder.add(ValueType.ARRAY); - builder.add(4); - builder.add(5); - builder.add(6); - builder.close(); - } - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityArrayInArray entity = mapper.readValue(vpack.getBuffer(), TestEntityArrayInArray.class); - assertThat(entity).isNotNull(); - assertThat(entity.a1.length).isEqualTo(2); - { - assertThat(entity.a1[0]).hasSize(3); - assertThat(entity.a1[0][0]).isEqualTo(1L); - assertThat(entity.a1[0][1]).isEqualTo(2L); - assertThat(entity.a1[0][2]).isEqualTo(3L); - } - { - assertThat(entity.a1[1]).hasSize(3); - assertThat(entity.a1[1][0]).isEqualTo(4L); - assertThat(entity.a1[1][1]).isEqualTo(5L); - assertThat(entity.a1[1][2]).isEqualTo(6L); - } - } - - @SuppressWarnings("serial") - public static class TestCollection extends LinkedList { - - } - - public static class TestEntityCollectionExtendedWithNulls { - - protected TestCollection a1; - - public TestCollection getA1() { - return a1; - } - - public void setA1(final TestCollection a1) { - this.a1 = a1; - } - - } - - @Test - void fromCollectionExtendedWithNulls() { - - final TestCollection collection = new TestCollection(); - collection.add("one"); - collection.add(null); - collection.add("two"); - - final TestEntityCollectionExtendedWithNulls entity = new TestEntityCollectionExtendedWithNulls(); - entity.setA1(collection); - - final VPackSlice vpack = new VPack.Builder().serializeNullValues(true).build().serialize(entity); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice a1 = vpack.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.getLength()).isEqualTo(entity.a1.size()); - - VPackSlice at = a1.get(0); - assertThat(at.isString()).isTrue(); - assertThat(at.getAsString()).isEqualTo(entity.a1.get(0)); - at = a1.get(1); - assertThat(at.isNull()).isTrue(); - at = a1.get(2); - assertThat(at.isString()).isTrue(); - assertThat(at.getAsString()).isEqualTo(entity.a1.get(2)); - } - } - - @Test - void toCollectionExtendedWithNulls() throws Exception { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("a1", ValueType.ARRAY); - builder.add("one"); - builder.add(ValueType.NULL); - builder.add("two"); - builder.close(); - } - builder.close(); - } - - final VPackSlice vpack = builder.slice(); - final TestEntityCollectionExtendedWithNulls entity = mapper.readValue(vpack.getBuffer(), - TestEntityCollectionExtendedWithNulls.class); - assertThat(entity).isNotNull(); - assertThat(entity.getA1()).isNotNull(); - assertThat(entity.getA1()).hasSize(3); - assertThat(entity.getA1()).contains("one", null, "two"); - } - - public static class TestEntityArrayInArrayInArray { - - private double[][][] a1; - - public double[][][] getA1() { - return a1; - } - - public void setA1(final double[][][] a1) { - this.a1 = a1; - } - - } - - @Test - void fromArrayInArrayInArray() throws JsonProcessingException { - final TestEntityArrayInArrayInArray entity = new TestEntityArrayInArrayInArray(); - entity.setA1(new double[][][]{{{1.5, 2.25}, {10.5, 20.25}}, {{100.5}, {200.25}}}); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice a1 = vpack.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.getLength()).isEqualTo(entity.a1.length); - for (int i = 0; i < a1.getLength(); i++) { - final VPackSlice at = a1.get(i); - assertThat(at.isArray()).isTrue(); - assertThat(at.getLength()).isEqualTo(entity.a1[i].length); - for (int j = 0; j < at.getLength(); j++) { - final VPackSlice atat = at.get(j); - assertThat(atat.isArray()).isTrue(); - assertThat(atat.getLength()).isEqualTo(entity.a1[i][j].length); - for (int k = 0; k < atat.getLength(); k++) { - final VPackSlice atatat = atat.get(k); - assertThat(atatat.isDouble()).isTrue(); - assertThat(atatat.getAsDouble()).isEqualTo(entity.a1[i][j][k]); - } - } - } - } - } - - @Test - void toArrayInArrayInArray() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("a1", ValueType.ARRAY); - builder.add(ValueType.ARRAY); - { - builder.add(ValueType.ARRAY); - builder.add(1.5); - builder.add(2.5); - builder.add(3.5); - builder.close(); - } - { - builder.add(ValueType.ARRAY); - builder.add(4.5); - builder.add(5.5); - builder.add(6.5); - builder.close(); - } - { - builder.add(ValueType.ARRAY); - builder.add(7.5); - builder.add(8.5); - builder.add(9.5); - builder.close(); - } - builder.close(); - builder.add(ValueType.ARRAY); - { - builder.add(ValueType.ARRAY); - builder.add(1.5); - builder.add(2.5); - builder.add(3.5); - builder.close(); - } - { - builder.add(ValueType.ARRAY); - builder.add(4.5); - builder.add(5.5); - builder.add(6.5); - builder.close(); - } - { - builder.add(ValueType.ARRAY); - builder.add(7.5); - builder.add(8.5); - builder.add(9.5); - builder.close(); - } - builder.close(); - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityArrayInArrayInArray entity = mapper.readValue(vpack.getBuffer(), - TestEntityArrayInArrayInArray.class); - assertThat(entity).isNotNull(); - assertThat(entity.a1.length).isEqualTo(2); - { - assertThat(entity.a1[0].length).isEqualTo(3); - assertThat(entity.a1[0][0]).hasSize(3); - assertThat(entity.a1[0][0][0]).isEqualTo(1.5); - assertThat(entity.a1[0][0][1]).isEqualTo(2.5); - assertThat(entity.a1[0][0][2]).isEqualTo(3.5); - assertThat(entity.a1[0][1]).hasSize(3); - assertThat(entity.a1[0][1][0]).isEqualTo(4.5); - assertThat(entity.a1[0][1][1]).isEqualTo(5.5); - assertThat(entity.a1[0][1][2]).isEqualTo(6.5); - assertThat(entity.a1[0][2]).hasSize(3); - assertThat(entity.a1[0][2][0]).isEqualTo(7.5); - assertThat(entity.a1[0][2][1]).isEqualTo(8.5); - assertThat(entity.a1[0][2][2]).isEqualTo(9.5); - } - { - assertThat(entity.a1[1].length).isEqualTo(3); - assertThat(entity.a1[1][0]).hasSize(3); - assertThat(entity.a1[1][0][0]).isEqualTo(1.5); - assertThat(entity.a1[1][0][1]).isEqualTo(2.5); - assertThat(entity.a1[1][0][2]).isEqualTo(3.5); - assertThat(entity.a1[1][1]).hasSize(3); - assertThat(entity.a1[1][1][0]).isEqualTo(4.5); - assertThat(entity.a1[1][1][1]).isEqualTo(5.5); - assertThat(entity.a1[1][1][2]).isEqualTo(6.5); - assertThat(entity.a1[1][2]).hasSize(3); - assertThat(entity.a1[1][2][0]).isEqualTo(7.5); - assertThat(entity.a1[1][2][1]).isEqualTo(8.5); - assertThat(entity.a1[1][2][2]).isEqualTo(9.5); - } - } - - public static class TestEntityObjectInArray { - private TestEntityString[] a1; - - public TestEntityString[] getA1() { - return a1; - } - - public void setA1(final TestEntityString[] a1) { - this.a1 = a1; - } - } - - @Test - void fromObjectInArray() throws JsonProcessingException { - final TestEntityObjectInArray entity = new TestEntityObjectInArray(); - { - final TestEntityString[] a1 = new TestEntityString[2]; - final TestEntityString s = new TestEntityString(); - s.setS("abc"); - a1[0] = s; - a1[1] = s; - entity.setA1(a1); - } - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice a1 = vpack.get("a1"); - assertThat(a1.isArray()).isTrue(); - assertThat(a1.getLength()).isEqualTo(2); - for (int i = 0; i < a1.getLength(); i++) { - final VPackSlice at = a1.get(i); - assertThat(at.isObject()).isTrue(); - final VPackSlice s = at.get("s"); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo("abc"); - } - } - } - - @Test - void toObjectInArray() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("a1", ValueType.ARRAY); - { - builder.add(ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - } - builder.close(); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityObjectInArray entity = mapper.readValue(vpack.getBuffer(), TestEntityObjectInArray.class); - assertThat(entity).isNotNull(); - assertThat(entity.a1).hasSize(1); - final TestEntityString st = entity.a1[0]; - assertThat(st).isNotNull(); - assertThat(st.s).isEqualTo("abc"); - } - - public static class TestEntityA { - private String a = "a"; - - public String getA() { - return a; - } - - public void setA(final String a) { - this.a = a; - } - } - - public static class TestEntityB extends TestEntityA { - private String b = "b"; - - public String getB() { - return b; - } - - public void setB(final String b) { - this.b = b; - } - } - - @Test - void fromInheritance() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityB())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(2); - { - final VPackSlice a = vpack.get("a"); - assertThat(a.isString()).isTrue(); - assertThat(a.getAsString()).isEqualTo("a"); - } - { - final VPackSlice b = vpack.get("b"); - assertThat(b.isString()).isTrue(); - assertThat(b.getAsString()).isEqualTo("b"); - } - } - - @Test - void toInheritance() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("a", "test"); - builder.add("b", "test"); - builder.close(); - } - final VPackSlice vpack = builder.slice(); - { - final TestEntityA entity = mapper.readValue(vpack.getBuffer(), TestEntityA.class); - assertThat(entity).isNotNull(); - assertThat(entity.getA()).isEqualTo("test"); - } - { - final TestEntityB entity = mapper.readValue(vpack.getBuffer(), TestEntityB.class); - assertThat(entity).isNotNull(); - assertThat(entity.getA()).isEqualTo("test"); - assertThat(entity.getB()).isEqualTo("test"); - } - } - - public static class TestEntityC { - private TestEntityD d; - - public TestEntityD getD() { - return d; - } - - public void setD(final TestEntityD d) { - this.d = d; - } - } - - protected interface TestEntityD { - String getD(); - - void setD(String d); - } - - public static class TestEntityDImpl implements TestEntityD { - private String d = "d"; - - @Override - public String getD() { - return d; - } - - @Override - public void setD(final String d) { - this.d = d; - } - } - - @Test - void fromInterface() throws JsonProcessingException { - final TestEntityC entity = new TestEntityC(); - entity.setD(new TestEntityDImpl()); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice d = vpack.get("d"); - assertThat(d.isObject()).isTrue(); - final VPackSlice dd = d.get("d"); - assertThat(dd.isString()).isTrue(); - assertThat(dd.getAsString()).isEqualTo("d"); - } - } - - @Test - void toInterface() { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("d", ValueType.OBJECT); - builder.add("d", "test"); - builder.close(); - builder.close(); - } - final VPackSlice slice = builder.slice(); - final VPack vPack = new VPack.Builder() - .registerInstanceCreator(TestEntityD.class, (VPackInstanceCreator) TestEntityDImpl::new).build(); - final TestEntityC entity = vPack.deserialize(slice, TestEntityC.class); - assertThat(entity).isNotNull(); - assertThat(entity.d).isNotNull(); - assertThat(entity.d.getD()).isEqualTo("test"); - } - - public static class TestEntityCollection { - private Collection c1 = new LinkedList<>(); - private List c2 = new ArrayList<>(); - private ArrayList c3 = new ArrayList<>(); - private Set c4 = new LinkedHashSet<>(); - private HashSet c5 = new HashSet<>(); - - public TestEntityCollection() { - super(); - } - - public Collection getC1() { - return c1; - } - - public void setC1(final Collection c1) { - this.c1 = c1; - } - - public List getC2() { - return c2; - } - - public void setC2(final List c2) { - this.c2 = c2; - } - - public ArrayList getC3() { - return c3; - } - - public void setC3(final ArrayList c3) { - this.c3 = c3; - } - - public Set getC4() { - return c4; - } - - public void setC4(final Set c4) { - this.c4 = c4; - } - - public HashSet getC5() { - return c5; - } - - public void setC5(final HashSet c5) { - this.c5 = c5; - } - } - - @Test - void fromCollection() throws JsonProcessingException { - final TestEntityCollection entity = new TestEntityCollection(); - { - entity.c1.add("test"); - entity.c2.add("test"); - entity.c3.add("test"); - entity.c4.add("test"); - entity.c5.add("test"); - } - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice c1 = vpack.get("c1"); - assertThat(c1.isArray()).isTrue(); - assertThat(c1.getLength()).isEqualTo(1); - assertThat(c1.get(0).getAsString()).isEqualTo("test"); - } - { - final VPackSlice c2 = vpack.get("c2"); - assertThat(c2.isArray()).isTrue(); - assertThat(c2.getLength()).isEqualTo(1); - assertThat(c2.get(0).getAsString()).isEqualTo("test"); - } - { - final VPackSlice c3 = vpack.get("c3"); - assertThat(c3.isArray()).isTrue(); - assertThat(c3.getLength()).isEqualTo(1); - assertThat(c3.get(0).getAsString()).isEqualTo("test"); - } - { - final VPackSlice c4 = vpack.get("c4"); - assertThat(c4.isArray()).isTrue(); - assertThat(c4.getLength()).isEqualTo(1); - assertThat(c4.get(0).getAsString()).isEqualTo("test"); - } - { - final VPackSlice c5 = vpack.get("c5"); - assertThat(c5.isArray()).isTrue(); - assertThat(c5.getLength()).isEqualTo(1); - assertThat(c5.get(0).getAsString()).isEqualTo("test"); - } - } - - @Test - void toCollection() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("c1", ValueType.ARRAY); - builder.add("test1"); - builder.add("test2"); - builder.close(); - } - { - builder.add("c2", ValueType.ARRAY); - builder.add("test1"); - builder.add("test2"); - builder.close(); - } - { - builder.add("c3", ValueType.ARRAY); - builder.add("test1"); - builder.add("test2"); - builder.close(); - } - { - builder.add("c4", ValueType.ARRAY); - builder.add("test1"); - builder.add("test2"); - builder.close(); - } - { - builder.add("c5", ValueType.ARRAY); - builder.add("test1"); - builder.add("test2"); - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityCollection entity = mapper.readValue(vpack.getBuffer(), TestEntityCollection.class); - assertThat(entity).isNotNull(); - { - checkCollection(entity.c1); - checkCollection(entity.c2); - checkCollection(entity.c3); - checkCollection(entity.c4); - checkCollection(entity.c5); - } - } - - private void checkCollection(final Collection col) { - assertThat(col).isNotNull(); - assertThat(col).hasSize(2); - for (final String next : col) { - assertThat("test1".equals(next) || "test2".equals(next)).isTrue(); - } - } - - public static class TestEntityCollectionWithObjects { - private Collection c1; - private Set c2; - - public Collection getC1() { - return c1; - } - - public void setC1(final Collection c1) { - this.c1 = c1; - } - - public Set getC2() { - return c2; - } - - public void setC2(final Set c2) { - this.c2 = c2; - } - } - - @Test - void fromCollectionWithObjects() throws JsonProcessingException { - final TestEntityCollectionWithObjects entity = new TestEntityCollectionWithObjects(); - { - final Collection c1 = new ArrayList<>(); - c1.add(new TestEntityString()); - c1.add(new TestEntityString()); - entity.setC1(c1); - final Set c2 = new HashSet<>(); - c2.add(new TestEntityArray()); - entity.setC2(c2); - } - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice c1 = vpack.get("c1"); - assertThat(c1.isArray()).isTrue(); - assertThat(c1.getLength()).isEqualTo(2); - assertThat(c1.get(0).isObject()).isTrue(); - assertThat(c1.get(1).isObject()).isTrue(); - { - final VPackSlice s = c1.get(0).get("s"); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo("test"); - } - } - { - final VPackSlice c2 = vpack.get("c2"); - assertThat(c2.isArray()).isTrue(); - assertThat(c2.getLength()).isEqualTo(1); - assertThat(c2.get(0).isObject()).isTrue(); - { - final VPackSlice a2 = c2.get(0).get("a2"); - assertThat(a2.isArray()).isTrue(); - assertThat(a2.getLength()).isEqualTo(5); - for (int i = 0; i < a2.getLength(); i++) { - final VPackSlice at = a2.get(i); - assertThat(at.isInteger()).isTrue(); - assertThat(at.getAsInt()).isEqualTo(i + 1); - } - } - } - } - - @Test - void toCollectionWithObjects() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("c1", ValueType.ARRAY); - builder.add(ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - builder.close(); - } - { - builder.add("c2", ValueType.ARRAY); - builder.add(ValueType.OBJECT); - builder.add("a2", ValueType.ARRAY); - for (int i = 0; i < 10; i++) { - builder.add(i); - } - builder.close(); - builder.close(); - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityCollectionWithObjects entity = mapper.readValue(vpack.getBuffer(), - TestEntityCollectionWithObjects.class); - assertThat(entity).isNotNull(); - { - assertThat(entity.c1).isNotNull(); - assertThat(entity.c1).hasSize(1); - assertThat(entity.c1.iterator().next().s).isEqualTo("abc"); - } - { - assertThat(entity.c2).isNotNull(); - assertThat(entity.c2).hasSize(1); - final int[] array = entity.c2.iterator().next().a2; - for (int i = 0; i < array.length; i++) { - assertThat(array[i]).isEqualTo(i); - } - } - } - - public static class TestEntityMap { - private Map m1; - private HashMap m2; - private Map m3; - - public Map getM1() { - return m1; - } - - public void setM1(final Map m1) { - this.m1 = m1; - } - - public HashMap getM2() { - return m2; - } - - public void setM2(final HashMap m2) { - this.m2 = m2; - } - - public Map getM3() { - return m3; - } - - public void setM3(final Map m3) { - this.m3 = m3; - } - } - - @Test - void fromMap() throws JsonProcessingException { - final TestEntityMap entity = new TestEntityMap(); - { - final Map m1 = new LinkedHashMap<>(); - m1.put("a", "b"); - m1.put("c", "d"); - entity.setM1(m1); - final HashMap m2 = new HashMap<>(); - m2.put(1, "a"); - m2.put(2, "b"); - entity.setM2(m2); - final Map m3 = new HashMap<>(); - final TestEntityString s = new TestEntityString(); - s.setS("abc"); - m3.put("a", s); - entity.setM3(m3); - } - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice m1 = vpack.get("m1"); - assertThat(m1.isObject()).isTrue(); - assertThat(m1.getLength()).isEqualTo(2); - { - final VPackSlice a = m1.get("a"); - assertThat(a.isString()).isTrue(); - assertThat(a.getAsString()).isEqualTo("b"); - } - { - final VPackSlice c = m1.get("c"); - assertThat(c.isString()).isTrue(); - assertThat(c.getAsString()).isEqualTo("d"); - } - } - { - final VPackSlice m2 = vpack.get("m2"); - assertThat(m2.isObject()).isTrue(); - assertThat(m2.getLength()).isEqualTo(2); - { - final VPackSlice one = m2.get("1"); - assertThat(one.isString()).isTrue(); - assertThat(one.getAsString()).isEqualTo("a"); - } - { - final VPackSlice two = m2.get("2"); - assertThat(two.isString()).isTrue(); - assertThat(two.getAsString()).isEqualTo("b"); - } - } - { - final VPackSlice m3 = vpack.get("m3"); - assertThat(m3.isObject()).isTrue(); - assertThat(m3.getLength()).isEqualTo(1); - final VPackSlice a = m3.get("a"); - assertThat(a.isObject()).isTrue(); - final VPackSlice s = a.get("s"); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo("abc"); - } - } - - @Test - void toMap() throws IOException { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - { - builder.add("m1", ValueType.OBJECT); - builder.add("a", "a"); - builder.add("b", "b"); - builder.close(); - } - { - builder.add("m2", ValueType.OBJECT); - builder.add("1", "a"); - builder.add("-1", "a"); - builder.close(); - } - { - builder.add("m3", ValueType.OBJECT); - builder.add("a", ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - builder.close(); - } - builder.close(); - } - final VPackSlice vpack = builder.slice(); - final TestEntityMap entity = mapper.readValue(vpack.getBuffer(), TestEntityMap.class); - assertThat(entity).isNotNull(); - { - assertThat(entity.m1).isNotNull(); - assertThat(entity.m1).hasSize(2); - final String a = entity.m1.get("a"); - assertThat(a).isNotNull(); - assertThat(a).isEqualTo("a"); - final String b = entity.m1.get("b"); - assertThat(b).isNotNull(); - assertThat(b).isEqualTo("b"); - } - { - assertThat(entity.m2).isNotNull(); - assertThat(entity.m2).hasSize(2); - final String one = entity.m2.get(1); - assertThat(one).isNotNull(); - assertThat(one).isEqualTo("a"); - final String oneNegative = entity.m2.get(-1); - assertThat(oneNegative).isNotNull(); - assertThat(oneNegative).isEqualTo("a"); - } - { - assertThat(entity.m3).isNotNull(); - assertThat(entity.m3).hasSize(1); - final TestEntityString a = entity.m3.get("a"); - assertThat(a).isNotNull(); - assertThat(a.s).isEqualTo("abc"); - } - } - - public static class TestEntityMapStringableKey { - private Map m1; - private Map m2; - private Map m3; - private Map m4; - private Map m5; - private Map m6; - private Map m7; - private Map m8; - private Map m9; - private Map m10; - private Map m11; - - public Map getM1() { - return m1; - } - - public void setM1(final Map m1) { - this.m1 = m1; - } - - public Map getM2() { - return m2; - } - - public void setM2(final Map m2) { - this.m2 = m2; - } - - public Map getM3() { - return m3; - } - - public void setM3(final Map m3) { - this.m3 = m3; - } - - public Map getM4() { - return m4; - } - - public void setM4(final Map m4) { - this.m4 = m4; - } - - public Map getM5() { - return m5; - } - - public void setM5(final Map m5) { - this.m5 = m5; - } - - public Map getM6() { - return m6; - } - - public void setM6(final Map m6) { - this.m6 = m6; - } - - public Map getM7() { - return m7; - } - - public void setM7(final Map m7) { - this.m7 = m7; - } - - public Map getM8() { - return m8; - } - - public void setM8(final Map m8) { - this.m8 = m8; - } - - public Map getM9() { - return m9; - } - - public void setM9(final Map m9) { - this.m9 = m9; - } - - public Map getM10() { - return m10; - } - - public void setM10(final Map m10) { - this.m10 = m10; - } - - public Map getM11() { - return m11; - } - - public void setM11(final Map m11) { - this.m11 = m11; - } - - } - - @Test - void fromMapStringableKey() throws JsonProcessingException { - final TestEntityMapStringableKey entity = new TestEntityMapStringableKey(); - final String value = "test"; - { - final Map m1 = new HashMap<>(); - m1.put(true, value); - m1.put(false, value); - entity.setM1(m1); - } - { - final Map m2 = new HashMap<>(); - m2.put(1, value); - m2.put(2, value); - entity.setM2(m2); - } - { - final Map m3 = new HashMap<>(); - m3.put(1L, value); - m3.put(2L, value); - entity.setM3(m3); - } - { - final Map m4 = new HashMap<>(); - m4.put(1.5F, value); - m4.put(2.25F, value); - entity.setM4(m4); - } - { - final Map m5 = new HashMap<>(); - m5.put(Short.valueOf("1"), value); - m5.put(Short.valueOf("2"), value); - entity.setM5(m5); - } - { - final Map m6 = new HashMap<>(); - m6.put(1.5, value); - m6.put(2.25, value); - entity.setM6(m6); - } - { - final Map m7 = new HashMap<>(); - m7.put(1.5, value); - m7.put(1L, value); - entity.setM7(m7); - } - { - final Map m8 = new HashMap<>(); - m8.put(new BigInteger("1"), value); - m8.put(new BigInteger("2"), value); - entity.setM8(m8); - } - { - final Map m9 = new HashMap<>(); - m9.put(new BigDecimal("1.5"), value); - m9.put(new BigDecimal("2.25"), value); - entity.setM9(m9); - } - { - final Map m10 = new HashMap<>(); - m10.put('1', value); - m10.put('a', value); - entity.setM10(m10); - } - { - final Map m11 = new HashMap<>(); - m11.put(TestEnum.A, value); - m11.put(TestEnum.B, value); - entity.setM11(m11); - } - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - final VPackSlice m1 = vpack.get("m1"); - assertThat(m1.isObject()).isTrue(); - assertThat(m1.getLength()).isEqualTo(2); - checkMapAttribute(m1.get("true")); - checkMapAttribute(m1.get("false")); - } - { - final VPackSlice m2 = vpack.get("m2"); - assertThat(m2.isObject()).isTrue(); - assertThat(m2.getLength()).isEqualTo(2); - checkMapAttribute(m2.get("1")); - checkMapAttribute(m2.get("2")); - } - { - final VPackSlice m3 = vpack.get("m3"); - assertThat(m3.isObject()).isTrue(); - assertThat(m3.getLength()).isEqualTo(2); - checkMapAttribute(m3.get("1")); - checkMapAttribute(m3.get("2")); - } - { - final VPackSlice m4 = vpack.get("m4"); - assertThat(m4.isObject()).isTrue(); - assertThat(m4.getLength()).isEqualTo(2); - checkMapAttribute(m4.get("1.5")); - checkMapAttribute(m4.get("2.25")); - } - { - final VPackSlice m5 = vpack.get("m5"); - assertThat(m5.isObject()).isTrue(); - assertThat(m5.getLength()).isEqualTo(2); - checkMapAttribute(m5.get("1")); - checkMapAttribute(m5.get("2")); - } - { - final VPackSlice m6 = vpack.get("m6"); - assertThat(m6.isObject()).isTrue(); - assertThat(m6.getLength()).isEqualTo(2); - checkMapAttribute(m6.get("1.5")); - checkMapAttribute(m6.get("2.25")); - } - { - final VPackSlice m7 = vpack.get("m7"); - assertThat(m7.isObject()).isTrue(); - assertThat(m7.getLength()).isEqualTo(2); - checkMapAttribute(m7.get("1.5")); - checkMapAttribute(m7.get("1")); - } - { - final VPackSlice m8 = vpack.get("m8"); - assertThat(m8.isObject()).isTrue(); - assertThat(m8.getLength()).isEqualTo(2); - checkMapAttribute(m8.get("1")); - checkMapAttribute(m8.get("2")); - } - { - final VPackSlice m9 = vpack.get("m9"); - assertThat(m9.isObject()).isTrue(); - assertThat(m9.getLength()).isEqualTo(2); - checkMapAttribute(m9.get("1.5")); - checkMapAttribute(m9.get("2.25")); - } - { - final VPackSlice m10 = vpack.get("m10"); - assertThat(m10.isObject()).isTrue(); - assertThat(m10.getLength()).isEqualTo(2); - checkMapAttribute(m10.get("1")); - checkMapAttribute(m10.get("a")); - } - { - final VPackSlice m11 = vpack.get("m11"); - assertThat(m11.isObject()).isTrue(); - assertThat(m11.getLength()).isEqualTo(2); - checkMapAttribute(m11.get(TestEnum.A.name())); - checkMapAttribute(m11.get(TestEnum.B.name())); - } - } - - @Test - void toMapSringableKey() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - { - builder.add("m1", ValueType.OBJECT); - builder.add("true", "test"); - builder.add("false", "test"); - builder.close(); - } - { - builder.add("m2", ValueType.OBJECT); - builder.add("1", "test"); - builder.add("2", "test"); - builder.close(); - } - { - builder.add("m3", ValueType.OBJECT); - builder.add("1", "test"); - builder.add("2", "test"); - builder.close(); - } - { - builder.add("m4", ValueType.OBJECT); - builder.add("1.5", "test"); - builder.add("2.25", "test"); - builder.close(); - } - { - builder.add("m5", ValueType.OBJECT); - builder.add("1", "test"); - builder.add("2", "test"); - builder.close(); - } - { - builder.add("m6", ValueType.OBJECT); - builder.add("1.5", "test"); - builder.add("2.25", "test"); - builder.close(); - } - { - builder.add("m7", ValueType.OBJECT); - builder.add("1.5", "test"); - builder.add("1", "test"); - builder.close(); - } - { - builder.add("m8", ValueType.OBJECT); - builder.add("1", "test"); - builder.add("2", "test"); - builder.close(); - } - { - builder.add("m9", ValueType.OBJECT); - builder.add("1.5", "test"); - builder.add("2.25", "test"); - builder.close(); - } - { - builder.add("m10", ValueType.OBJECT); - builder.add("1", "test"); - builder.add("a", "test"); - builder.close(); - } - { - builder.add("m11", ValueType.OBJECT); - builder.add(TestEnum.A.name(), "test"); - builder.add(TestEnum.B.name(), "test"); - builder.close(); - } - builder.close(); - final TestEntityMapStringableKey entity = new VPack.Builder().build().deserialize(builder.slice(), - TestEntityMapStringableKey.class); - { - assertThat(entity.m1).hasSize(2); - checkMapAttribute(entity.m1.get(true)); - checkMapAttribute(entity.m1.get(false)); - } - { - assertThat(entity.m2).hasSize(2); - checkMapAttribute(entity.m2.get(1)); - checkMapAttribute(entity.m2.get(2)); - } - { - assertThat(entity.m3).hasSize(2); - checkMapAttribute(entity.m3.get(1L)); - checkMapAttribute(entity.m3.get(2L)); - } - { - assertThat(entity.m4).hasSize(2); - checkMapAttribute(entity.m4.get(1.5F)); - checkMapAttribute(entity.m4.get(2.25F)); - } - { - assertThat(entity.m5).hasSize(2); - checkMapAttribute(entity.m5.get(Short.valueOf("1"))); - checkMapAttribute(entity.m5.get(Short.valueOf("2"))); - } - { - assertThat(entity.m6).hasSize(2); - checkMapAttribute(entity.m6.get(1.5)); - checkMapAttribute(entity.m6.get(2.25)); - } - { - assertThat(entity.m7).hasSize(2); - checkMapAttribute(entity.m7.get(1.5)); - checkMapAttribute(entity.m7.get((double) 1L)); - } - { - assertThat(entity.m8).hasSize(2); - checkMapAttribute(entity.m8.get(new BigInteger("1"))); - checkMapAttribute(entity.m8.get(new BigInteger("2"))); - } - { - assertThat(entity.m9).hasSize(2); - checkMapAttribute(entity.m9.get(new BigDecimal("1.5"))); - checkMapAttribute(entity.m9.get(new BigDecimal("2.25"))); - } - { - assertThat(entity.m10).hasSize(2); - checkMapAttribute(entity.m10.get('1')); - checkMapAttribute(entity.m10.get('a')); - } - { - assertThat(entity.m11).hasSize(2); - checkMapAttribute(entity.m11.get(TestEnum.A)); - checkMapAttribute(entity.m11.get(TestEnum.B)); - } - } - - private void checkMapAttribute(final VPackSlice attr) { - assertThat(attr.isString()).isTrue(); - assertThat(attr.getAsString()).isEqualTo("test"); - } - - private void checkMapAttribute(final String attr) { - assertThat(attr).isEqualTo("test"); - } - - public static class TestEntityMapWithObjectKey { - private Map m1; - private Map m2; - - public Map getM1() { - return m1; - } - - public void setM1(final Map m1) { - this.m1 = m1; - } - - public Map getM2() { - return m2; - } - - public void setM2(final Map m2) { - this.m2 = m2; - } - } - - @Test - void toMapWithObjectKey() { - final int size = 2; - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - { - builder.add("m1", ValueType.ARRAY); - for (int i = 0; i < size; i++) { - builder.add(ValueType.OBJECT); - { - builder.add("key", ValueType.OBJECT); - builder.add("l1", 5L); - builder.close(); - } - { - builder.add("value", ValueType.OBJECT); - builder.add("c1", ValueType.ARRAY); - builder.add("test"); - builder.close(); - builder.close(); - } - builder.close(); - } - builder.close(); - } - { - builder.add("m2", ValueType.ARRAY); - for (int i = 0; i < size; i++) { - builder.add(ValueType.OBJECT); - { - builder.add("key", ValueType.OBJECT); - builder.add("l1", 5L); - builder.close(); - } - { - builder.add("value", "test"); - } - builder.close(); - } - builder.close(); - } - builder.close(); - final TestEntityMapWithObjectKey entity = new VPack.Builder().build().deserialize(builder.slice(), - TestEntityMapWithObjectKey.class); - assertThat(entity).isNotNull(); - { - assertThat(entity.m1).isNotNull(); - assertThat(entity.m1).hasSize(size); - for (final Entry entry : entity.m1.entrySet()) { - assertThat(entry.getKey().l1).isEqualTo(5L); - assertThat(entry.getValue().c1).hasSize(1); - assertThat(entry.getValue().c1.iterator().next()).isEqualTo("test"); - } - } - { - assertThat(entity.m2).isNotNull(); - assertThat(entity.m2).hasSize(2); - for (final Entry entry : entity.m2.entrySet()) { - assertThat(entry.getKey().l1).isEqualTo(5L); - assertThat(entry.getValue()).isEqualTo("test"); - } - } - } - - public static class TestEntityEmpty { - - } - - @Test - void fromEmptyObject() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityEmpty())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.getLength()).isZero(); - } - - @Test - void toEmptyObject() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.close(); - final TestEntityEmpty entity = new VPack.Builder().build().deserialize(builder.slice(), TestEntityEmpty.class); - assertThat(entity).isNotNull(); - } - - public static class TestEntityEmptyMap { - private Map m; - - public Map getM() { - return m; - } - - public void setM(final Map m) { - this.m = m; - } - } - - @Test - void fromEmptyMap() throws JsonProcessingException { - final TestEntityEmptyMap entity = new TestEntityEmptyMap(); - entity.setM(new HashMap<>()); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(1); - final VPackSlice m = vpack.get("m"); - assertThat(m.isObject()).isTrue(); - assertThat(m.getLength()).isZero(); - } - - @Test - void toEmptyMap() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("m", ValueType.OBJECT); - builder.close(); - builder.close(); - final TestEntityEmptyMap entity = new VPack.Builder().build().deserialize(builder.slice(), - TestEntityEmptyMap.class); - assertThat(entity).isNotNull(); - assertThat(entity.m).isNotNull(); - assertThat(entity.m).isEmpty(); - } - - public static class TestEntityBaseAttributes { - private String _key = "test1"; - private String _rev = "test2"; - private String _id = "test3"; - private String _from = "test4"; - private String _to = "test5"; - - public String get_key() { - return _key; - } - - public void set_key(final String _key) { - this._key = _key; - } - - public String get_rev() { - return _rev; - } - - public void set_rev(final String _rev) { - this._rev = _rev; - } - - public String get_id() { - return _id; - } - - public void set_id(final String _id) { - this._id = _id; - } - - public String get_from() { - return _from; - } - - public void set_from(final String _from) { - this._from = _from; - } - - public String get_to() { - return _to; - } - - public void set_to(final String _to) { - this._to = _to; - } - - } - - @Test - void fromObjectWithAttributeAdapter() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityBaseAttributes())); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(5); - { - final VPackSlice key = vpack.get("_key"); - assertThat(key.isString()).isTrue(); - assertThat(key.getAsString()).isEqualTo("test1"); - } - { - final VPackSlice rev = vpack.get("_rev"); - assertThat(rev.isString()).isTrue(); - assertThat(rev.getAsString()).isEqualTo("test2"); - } - { - final VPackSlice id = vpack.get("_id"); - assertThat(id.isString()).isTrue(); - assertThat(id.getAsString()).isEqualTo("test3"); - } - { - final VPackSlice from = vpack.get("_from"); - assertThat(from.isString()).isTrue(); - assertThat(from.getAsString()).isEqualTo("test4"); - } - { - final VPackSlice to = vpack.get("_to"); - assertThat(to.isString()).isTrue(); - assertThat(to.getAsString()).isEqualTo("test5"); - } - } - - @Test - void toObjectWithAttributeAdapter() { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("_key", "a"); - builder.add("_rev", "b"); - builder.add("_id", "c"); - builder.add("_from", "d"); - builder.add("_to", "e"); - builder.close(); - } - final TestEntityBaseAttributes entity = new VPack.Builder().build().deserialize(builder.slice(), - TestEntityBaseAttributes.class); - assertThat(entity).isNotNull(); - assertThat(entity._key).isEqualTo("a"); - assertThat(entity._rev).isEqualTo("b"); - assertThat(entity._id).isEqualTo("c"); - assertThat(entity._from).isEqualTo("d"); - assertThat(entity._to).isEqualTo("e"); - } - - @Test - void fromMapWithAttributeAdapter() throws JsonProcessingException { - final TestEntityMap entity = new TestEntityMap(); - { - final Map m1 = new HashMap<>(); - m1.put("_key", "test1"); - m1.put("_rev", "test2"); - m1.put("_id", "test3"); - m1.put("_from", "test4"); - m1.put("_to", "test5"); - entity.setM1(m1); - } - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice m1 = vpack.get("m1"); - assertThat(m1.isObject()).isTrue(); - assertThat(m1.getLength()).isEqualTo(5); - { - final VPackSlice key = m1.get("_key"); - assertThat(key.isString()).isTrue(); - assertThat(key.getAsString()).isEqualTo("test1"); - } - { - final VPackSlice rev = m1.get("_rev"); - assertThat(rev.isString()).isTrue(); - assertThat(rev.getAsString()).isEqualTo("test2"); - } - { - final VPackSlice id = m1.get("_id"); - assertThat(id.isString()).isTrue(); - assertThat(id.getAsString()).isEqualTo("test3"); - } - { - final VPackSlice from = m1.get("_from"); - assertThat(from.isString()).isTrue(); - assertThat(from.getAsString()).isEqualTo("test4"); - } - { - final VPackSlice to = m1.get("_to"); - assertThat(to.isString()).isTrue(); - assertThat(to.getAsString()).isEqualTo("test5"); - } - } - - @Test - void toMapWithAttributeAdapter() { - final VPackBuilder builder = new VPackBuilder(); - { - builder.add(ValueType.OBJECT); - builder.add("m1", ValueType.OBJECT); - builder.add("_key", "a"); - builder.add("_rev", "b"); - builder.add("_id", "c"); - builder.add("_from", "d"); - builder.add("_to", "e"); - builder.close(); - builder.close(); - } - final TestEntityMap entity = new VPack.Builder().build().deserialize(builder.slice(), TestEntityMap.class); - assertThat(entity).isNotNull(); - assertThat(entity.m1).hasSize(5); - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - private @interface CustomFilterAnnotation { - boolean serialize() - - default true; - - boolean deserialize() default true; - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - private @interface CustomNamingAnnotation { - String name(); - } - - private static class CustomAnEntity { - @CustomFilterAnnotation(serialize = false) - private String a = null; - @CustomFilterAnnotation(deserialize = false) - private String b = null; - @CustomNamingAnnotation(name = "d") - @CustomFilterAnnotation(deserialize = false) - private String c = null; - - CustomAnEntity() { - super(); - } - } - - @Test - void fromCutsomAnnotation() { - final CustomAnEntity entity = new CustomAnEntity(); - entity.a = "1"; - entity.b = "2"; - entity.c = "3"; - final VPackSlice vpack = new VPack.Builder().annotationFieldFilter(CustomFilterAnnotation.class, - new VPackAnnotationFieldFilter() { - - @Override - public boolean serialize(final CustomFilterAnnotation annotation) { - return annotation.serialize(); - } - - @Override - public boolean deserialize(final CustomFilterAnnotation annotation) { - return annotation.deserialize(); - } - }).annotationFieldNaming(CustomNamingAnnotation.class, - CustomNamingAnnotation::name).build().serialize(entity); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.get("a").isNone()).isTrue(); - assertThat(vpack.get("b").isString()).isTrue(); - assertThat(vpack.get("b").getAsString()).isEqualTo("2"); - assertThat(vpack.get("c").isNone()).isTrue(); - assertThat(vpack.get("d").isString()).isTrue(); - assertThat(vpack.get("d").getAsString()).isEqualTo("3"); - } - - @Test - void directFromCollection() throws JsonProcessingException { - final Collection list = new ArrayList<>(); - list.add("test"); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(list)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isArray()).isTrue(); - assertThat(vpack.size()).isEqualTo(1); - final VPackSlice test = vpack.get(0); - assertThat(test.isString()).isTrue(); - assertThat(test.getAsString()).isEqualTo("test"); - } - - @Test - void directFromCollectionWithType() throws JsonProcessingException { - final Collection list = new ArrayList<>(); - list.add(new TestEntityString()); - list.add(new TestEntityString()); - - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(list)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isArray()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(list.size()); - for (int i = 0; i < list.size(); i++) { - final VPackSlice entry = vpack.get(i); - assertThat(entry.isObject()).isTrue(); - assertThat(entry.getLength()).isEqualTo(3); - final VPackSlice s = entry.get("s"); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo("test"); - } - } - - @Test - void directToCollection() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.ARRAY); - builder.add(ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - builder.close(); - final List list = new VPack.Builder().build().deserialize(builder.slice(), - new Type>() { - }.getType()); - assertThat(list).hasSize(1); - final TestEntityString entry = list.get(0); - assertThat(entry.s).isEqualTo("abc"); - } - - @Test - void directFromStringMap() throws JsonProcessingException { - final Map map = new HashMap<>(); - map.put("a", new TestEntityString()); - map.put("b", new TestEntityString()); - - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(map)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(2); - final VPackSlice a = vpack.get("a"); - checkStringEntity(a); - } - - @Test - void directToStringMap() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("a", ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - builder.close(); - final Map map = new VPack.Builder().build().deserialize(builder.slice(), - new Type>() { - }.getType()); - assertThat(map).hasSize(1); - final TestEntityString a = map.get("a"); - assertThat(a).isNotNull(); - assertThat(a.s).isEqualTo("abc"); - } - - @Test - void directFromMap() throws JsonProcessingException { - final Map map = new HashMap<>(); - final TestEntityA entity = new TestEntityA(); - entity.a = "test"; - map.put("test", entity); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(map)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice test = vpack.get("test"); - assertThat(test.isObject()).isTrue(); - final VPackSlice a = test.get("a"); - assertThat(a.isString()).isTrue(); - assertThat(a.getAsString()).isEqualTo("test"); - } - - @Test - void directFromMapWithinMap() throws JsonProcessingException { - final Map map = new HashMap<>(); - final Map map2 = new HashMap<>(); - map2.put("b", "test"); - map.put("a", map2); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(map)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.size()).isEqualTo(1); - final VPackSlice a = vpack.get("a"); - assertThat(a.isObject()).isTrue(); - assertThat(a.size()).isEqualTo(1); - final VPackSlice b = a.get("b"); - assertThat(b.isString()).isTrue(); - assertThat(b.getAsString()).isEqualTo("test"); - } - - private void checkStringEntity(final VPackSlice vpack) { - final TestEntityString expected = new TestEntityString(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(3); - final VPackSlice s = vpack.get("s"); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo(expected.s); - final VPackSlice c1 = vpack.get("c1"); - assertThat(c1.isString()).isTrue(); - assertThat(new Character(c1.getAsChar())).isEqualTo(expected.c1); - final VPackSlice c2 = vpack.get("c2"); - assertThat(c2.isString()).isTrue(); - assertThat(c2.getAsChar()).isEqualTo(expected.c2); - } - - @Test - void directToObjectMap() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.ARRAY); - builder.add(ValueType.OBJECT); - builder.add("key", ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - builder.add("value", ValueType.OBJECT); - builder.add("s", "abc"); - builder.close(); - builder.close(); - builder.close(); - final Map map = new VPack.Builder().build().deserialize(builder.slice(), - new Type>() { - }.getType()); - assertThat(map).hasSize(1); - for (final Entry entry : map.entrySet()) { - assertThat(entry.getKey().s).isEqualTo("abc"); - assertThat(entry.getValue().s).isEqualTo("abc"); - } - } - - @SuppressWarnings("unchecked") - @Test - void directToMapWithinMap() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("a", ValueType.OBJECT); - builder.add("b", "test"); - builder.add("c", true); - builder.add("d", 1L); - builder.add("e", 1.5); - final Date date = new Date(); - builder.add("f", date); - builder.add("g", ValueType.ARRAY); - builder.close(); - builder.close(); - builder.close(); - final Map map = new VPack.Builder().build().deserialize(builder.slice(), Map.class); - assertThat(map).hasSize(1); - final Object a = map.get("a"); - assertThat(Map.class.isAssignableFrom(a.getClass())).isTrue(); - final Map mapA = (Map) a; - assertThat(mapA).hasSize(6); - final Object b = mapA.get("b"); - assertThat(String.class.isAssignableFrom(b.getClass())).isTrue(); - assertThat(b).hasToString("test"); - final Object c = mapA.get("c"); - assertThat(Boolean.class.isAssignableFrom(c.getClass())).isTrue(); - assertThat((Boolean) c).isTrue(); - final Object d = mapA.get("d"); - assertThat(Number.class.isAssignableFrom(d.getClass())).isTrue(); - assertThat(((Number) d).longValue()).isEqualTo(1L); - final Object e = mapA.get("e"); - assertThat(Double.class.isAssignableFrom(e.getClass())).isTrue(); - assertThat((Double) e).isEqualTo(1.5); - final Object f = mapA.get("f"); - assertThat(Date.class.isAssignableFrom(f.getClass())).isTrue(); - assertThat((Date) f).isEqualTo(date); - final Object g = mapA.get("g"); - assertThat(Collection.class.isAssignableFrom(g.getClass())).isTrue(); - assertThat(List.class.isAssignableFrom(g.getClass())).isTrue(); - } - - @Test - void dontSerializeNullValues() { - final VPack serializer = new VPack.Builder().serializeNullValues(false).build(); - final TestEntityString entity = new TestEntityString(); - entity.setS(null); - final VPackSlice vpack = serializer.serialize(entity); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice s = vpack.get("s"); - assertThat(s.isNone()).isTrue(); - } - - @Test - void serializeNullValue() { - final VPack serializer = new VPack.Builder().serializeNullValues(true).build(); - final TestEntityString entity = new TestEntityString(); - entity.setS(null); - final VPackSlice vpack = serializer.serialize(entity); - assertThat(vpack).isNotNull(); - final VPackSlice s = vpack.get("s"); - assertThat(s.isNull()).isTrue(); - } - - @Test - void toNullValue() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("s", ValueType.NULL); - builder.close(); - final TestEntityString entity = new VPack.Builder().build().deserialize(builder.slice(), - TestEntityString.class); - assertThat(entity).isNotNull(); - assertThat(entity.s).isNull(); - assertThat(entity.c1).isNotNull(); - assertThat(entity.c2).isNotNull(); - } - - @Test - void toSimpleString() { - final VPackBuilder builder = new VPackBuilder(); - builder.add("test"); - final String s = new VPack.Builder().build().deserialize(builder.slice(), String.class); - assertThat(s).isEqualTo("test"); - } - - @Test - void fromSimpleString() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes("test")); - assertThat(vpack).isNotNull(); - assertThat(vpack.isString()).isTrue(); - assertThat(vpack.getAsString()).isEqualTo("test"); - } - - public static class TestEntityTyped { - private T e; - } - - @Test - void fromStringTypedEntity() throws JsonProcessingException { - final TestEntityTyped entity = new TestEntityTyped<>(); - entity.e = "test"; - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice e = vpack.get("e"); - assertThat(e).isNotNull(); - assertThat(e.isString()).isTrue(); - assertThat(e.getAsString()).isEqualTo("test"); - } - - @Test - void fromObjectTypedEntity() throws JsonProcessingException { - final TestEntityTyped entity = new TestEntityTyped<>(); - entity.e = new TestEntityString(); - entity.e.s = "test2"; - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice e = vpack.get("e"); - assertThat(e).isNotNull(); - assertThat(e.isObject()).isTrue(); - final VPackSlice s = e.get("s"); - assertThat(s).isNotNull(); - assertThat(s.isString()).isTrue(); - assertThat(s.getAsString()).isEqualTo("test2"); - } - - @Test - void fromTypedTypedEntity() throws JsonProcessingException { - final TestEntityTyped> entity = new TestEntityTyped<>(); - entity.e = new TestEntityTyped<>(); - entity.e.e = "test"; - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice e = vpack.get("e"); - assertThat(e).isNotNull(); - assertThat(e.isObject()).isTrue(); - final VPackSlice e2 = e.get("e"); - assertThat(e2).isNotNull(); - assertThat(e2.isString()).isTrue(); - assertThat(e2.getAsString()).isEqualTo("test"); - } - - @Test - void fieldNamingStrategySerialize() { - final VPackSlice vpack = new VPack.Builder().fieldNamingStrategy(field -> "bla").build().serialize(new TestEntityA()); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - final VPackSlice bla = vpack.get("bla"); - assertThat(bla.isString()).isTrue(); - assertThat(bla.getAsString()).isEqualTo("a"); - } - - @Test - void fieldNamingStrategyDeserialize() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("bla", "test"); - builder.close(); - final TestEntityA entity = new VPack.Builder().fieldNamingStrategy(field -> "bla").build().deserialize(builder.slice(), TestEntityA.class); - assertThat(entity).isNotNull(); - assertThat(entity.a).isEqualTo("test"); - } - - @Test - void serializeVPack() throws JsonProcessingException { - final VPackBuilder builder = new VPackBuilder(); - builder.add("test"); - final VPackSlice slice = builder.slice(); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(slice)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isString()).isTrue(); - assertThat(vpack.getAsString()).isEqualTo("test"); - } - - @Test - void deserializeVPack() { - final VPackBuilder builder = new VPackBuilder(); - builder.add("test"); - final VPackSlice slice = builder.slice(); - final VPackSlice vpack = new VPack.Builder().build().deserialize(slice, slice.getClass()); - assertThat(vpack).isNotNull(); - assertThat(vpack.isString()).isTrue(); - assertThat(vpack.getAsString()).isEqualTo("test"); - } - - public static class TestEntityDate { - private java.util.Date utilDate = new Date(1474988621); - private java.sql.Date sqlDate = new java.sql.Date(1474988621); - private java.sql.Timestamp timestamp = new java.sql.Timestamp(1474988621); - - public java.util.Date getUtilDate() { - return utilDate; - } - - public void setUtilDate(final java.util.Date utilDate) { - this.utilDate = utilDate; - } - - public java.sql.Date getSqlDate() { - return sqlDate; - } - - public void setSqlDate(final java.sql.Date sqlDate) { - this.sqlDate = sqlDate; - } - - public java.sql.Timestamp getTimestamp() { - return timestamp; - } - - public void setTimestamp(final java.sql.Timestamp timestamp) { - this.timestamp = timestamp; - } - - } - - @Test - void fromDate() throws JsonProcessingException { - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityDate())); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - { - assertThat(vpack.get("utilDate").isString()).isTrue(); - assertThat(vpack.get("utilDate").getAsString()).isEqualTo(DATE_FORMAT.format(new Date(1474988621))); - } - { - assertThat(vpack.get("sqlDate").isString()).isTrue(); - assertThat(vpack.get("sqlDate").getAsString()).isEqualTo(DATE_FORMAT.format(new java.sql.Date(1474988621))); - } - { - assertThat(vpack.get("timestamp").isString()).isTrue(); - assertThat(vpack.get("timestamp").getAsString()).isEqualTo(DATE_FORMAT.format(new java.sql.Timestamp(1474988621))); - } - } - - @Test - void toDate() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("utilDate", new Date(1475062216)); - builder.add("sqlDate", new java.sql.Date(1475062216)); - builder.add("timestamp", new java.sql.Timestamp(1475062216)); - builder.close(); - - final TestEntityDate entity = new VPack.Builder().build().deserialize(builder.slice(), TestEntityDate.class); - assertThat(entity).isNotNull(); - assertThat(entity.utilDate).isEqualTo(new Date(1475062216)); - assertThat(entity.sqlDate).isEqualTo(new java.sql.Date(1475062216)); - assertThat(entity.timestamp).isEqualTo(new java.sql.Timestamp(1475062216)); - } - - @Test - void toDateFromString() { - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("utilDate", DATE_FORMAT.format(new Date(1475062216))); - builder.add("sqlDate", DATE_FORMAT.format(new java.sql.Date(1475062216))); - builder.add("timestamp", DATE_FORMAT.format(new java.sql.Timestamp(1475062216))); - builder.close(); - - final TestEntityDate entity = new VPack.Builder().build().deserialize(builder.slice(), TestEntityDate.class); - assertThat(entity).isNotNull(); - assertThat(entity.utilDate).isEqualTo(new Date(1475062216)); - assertThat(entity.sqlDate).isEqualTo(new java.sql.Date(1475062216)); - assertThat(entity.timestamp).isEqualTo(new java.sql.Timestamp(1475062216)); - } - - public static class TestEntityUUID { - private UUID uuid; - - UUID getUuid() { - return uuid; - } - - void setUuid(final UUID uuid) { - this.uuid = uuid; - } - } - - @Test - void fromUUID() throws IOException { - final TestEntityUUID entity = new TestEntityUUID(); - entity.setUuid(UUID.randomUUID()); - byte[] bytes = mapper.writeValueAsBytes(entity); - final VPackSlice vpack = new VPackSlice(bytes); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - - final VPackSlice uuid = vpack.get("uuid"); - assertThat(uuid.isString()).isTrue(); - assertThat(uuid.getAsString()).isEqualTo(entity.getUuid().toString()); - assertThat(mapper.readValue(bytes, TestEntityUUID.class).getUuid()).isEqualTo(entity.getUuid()); - } - - @Test - void toUUID() { - final UUID uuid = UUID.randomUUID(); - final VPackBuilder builder = new VPackBuilder(); - builder.add(ValueType.OBJECT); - builder.add("uuid", uuid.toString()); - builder.close(); - - final TestEntityUUID entity = new VPack.Builder().build().deserialize(builder.slice(), TestEntityUUID.class); - assertThat(entity).isNotNull(); - assertThat(entity.uuid).isEqualTo(uuid); - } - - @Test - void uuid() { - final TestEntityUUID entity = new TestEntityUUID(); - entity.setUuid(UUID.randomUUID()); - final VPack vpacker = new VPack.Builder().build(); - final VPackSlice vpack = vpacker.serialize(entity); - final TestEntityUUID entity2 = vpacker.deserialize(vpack, TestEntityUUID.class); - assertThat(entity2).isNotNull(); - assertThat(entity2.getUuid()).isEqualTo(entity.getUuid()); - } - - private static class BinaryEntity { - private byte[] foo; - - BinaryEntity() { - super(); - } - } - - @Test - void fromBinary() throws JsonProcessingException { - final BinaryEntity entity = new BinaryEntity(); - entity.foo = "bar".getBytes(); - final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity)); - assertThat(vpack).isNotNull(); - assertThat(vpack.isObject()).isTrue(); - assertThat(vpack.get("foo").isString()).isTrue(); - assertThat(vpack.get("foo").getAsString()).isEqualTo(Base64.getEncoder().encodeToString(entity.foo)); - } - - @Test - void toBinary() throws IOException { - final String value = Base64.getEncoder().encodeToString("bar".getBytes()); - final VPackSlice vpack = new VPackBuilder().add(ValueType.OBJECT).add("foo", value).close().slice(); - final BinaryEntity entity = mapper.readValue(vpack.getBuffer(), BinaryEntity.class); - assertThat(entity).isNotNull(); - assertThat(entity.foo).isEqualTo("bar".getBytes()); - } - - @Test - void asFloatingNumber() { - final VPackSlice vpack = new VPackBuilder().add(ValueType.OBJECT).add("value", 12000).close().slice(); - assertThat(vpack.get("value").getAsInt()).isEqualTo(12000); - assertThat(vpack.get("value").getAsFloat()).isEqualTo(12000F); - assertThat(vpack.get("value").getAsDouble()).isEqualTo(12000.); - } - - @Test - void toVPackSlice() throws IOException { - final VPackSlice value = new VPackBuilder().add(ValueType.OBJECT).add("key", "value").close().slice(); - final VPackSlice entity = mapper.readValue(value.getBuffer(), VPackSlice.class); - assertThat(entity).isEqualTo(value); - } - - -} diff --git a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java index 0aa1ace84..1e1389b9c 100644 --- a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java +++ b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java @@ -20,11 +20,12 @@ package com.arangodb.mapping.annotations; -import com.arangodb.mapping.ArangoJack; -import com.arangodb.velocypack.VPackSlice; -import org.junit.jupiter.api.Test; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.DataType; +import com.arangodb.serde.JacksonSerde; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; -import java.util.HashMap; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -34,10 +35,11 @@ */ class ArangoAnnotationsTest { - private final ArangoJack mapper = new ArangoJack(); + @ParameterizedTest + @EnumSource(DataType.class) + void documentFieldAnnotations(DataType dataType) { + ArangoSerde mapper = JacksonSerde.of(dataType); - @Test - void documentFieldAnnotations() { AnnotatedEntity e = new AnnotatedEntity(); e.setId("Id"); e.setKey("Key"); @@ -45,9 +47,8 @@ void documentFieldAnnotations() { e.setFrom("From"); e.setTo("To"); - VPackSlice slice = mapper.serialize(e); - System.out.println(slice); - Map deserialized = mapper.deserialize(slice, Object.class); + byte[] serialized = mapper.serialize(e); + Map deserialized = mapper.deserialize(serialized, Map.class); assertThat(deserialized) .containsEntry("_id", e.getId()) .containsEntry("_key", e.getKey()) @@ -56,70 +57,8 @@ void documentFieldAnnotations() { .containsEntry("_to", e.getTo()) .hasSize(5); - AnnotatedEntity deserializedEntity = mapper.deserialize(slice, AnnotatedEntity.class); + AnnotatedEntity deserializedEntity = mapper.deserialize(serialized, AnnotatedEntity.class); assertThat(deserializedEntity).isEqualTo(e); } - @Test - void serializedName() { - SerializedNameEntity e = new SerializedNameEntity(); - e.setA("A"); - e.setB("B"); - e.setC("C"); - - VPackSlice slice = mapper.serialize(e); - System.out.println(slice); - Map deserialized = mapper.deserialize(slice, Object.class); - assertThat(deserialized) - .containsEntry(SerializedNameEntity.SERIALIZED_NAME_A, e.getA()) - .containsEntry(SerializedNameEntity.SERIALIZED_NAME_B, e.getB()) - .containsEntry(SerializedNameEntity.SERIALIZED_NAME_C, e.getC()) - .hasSize(3); - - SerializedNameEntity deserializedEntity = mapper.deserialize(slice, SerializedNameEntity.class); - assertThat(deserializedEntity).isEqualTo(e); - } - - @Test - void serializedNameParameter() { - Map e = new HashMap<>(); - e.put(SerializedNameParameterEntity.SERIALIZED_NAME_A, "A"); - e.put(SerializedNameParameterEntity.SERIALIZED_NAME_B, "B"); - e.put(SerializedNameParameterEntity.SERIALIZED_NAME_C, "C"); - - VPackSlice slice = mapper.serialize(e); - SerializedNameParameterEntity deserializedEntity = mapper - .deserialize(slice, SerializedNameParameterEntity.class); - assertThat(deserializedEntity).isEqualTo(new SerializedNameParameterEntity("A", "B", "C")); - } - - @Test - void expose() { - ExposeEntity e = new ExposeEntity(); - e.setReadWrite("readWrite"); - e.setReadOnly("readOnly"); - e.setWriteOnly("writeOnly"); - e.setIgnored("ignored"); - - VPackSlice serializedEntity = mapper.serialize(e); - Map deserializedEntity = mapper.deserialize(serializedEntity, Object.class); - assertThat(deserializedEntity) - .containsEntry("readWrite", "readWrite") - .containsEntry("readOnly", "readOnly") - .hasSize(2); - - Map map = new HashMap<>(); - map.put("readWrite", "readWrite"); - map.put("readOnly", "readOnly"); - map.put("writeOnly", "writeOnly"); - map.put("ignored", "ignored"); - - VPackSlice serializedMap = mapper.serialize(map); - ExposeEntity deserializedMap = mapper.deserialize(serializedMap, ExposeEntity.class); - assertThat(deserializedMap.getIgnored()).isNull(); - assertThat(deserializedMap.getReadOnly()).isNull(); - assertThat(deserializedMap.getWriteOnly()).isEqualTo("writeOnly"); - assertThat(deserializedMap.getReadWrite()).isEqualTo("readWrite"); - } - } diff --git a/src/test/java/com/arangodb/mapping/annotations/ExposeEntity.java b/src/test/java/com/arangodb/mapping/annotations/ExposeEntity.java deleted file mode 100644 index 3100f9b38..000000000 --- a/src/test/java/com/arangodb/mapping/annotations/ExposeEntity.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.mapping.annotations; - -import com.arangodb.velocypack.annotations.Expose; - -import java.util.Objects; - -/** - * @author Michele Rastelli - */ -public class ExposeEntity { - - @Expose() - private String readWrite; - - @Expose(deserialize = false) - private String readOnly; - - @Expose(serialize = false) - private String writeOnly; - - @Expose(serialize = false, - deserialize = false) - private String ignored; - - public ExposeEntity() { - } - - public String getReadWrite() { - return readWrite; - } - - public void setReadWrite(String readWrite) { - this.readWrite = readWrite; - } - - public String getReadOnly() { - return readOnly; - } - - public void setReadOnly(String readOnly) { - this.readOnly = readOnly; - } - - public String getWriteOnly() { - return writeOnly; - } - - public void setWriteOnly(String writeOnly) { - this.writeOnly = writeOnly; - } - - public String getIgnored() { - return ignored; - } - - public void setIgnored(String ignored) { - this.ignored = ignored; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - ExposeEntity that = (ExposeEntity) o; - return Objects.equals(readWrite, that.readWrite) && Objects.equals(readOnly, that.readOnly) && Objects - .equals(writeOnly, that.writeOnly) && Objects.equals(ignored, that.ignored); - } - - @Override - public int hashCode() { - return Objects.hash(readWrite, readOnly, writeOnly, ignored); - } - - @Override - public String toString() { - return "ExposeEntity{" + "readWrite='" + readWrite + '\'' + ", readOnly='" + readOnly + '\'' + ", writeOnly='" - + writeOnly + '\'' + ", ignored='" + ignored + '\'' + '}'; - } -} \ No newline at end of file diff --git a/src/test/java/com/arangodb/mapping/annotations/SerializedNameEntity.java b/src/test/java/com/arangodb/mapping/annotations/SerializedNameEntity.java deleted file mode 100644 index 110d750be..000000000 --- a/src/test/java/com/arangodb/mapping/annotations/SerializedNameEntity.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.mapping.annotations; - -import com.arangodb.velocypack.annotations.SerializedName; - -import java.util.Objects; - -/** - * @author Michele Rastelli - */ -public class SerializedNameEntity { - - final static String SERIALIZED_NAME_A = "aSerializedName"; - final static String SERIALIZED_NAME_B = "bSerializedName"; - final static String SERIALIZED_NAME_C = "cSerializedName"; - - @SerializedName(SERIALIZED_NAME_A) - private String a; - private String b; - private String c; - - public SerializedNameEntity() { - } - - public String getA() { - return a; - } - - public void setA(String a) { - this.a = a; - } - - @SerializedName(SERIALIZED_NAME_B) - public String getB() { - return b; - } - - public void setB(String b) { - this.b = b; - } - - public String getC() { - return c; - } - - @SerializedName(SERIALIZED_NAME_C) - public void setC(String c) { - this.c = c; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - SerializedNameEntity that = (SerializedNameEntity) o; - return Objects.equals(a, that.a) && Objects.equals(b, that.b) && Objects.equals(c, that.c); - } - - @Override - public int hashCode() { - return Objects.hash(a, b, c); - } - - @Override - public String toString() { - return "SerializedNameEntity{" + "a='" + a + '\'' + ", b='" + b + '\'' + ", c='" + c + '\'' + '}'; - } -} diff --git a/src/test/java/com/arangodb/mapping/annotations/SerializedNameParameterEntity.java b/src/test/java/com/arangodb/mapping/annotations/SerializedNameParameterEntity.java deleted file mode 100644 index 034c00f93..000000000 --- a/src/test/java/com/arangodb/mapping/annotations/SerializedNameParameterEntity.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.mapping.annotations; - -import com.arangodb.velocypack.annotations.SerializedName; - -import java.util.Objects; - -/** - * @author Michele Rastelli - */ -public class SerializedNameParameterEntity { - - final static String SERIALIZED_NAME_A = "aSerializedName"; - final static String SERIALIZED_NAME_B = "bSerializedName"; - final static String SERIALIZED_NAME_C = "cSerializedName"; - - private String a; - private String b; - private String c; - - public SerializedNameParameterEntity( - @SerializedName(SERIALIZED_NAME_A) - String a, - @SerializedName(SERIALIZED_NAME_B) - String b, - @SerializedName(SERIALIZED_NAME_C) - String c) { - this.a = a; - this.b = b; - this.c = c; - } - - public String getA() { - return a; - } - - public String getB() { - return b; - } - - public String getC() { - return c; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - SerializedNameParameterEntity that = (SerializedNameParameterEntity) o; - return Objects.equals(a, that.a) && Objects.equals(b, that.b) && Objects.equals(c, that.c); - } - - @Override - public int hashCode() { - return Objects.hash(a, b, c); - } - - @Override - public String toString() { - return "SerializedNameParameterEntity{" + "a='" + a + '\'' + ", b='" + b + '\'' + ", c='" + c + '\'' + '}'; - } -} diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index 834d1cd56..5fae2ba2f 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -25,19 +25,10 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDatabase; import com.arangodb.DbName; -import com.arangodb.entity.BaseDocument; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.module.SimpleModule; import org.junit.jupiter.api.AfterAll; @@ -48,12 +39,11 @@ import java.math.BigInteger; import java.util.Collections; import java.util.HashMap; +import java.util.Map; import java.util.UUID; -import static com.arangodb.internal.util.ArangoSerializationFactory.Serializer.CUSTOM; import static com.fasterxml.jackson.databind.DeserializationFeature.USE_BIG_INTEGER_FOR_INTS; import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED; - import static org.assertj.core.api.Assertions.assertThat; @@ -100,15 +90,15 @@ static class Person { @BeforeAll static void init() { - ArangoJack arangoJack = new ArangoJack(); - arangoJack.configure((mapper) -> { + JacksonSerde serde = JacksonSerde.of(DataType.VPACK); + serde.configure((mapper) -> { mapper.configure(WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true); mapper.configure(USE_BIG_INTEGER_FOR_INTS, true); SimpleModule module = new SimpleModule("PersonModule"); module.addDeserializer(Person.class, new PersonDeserializer()); mapper.registerModule(module); }); - arangoDB = new ArangoDB.Builder().serializer(arangoJack).build(); + arangoDB = new ArangoDB.Builder().serializer(serde).build(); db = arangoDB.db(DbName.of("custom-serde-test")); if (!db.exists()) { @@ -142,9 +132,9 @@ void customPersonDeserializer() { void manualCustomPersonDeserializer() { Person person = new Person(); person.name = "Joe"; - ArangoSerialization serialization = arangoDB.util(CUSTOM); - VPackSlice serializedPerson = serialization.serialize(person); - Person deserializedPerson = serialization.deserialize(serializedPerson, Person.class); + ArangoSerde serialization = arangoDB.getUserSerde(); + byte[] serialized = serialization.serialize(person); + Person deserializedPerson = serialization.deserialize(serialized, Person.class); assertThat(deserializedPerson.name).isEqualTo(PERSON_DESERIALIZER_ADDED_PREFIX + PERSON_SERIALIZER_ADDED_PREFIX + person.name); } @@ -152,91 +142,95 @@ void manualCustomPersonDeserializer() { void aqlSerialization() { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); HashMap params = new HashMap<>(); params.put("doc", doc); params.put("@collection", COLLECTION_NAME); - BaseDocument result = db.query( + Map result = db.query( "INSERT @doc INTO @@collection RETURN NEW", params, - BaseDocument.class + Map.class ).next(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void aqlDeserialization() { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); collection.insertDocument(doc, null); - final BaseDocument result = db.query( + final Map result = db.query( "RETURN DOCUMENT(@docId)", Collections.singletonMap("docId", COLLECTION_NAME + "/" + key), - BaseDocument.class + Map.class ).next(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void insertDocument() { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); - BaseDocument result = collection.insertDocument( + Map result = collection.insertDocument( doc, new DocumentCreateOptions().returnNew(true) ).getNew(); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void getDocument() { String key = "test-" + UUID.randomUUID(); - BaseDocument doc = new BaseDocument(key); - doc.addAttribute("arr", Collections.singletonList("hello")); - doc.addAttribute("int", 10); + Map doc = new HashMap<>(); + doc.put("_key", key); + doc.put("arr", Collections.singletonList("hello")); + doc.put("int", 10); collection.insertDocument(doc, null); - final BaseDocument result = db.collection(COLLECTION_NAME).getDocument( + final Map result = db.collection(COLLECTION_NAME).getDocument( key, - BaseDocument.class, + Map.class, null); - assertThat(result.getAttribute("arr")).isInstanceOf(String.class); - assertThat(result.getAttribute("arr")).isEqualTo("hello"); - assertThat(result.getAttribute("int")).isInstanceOf(BigInteger.class); - assertThat(result.getAttribute("int")).isEqualTo(BigInteger.valueOf(10)); + assertThat(result.get("arr")).isInstanceOf(String.class); + assertThat(result.get("arr")).isEqualTo("hello"); + assertThat(result.get("int")).isInstanceOf(BigInteger.class); + assertThat(result.get("int")).isEqualTo(BigInteger.valueOf(10)); } @Test void parseNullString() { - final String json = arangoDB.util(CUSTOM).deserialize(new VPackBuilder().add((String) null).slice(), String.class); + final String json = arangoDB.getUserSerde().deserialize(arangoDB.getUserSerde().serialize(null), String.class); assertThat(json).isNull(); } diff --git a/src/test/java/com/arangodb/serde/CustomTypeHintTest.java b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java index a19eda063..d2144e0ee 100644 --- a/src/test/java/com/arangodb/serde/CustomTypeHintTest.java +++ b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java @@ -21,13 +21,9 @@ package com.arangodb.serde; -import com.arangodb.ArangoCollection; -import com.arangodb.ArangoDB; -import com.arangodb.ArangoDatabase; -import com.arangodb.DbName; -import com.arangodb.mapping.ArangoJack; +import com.arangodb.*; +import com.arangodb.entity.Key; import com.arangodb.model.DocumentCreateOptions; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -61,7 +57,7 @@ public void setName(String name) { public static class Zoo { - @JsonProperty("_key") + @Key private String key; private Animal animal; @@ -90,9 +86,7 @@ public void setAnimal(Animal animal) { @BeforeEach void init() { - ArangoDB arangoDB = new ArangoDB.Builder() - .serializer(new ArangoJack()) - .build(); + ArangoDB arangoDB = new ArangoDB.Builder().build(); db = arangoDB.db(DbName.of("custom-serde-test")); if (!db.exists()) { diff --git a/src/test/java/com/arangodb/serde/SerdeTest.java b/src/test/java/com/arangodb/serde/SerdeTest.java new file mode 100644 index 000000000..75c374659 --- /dev/null +++ b/src/test/java/com/arangodb/serde/SerdeTest.java @@ -0,0 +1,69 @@ +package com.arangodb.serde; + +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + + +import java.sql.Date; + +import static org.assertj.core.api.Assertions.assertThat; + + +class SerdeTest { + + @ParameterizedTest + @EnumSource(DataType.class) + void rawJsonSerde(DataType type) { + InternalSerde s = InternalSerde.of(type, null); + ObjectNode node = JsonNodeFactory.instance.objectNode().put("foo", "bar"); + RawJson raw = RawJson.of(SerdeUtils.INSTANCE.writeJson(node)); + byte[] serialized = s.serialize(raw); + RawJson deserialized = s.deserialize(serialized, RawJson.class); + assertThat(deserialized).isEqualTo(raw); + } + + @ParameterizedTest + @EnumSource(DataType.class) + void rawBytesSerde(DataType type) { + InternalSerde s = InternalSerde.of(type, null); + ObjectNode node = JsonNodeFactory.instance.objectNode().put("foo", "bar"); + RawBytes raw = RawBytes.of(s.serialize(node)); + byte[] serialized = s.serialize(raw); + RawBytes deserialized = s.deserialize(serialized, RawBytes.class); + assertThat(deserialized).isEqualTo(raw); + } + + @ParameterizedTest + @EnumSource(DataType.class) + void utilDateSerde(DataType type) { + InternalSerde s = InternalSerde.of(type, null); + long ts = 1000000000000L; + java.util.Date date = new java.util.Date(ts); + byte[] ser = s.serialize(date); + JsonNode node = s.parse(ser); + assertThat(node.isLong()).isTrue(); + assertThat(node.longValue()).isEqualTo(ts); + java.util.Date deser = s.deserialize(ser, java.util.Date.class); + assertThat(deser).isEqualTo(date); + } + + @ParameterizedTest + @EnumSource(DataType.class) + void sqlDateSerde(DataType type) { + InternalSerde s = InternalSerde.of(type, null); + long ts = 1000000000000L; + java.sql.Date date = new Date(ts); + byte[] ser = s.serialize(date); + JsonNode node = s.parse(ser); + assertThat(node.isLong()).isTrue(); + assertThat(node.longValue()).isEqualTo(ts); + java.sql.Date deser = s.deserialize(ser, java.sql.Date.class); + assertThat(deser).isEqualTo(date); + } + +} diff --git a/src/test/java/com/arangodb/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java deleted file mode 100644 index d17bd27c4..000000000 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.util; - -import com.arangodb.ArangoDB; -import com.arangodb.entity.BaseDocument; -import com.arangodb.mapping.ArangoJack; -import com.arangodb.velocypack.*; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - - -/** - * @author Mark Vollmary - */ -class ArangoSerializationTest { - - private static ArangoSerialization util; - - @BeforeAll - static void setup() { - final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); - util = arangoDB.util(); - } - - @Test - void deserialize() { - final VPackBuilder builder = new VPackBuilder().add(ValueType.OBJECT).add("foo", "bar").close(); - final BaseDocument doc = util.deserialize(builder.slice(), BaseDocument.class); - assertThat(doc.getAttribute("foo")).isEqualTo("bar"); - } - - @Test - void serialize() { - final BaseDocument entity = new BaseDocument(); - entity.addAttribute("foo", "bar"); - final VPackSlice vpack = util.serialize(entity); - assertThat(vpack.get("foo").isString()).isTrue(); - assertThat(vpack.get("foo").getAsString()).isEqualTo("bar"); - } - - @Test - void serializeNullValues() { - final BaseDocument entity = new BaseDocument(); - entity.addAttribute("foo", null); - final VPackSlice vpack = util.serialize(entity, new ArangoSerializer.Options().serializeNullValues(true)); - assertThat(vpack.get("foo").isNull()).isTrue(); - } - - @Test - void skipSerializeNullValues() { - final BaseDocument entity = new BaseDocument(); - entity.addAttribute("bar", null); - final VPackSlice vpack = util.serialize(entity); - assertThat(vpack.get("bar").isNone()).isTrue(); - } - - @Test - void serializeType() { - final Collection list = new ArrayList<>(); - list.add(new BaseDocument()); - list.add(new BaseDocument()); - - final VPackSlice vpack = util.serialize(list, - new ArangoSerializer.Options().type(new Type>() { - }.getType())); - assertThat(vpack.isArray()).isTrue(); - assertThat(vpack.getLength()).isEqualTo(list.size()); - } - - @Test - void parseJsonIncludeNull() { - final Map entity = new HashMap<>(); - entity.put("value", new String[]{"test", null}); - final String json = util.deserialize(util.serialize(entity, new ArangoSerializer.Options()), String.class); - assertThat(json).isEqualTo("{\"value\":[\"test\",null]}"); - } - - @Test - void parseNullString() { - final String json = util.deserialize(new VPackBuilder().add((String) null).slice(), String.class); - assertThat(json).isNull(); - } - -} diff --git a/src/main/java/com/arangodb/util/MapBuilder.java b/src/test/java/com/arangodb/util/MapBuilder.java similarity index 96% rename from src/main/java/com/arangodb/util/MapBuilder.java rename to src/test/java/com/arangodb/util/MapBuilder.java index 955bbe24e..61d05865e 100644 --- a/src/main/java/com/arangodb/util/MapBuilder.java +++ b/src/test/java/com/arangodb/util/MapBuilder.java @@ -1,46 +1,46 @@ -/* - * DISCLAIMER - * - * Copyright 2016 ArangoDB GmbH, Cologne, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is ArangoDB GmbH, Cologne, Germany - */ - -package com.arangodb.util; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * @author Mark Vollmary - */ -public class MapBuilder { - - private final Map map; - - public MapBuilder() { - super(); - map = new LinkedHashMap<>(); - } - - public MapBuilder put(final String key, final Object value) { - map.put(key, value); - return this; - } - - public Map get() { - return map; - } -} +/* + * DISCLAIMER + * + * Copyright 2016 ArangoDB GmbH, Cologne, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright holder is ArangoDB GmbH, Cologne, Germany + */ + +package com.arangodb.util; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author Mark Vollmary + */ +public class MapBuilder { + + private final Map map; + + public MapBuilder() { + super(); + map = new LinkedHashMap<>(); + } + + public MapBuilder put(final String key, final Object value) { + map.put(key, value); + return this; + } + + public Map get() { + return map; + } +} diff --git a/src/test/java/helper/NativeImageHelper.java b/src/test/java/helper/NativeImageHelper.java index 39bb227e5..5ec356589 100644 --- a/src/test/java/helper/NativeImageHelper.java +++ b/src/test/java/helper/NativeImageHelper.java @@ -1,19 +1,20 @@ package helper; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import org.reflections.Reflections; -import org.reflections.scanners.MethodParameterScanner; +import org.reflections.scanners.SubTypesScanner; import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; import org.reflections.util.FilterBuilder; -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; /** * Helper scripts to generate GraalVM native image configuration @@ -30,33 +31,52 @@ private static void generateReflectConfig() throws JsonProcessingException { System.out.println("--- reflect-config.json ---"); System.out.println("---------------------------"); - List packages = Arrays.asList("com.arangodb.entity", "com.arangodb.model"); + List packages = Arrays.asList( + "com.arangodb.entity", + "com.arangodb.model", + "com.arangodb.internal.cursor.entity" + ); ObjectMapper mapper = new ObjectMapper(); ArrayNode rootNode = mapper.createArrayNode(); - ObjectNode noArgConstructor = mapper.createObjectNode(); - noArgConstructor.put("name", ""); - noArgConstructor.set("parameterTypes", mapper.createArrayNode()); - ArrayNode methods = mapper.createArrayNode(); - methods.add(noArgConstructor); - packages.stream() + String serdePackage = "com.arangodb.serde"; + Reflections r = new Reflections(new ConfigurationBuilder() + .setScanners(new SubTypesScanner(false)) + .setUrls(ClasspathHelper.forPackage(serdePackage)) + .filterInputsBy(new FilterBuilder().includePackage(serdePackage))); + Stream serializers = r.getSubTypesOf(JsonSerializer.class).stream() + .filter(it -> !it.isAnonymousClass()) + .map(Class::getName); + Stream deserializers = r.getSubTypesOf(JsonDeserializer.class).stream() + .filter(it -> !it.isAnonymousClass()) + .map(Class::getName); + Stream serdeClasses = Stream.concat(serializers, deserializers) + .filter(it -> it.contains("InternalSerializers") || it.contains("InternalDeserializers")); + + Stream entityClasses = packages.stream() .flatMap(p -> { final ConfigurationBuilder config = new ConfigurationBuilder() - .setScanners(new MethodParameterScanner()) + .setScanners(new SubTypesScanner(false)) .setUrls(ClasspathHelper.forPackage(p)) .filterInputsBy(new FilterBuilder().includePackage(p)); - return new Reflections(config).getConstructorsMatchParams().stream(); - }) - .filter((it -> Modifier.isPublic(it.getDeclaringClass().getModifiers()))) - .filter(it -> Modifier.isPublic(it.getModifiers())) - .map(Constructor::getName) + Reflections reflections = new Reflections(config); + return Stream.concat( + reflections.getAllTypes().stream(), + reflections + .getSubTypesOf(Enum.class) + .stream() + .map(Class::getName) + ); + }); + Stream.concat(serdeClasses, entityClasses) .map(className -> { ObjectNode entry = mapper.createObjectNode(); entry.put("name", className); entry.put("allDeclaredFields", true); - entry.set("methods", methods); + entry.put("allDeclaredMethods", true); + entry.put("allDeclaredConstructors", true); return entry; }) .forEach(rootNode::add); diff --git a/src/test/java/perf/SimpleSyncPerfTest.java b/src/test/java/perf/SimpleSyncPerfTest.java index e801659ab..2d230779f 100644 --- a/src/test/java/perf/SimpleSyncPerfTest.java +++ b/src/test/java/perf/SimpleSyncPerfTest.java @@ -22,7 +22,6 @@ import com.arangodb.ArangoDB; import com.arangodb.Protocol; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -45,7 +44,7 @@ private void doGetVersion(ArangoDB arangoDB) { @ParameterizedTest @EnumSource(Protocol.class) void getVersion(Protocol protocol) throws InterruptedException { - ArangoDB arangoDB = new ArangoDB.Builder().useProtocol(protocol).serializer(new ArangoJack()).build(); + ArangoDB arangoDB = new ArangoDB.Builder().useProtocol(protocol).build(); // warmup doGetVersion(arangoDB); diff --git a/src/test/resources/META-INF/native-image/reflect-config.json b/src/test/resources/META-INF/native-image/reflect-config.json index f3181a2c9..a7c217b64 100644 --- a/src/test/resources/META-INF/native-image/reflect-config.json +++ b/src/test/resources/META-INF/native-image/reflect-config.json @@ -77,9 +77,13 @@ "name": "com.arangodb.ArangoCollectionTest$TestUpdateEntity", "allDeclaredFields": true, "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true + "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.ArangoCollectionTest$TestUpdateEntitySerializeNullFalse", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.ArangoDatabaseTest$TransactionTestEntity", @@ -207,335 +211,6 @@ "allDeclaredConstructors": true, "allDeclaredClasses": true }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$BinaryEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allDeclaredConstructors": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$CustomAnEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$CustomFilterAnnotation" - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$CustomNamingAnnotation" - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestCollection", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityA", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityArray", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityArrayInArray", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityArrayInArrayInArray", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityB", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityBaseAttributes", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityBigNumber", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityBoolean", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityByte", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityC", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityCollection", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityCollectionExtendedWithNulls", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityCollectionWithObjects", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityD", - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityDImpl", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityDate", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityDouble", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityEmpty", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityEmptyMap", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityEnum", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityFloat", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityInteger", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityLong", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityMap", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityMapStringableKey", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityMapWithObjectKey", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityObject", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityObjectInArray", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityShort", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityString", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityTyped", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEntityUUID", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.VPackSerializeDeserializeTest$TestEnum", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.annotations.DocumentFieldEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.annotations.AnnotatedEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.annotations.ExposeEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.annotations.SerializedNameEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, - { - "name": "com.arangodb.mapping.annotations.SerializedNameParameterEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true - }, { "name": "com.arangodb.serde.CustomSerdeTest$Person", "allDeclaredFields": true, @@ -587,5 +262,29 @@ "name": "java.util.HashSet", "allDeclaredMethods": true, "allDeclaredConstructors": true + }, + { + "name": "com.arangodb.mapping.annotations.AnnotatedEntity", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, + { + "name": "com.fasterxml.jackson.databind.deser.std.DateDeserializers$SqlDateDeserializer", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "com.fasterxml.jackson.databind.ser.std.SqlDateSerializer", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] } ] diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index f67855e9c..579f1b9db 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -8,7 +8,7 @@ - +