From 7080d53161a44c52f1c461dcce0dccb9a05a9543 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 28 Jun 2022 15:50:21 +0200 Subject: [PATCH 01/52] new serializer API --- .../java/com/arangodb/serde/ArangoSerde.java | 60 ++++++++++++++++++ .../java/com/arangodb/serde/DataType.java | 24 +++++++ .../com/arangodb/serde/InternalSerde.java | 42 +++++++++++++ .../com/arangodb/serde/InternalSerdeImpl.java | 44 +++++++++++++ .../java/com/arangodb/serde/JacksonSerde.java | 63 +++++++++++++++++++ .../com/arangodb/serde/JacksonSerdeImpl.java | 53 ++++++++++++++++ 6 files changed, 286 insertions(+) create mode 100644 src/main/java/com/arangodb/serde/ArangoSerde.java create mode 100644 src/main/java/com/arangodb/serde/DataType.java create mode 100644 src/main/java/com/arangodb/serde/InternalSerde.java create mode 100644 src/main/java/com/arangodb/serde/InternalSerdeImpl.java create mode 100644 src/main/java/com/arangodb/serde/JacksonSerde.java create mode 100644 src/main/java/com/arangodb/serde/JacksonSerdeImpl.java 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..3b310548c --- /dev/null +++ b/src/main/java/com/arangodb/serde/ArangoSerde.java @@ -0,0 +1,60 @@ +package com.arangodb.serde; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.lang.reflect.Type; + +/** + * 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 other than Jackson Databind, 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 databinding code generation) + * - lower level libraries without support to data binding + *

+ * This interface should not be directly implemented as an adapter to Jackson Databind. A more performant way to provide + * custom implementations based on Jackson Databind is by extending {@link JacksonSerde}, which exposes additional + * methods based on Jackson's types. + * Furthermore, existing implementations {@link JacksonSerde} can be instantiated providing a custom configured Jackson + * ObjectMapper, see {@link JacksonSerde#of(DataType, ObjectMapper)}. + */ +public interface ArangoSerde { + + /** + * @return the data type supported by this implementation + */ + DataType getDataType(); + + /** + * 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/serde/DataType.java b/src/main/java/com/arangodb/serde/DataType.java new file mode 100644 index 000000000..0b071915a --- /dev/null +++ b/src/main/java/com/arangodb/serde/DataType.java @@ -0,0 +1,24 @@ +/* + * 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; + +public enum DataType { + JSON, VPACK +} 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..bdc40760b --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -0,0 +1,42 @@ +package com.arangodb.serde; + +import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.fasterxml.jackson.databind.ObjectMapper; + +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 JacksonSerde of(final DataType dataType) { + if (dataType == DataType.JSON) { + return new InternalSerdeImpl(dataType, new ObjectMapper()); + } else if (dataType == DataType.VPACK) { + return new InternalSerdeImpl(dataType, new VPackMapper()); + } else { + throw new IllegalStateException("Unexpected value: " + dataType); + } + } + + /** + * 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 user data + * @return byte array + */ + byte[] extract(byte[] content, String jsonPointer); + +} 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..4cf6c3e77 --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -0,0 +1,44 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDBException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { + private final ObjectMapper jsonMapper = new ObjectMapper(); + + InternalSerdeImpl(DataType dataType, ObjectMapper mapper) { + super(dataType, mapper); + } + + @Override + public String toJsonString(final byte[] content) { + switch (dataType) { + case JSON: + return new String(content, StandardCharsets.UTF_8); + case VPACK: + try { + JsonNode tree = mapper.readTree(content); + return jsonMapper.writeValueAsString(tree); + } catch (IOException e) { + throw new ArangoDBException(e); + } + default: + throw new IllegalStateException("Unexpected value: " + dataType); + } + } + + @Override + public byte[] extract(final byte[] content, final String jsonPointer) { + try { + JsonNode target = mapper.readTree(content).at(jsonPointer); + return mapper.writeValueAsBytes(target); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + +} 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..9887a7767 --- /dev/null +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -0,0 +1,63 @@ +package com.arangodb.serde; + +import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.lang.reflect.Type; + +/** + * Contract for serialization/deserialization of user data, based on Jackson Databind. + * In comparison to {@link ArangoSerde}, this API improves the deserialization performance by allowing reusing the JSON + * tree already parsed by the root deserializer. + */ +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) { + if (dataType == DataType.JSON) { + return of(dataType, new ObjectMapper()); + } else if (dataType == DataType.VPACK) { + return of(dataType, new VPackMapper()); + } else { + throw new IllegalStateException("Unexpected value: " + dataType); + } + } + + /** + * Creates a new JacksonSerde using the provided ObjectMapper. + * + * @param dataType serialization target data type + * @param mapper Jackson ObjectMapper to use + * @return the created JacksonSerde + */ + static JacksonSerde of(final DataType dataType, final ObjectMapper mapper) { + return new JacksonSerdeImpl(dataType, mapper); + } + + /** + * 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); + +} 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..3964f0ea4 --- /dev/null +++ b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java @@ -0,0 +1,53 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDBException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.lang.reflect.Type; + +class JacksonSerdeImpl implements JacksonSerde { + + protected final DataType dataType; + protected final ObjectMapper mapper; + + JacksonSerdeImpl(final DataType dataType, final ObjectMapper mapper) { + this.dataType = dataType; + this.mapper = mapper; + } + + @Override + public DataType getDataType() { + return dataType; + } + + @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 T deserialize(final JsonNode node, final Type type) { + try { + return mapper.readerFor(mapper.constructType(type)).readValue(node); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + +} From fa459854f524ec6eddad6be952192ad957cb782d Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 29 Jun 2022 11:10:05 +0200 Subject: [PATCH 02/52] serde InternalModule --- .../com/arangodb/serde/InternalModule.java | 24 ++++++++++++++++ .../com/arangodb/serde/InternalSerde.java | 2 +- .../com/arangodb/serde/InternalSerdeImpl.java | 1 + .../arangodb/serde/InternalSerializers.java | 28 +++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/arangodb/serde/InternalModule.java create mode 100644 src/main/java/com/arangodb/serde/InternalSerializers.java 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..cd0679b25 --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -0,0 +1,24 @@ +package com.arangodb.serde; + +import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +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(AuthenticationRequest.class, InternalSerializers.AUTHENTICATION_REQUEST); + } + + @Override + public Module get() { + return module; + } + +} diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index bdc40760b..839c7e5f5 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -11,7 +11,7 @@ public interface InternalSerde extends JacksonSerde { * @param dataType serialization target data type * @return the created InternalSerde */ - static JacksonSerde of(final DataType dataType) { + static InternalSerde of(final DataType dataType) { if (dataType == DataType.JSON) { return new InternalSerdeImpl(dataType, new ObjectMapper()); } else if (dataType == DataType.VPACK) { diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 4cf6c3e77..4ef9b3c72 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -12,6 +12,7 @@ class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { InternalSerdeImpl(DataType dataType, ObjectMapper mapper) { super(dataType, mapper); + mapper.registerModule(InternalModule.INSTANCE.get()); } @Override 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..5ec7ae03c --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -0,0 +1,28 @@ +package com.arangodb.serde; + +import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; + +final class InternalSerializers { + + private InternalSerializers() { + } + + 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(); + } + }; + +} From f1ac12a521e2cd743e9f4b4b58bafcb4e95673d1 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 29 Jun 2022 13:36:24 +0200 Subject: [PATCH 03/52] serde serialization refactoring --- src/main/java/com/arangodb/ArangoDB.java | 7 +++++- .../com/arangodb/async/ArangoDBAsync.java | 5 +++- .../java/com/arangodb/entity/Permissions.java | 7 ++++++ .../internal/http/HttpConnection.java | 5 +++- .../util/DefaultArangoSerialization.java | 20 +++++++++++++-- .../velocypack/VPackDeserializers.java | 3 ++- .../com/arangodb/model/AqlQueryOptions.java | 7 +++--- .../model/CollectionCreateOptions.java | 2 +- .../com/arangodb/model/UserAccessOptions.java | 2 +- .../com/arangodb/model/UserCreateOptions.java | 4 +-- .../com/arangodb/serde/InternalModule.java | 2 ++ .../arangodb/serde/InternalSerializers.java | 25 +++++++++++++++++++ .../com/arangodb/velocystream/Response.java | 19 +++++++++++++- 13 files changed, 93 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index f58064a08..0686ca6cc 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -38,6 +38,9 @@ import com.arangodb.model.LogOptions; import com.arangodb.model.UserCreateOptions; import com.arangodb.model.UserUpdateOptions; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.DataType; +import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoCursorInitializer; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; @@ -362,8 +365,10 @@ public synchronized ArangoDB build() { : new ArangoSerializerImpl(vpacker, vpackerNull, vpackParser); final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer : new ArangoDeserializerImpl(vpackerNull, vpackParser); + final InternalSerde internalSerde = protocol == Protocol.HTTP_JSON ? InternalSerde.of(DataType.JSON) + : InternalSerde.of(DataType.VPACK); final DefaultArangoSerialization internal = new DefaultArangoSerialization(serializerTemp, - deserializerTemp); + deserializerTemp, internalSerde); final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 8b3b0b75d..28dff5ee6 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -41,6 +41,8 @@ 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.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; import com.arangodb.util.ArangoSerializer; @@ -523,8 +525,9 @@ public synchronized ArangoDBAsync build() { : new ArangoSerializerImpl(vpacker, vpackerNull, vpackParser); final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer : new ArangoDeserializerImpl(vpackerNull, vpackParser); + final InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); final DefaultArangoSerialization internal = new DefaultArangoSerialization(serializerTemp, - deserializerTemp); + deserializerTemp, internalSerde); final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); 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/internal/http/HttpConnection.java b/src/main/java/com/arangodb/internal/http/HttpConnection.java index 7cc380e22..c74af9b2a 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnection.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnection.java @@ -27,6 +27,7 @@ import com.arangodb.internal.net.HostDescription; import com.arangodb.internal.util.IOUtils; import com.arangodb.internal.util.ResponseUtils; +import com.arangodb.serde.DataType; import com.arangodb.util.ArangoSerialization; import com.arangodb.util.ArangoSerializer.Options; import com.arangodb.velocypack.VPackSlice; @@ -173,6 +174,7 @@ public HttpConnection build() { private final ArangoSerialization util; private final Boolean useSsl; private final Protocol contentType; + private final DataType dataType; private final HostDescription host; private HttpConnection(final HostDescription host, final Integer timeout, final String user, final String password, @@ -185,6 +187,7 @@ private HttpConnection(final HostDescription host, final Integer timeout, final this.useSsl = useSsl; this.util = util; this.contentType = contentType; + dataType = contentType == Protocol.HTTP_JSON ? DataType.JSON : DataType.VPACK; final RegistryBuilder registryBuilder = RegistryBuilder .create(); if (Boolean.TRUE == useSsl) { @@ -355,7 +358,7 @@ private static void addHeader(final Request request, final HttpRequestBase httpR public Response buildResponse(final CloseableHttpResponse httpResponse) throws UnsupportedOperationException, IOException { - final Response response = new Response(); + final Response response = new Response(dataType); response.setResponseCode(httpResponse.getStatusLine().getStatusCode()); final HttpEntity entity = httpResponse.getEntity(); if (entity != null && entity.getContent() != null) { diff --git a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java index f77f2ee49..d6a6c6e29 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -21,9 +21,12 @@ package com.arangodb.internal.util; import com.arangodb.ArangoDBException; +import com.arangodb.serde.DataType; +import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; import com.arangodb.util.ArangoSerializer; +import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; import java.lang.reflect.Type; @@ -35,16 +38,29 @@ public class DefaultArangoSerialization implements ArangoSerialization { private final ArangoSerializer serializer; private final ArangoDeserializer deserializer; + private final InternalSerde serde; - public DefaultArangoSerialization(final ArangoSerializer serializer, final ArangoDeserializer deserializer) { + public DefaultArangoSerialization(final ArangoSerializer serializer, final ArangoDeserializer deserializer, final InternalSerde serde) { super(); this.serializer = serializer; this.deserializer = deserializer; + this.serde = serde; } @Override public VPackSlice serialize(final Object entity) throws ArangoDBException { - return serializer.serialize(entity); +// return serializer.serialize(entity); + DataType dataType = serde.getDataType(); + switch (dataType) { + case JSON: + String json = new String(serde.serialize(entity)); + VPackParser parser = new VPackParser.Builder().build(); + return parser.fromJson(json); + case VPACK: + return new VPackSlice(serde.serialize(entity)); + default: + throw new IllegalStateException("Unexpected value: " + dataType); + } } @Override diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java index 2e8849214..344b66983 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java @@ -45,6 +45,7 @@ import com.arangodb.entity.arangosearch.analyzer.*; import com.arangodb.model.CollectionSchema; import com.arangodb.model.ZKDIndexOptions; +import com.arangodb.serde.DataType; import com.arangodb.velocypack.VPackDeserializer; import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; @@ -66,7 +67,7 @@ public class VPackDeserializers { 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(); + final Response response = new Response(DataType.VPACK); response.setVersion(vpack.get(0).getAsInt()); response.setType(vpack.get(1).getAsInt()); response.setResponseCode(vpack.get(2).getAsInt()); diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 52e344663..ddb5a4f16 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -42,7 +42,6 @@ public class AqlQueryOptions implements Serializable { private Integer ttl; private Integer batchSize; private Boolean cache; - private Boolean fillBlockCache; private Long memoryLimit; private VPackSlice bindVars; private String query; @@ -165,7 +164,7 @@ protected AqlQueryOptions bindVars(final VPackSlice bindVars) { return this; } - protected String getQuery() { + public String getQuery() { return query; } @@ -430,14 +429,14 @@ public static class Options implements Serializable { private Double maxRuntime; private Boolean fillBlockCache; - protected Optimizer getOptimizer() { + public Optimizer getOptimizer() { if (optimizer == null) { optimizer = new Optimizer(); } return optimizer; } - protected Collection getShardIds() { + public Collection getShardIds() { if (shardIds == null) { shardIds = new ArrayList<>(); } diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index e4c425aa0..a8c89af51 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -53,7 +53,7 @@ public CollectionCreateOptions() { replicationFactor = new ReplicationFactor(); } - protected String getName() { + public String getName() { return name; } diff --git a/src/main/java/com/arangodb/model/UserAccessOptions.java b/src/main/java/com/arangodb/model/UserAccessOptions.java index 85f86bc66..12355c642 100644 --- a/src/main/java/com/arangodb/model/UserAccessOptions.java +++ b/src/main/java/com/arangodb/model/UserAccessOptions.java @@ -33,7 +33,7 @@ public UserAccessOptions() { super(); } - protected Permissions getGrant() { + public Permissions getGrant() { return grant; } diff --git a/src/main/java/com/arangodb/model/UserCreateOptions.java b/src/main/java/com/arangodb/model/UserCreateOptions.java index 2ac216259..f4808da27 100644 --- a/src/main/java/com/arangodb/model/UserCreateOptions.java +++ b/src/main/java/com/arangodb/model/UserCreateOptions.java @@ -37,7 +37,7 @@ public UserCreateOptions() { super(); } - protected String getUser() { + public String getUser() { return user; } @@ -50,7 +50,7 @@ protected UserCreateOptions user(final String user) { return this; } - protected String getPasswd() { + public String getPasswd() { return passwd; } diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index cd0679b25..26ab243ae 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -1,6 +1,7 @@ package com.arangodb.serde; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +import com.arangodb.velocystream.Request; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -14,6 +15,7 @@ enum InternalModule implements Supplier { InternalModule() { module = new SimpleModule(); module.addSerializer(AuthenticationRequest.class, InternalSerializers.AUTHENTICATION_REQUEST); + module.addSerializer(Request.class, InternalSerializers.REQUEST); } @Override diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 5ec7ae03c..feffa6c5a 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -1,11 +1,13 @@ package com.arangodb.serde; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; +import java.util.Map; final class InternalSerializers { @@ -25,4 +27,27 @@ public void serialize(AuthenticationRequest value, JsonGenerator gen, Serializer } }; + 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(); + } + }; + } diff --git a/src/main/java/com/arangodb/velocystream/Response.java b/src/main/java/com/arangodb/velocystream/Response.java index 9e3811793..9c5869869 100644 --- a/src/main/java/com/arangodb/velocystream/Response.java +++ b/src/main/java/com/arangodb/velocystream/Response.java @@ -20,9 +20,11 @@ package com.arangodb.velocystream; +import com.arangodb.serde.DataType; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.annotations.Expose; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -38,8 +40,11 @@ public class Response { @Expose(deserialize = false) private VPackSlice body = null; - public Response() { + private final DataType dataType; + + public Response(final DataType dataType) { super(); + this.dataType = dataType; meta = new HashMap<>(); } @@ -83,4 +88,16 @@ public void setBody(final VPackSlice body) { this.body = body; } + public byte[] getBodyBytes() { + if (body == null) { + return new byte[0]; + } else if (dataType == DataType.JSON) { + return body.toString().getBytes(StandardCharsets.UTF_8); + } else if (dataType == DataType.VPACK) { + return body.toByteArray(); + } else { + throw new IllegalStateException("Unexpected value: " + dataType); + } + } + } From 638baf44a56d7ef092e355c35ab1515395d349b4 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 29 Jun 2022 14:05:23 +0200 Subject: [PATCH 04/52] serde serialization refactoring: graph API --- src/main/java/com/arangodb/ArangoDB.java | 1 - .../java/com/arangodb/entity/EdgeDefinition.java | 14 +++++++++++--- .../com/arangodb/model/GraphCreateOptions.java | 9 ++++++--- .../arangodb/model/StreamTransactionOptions.java | 4 ++++ .../model/TransactionCollectionOptions.java | 7 ++++--- .../model/VertexCollectionCreateOptions.java | 9 ++++++--- src/test/java/com/arangodb/ArangoDBTest.java | 2 ++ src/test/java/com/arangodb/async/ArangoDBTest.java | 2 ++ .../com/arangodb/async/ArangoDatabaseTest.java | 4 ++-- .../java/com/arangodb/async/ArangoGraphTest.java | 2 +- src/test/resources/logback-test.xml | 2 +- 11 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index 0686ca6cc..5dbad9ef3 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -38,7 +38,6 @@ import com.arangodb.model.LogOptions; import com.arangodb.model.UserCreateOptions; import com.arangodb.model.UserUpdateOptions; -import com.arangodb.serde.ArangoSerde; import com.arangodb.serde.DataType; import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoCursorInitializer; diff --git a/src/main/java/com/arangodb/entity/EdgeDefinition.java b/src/main/java/com/arangodb/entity/EdgeDefinition.java index 140e01567..8fc808428 100644 --- a/src/main/java/com/arangodb/entity/EdgeDefinition.java +++ b/src/main/java/com/arangodb/entity/EdgeDefinition.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** * @author Mark Vollmary @@ -32,7 +33,7 @@ public 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; + private Collection satellites = Collections.emptyList(); + + public Collection getSatellites() { + return satellites; + } } } diff --git a/src/main/java/com/arangodb/model/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index 6d75fb4e1..1f4c3780b 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; /** * @author Mark Vollmary @@ -33,8 +35,8 @@ public class GraphCreateOptions { private String name; - private Collection edgeDefinitions; - private Collection orphanCollections; + private Collection edgeDefinitions = Collections.emptyList(); + private Collection orphanCollections = Collections.emptyList(); private Boolean isSmart; private SmartOptions options; @@ -42,7 +44,7 @@ public GraphCreateOptions() { super(); } - protected String getName() { + public String getName() { return name; } @@ -64,6 +66,7 @@ public Collection getEdgeDefinitions() { * @return options */ protected GraphCreateOptions edgeDefinitions(final Collection edgeDefinitions) { + Objects.requireNonNull(edgeDefinitions); this.edgeDefinitions = edgeDefinitions; return this; } diff --git a/src/main/java/com/arangodb/model/StreamTransactionOptions.java b/src/main/java/com/arangodb/model/StreamTransactionOptions.java index 98f8b451d..52cae19d2 100644 --- a/src/main/java/com/arangodb/model/StreamTransactionOptions.java +++ b/src/main/java/com/arangodb/model/StreamTransactionOptions.java @@ -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..e16060a33 100644 --- a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** * @author Mark Vollmary @@ -29,9 +30,9 @@ */ public class TransactionCollectionOptions { - private Collection read; - private Collection write; - private Collection exclusive; + private Collection read = Collections.emptyList(); + private Collection write = Collections.emptyList(); + private Collection exclusive = Collections.emptyList(); private Boolean allowImplicit; public Collection getRead() { diff --git a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java index b79b8ed41..4013a2c74 100644 --- a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java @@ -29,13 +29,13 @@ public 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; } @@ -60,13 +60,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 { private Collection satellites; + + public Collection getSatellites() { + return satellites; + } } } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 76d991e6a..4495121d0 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -31,6 +31,7 @@ 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; @@ -591,6 +592,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/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 6b7f7321c..965f84a3a 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -28,6 +28,7 @@ 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; @@ -501,6 +502,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..01a34350b 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -847,7 +847,7 @@ void createGetDeleteAqlFunctionWithNamespace() throws InterruptedException, Exec @Test void createGraph() throws InterruptedException, ExecutionException { try { - db.createGraph(GRAPH_NAME, null, null) + db.createGraph(GRAPH_NAME, Collections.emptyList(), null) .whenComplete((result, ex) -> { assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo(GRAPH_NAME); @@ -861,7 +861,7 @@ void createGraph() throws InterruptedException, ExecutionException { @Test void getGraphs() throws InterruptedException, ExecutionException { try { - db.createGraph(GRAPH_NAME, null, null).get(); + db.createGraph(GRAPH_NAME, Collections.emptyList(), null).get(); db.getGraphs() .whenComplete((graphs, ex) -> { assertThat(graphs).isNotNull(); diff --git a/src/test/java/com/arangodb/async/ArangoGraphTest.java b/src/test/java/com/arangodb/async/ArangoGraphTest.java index 9513d4fec..93a266c0f 100644 --- a/src/test/java/com/arangodb/async/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/async/ArangoGraphTest.java @@ -85,7 +85,7 @@ void teardown() throws InterruptedException, ExecutionException { @Test void create() throws InterruptedException, ExecutionException { try { - final GraphEntity result = db.graph(GRAPH_NAME + "_1").create(null).get(); + final GraphEntity result = db.graph(GRAPH_NAME + "_1").create(Collections.emptyList()).get(); assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo(GRAPH_NAME + "_1"); } finally { 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 @@ - + From 1b2aff6a2174c8a7404ff0dcb9a88829236565fc Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 29 Jun 2022 20:11:15 +0200 Subject: [PATCH 05/52] serde serialization refactoring: collections API --- .../internal/InternalArangoCollection.java | 2 +- .../util/DefaultArangoSerialization.java | 8 ++++++-- .../java/com/arangodb/mapping/ArangoJack.java | 5 +++++ .../model/AqlFunctionCreateOptions.java | 4 ++-- .../model/AqlQueryExplainOptions.java | 4 ++-- .../arangodb/model/AqlQueryParseOptions.java | 2 +- .../model/CollectionCreateOptions.java | 5 ++++- .../com/arangodb/model/CollectionSchema.java | 17 ++++++++-------- .../arangodb/model/FulltextIndexOptions.java | 4 ++-- .../com/arangodb/model/GeoIndexOptions.java | 4 ++-- .../com/arangodb/model/HashIndexOptions.java | 4 ++-- .../java/com/arangodb/model/IndexOptions.java | 2 +- .../model/PersistentIndexOptions.java | 6 +++--- .../arangodb/model/SkiplistIndexOptions.java | 4 ++-- .../arangodb/model/TransactionOptions.java | 2 +- .../com/arangodb/model/TtlIndexOptions.java | 6 +++--- .../com/arangodb/model/ZKDIndexOptions.java | 6 ++++-- .../com/arangodb/serde/InternalModule.java | 2 ++ .../com/arangodb/serde/InternalSerde.java | 8 ++++++++ .../com/arangodb/serde/InternalSerdeImpl.java | 10 ++++++++++ .../arangodb/serde/InternalSerializers.java | 20 ++++++++++++++++++- .../arangodb/util/ArangoSerialization.java | 4 +++- .../com/arangodb/ArangoCollectionTest.java | 2 +- .../arangodb/ArangoVertexCollectionTest.java | 2 +- 24 files changed, 94 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 70b32b23c..4d9bcbba9 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -180,7 +180,7 @@ 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(util().serialize(util().parseJson(values))); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { diff --git a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java index d6a6c6e29..f9ae383d3 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -28,6 +28,7 @@ import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import java.lang.reflect.Type; @@ -49,13 +50,12 @@ public DefaultArangoSerialization(final ArangoSerializer serializer, final Arang @Override public VPackSlice serialize(final Object entity) throws ArangoDBException { -// return serializer.serialize(entity); DataType dataType = serde.getDataType(); switch (dataType) { case JSON: String json = new String(serde.serialize(entity)); VPackParser parser = new VPackParser.Builder().build(); - return parser.fromJson(json); + return parser.fromJson(json, true); case VPACK: return new VPackSlice(serde.serialize(entity)); default: @@ -73,4 +73,8 @@ public T deserialize(final VPackSlice vpack, final Type type) throws ArangoD return deserializer.deserialize(vpack, type); } + @Override + public JsonNode parseJson(String json) { + return serde.parseJson(json); + } } diff --git a/src/main/java/com/arangodb/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index 132a724b2..b768ea727 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -51,6 +51,11 @@ */ public class ArangoJack implements ArangoSerialization { + @Override + public JsonNode parseJson(String json) { + return null; + } + public interface ConfigureFunction { void configure(ObjectMapper mapper); } diff --git a/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java b/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java index a1897c491..d9c578804 100644 --- a/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java +++ b/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java @@ -44,7 +44,7 @@ protected AqlFunctionCreateOptions name(final String name) { return this; } - protected String getName() { + public String getName() { return name; } @@ -57,7 +57,7 @@ protected AqlFunctionCreateOptions code(final String code) { return this; } - protected String getCode() { + public String getCode() { return code; } diff --git a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java index 27b962465..7e453a4b7 100644 --- a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java @@ -52,7 +52,7 @@ protected AqlQueryExplainOptions bindVars(final VPackSlice bindVars) { return this; } - protected String getQuery() { + public String getQuery() { return query; } @@ -119,7 +119,7 @@ public static class Options { private Integer maxNumberOfPlans; private Boolean allPlans; - protected Optimizer getOptimizer() { + public Optimizer getOptimizer() { if (optimizer == null) { optimizer = new Optimizer(); } diff --git a/src/main/java/com/arangodb/model/AqlQueryParseOptions.java b/src/main/java/com/arangodb/model/AqlQueryParseOptions.java index b2194779c..2059415e2 100644 --- a/src/main/java/com/arangodb/model/AqlQueryParseOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryParseOptions.java @@ -32,7 +32,7 @@ public AqlQueryParseOptions() { super(); } - protected String getQuery() { + public String getQuery() { return query; } diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index a8c89af51..5dafdf6f2 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -25,6 +25,8 @@ import com.arangodb.entity.KeyType; import com.arangodb.entity.ReplicationFactor; +import java.util.Objects; + /** * @author Mark Vollmary * @see API @@ -37,7 +39,7 @@ public class CollectionCreateOptions { private Integer writeConcern; private KeyOptions keyOptions; private Boolean waitForSync; - private String[] shardKeys; + private String[] shardKeys = new String[]{}; private Integer numberOfShards; private Boolean isSystem; private CollectionType type; @@ -166,6 +168,7 @@ public String[] getShardKeys() { * @return options */ public CollectionCreateOptions shardKeys(final String... shardKeys) { + Objects.requireNonNull(shardKeys); this.shardKeys = shardKeys; return this; } diff --git a/src/main/java/com/arangodb/model/CollectionSchema.java b/src/main/java/com/arangodb/model/CollectionSchema.java index 49b6fea85..bbc956c86 100644 --- a/src/main/java/com/arangodb/model/CollectionSchema.java +++ b/src/main/java/com/arangodb/model/CollectionSchema.java @@ -22,6 +22,10 @@ package com.arangodb.model; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + /** * @author Michele Rastelli * @see API Documentation @@ -29,14 +33,6 @@ */ 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); - private String rule; private Level level; private String message; @@ -44,6 +40,7 @@ public class CollectionSchema { /** * @return JSON Schema description */ + @JsonSerialize(using = InternalSerializers.CollectionSchemaRuleSerializer.class) public String getRule() { return rule; } @@ -82,11 +79,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 +94,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/FulltextIndexOptions.java b/src/main/java/com/arangodb/model/FulltextIndexOptions.java index 9bf8f82a5..607e1b908 100644 --- a/src/main/java/com/arangodb/model/FulltextIndexOptions.java +++ b/src/main/java/com/arangodb/model/FulltextIndexOptions.java @@ -42,7 +42,7 @@ protected FulltextIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -55,7 +55,7 @@ protected FulltextIndexOptions fields(final Iterable 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..c55ba0c70 100644 --- a/src/main/java/com/arangodb/model/GeoIndexOptions.java +++ b/src/main/java/com/arangodb/model/GeoIndexOptions.java @@ -41,7 +41,7 @@ protected GeoIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -54,7 +54,7 @@ protected GeoIndexOptions fields(final Iterable fields) { return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 3af784ebb..6268a3718 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -47,7 +47,7 @@ protected HashIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -60,7 +60,7 @@ protected HashIndexOptions fields(final Iterable 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..7cafad173 100644 --- a/src/main/java/com/arangodb/model/IndexOptions.java +++ b/src/main/java/com/arangodb/model/IndexOptions.java @@ -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/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index c9ba08c34..d7a752cd2 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -30,7 +30,7 @@ public 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; @@ -45,7 +45,7 @@ protected PersistentIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -58,7 +58,7 @@ protected PersistentIndexOptions fields(final Iterable fields) { return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index 15f3dcdfe..981d7fa62 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -47,7 +47,7 @@ protected SkiplistIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -60,7 +60,7 @@ protected SkiplistIndexOptions fields(final Iterable fields) { return this; } - protected IndexType getType() { + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/TransactionOptions.java b/src/main/java/com/arangodb/model/TransactionOptions.java index e1226a1bd..249985805 100644 --- a/src/main/java/com/arangodb/model/TransactionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionOptions.java @@ -40,7 +40,7 @@ public TransactionOptions() { collections = new TransactionCollectionOptions(); } - protected String getAction() { + public String getAction() { return action; } diff --git a/src/main/java/com/arangodb/model/TtlIndexOptions.java b/src/main/java/com/arangodb/model/TtlIndexOptions.java index 59ee57e82..a12e45ceb 100644 --- a/src/main/java/com/arangodb/model/TtlIndexOptions.java +++ b/src/main/java/com/arangodb/model/TtlIndexOptions.java @@ -41,7 +41,7 @@ protected TtlIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -54,7 +54,7 @@ protected TtlIndexOptions fields(final Iterable 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/ZKDIndexOptions.java b/src/main/java/com/arangodb/model/ZKDIndexOptions.java index 4e570a9ad..6f17e5b87 100644 --- a/src/main/java/com/arangodb/model/ZKDIndexOptions.java +++ b/src/main/java/com/arangodb/model/ZKDIndexOptions.java @@ -21,6 +21,7 @@ package com.arangodb.model; import com.arangodb.entity.IndexType; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Michele Rastelli @@ -43,7 +44,7 @@ protected ZKDIndexOptions getThis() { return this; } - protected Iterable getFields() { + public Iterable getFields() { return fields; } @@ -56,7 +57,7 @@ protected ZKDIndexOptions fields(final Iterable 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/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index 26ab243ae..454d176ff 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -1,5 +1,6 @@ package com.arangodb.serde; +import com.arangodb.entity.CollectionType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.databind.Module; @@ -16,6 +17,7 @@ enum InternalModule implements Supplier { module = new SimpleModule(); module.addSerializer(AuthenticationRequest.class, InternalSerializers.AUTHENTICATION_REQUEST); module.addSerializer(Request.class, InternalSerializers.REQUEST); + module.addSerializer(CollectionType.class, InternalSerializers.COLLECTION_TYPE); } @Override diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 839c7e5f5..3d22df9fa 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -1,6 +1,7 @@ package com.arangodb.serde; import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public interface InternalSerde extends JacksonSerde { @@ -39,4 +40,11 @@ static InternalSerde of(final DataType dataType) { */ byte[] extract(byte[] content, String jsonPointer); + /** + * Parse a JSON string. + * @param json JSON string to parse + * @return root of the parsed tree + */ + JsonNode parseJson(String json); + } diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 4ef9b3c72..124ea7714 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -1,6 +1,7 @@ package com.arangodb.serde; import com.arangodb.ArangoDBException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -42,4 +43,13 @@ public byte[] extract(final byte[] content, final String jsonPointer) { } } + @Override + public JsonNode parseJson(final String json) { + try { + return jsonMapper.readTree(json); + } catch (JsonProcessingException e) { + throw new ArangoDBException(e); + } + } + } diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index feffa6c5a..9498c16cc 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -1,15 +1,26 @@ package com.arangodb.serde; +import com.arangodb.entity.CollectionType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; import java.util.Map; -final class InternalSerializers { +public final class InternalSerializers { + + private static final ObjectMapper jsonMapper = new ObjectMapper(); + + public static class CollectionSchemaRuleSerializer extends JsonSerializer { + @Override + public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeTree(jsonMapper.readTree(value)); + } + } private InternalSerializers() { } @@ -50,4 +61,11 @@ public void serialize(Request value, JsonGenerator gen, SerializerProvider seria } }; + 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/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index 2396d51b2..a2667a0d2 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -20,9 +20,11 @@ package com.arangodb.util; +import com.fasterxml.jackson.databind.JsonNode; + /** * @author Mark Vollmary */ public interface ArangoSerialization extends ArangoSerializer, ArangoDeserializer { - + JsonNode parseJson(String json); } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index d332312e9..cf4aa26e8 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -2807,7 +2807,7 @@ void changeProperties(ArangoCollection collection) { // revert changes CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions() .waitForSync(properties.getWaitForSync()) - .schema(CollectionSchema.NULL_SCHEMA) + .schema(null) ); if (isAtLeastVersion(3, 7)) { assertThat(revertedProperties.getSchema()).isNull(); diff --git a/src/test/java/com/arangodb/ArangoVertexCollectionTest.java b/src/test/java/com/arangodb/ArangoVertexCollectionTest.java index 84283f19f..84f6530e4 100644 --- a/src/test/java/com/arangodb/ArangoVertexCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoVertexCollectionTest.java @@ -58,7 +58,7 @@ static void init() { initCollections(COLLECTION_NAME); initGraph( GRAPH_NAME, - null, + Collections.emptyList(), new GraphCreateOptions().orphanCollections(COLLECTION_NAME) ); } From a069170faf24e3211ab5967d732cd03764a6203d Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 30 Jun 2022 09:32:48 +0200 Subject: [PATCH 06/52] serde serialization refactoring: vertex collection API --- .../java/com/arangodb/async/ArangoVertexCollectionTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java b/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java index cdaa860c8..3da69c137 100644 --- a/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java @@ -31,6 +31,7 @@ import java.util.Collection; +import java.util.Collections; import java.util.concurrent.ExecutionException; @@ -51,7 +52,7 @@ static void setup() throws InterruptedException, ExecutionException { db.createCollection(COLLECTION_NAME, null).get(); } final GraphCreateOptions options = new GraphCreateOptions().orphanCollections(COLLECTION_NAME); - db.createGraph(GRAPH_NAME, null, options).get(); + db.createGraph(GRAPH_NAME, Collections.emptyList(), options).get(); } @AfterEach From 6f8e892a088b6820108676577f5c5fcd96a5b6af Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 30 Jun 2022 12:44:33 +0200 Subject: [PATCH 07/52] serde serialization refactoring: ArangoSearch API --- .../arangodb/entity/DocumentUpdateEntity.java | 2 + .../com/arangodb/entity/EdgeUpdateEntity.java | 2 + .../arangodb/entity/VertexUpdateEntity.java | 2 + .../java/com/arangodb/entity/ViewType.java | 3 + .../arangosearch/ArangoSearchProperties.java | 4 ++ .../entity/arangosearch/CollectionLink.java | 6 ++ .../arangosearch/ConsolidationType.java | 8 ++- .../entity/arangosearch/FieldLink.java | 6 ++ .../entity/arangosearch/StoreValuesType.java | 4 ++ .../analyzer/NormAnalyzerProperties.java | 2 + .../SegmentationAnalyzerProperties.java | 3 + .../analyzer/StopwordsAnalyzerProperties.java | 8 +++ .../analyzer/TextAnalyzerProperties.java | 2 + .../velocypack/VPackDriverModule.java | 1 - .../internal/velocypack/VPackSerializers.java | 7 -- .../com/arangodb/model/CollectionSchema.java | 8 +++ .../arangodb/model/GraphCreateOptions.java | 2 - .../ArangoSearchCreateOptions.java | 72 ++++++++++++++++--- .../ArangoSearchPropertiesOptions.java | 52 +++++++++----- .../com/arangodb/serde/InternalSerdeImpl.java | 2 + .../arangodb/serde/InternalSerializers.java | 27 ++++++- .../com/arangodb/ArangoCollectionTest.java | 2 +- .../java/com/arangodb/ArangoGraphTest.java | 4 +- .../arangodb/ArangoVertexCollectionTest.java | 2 +- .../arangodb/async/ArangoDatabaseTest.java | 4 +- .../com/arangodb/async/ArangoGraphTest.java | 6 +- .../async/ArangoVertexCollectionTest.java | 3 +- 27 files changed, 195 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java index 009468000..c2bacbf94 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -22,6 +22,7 @@ import com.arangodb.velocypack.annotations.Expose; import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @param @@ -31,6 +32,7 @@ */ public class DocumentUpdateEntity extends DocumentEntity { + @JsonProperty("_oldRev") @SerializedName("_oldRev") private String oldRev; @Expose(deserialize = false) diff --git a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java index f872666a3..ea26e50ed 100644 --- a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java @@ -21,6 +21,7 @@ package com.arangodb.entity; import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Mark Vollmary @@ -28,6 +29,7 @@ */ public class EdgeUpdateEntity extends DocumentEntity { + @JsonProperty("_oldRev") @SerializedName("_oldRev") private String oldRev; diff --git a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java index 22d2d1078..89be57062 100644 --- a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java @@ -21,12 +21,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 { + @JsonProperty("_oldRev") @SerializedName("_oldRev") private String oldRev; 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 index 7353cba66..443ac0dfe 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java @@ -20,6 +20,9 @@ package com.arangodb.entity.arangosearch; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -80,6 +83,7 @@ public void setConsolidationPolicy(final ConsolidationPolicy consolidationPolicy this.consolidationPolicy = consolidationPolicy; } + @JsonSerialize(using = InternalSerializers.CollectionLinksSerializer.class) public Collection getLinks() { return links; } diff --git a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java index adf57d9da..897119991 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java @@ -20,6 +20,10 @@ package com.arangodb.entity.arangosearch; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -100,6 +104,7 @@ public CollectionLink fields(final FieldLink... fields) { return this; } + @JsonIgnore public String getName() { return name; } @@ -120,6 +125,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/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..4027498fe 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java @@ -1,5 +1,9 @@ package com.arangodb.entity.arangosearch; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -77,6 +81,7 @@ public FieldLink fields(final FieldLink... 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/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/analyzer/NormAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java index cb1bcfbb8..ec0d7820c 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java @@ -22,6 +22,7 @@ import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; @@ -34,6 +35,7 @@ public class NormAnalyzerProperties { private boolean accent; + @JsonProperty("case") @SerializedName("case") private SearchAnalyzerCase analyzerCase; 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..0140437c8 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java @@ -22,6 +22,7 @@ import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; @@ -31,9 +32,11 @@ */ public class SegmentationAnalyzerProperties { + @JsonProperty("break") @SerializedName("break") private BreakMode breakMode; + @JsonProperty("case") @SerializedName("case") private SearchAnalyzerCase analyzerCase; 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..d00809337 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; @@ -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/TextAnalyzerProperties.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java index b22f7bc34..5b68d0247 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java @@ -22,6 +22,7 @@ import com.arangodb.velocypack.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collections; import java.util.List; @@ -40,6 +41,7 @@ public TextAnalyzerProperties() { private boolean accent; + @JsonProperty("case") @SerializedName("case") private SearchAnalyzerCase analyzerCase; diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java index ca86c5946..3635f386c 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java @@ -75,7 +75,6 @@ public > void setup(final C context) { 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); diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java index 399c8c8b5..fd94cc022 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java @@ -27,7 +27,6 @@ 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; @@ -119,12 +118,6 @@ public class VPackSerializers { 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) { diff --git a/src/main/java/com/arangodb/model/CollectionSchema.java b/src/main/java/com/arangodb/model/CollectionSchema.java index bbc956c86..8aa7bf098 100644 --- a/src/main/java/com/arangodb/model/CollectionSchema.java +++ b/src/main/java/com/arangodb/model/CollectionSchema.java @@ -33,6 +33,14 @@ */ 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); + private String rule; private Level level; private String message; diff --git a/src/main/java/com/arangodb/model/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index 1f4c3780b..989999c08 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Objects; /** * @author Mark Vollmary @@ -66,7 +65,6 @@ public Collection getEdgeDefinitions() { * @return options */ protected GraphCreateOptions edgeDefinitions(final Collection edgeDefinitions) { - Objects.requireNonNull(edgeDefinitions); this.edgeDefinitions = edgeDefinitions; return this; } diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java index 2fcfe376b..66653bd5d 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java @@ -22,6 +22,11 @@ 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 @@ -32,12 +37,18 @@ public class ArangoSearchCreateOptions { 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) { @@ -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..5283169d3 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java @@ -20,26 +20,26 @@ 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; +import java.util.Collections; /** * @author Mark Vollmary */ public class ArangoSearchPropertiesOptions { - private final ArangoSearchProperties properties; - - 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 +50,7 @@ public ArangoSearchProperties getProperties() { * @return options */ public ArangoSearchPropertiesOptions consolidationIntervalMsec(final Long consolidationIntervalMsec) { - properties.setConsolidationIntervalMsec(consolidationIntervalMsec); + this.consolidationIntervalMsec = consolidationIntervalMsec; return this; } @@ -63,7 +63,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 +72,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 +81,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 +90,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/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 124ea7714..6ff759591 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -1,6 +1,7 @@ package com.arangodb.serde; import com.arangodb.ArangoDBException; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -14,6 +15,7 @@ class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { InternalSerdeImpl(DataType dataType, ObjectMapper mapper) { super(dataType, mapper); mapper.registerModule(InternalModule.INSTANCE.get()); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Override diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 9498c16cc..a6ec41e11 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -1,6 +1,9 @@ package com.arangodb.serde; import com.arangodb.entity.CollectionType; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.FieldLink; +import com.arangodb.entity.arangosearch.StoreValuesType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; @@ -9,7 +12,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; -import java.util.Map; +import java.util.*; public final class InternalSerializers { @@ -22,6 +25,28 @@ public void serialize(String value, JsonGenerator gen, SerializerProvider serial } } + 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() { } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index cf4aa26e8..d332312e9 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -2807,7 +2807,7 @@ void changeProperties(ArangoCollection collection) { // revert changes CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions() .waitForSync(properties.getWaitForSync()) - .schema(null) + .schema(CollectionSchema.NULL_SCHEMA) ); if (isAtLeastVersion(3, 7)) { assertThat(revertedProperties.getSchema()).isNull(); diff --git a/src/test/java/com/arangodb/ArangoGraphTest.java b/src/test/java/com/arangodb/ArangoGraphTest.java index 93aa505ce..f42d5848b 100644 --- a/src/test/java/com/arangodb/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/ArangoGraphTest.java @@ -165,7 +165,7 @@ 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(); @@ -229,7 +229,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(); diff --git a/src/test/java/com/arangodb/ArangoVertexCollectionTest.java b/src/test/java/com/arangodb/ArangoVertexCollectionTest.java index 84f6530e4..84283f19f 100644 --- a/src/test/java/com/arangodb/ArangoVertexCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoVertexCollectionTest.java @@ -58,7 +58,7 @@ static void init() { initCollections(COLLECTION_NAME); initGraph( GRAPH_NAME, - Collections.emptyList(), + null, new GraphCreateOptions().orphanCollections(COLLECTION_NAME) ); } diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index 01a34350b..b58e1e6ef 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -847,7 +847,7 @@ void createGetDeleteAqlFunctionWithNamespace() throws InterruptedException, Exec @Test void createGraph() throws InterruptedException, ExecutionException { try { - db.createGraph(GRAPH_NAME, Collections.emptyList(), null) + db.createGraph(GRAPH_NAME, null, null) .whenComplete((result, ex) -> { assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo(GRAPH_NAME); @@ -861,7 +861,7 @@ void createGraph() throws InterruptedException, ExecutionException { @Test void getGraphs() throws InterruptedException, ExecutionException { try { - db.createGraph(GRAPH_NAME, Collections.emptyList(), null).get(); + db.createGraph(GRAPH_NAME, null, null).get(); db.getGraphs() .whenComplete((graphs, ex) -> { assertThat(graphs).isNotNull(); diff --git a/src/test/java/com/arangodb/async/ArangoGraphTest.java b/src/test/java/com/arangodb/async/ArangoGraphTest.java index 93a266c0f..60658aa86 100644 --- a/src/test/java/com/arangodb/async/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/async/ArangoGraphTest.java @@ -85,7 +85,7 @@ void teardown() throws InterruptedException, ExecutionException { @Test void create() throws InterruptedException, ExecutionException { try { - final GraphEntity result = db.graph(GRAPH_NAME + "_1").create(Collections.emptyList()).get(); + final GraphEntity result = db.graph(GRAPH_NAME + "_1").create(null).get(); assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo(GRAPH_NAME + "_1"); } finally { @@ -169,7 +169,7 @@ 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(); @@ -229,7 +229,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(); diff --git a/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java b/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java index 3da69c137..cdaa860c8 100644 --- a/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoVertexCollectionTest.java @@ -31,7 +31,6 @@ import java.util.Collection; -import java.util.Collections; import java.util.concurrent.ExecutionException; @@ -52,7 +51,7 @@ static void setup() throws InterruptedException, ExecutionException { db.createCollection(COLLECTION_NAME, null).get(); } final GraphCreateOptions options = new GraphCreateOptions().orphanCollections(COLLECTION_NAME); - db.createGraph(GRAPH_NAME, Collections.emptyList(), options).get(); + db.createGraph(GRAPH_NAME, null, options).get(); } @AfterEach From 5afdba0cd5a0aa988529a46a2322f351cb05a48c Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 30 Jun 2022 17:27:53 +0200 Subject: [PATCH 08/52] SerdeUtils --- .../internal/InternalArangoCollection.java | 3 +- .../util/DefaultArangoSerialization.java | 4 -- .../java/com/arangodb/mapping/ArangoJack.java | 5 --- .../com/arangodb/serde/InternalSerde.java | 8 ---- .../com/arangodb/serde/InternalSerdeImpl.java | 13 +------ .../arangodb/serde/InternalSerializers.java | 10 ++--- .../java/com/arangodb/serde/SerdeUtils.java | 39 +++++++++++++++++++ .../arangodb/util/ArangoSerialization.java | 3 -- 8 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 src/main/java/com/arangodb/serde/SerdeUtils.java diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 4d9bcbba9..2f48005dc 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -28,6 +28,7 @@ import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; +import com.arangodb.serde.SerdeUtils; import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.Type; import com.arangodb.velocypack.VPackSlice; @@ -180,7 +181,7 @@ protected ResponseDeserializer>> } protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(util().serialize(util().parseJson(values))); + return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(util().serialize(SerdeUtils.INSTANCE.parseJson(values))); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { diff --git a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java index f9ae383d3..8672016bd 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -73,8 +73,4 @@ public T deserialize(final VPackSlice vpack, final Type type) throws ArangoD return deserializer.deserialize(vpack, type); } - @Override - public JsonNode parseJson(String json) { - return serde.parseJson(json); - } } diff --git a/src/main/java/com/arangodb/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index b768ea727..132a724b2 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -51,11 +51,6 @@ */ public class ArangoJack implements ArangoSerialization { - @Override - public JsonNode parseJson(String json) { - return null; - } - public interface ConfigureFunction { void configure(ObjectMapper mapper); } diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 3d22df9fa..839c7e5f5 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -1,7 +1,6 @@ package com.arangodb.serde; import com.arangodb.jackson.dataformat.velocypack.VPackMapper; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public interface InternalSerde extends JacksonSerde { @@ -40,11 +39,4 @@ static InternalSerde of(final DataType dataType) { */ byte[] extract(byte[] content, String jsonPointer); - /** - * Parse a JSON string. - * @param json JSON string to parse - * @return root of the parsed tree - */ - JsonNode parseJson(String json); - } diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 6ff759591..a56bb25f8 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -2,7 +2,6 @@ import com.arangodb.ArangoDBException; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -10,7 +9,6 @@ import java.nio.charset.StandardCharsets; class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { - private final ObjectMapper jsonMapper = new ObjectMapper(); InternalSerdeImpl(DataType dataType, ObjectMapper mapper) { super(dataType, mapper); @@ -26,7 +24,7 @@ public String toJsonString(final byte[] content) { case VPACK: try { JsonNode tree = mapper.readTree(content); - return jsonMapper.writeValueAsString(tree); + return SerdeUtils.INSTANCE.writeJson(tree); } catch (IOException e) { throw new ArangoDBException(e); } @@ -45,13 +43,4 @@ public byte[] extract(final byte[] content, final String jsonPointer) { } } - @Override - public JsonNode parseJson(final String json) { - try { - return jsonMapper.readTree(json); - } catch (JsonProcessingException e) { - throw new ArangoDBException(e); - } - } - } diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index a6ec41e11..bcdb81fc9 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -3,25 +3,23 @@ import com.arangodb.entity.CollectionType; import com.arangodb.entity.arangosearch.CollectionLink; import com.arangodb.entity.arangosearch.FieldLink; -import com.arangodb.entity.arangosearch.StoreValuesType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; public final class InternalSerializers { - private static final ObjectMapper jsonMapper = new ObjectMapper(); - public static class CollectionSchemaRuleSerializer extends JsonSerializer { @Override public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeTree(jsonMapper.readTree(value)); + gen.writeTree(SerdeUtils.INSTANCE.parseJson(value)); } } 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..27e0c9eae --- /dev/null +++ b/src/main/java/com/arangodb/serde/SerdeUtils.java @@ -0,0 +1,39 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDBException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public enum SerdeUtils { + INSTANCE; + + private 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); + } + } + +} diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index a2667a0d2..c6f710171 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -20,11 +20,8 @@ package com.arangodb.util; -import com.fasterxml.jackson.databind.JsonNode; - /** * @author Mark Vollmary */ public interface ArangoSerialization extends ArangoSerializer, ArangoDeserializer { - JsonNode parseJson(String json); } From dcc54e6880b6bc5bf99fa2e13070abb80df630a6 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 30 Jun 2022 20:19:34 +0200 Subject: [PATCH 09/52] serde serialization refactoring: View API --- .../java/com/arangodb/entity/LogLevelEntity.java | 4 ++++ .../com/arangodb/model/ViewCreateOptions.java | 8 ++++++++ .../java/com/arangodb/serde/InternalModule.java | 2 ++ .../com/arangodb/serde/InternalSerializers.java | 15 +++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/src/main/java/com/arangodb/entity/LogLevelEntity.java b/src/main/java/com/arangodb/entity/LogLevelEntity.java index adcc1b393..1801d0cea 100644 --- a/src/main/java/com/arangodb/entity/LogLevelEntity.java +++ b/src/main/java/com/arangodb/entity/LogLevelEntity.java @@ -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/model/ViewCreateOptions.java b/src/main/java/com/arangodb/model/ViewCreateOptions.java index b2287a6de..0fa34d0aa 100644 --- a/src/main/java/com/arangodb/model/ViewCreateOptions.java +++ b/src/main/java/com/arangodb/model/ViewCreateOptions.java @@ -46,4 +46,12 @@ protected ViewCreateOptions type(final ViewType type) { return this; } + public String getName() { + return name; + } + + public ViewType getType() { + return type; + } + } diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index 454d176ff..c30b5c663 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -2,6 +2,7 @@ import com.arangodb.entity.CollectionType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; +import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -16,6 +17,7 @@ enum InternalModule implements Supplier { InternalModule() { module = new SimpleModule(); 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); } diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index bcdb81fc9..1917fc45b 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -1,9 +1,12 @@ package com.arangodb.serde; +import com.arangodb.entity.BaseDocument; 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.velocypack.ValueType; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; @@ -61,6 +64,18 @@ public void serialize(AuthenticationRequest value, JsonGenerator gen, Serializer } }; + 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 { From 508393c4a2de93bc925fcb69387e20b431275a14 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 1 Jul 2022 10:24:11 +0200 Subject: [PATCH 10/52] serde serialization refactoring: ArangoJack --- src/main/java/com/arangodb/ArangoDB.java | 2 +- .../com/arangodb/entity/BaseDocument.java | 4 ++ .../internal/InternalArangoCollection.java | 8 ++- .../internal/mapping/VPackDeserializers.java | 18 ------ .../internal/mapping/VPackSerializers.java | 35 ---------- .../util/DefaultArangoSerialization.java | 1 - .../java/com/arangodb/mapping/ArangoJack.java | 64 ++++++++----------- .../com/arangodb/serde/InternalSerdeImpl.java | 3 + .../com/arangodb/example/ExampleBase.java | 7 +- 9 files changed, 44 insertions(+), 98 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index 5dbad9ef3..ec3265318 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -378,7 +378,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, internal, protocol, connectionTtl, httpCookieSpec, httpRequestRetryHandler); final Collection hostList = createHostList(max, connectionFactory); diff --git a/src/main/java/com/arangodb/entity/BaseDocument.java b/src/main/java/com/arangodb/entity/BaseDocument.java index 2d6fe1967..72ea06cdc 100644 --- a/src/main/java/com/arangodb/entity/BaseDocument.java +++ b/src/main/java/com/arangodb/entity/BaseDocument.java @@ -21,6 +21,8 @@ package com.arangodb.entity; import com.arangodb.internal.DocumentFields; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import java.io.Serializable; import java.util.HashMap; @@ -92,6 +94,7 @@ public void setRevision(final String revision) { this.revision = revision; } + @JsonAnyGetter public Map getProperties() { return properties; } @@ -100,6 +103,7 @@ public void setProperties(final Map properties) { this.properties = properties; } + @JsonAnySetter public void addAttribute(final String key, final Object value) { properties.put(key, value); } diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 2f48005dc..7314b325e 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -92,7 +92,13 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - request.setBody(util(Serializer.CUSTOM).serialize(value)); + VPackSlice body; + if (value instanceof String) { + body = util().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + } else { + body = util(Serializer.CUSTOM).serialize(value); + } + request.setBody(body); return request; } diff --git a/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java b/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java index a30d9d0cf..6402a9e26 100644 --- a/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java +++ b/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java @@ -93,22 +93,4 @@ public java.sql.Timestamp deserialize(final JsonParser p, final DeserializationC } }; - 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 index eb4b4ad8f..3f8f34577 100644 --- a/src/main/java/com/arangodb/internal/mapping/VPackSerializers.java +++ b/src/main/java/com/arangodb/internal/mapping/VPackSerializers.java @@ -21,9 +21,6 @@ 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; @@ -35,8 +32,6 @@ import java.io.IOException; import java.sql.Date; import java.sql.Timestamp; -import java.util.HashMap; -import java.util.Map; /** * @author Mark Vollmary @@ -79,34 +74,4 @@ public void serialize(final Timestamp value, final JsonGenerator gen, final Seri } }; - 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/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java index 8672016bd..166f36644 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -28,7 +28,6 @@ import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; -import com.fasterxml.jackson.databind.JsonNode; import java.lang.reflect.Type; diff --git a/src/main/java/com/arangodb/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index 132a724b2..06fb8e695 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -21,20 +21,18 @@ 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.serde.DataType; +import com.arangodb.serde.JacksonSerde; 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; @@ -44,7 +42,6 @@ import java.io.IOException; import java.lang.reflect.Type; import java.util.Arrays; -import java.util.Iterator; /** * @author Mark Vollmary @@ -60,6 +57,8 @@ public interface ConfigureFunction { private final ObjectMapper jsonMapper; private final VPackParser vpackParser; + private final JacksonSerde serde; + private static final class ArangoModule extends SimpleModule { @Override public void setupModule(SetupContext context) { @@ -73,39 +72,43 @@ static VPackMapper createDefaultMapper() { mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + return configureDefaultMapper(mapper); + } + static VPackMapper configureDefaultMapper(final VPackMapper mapper) { 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()); + this(createDefaultMapper(), JacksonSerde.of(DataType.VPACK, configureDefaultMapper(new VPackMapper()))); + } + + public ArangoJack(final JacksonSerde jacksonSerde) { + this(createDefaultMapper(), jacksonSerde); } /** * @param mapper configured VPackMapper to use. A defensive copy is created and used. */ - public ArangoJack(final VPackMapper mapper) { + public ArangoJack(final VPackMapper mapper, final JacksonSerde jacksonSerde) { 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(); + this.serde = jacksonSerde; } public void configure(final ArangoJack.ConfigureFunction f) { @@ -116,37 +119,24 @@ public void configure(final ArangoJack.ConfigureFunction f) { @Override public VPackSlice serialize(final Object entity) throws ArangoDBException { - return serialize(entity, new ArangoSerializer.Options()); + DataType dataType = serde.getDataType(); + switch (dataType) { + case JSON: + String json = new String(serde.serialize(entity)); + VPackParser parser = new VPackParser.Builder().build(); + return parser.fromJson(json, true); + case VPACK: + return new VPackSlice(serde.serialize(entity)); + default: + throw new IllegalStateException("Unexpected value: " + dataType); + } + } @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); - } + return serialize(entity); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index a56bb25f8..10b46c980 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -17,6 +17,9 @@ class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { } @Override + // FIXME: refactor to: + // return SerdeUtils.INSTANCE.writeJson(mapper.readTree(content)); + // afterwards dataType should not be needed anymore public String toJsonString(final byte[] content) { switch (dataType) { case JSON: diff --git a/src/test/java/com/arangodb/example/ExampleBase.java b/src/test/java/com/arangodb/example/ExampleBase.java index b4bd582e6..0c189b295 100644 --- a/src/test/java/com/arangodb/example/ExampleBase.java +++ b/src/test/java/com/arangodb/example/ExampleBase.java @@ -20,10 +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.*; import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -42,7 +39,7 @@ public class ExampleBase { @BeforeAll static void setUp() { - arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); + arangoDB = new ArangoDB.Builder().useProtocol(Protocol.VST).serializer(new ArangoJack()).build(); DbName dbName = DbName.of(DB_NAME); if (arangoDB.db(dbName).exists()) arangoDB.db(dbName).drop(); From 3fe5e55f6254a51ee46899e11c98e864774b8c0a Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 1 Jul 2022 11:59:43 +0200 Subject: [PATCH 11/52] serde serialization refactoring: Collection API --- .../internal/InternalArangoCollection.java | 36 ++++++++++++------ .../arangodb/model/DocumentUpdateOptions.java | 16 -------- .../com/arangodb/ArangoCollectionTest.java | 37 ++++++++++++++++--- .../com/arangodb/example/ExampleBase.java | 2 +- .../arangodb/serde/CustomTypeHintTest.java | 4 +- 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 7314b325e..6d2082750 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -29,11 +29,11 @@ import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; import com.arangodb.serde.SerdeUtils; -import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.Type; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; +import com.fasterxml.jackson.databind.JsonNode; import java.util.*; @@ -137,8 +137,9 @@ protected Request insertDocumentsRequest(final Collection values, final D 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))); + VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) + : util(Serializer.CUSTOM).serialize(values); + request.setBody(body); return request; } @@ -191,8 +192,9 @@ protected Request importDocumentsRequest(final String values, final DocumentImpo } 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))); + VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) + : util(Serializer.CUSTOM).serialize(values); + return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(body); } protected Request importDocumentsRequest(final DocumentImportOptions options) { @@ -304,8 +306,10 @@ 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))); + + VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) + : util(Serializer.CUSTOM).serialize(values); + request.setBody(body); return request; } @@ -366,8 +370,7 @@ 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(util(Serializer.CUSTOM).serialize(value)); return request; } @@ -405,9 +408,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))); + + VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) + : util(Serializer.CUSTOM).serialize(values); + request.setBody(body); return request; } @@ -699,4 +703,12 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() }; } + private boolean isStringCollection(final Collection values) { + return values.stream().allMatch(String.class::isInstance); + } + + private JsonNode stringCollectionToJsonArray(final Collection values) { + return SerdeUtils.INSTANCE.parseJson("[" + String.join(",", values) + "]"); + } + } diff --git a/src/main/java/com/arangodb/model/DocumentUpdateOptions.java b/src/main/java/com/arangodb/model/DocumentUpdateOptions.java index 20d7b8cca..4ca261670 100644 --- a/src/main/java/com/arangodb/model/DocumentUpdateOptions.java +++ b/src/main/java/com/arangodb/model/DocumentUpdateOptions.java @@ -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/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index d332312e9..2e6ef6278 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -39,6 +39,8 @@ import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.util.MapBuilder; import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonIncludeProperties; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeAll; @@ -161,6 +163,7 @@ void insertDocumentReturnNew(ArangoCollection collection) { assertThat(doc.getRev()).isNotNull(); assertThat(doc.getNew()).isNotNull(); } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void insertDocumentOverwriteModeIgnore(ArangoCollection collection) { @@ -732,6 +735,29 @@ void updateDocumentKeepNullFalse(ArangoCollection collection) { static class TestUpdateEntity { @SuppressWarnings("unused") private String a, b; + + public String getA() { + return a; + } + + public String getB() { + return b; + } + } + + 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}") @@ -758,14 +784,14 @@ 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()); @@ -2752,6 +2778,7 @@ void replaceDocumentsJson(ArangoCollection collection) { assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void getInfo(ArangoCollection collection) { diff --git a/src/test/java/com/arangodb/example/ExampleBase.java b/src/test/java/com/arangodb/example/ExampleBase.java index 0c189b295..b903a31d5 100644 --- a/src/test/java/com/arangodb/example/ExampleBase.java +++ b/src/test/java/com/arangodb/example/ExampleBase.java @@ -39,7 +39,7 @@ public class ExampleBase { @BeforeAll static void setUp() { - arangoDB = new ArangoDB.Builder().useProtocol(Protocol.VST).serializer(new ArangoJack()).build(); + arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); DbName dbName = DbName.of(DB_NAME); if (arangoDB.db(dbName).exists()) arangoDB.db(dbName).drop(); diff --git a/src/test/java/com/arangodb/serde/CustomTypeHintTest.java b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java index a19eda063..f3e9bf046 100644 --- a/src/test/java/com/arangodb/serde/CustomTypeHintTest.java +++ b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java @@ -25,9 +25,9 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDatabase; import com.arangodb.DbName; +import com.arangodb.entity.Key; import com.arangodb.mapping.ArangoJack; 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 +61,7 @@ public void setName(String name) { public static class Zoo { - @JsonProperty("_key") + @Key private String key; private Animal animal; From 663afe67a1f005d0c22dcb162c5c9f8510a92a13 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 1 Jul 2022 12:17:31 +0200 Subject: [PATCH 12/52] JacksonSerde configuration --- src/main/java/com/arangodb/mapping/ArangoJack.java | 11 ++++------- src/main/java/com/arangodb/serde/JacksonSerde.java | 7 +++++++ .../java/com/arangodb/serde/JacksonSerdeImpl.java | 6 ++++++ src/test/java/com/arangodb/serde/CustomSerdeTest.java | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/arangodb/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index 06fb8e695..e8c318232 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -92,29 +92,26 @@ static VPackMapper configureDefaultMapper(final VPackMapper mapper) { } public ArangoJack() { - this(createDefaultMapper(), JacksonSerde.of(DataType.VPACK, configureDefaultMapper(new VPackMapper()))); - } - - public ArangoJack(final JacksonSerde jacksonSerde) { - this(createDefaultMapper(), jacksonSerde); + this(createDefaultMapper()); } /** * @param mapper configured VPackMapper to use. A defensive copy is created and used. */ - public ArangoJack(final VPackMapper mapper, final JacksonSerde jacksonSerde) { + 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(); - this.serde = jacksonSerde; + serde = JacksonSerde.of(DataType.VPACK, configureDefaultMapper(new VPackMapper())); } public void configure(final ArangoJack.ConfigureFunction f) { f.configure(vpackMapper); f.configure(vpackMapperNull); f.configure(jsonMapper); + serde.configure(f::configure); } @Override diff --git a/src/main/java/com/arangodb/serde/JacksonSerde.java b/src/main/java/com/arangodb/serde/JacksonSerde.java index 9887a7767..91d9ede18 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerde.java +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.lang.reflect.Type; +import java.util.function.Consumer; /** * Contract for serialization/deserialization of user data, based on Jackson Databind. @@ -40,6 +41,12 @@ static JacksonSerde of(final DataType dataType, final ObjectMapper mapper) { return new JacksonSerdeImpl(dataType, mapper); } + /** + * Allows configuring the underlying Jackson ObjectMapper + * @param configureFunction function to configure the Jackson ObjectMapper + */ + void configure(final Consumer configureFunction); + /** * Deserializes the parsed json node and binds it to the target data type. * diff --git a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java index 3964f0ea4..e6c373a04 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.lang.reflect.Type; +import java.util.function.Consumer; class JacksonSerdeImpl implements JacksonSerde { @@ -41,6 +42,11 @@ public T deserialize(final byte[] content, final Type type) { } } + @Override + public void configure(Consumer configureFunction) { + configureFunction.accept(mapper); + } + @Override public T deserialize(final JsonNode node, final Type type) { try { diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index 834d1cd56..e5cd72078 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -26,6 +26,7 @@ import com.arangodb.ArangoDatabase; import com.arangodb.DbName; import com.arangodb.entity.BaseDocument; +import com.arangodb.jackson.dataformat.velocypack.VPackMapper; import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; import com.arangodb.util.ArangoSerialization; From 59e861d8d35274f34a193dbe51b2f223d076d3b0 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 1 Jul 2022 12:54:30 +0200 Subject: [PATCH 13/52] VPackSlice serializer --- .../java/com/arangodb/model/AqlQueryOptions.java | 4 ++-- .../java/com/arangodb/serde/InternalModule.java | 2 ++ .../com/arangodb/serde/InternalSerializers.java | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index ddb5a4f16..56fc50c68 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -151,7 +151,7 @@ public AqlQueryOptions fillBlockCache(final Boolean fillBlockCache) { return this; } - protected VPackSlice getBindVars() { + public VPackSlice getBindVars() { return bindVars; } @@ -172,7 +172,7 @@ public 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; } diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index c30b5c663..2c8d1442d 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -3,6 +3,7 @@ import com.arangodb.entity.CollectionType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; +import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -16,6 +17,7 @@ enum InternalModule implements Supplier { InternalModule() { module = new SimpleModule(); + module.addSerializer(VPackSlice.class, InternalSerializers.VPACK_SLICE_JSON_SERIALIZER); module.addSerializer(AuthenticationRequest.class, InternalSerializers.AUTHENTICATION_REQUEST); module.addSerializer(JwtAuthenticationRequest.class, InternalSerializers.JWT_AUTHENTICATION_REQUEST); module.addSerializer(Request.class, InternalSerializers.REQUEST); diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 1917fc45b..46514b8c3 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -1,12 +1,12 @@ package com.arangodb.serde; -import com.arangodb.entity.BaseDocument; 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.velocypack.ValueType; +import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; @@ -48,9 +48,18 @@ public void serialize(Collection value, JsonGenerator gen, Seria } } + private static final VPackMapper vPackMapper = new VPackMapper(); + private InternalSerializers() { } + static final JsonSerializer VPACK_SLICE_JSON_SERIALIZER = new JsonSerializer() { + @Override + public void serialize(VPackSlice value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeObject(vPackMapper.readTree(value.toByteArray())); + } + }; + static final JsonSerializer AUTHENTICATION_REQUEST = new JsonSerializer() { @Override public void serialize(AuthenticationRequest value, JsonGenerator gen, SerializerProvider serializers) throws IOException { From 9a6d67a740c5a7598981b8eca950bc230869e566 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 1 Jul 2022 13:04:34 +0200 Subject: [PATCH 14/52] serde serialization refactoring: Transactions API --- src/main/java/com/arangodb/model/TransactionOptions.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/arangodb/model/TransactionOptions.java b/src/main/java/com/arangodb/model/TransactionOptions.java index 249985805..ebe31c7d9 100644 --- a/src/main/java/com/arangodb/model/TransactionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionOptions.java @@ -40,6 +40,10 @@ public TransactionOptions() { collections = new TransactionCollectionOptions(); } + public TransactionCollectionOptions getCollections() { + return collections; + } + public String getAction() { return action; } From c496c86328545188f3ed44cb4abb3b9490273b7c Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 1 Jul 2022 13:07:18 +0200 Subject: [PATCH 15/52] serde serialization refactoring: Cursor API --- .../InternalArangoVertexCollection.java | 10 +++- .../com/arangodb/model/AqlQueryOptions.java | 58 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 0472adbb9..4962fa6fa 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -27,6 +27,7 @@ import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; +import com.arangodb.serde.SerdeUtils; import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; @@ -73,7 +74,14 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio 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)); + + VPackSlice body; + if (value instanceof String) { + body = util().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + } else { + body = util(Serializer.CUSTOM).serialize(value); + } + request.setBody(body); return request; } diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 56fc50c68..51e8494f7 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -402,7 +402,7 @@ public AqlQueryOptions shardIds(final String... shardIds) { return this; } - private Options getOptions() { + public Options getOptions() { if (options == null) { options = new Options(); } @@ -429,6 +429,58 @@ public static class Options implements Serializable { private Double maxRuntime; private Boolean fillBlockCache; + 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(); @@ -447,6 +499,10 @@ public Collection getShardIds() { public static class Optimizer { private Collection rules; + + public Collection getRules() { + return rules; + } } /** From 77b1f93d5d3132fe417fa3ccf8f91ce134e74713 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 5 Jul 2022 12:27:42 +0200 Subject: [PATCH 16/52] ReplicationFactor refactoring --- .../entity/CollectionPropertiesEntity.java | 22 +++------ .../com/arangodb/entity/DatabaseEntity.java | 15 ++----- .../java/com/arangodb/entity/GraphEntity.java | 8 +--- .../arangodb/entity/ReplicationFactor.java | 45 +++++++++++-------- .../velocypack/VPackDeserializers.java | 6 +-- .../velocypack/VPackDriverModule.java | 1 - .../internal/velocypack/VPackSerializers.java | 9 ---- .../model/CollectionCreateOptions.java | 35 +++++++-------- .../com/arangodb/model/DatabaseOptions.java | 36 +++++++-------- .../arangodb/model/GraphCreateOptions.java | 42 ++++++----------- .../model/VertexCollectionCreateOptions.java | 4 ++ src/test/java/com/arangodb/ArangoDBTest.java | 8 ++-- .../java/com/arangodb/ArangoDatabaseTest.java | 21 ++++----- .../java/com/arangodb/ArangoGraphTest.java | 21 ++++----- .../java/com/arangodb/async/ArangoDBTest.java | 8 ++-- .../arangodb/async/ArangoDatabaseTest.java | 5 +-- .../com/arangodb/async/ArangoGraphTest.java | 27 +++++------ 17 files changed, 127 insertions(+), 186 deletions(-) diff --git a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java index 73f55d758..050104ffe 100644 --- a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java @@ -33,14 +33,13 @@ public class CollectionPropertiesEntity extends CollectionEntity { 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/DatabaseEntity.java b/src/main/java/com/arangodb/entity/DatabaseEntity.java index 975065f50..524db2c63 100644 --- a/src/main/java/com/arangodb/entity/DatabaseEntity.java +++ b/src/main/java/com/arangodb/entity/DatabaseEntity.java @@ -30,13 +30,12 @@ public class DatabaseEntity implements Entity { 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/GraphEntity.java b/src/main/java/com/arangodb/entity/GraphEntity.java index 151979131..858a60acd 100644 --- a/src/main/java/com/arangodb/entity/GraphEntity.java +++ b/src/main/java/com/arangodb/entity/GraphEntity.java @@ -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/ReplicationFactor.java b/src/main/java/com/arangodb/entity/ReplicationFactor.java index b228f3f66..9b84bbf4f 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; - } + 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/internal/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java index 344b66983..f2cad52d6 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java @@ -141,13 +141,11 @@ public class VPackDeserializers { 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); + return ReplicationFactor.ofSatellite(); } else { - replicationFactor.setReplicationFactor(vpack.getAsInt()); + return ReplicationFactor.of(vpack.getAsInt()); } - return replicationFactor; }; public static final VPackDeserializer VIEW_TYPE = (parent, vpack, context) -> "arangosearch".equals(vpack.getAsString()) ? ViewType.ARANGO_SEARCH diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java index 3635f386c..5172f8e3a 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java @@ -73,7 +73,6 @@ public > void setup(final C context) { 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(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES); context.registerSerializer(ConsolidationType.class, VPackSerializers.CONSOLIDATE_TYPE); diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java index fd94cc022..56494405f 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java @@ -104,15 +104,6 @@ public class VPackSerializers { 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); diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index 5dafdf6f2..4f98a9dcd 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -35,7 +35,7 @@ public class CollectionCreateOptions { private String name; - private final ReplicationFactor replicationFactor; + private ReplicationFactor replicationFactor; private Integer writeConcern; private KeyOptions keyOptions; private Boolean waitForSync; @@ -52,7 +52,6 @@ public class CollectionCreateOptions { public CollectionCreateOptions() { super(); - replicationFactor = new ReplicationFactor(); } public String getName() { @@ -68,8 +67,8 @@ protected CollectionCreateOptions name(final String name) { return this; } - public Integer getReplicationFactor() { - return replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return replicationFactor; } /** @@ -82,8 +81,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; } @@ -104,20 +113,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; } diff --git a/src/main/java/com/arangodb/model/DatabaseOptions.java b/src/main/java/com/arangodb/model/DatabaseOptions.java index 81052c6c5..df5cca03b 100644 --- a/src/main/java/com/arangodb/model/DatabaseOptions.java +++ b/src/main/java/com/arangodb/model/DatabaseOptions.java @@ -28,27 +28,22 @@ */ public 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/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index 989999c08..f6453a4e1 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -110,8 +110,8 @@ public GraphCreateOptions isDisjoint(final Boolean isDisjoint) { return this; } - public Integer getReplicationFactor() { - return getOptions().replicationFactor.getReplicationFactor(); + public ReplicationFactor getReplicationFactor() { + return getOptions().replicationFactor; } /** @@ -124,23 +124,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; } @@ -204,7 +199,7 @@ public GraphCreateOptions satellites(final String... satellites) { return this; } - private SmartOptions getOptions() { + public SmartOptions getOptions() { if (options == null) { options = new SmartOptions(); } @@ -221,23 +216,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/VertexCollectionCreateOptions.java b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java index 4013a2c74..2e4f97a9c 100644 --- a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java @@ -48,6 +48,10 @@ protected VertexCollectionCreateOptions collection(final String collection) { return this; } + public Options getOptions() { + return options; + } + public Collection getSatellites() { return options.satellites; } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 4495121d0..284ae526e 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -147,10 +147,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(); @@ -168,15 +167,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(); diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 35073c24b..068107c5e 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -115,8 +115,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 +130,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 +142,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}") @@ -1079,14 +1076,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 +1099,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); } } diff --git a/src/test/java/com/arangodb/ArangoGraphTest.java b/src/test/java/com/arangodb/ArangoGraphTest.java index f42d5848b..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); } } @@ -170,7 +171,7 @@ void addSatelliteVertexCollection(ArangoDatabase db) { 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); } @@ -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/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 965f84a3a..429f2c643 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -169,10 +169,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(); @@ -189,15 +188,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(); diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index b58e1e6ef..54df6dedb 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -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(); } diff --git a/src/test/java/com/arangodb/async/ArangoGraphTest.java b/src/test/java/com/arangodb/async/ArangoGraphTest.java index 60658aa86..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); } } } @@ -174,7 +171,7 @@ void addSatelliteVertexCollection() throws ExecutionException, InterruptedExcept 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(); @@ -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 From 6a161fedec92f570785fae231210de822da4fb6e Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 5 Jul 2022 13:01:11 +0200 Subject: [PATCH 17/52] ArangoSerializer refactoring --- .../arangodb/ArangoSerializationAccessor.java | 11 +- .../async/internal/ArangoDBAsyncImpl.java | 9 +- .../com/arangodb/internal/ArangoDBImpl.java | 7 +- .../arangodb/internal/ArangoExecuteable.java | 14 ++- .../com/arangodb/internal/ArangoExecutor.java | 5 +- .../internal/InternalArangoCollection.java | 113 +++++++++--------- .../arangodb/internal/InternalArangoDB.java | 22 ++-- .../internal/InternalArangoDatabase.java | 57 +++++---- .../InternalArangoEdgeCollection.java | 15 ++- .../internal/InternalArangoGraph.java | 16 +-- .../internal/InternalArangoRoute.java | 2 +- .../internal/InternalArangoSearch.java | 4 +- .../InternalArangoVertexCollection.java | 17 ++- .../arangodb/internal/InternalArangoView.java | 2 +- .../internal/cursor/ArangoCursorIterator.java | 3 +- .../util/ArangoSerializationFactory.java | 28 ++--- src/test/java/com/arangodb/JwtAuthTest.java | 2 +- .../java/com/arangodb/async/JwtAuthTest.java | 2 +- .../com/arangodb/serde/CustomSerdeTest.java | 5 +- .../util/ArangoSerializationTest.java | 2 +- 20 files changed, 160 insertions(+), 176 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoSerializationAccessor.java b/src/main/java/com/arangodb/ArangoSerializationAccessor.java index f140f054e..1bd7dcfa4 100644 --- a/src/main/java/com/arangodb/ArangoSerializationAccessor.java +++ b/src/main/java/com/arangodb/ArangoSerializationAccessor.java @@ -20,7 +20,6 @@ package com.arangodb; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.util.ArangoSerialization; /** @@ -29,19 +28,17 @@ public interface ArangoSerializationAccessor { /** - * Returns driver internal serialization API for serializing and deserializing Java POJOs to/from {@link com.arangodb.velocypack.VPackSlice} + * Returns driver internal serialization implementation for serializing and deserializing driver's classes. * * @return ArangoSerialization */ - ArangoSerialization util(); + ArangoSerialization getInternalSerialization(); /** - * Returns serialization API for serializing and deserializing Java POJOs to/from {@link com.arangodb.velocypack.VPackSlice} by the given - * type + * Returns serialization implementation for serializing and deserializing user's classes. * - * @param serializer type of serializer * @return ArangoSerialization */ - ArangoSerialization util(Serializer serializer); + ArangoSerialization getUserSerialization(); } diff --git a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java index 23cf6af31..70c2ef595 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java @@ -32,7 +32,6 @@ 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.internal.velocystream.VstCommunication; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; @@ -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.getInternalSerialization()), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, context); - final VstCommunication cacheCom = syncCommBuilder.build(util.get(Serializer.INTERNAL)); + final VstCommunication cacheCom = syncCommBuilder.build(util.getInternalSerialization()); 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.getInternalSerialization()); + syncHostResolver.init(arangoExecutorSync, util.getInternalSerialization()); } diff --git a/src/main/java/com/arangodb/internal/ArangoDBImpl.java b/src/main/java/com/arangodb/internal/ArangoDBImpl.java index ea980dede..690991dc9 100644 --- a/src/main/java/com/arangodb/internal/ArangoDBImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDBImpl.java @@ -29,7 +29,6 @@ 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.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; import com.arangodb.model.DBCreateOptions; @@ -64,7 +63,7 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom 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.getInternalSerialization(), 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.getInternalSerialization(), protocol); this.hostHandler = hostHandler; - hostResolver.init(this.executor(), util()); + hostResolver.init(this.executor(), getInternalSerialization()); LOGGER.debug("ArangoDB Client is ready to use"); diff --git a/src/main/java/com/arangodb/internal/ArangoExecuteable.java b/src/main/java/com/arangodb/internal/ArangoExecuteable.java index dc58fe914..8145a1fd0 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecuteable.java +++ b/src/main/java/com/arangodb/internal/ArangoExecuteable.java @@ -20,9 +20,9 @@ package com.arangodb.internal; +import com.arangodb.ArangoSerializationAccessor; 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.velocystream.Request; @@ -33,7 +33,7 @@ /** * @author Mark Vollmary */ -public abstract class ArangoExecuteable { +public abstract class ArangoExecuteable implements ArangoSerializationAccessor { private static final String SLASH = "/"; @@ -52,12 +52,14 @@ protected E executor() { return executor; } - public ArangoSerialization util() { - return util.get(Serializer.INTERNAL); + @Override + public ArangoSerialization getInternalSerialization() { + return util.getInternalSerialization(); } - public ArangoSerialization util(final Serializer serializer) { - return util.get(serializer); + @Override + public ArangoSerialization getUserSerialization() { + return util.getUserSerialization(); } 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..bbdd8d1b1 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutor.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutor.java @@ -23,7 +23,6 @@ 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.velocystream.Request; import com.arangodb.velocystream.Response; @@ -41,9 +40,9 @@ public abstract class ArangoExecutor { 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); + return (T) util.getInternalSerialization().deserialize(response.getBody(), type); } else { - return (T) util.get(Serializer.CUSTOM).deserialize(response.getBody(), type); + return (T) util.getUserSerialization().deserialize(response.getBody(), type); } } else { return null; diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 6d2082750..8d9194dc2 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -24,7 +24,6 @@ import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; @@ -94,9 +93,9 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO VPackSlice body; if (value instanceof String) { - body = util().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + body = getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { - body = util(Serializer.CUSTOM).serialize(value); + body = getUserSerialization().serialize(value); } request.setBody(body); @@ -107,14 +106,14 @@ protected ResponseDeserializer> insertDocumentRespon final T value, final DocumentCreateOptions options) { return response -> { final VPackSlice body = response.getBody(); - final DocumentCreateEntity doc = util().deserialize(body, DocumentCreateEntity.class); + final DocumentCreateEntity doc = getInternalSerialization().deserialize(body, DocumentCreateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); + doc.setNew(getUserSerialization().deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); + doc.setOld(getUserSerialization().deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -137,8 +136,8 @@ protected Request insertDocumentsRequest(final Collection values, final D request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) - : util(Serializer.CUSTOM).serialize(values); + VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerialization().serialize(values); request.setBody(body); return request; } @@ -162,18 +161,18 @@ protected ResponseDeserializer>> 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 ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentCreateEntity doc = util().deserialize(next, DocumentCreateEntity.class); + final DocumentCreateEntity doc = getInternalSerialization().deserialize(next, DocumentCreateEntity.class); final VPackSlice newDoc = next.get(NEW); if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, type)); + doc.setNew(getUserSerialization().deserialize(newDoc, type)); } final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(oldDoc, type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -188,12 +187,12 @@ protected ResponseDeserializer>> } protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(util().serialize(SerdeUtils.INSTANCE.parseJson(values))); + return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson(values))); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { - VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) - : util(Serializer.CUSTOM).serialize(values); + VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerialization().serialize(values); return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(body); } @@ -224,7 +223,7 @@ protected Request getDocumentsRequest(final Collection keys, final Docum 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(getInternalSerialization().serialize(keys)) .putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); if (params.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); @@ -243,11 +242,11 @@ protected ResponseDeserializer> getDocumentsResponseD 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 ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final T doc = util(Serializer.CUSTOM).deserialize(next, type); + final T doc = getUserSerialization().deserialize(next, type); docs.add(doc); documentsAndErrors.add(doc); } @@ -271,7 +270,7 @@ 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(getUserSerialization().serialize(value)); return request; } @@ -279,14 +278,14 @@ protected ResponseDeserializer> replaceDocumentRespo final T value, final DocumentReplaceOptions options) { return response -> { final VPackSlice body = response.getBody(); - final DocumentUpdateEntity doc = util().deserialize(body, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); + doc.setNew(getUserSerialization().deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); + doc.setOld(getUserSerialization().deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -307,8 +306,8 @@ protected Request replaceDocumentsRequest(final Collection values, final request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) - : util(Serializer.CUSTOM).serialize(values); + VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerialization().serialize(values); request.setBody(body); return request; } @@ -332,18 +331,18 @@ protected ResponseDeserializer>> 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 ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); final VPackSlice newDoc = next.get(NEW); if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, type)); + doc.setNew(getUserSerialization().deserialize(newDoc, type)); } final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(oldDoc, type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -370,7 +369,7 @@ 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)); + request.setBody(getUserSerialization().serialize(value)); return request; } @@ -378,14 +377,14 @@ protected ResponseDeserializer> updateDocumentRes 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 DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, returnType)); + doc.setNew(getUserSerialization().deserialize(newDoc, returnType)); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, returnType)); + doc.setOld(getUserSerialization().deserialize(oldDoc, returnType)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -409,8 +408,8 @@ protected Request updateDocumentsRequest(final Collection values, final D request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - VPackSlice body = isStringCollection(values) ? util().serialize(stringCollectionToJsonArray((Collection) values)) - : util(Serializer.CUSTOM).serialize(values); + VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerialization().serialize(values); request.setBody(body); return request; } @@ -428,18 +427,18 @@ protected ResponseDeserializer>> 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 ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = util().deserialize(next, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); final VPackSlice newDoc = next.get(NEW); if (newDoc.isObject()) { - doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, returnType)); + doc.setNew(getUserSerialization().deserialize(newDoc, returnType)); } final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, returnType)); + doc.setOld(getUserSerialization().deserialize(oldDoc, returnType)); } docs.add(doc); documentsAndErrors.add(doc); @@ -469,10 +468,10 @@ protected ResponseDeserializer> deleteDocumentRespon final Class type) { return response -> { final VPackSlice body = response.getBody(); - final DocumentDeleteEntity doc = util().deserialize(body, DocumentDeleteEntity.class); + final DocumentDeleteEntity doc = getInternalSerialization().deserialize(body, DocumentDeleteEntity.class); final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(oldDoc, type)); } return doc; }; @@ -485,7 +484,7 @@ 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(getInternalSerialization().serialize(keys)); return request; } @@ -501,14 +500,14 @@ protected ResponseDeserializer>> 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 ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentDeleteEntity doc = util().deserialize(next, DocumentDeleteEntity.class); + final DocumentDeleteEntity doc = getInternalSerialization().deserialize(next, DocumentDeleteEntity.class); final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(oldDoc, type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -561,7 +560,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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); return request; } @@ -570,7 +569,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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); return request; } @@ -578,7 +577,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(getInternalSerialization().serialize( OptionsBuilder.build(options != null ? options : new PersistentIndexOptions(), fields))); return request; } @@ -587,7 +586,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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); return request; } @@ -595,7 +594,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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); return request; } @@ -603,7 +602,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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); return request; } @@ -611,7 +610,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(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new ZKDIndexOptions().fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE), fields))); return request; } @@ -623,7 +622,7 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("indexes"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody().get("indexes"), new Type>() { }.getType()); } @@ -655,19 +654,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(getInternalSerialization().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(getInternalSerialization().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(getUserSerialization().serialize(value)); return request; } @@ -677,7 +676,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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { @@ -696,7 +695,7 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone()) { - return util().deserialize(result, Permissions.class); + return getInternalSerialization().deserialize(result, Permissions.class); } } return null; diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index db5d9135d..e1ccaeef5 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -62,17 +62,17 @@ protected Request getServerIdRequest() { } protected ResponseDeserializer getRoleResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("role"), ServerRole.class); + return response -> getInternalSerialization().deserialize(response.getBody().get("role"), ServerRole.class); } protected ResponseDeserializer getServerIdResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("id"), String.class); + return response -> getInternalSerialization().deserialize(response.getBody().get("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(getInternalSerialization().serialize(options)); return request; } @@ -87,7 +87,7 @@ 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>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } @@ -116,7 +116,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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); return request; } @@ -135,7 +135,7 @@ 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>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } @@ -143,25 +143,25 @@ protected ResponseDeserializer> getUsersResponseDeseriali 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(getInternalSerialization().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(getInternalSerialization().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(getInternalSerialization().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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getLogEntriesRequest(final LogOptions options) { @@ -182,7 +182,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(getInternalSerialization().serialize(entity)); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 879f30987..294830a2e 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -25,7 +25,6 @@ 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; @@ -101,7 +100,7 @@ protected Request getEngineRequest() { protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) { - VPackSlice body = util() + VPackSlice body = getInternalSerialization() .serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)); return request(dbName, RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(body); @@ -118,7 +117,7 @@ protected Request getCollectionsRequest(final CollectionsReadOptions options) { protected ResponseDeserializer> getCollectionsResponseDeserializer() { return response -> { final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } @@ -133,7 +132,7 @@ protected ResponseDeserializer createDropResponseDeserializer() { 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))); + dbName.get()).setBody(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { @@ -143,7 +142,7 @@ protected Request resetAccessRequest(final String user) { 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))); + dbName.get(), "*").setBody(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getPermissionsRequest(final String user) { @@ -157,7 +156,7 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone()) { - return util().deserialize(result, Permissions.class); + return getInternalSerialization().deserialize(result, Permissions.class); } } return null; @@ -168,9 +167,9 @@ 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 + .setBody(getInternalSerialization().serialize(OptionsBuilder .build(opt, query, bindVars != null ? - util(ArangoSerializationFactory.Serializer.CUSTOM).serialize(bindVars, new ArangoSerializer.Options().serializeNullValues(true)) : + getUserSerialization().serialize(bindVars, new ArangoSerializer.Options().serializeNullValues(true)) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); @@ -222,17 +221,17 @@ protected Request explainQueryRequest( final AqlQueryExplainOptions opt = options != null ? options : new AqlQueryExplainOptions(); return request(dbName, RequestType.POST, PATH_API_EXPLAIN) - .setBody(util().serialize(OptionsBuilder.build( + .setBody(getInternalSerialization().serialize(OptionsBuilder.build( opt, query, - bindVars != null ? util(ArangoSerializationFactory.Serializer.CUSTOM).serialize( + bindVars != null ? getUserSerialization().serialize( bindVars, new ArangoSerializer.Options().serializeNullValues(true)) : null))); } protected Request parseQueryRequest(final String query) { return request(dbName, RequestType.POST, PATH_API_QUERY) - .setBody(util().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); + .setBody(getInternalSerialization().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); } protected Request clearQueryCacheRequest() { @@ -244,7 +243,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(getInternalSerialization().serialize(properties)); } protected Request getQueryTrackingPropertiesRequest() { @@ -252,7 +251,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(getInternalSerialization().serialize(properties)); } protected Request getCurrentlyRunningQueriesRequest() { @@ -273,7 +272,7 @@ protected Request killQueryRequest(final String id) { protected Request createAqlFunctionRequest( final String name, final String code, final AqlFunctionCreateOptions options) { - return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(util().serialize( + return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(getInternalSerialization().serialize( OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); } @@ -313,19 +312,19 @@ protected ResponseDeserializer> getAqlFunctionsRes // 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>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } protected Request createGraphRequest( final String name, final Collection edgeDefinitions, final GraphCreateOptions options) { - return request(dbName, RequestType.POST, InternalArangoGraph.PATH_API_GHARIAL).setBody(util().serialize( + return request(dbName, RequestType.POST, InternalArangoGraph.PATH_API_GHARIAL).setBody(getInternalSerialization().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 -> getInternalSerialization().deserialize(response.getBody().get("graph"), GraphEntity.class); } protected Request getGraphsRequest() { @@ -333,13 +332,13 @@ protected Request getGraphsRequest() { } protected ResponseDeserializer> getGraphsResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("graphs"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody().get("graphs"), new Type>() { }.getType()); } 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))); + getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); } protected ResponseDeserializer transactionResponseDeserializer(final Class type) { @@ -348,7 +347,7 @@ protected ResponseDeserializer transactionResponseDeserializer(final Clas if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone() && !result.isNull()) { - return util(Serializer.CUSTOM).deserialize(result, type); + return getUserSerialization().deserialize(result, type); } } return null; @@ -357,7 +356,7 @@ protected ResponseDeserializer transactionResponseDeserializer(final Clas protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION) - .setBody(util().serialize(options != null ? options : new StreamTransactionOptions())); + .setBody(getInternalSerialization().serialize(options != null ? options : new StreamTransactionOptions())); } protected Request abortStreamTransactionRequest(String id) { @@ -375,7 +374,7 @@ protected Request getStreamTransactionRequest(String id) { protected ResponseDeserializer> transactionsResponseDeserializer() { return response -> { final VPackSlice result = response.getBody().get("transactions"); - return util().deserialize(result, new Type>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } @@ -385,7 +384,7 @@ protected Request commitStreamTransactionRequest(String id) { } protected ResponseDeserializer streamTransactionResponseDeserializer() { - return response -> util() + return response -> getInternalSerialization() .deserialize(response.getBody().get(ArangoResponseField.RESULT), StreamTransactionEntity.class); } @@ -394,7 +393,7 @@ protected Request getInfoRequest() { } protected ResponseDeserializer getInfoResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(ArangoResponseField.RESULT), DatabaseEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody().get(ArangoResponseField.RESULT), DatabaseEntity.class); } protected Request reloadRoutingRequest() { @@ -408,18 +407,18 @@ protected Request getViewsRequest() { protected ResponseDeserializer> getViewsResponseDeserializer() { return response -> { final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } 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))); + .setBody(getInternalSerialization().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( + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getInternalSerialization().serialize( ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); } @@ -434,14 +433,14 @@ protected Request getAnalyzersRequest() { protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { return response -> { final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return util().deserialize(result, new Type>() { + return getInternalSerialization().deserialize(result, new Type>() { }.getType()); }; } protected Request createAnalyzerRequest(final SearchAnalyzer options) { return request(dbName, RequestType.POST, InternalArangoView.PATH_API_ANALYZER) - .setBody(util().serialize(options)); + .setBody(getInternalSerialization().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..6b6271c8b 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -23,7 +23,6 @@ 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.*; @@ -69,14 +68,14 @@ protected Request insertEdgeRequest(final T value, final EdgeCreateOptions o 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(getUserSerialization().serialize(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 = getInternalSerialization().deserialize(body, EdgeEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -100,7 +99,7 @@ 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 -> getUserSerialization().deserialize(response.getBody().get(EDGE), type); } protected Request replaceEdgeRequest(final String key, final T value, final EdgeReplaceOptions options) { @@ -110,14 +109,14 @@ protected Request replaceEdgeRequest(final String key, final T value, final 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(getUserSerialization().serialize(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 = getInternalSerialization().deserialize(body, EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -135,14 +134,14 @@ protected Request updateEdgeRequest(final String key, final T value, final E 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))); + getUserSerialization().serialize(value, new ArangoSerializer.Options().serializeNullValues(true))); 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 = getInternalSerialization().deserialize(body, EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index a03e090e6..10059c705 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoGraph.java +++ b/src/main/java/com/arangodb/internal/InternalArangoGraph.java @@ -84,13 +84,13 @@ protected Request getVertexCollectionsRequest() { } protected ResponseDeserializer> getVertexCollectionsResponseDeserializer() { - return response -> util().deserialize(response.getBody().get("collections"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody().get("collections"), new Type>() { }.getType()); } 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(getInternalSerialization().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>() { + return response -> getInternalSerialization().deserialize(response.getBody().get("collections"), new Type>() { }.getType()); } 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(getInternalSerialization().serialize(definition)); return request; } protected ResponseDeserializer addEdgeDefinitionResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody().get(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(getInternalSerialization().serialize(definition)); return request; } protected ResponseDeserializer replaceEdgeDefinitionResponseDeserializer() { - return response -> util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody().get(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 -> getInternalSerialization().deserialize(response.getBody().get(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..f0936eb87 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoRoute.java +++ b/src/main/java/com/arangodb/internal/InternalArangoRoute.java @@ -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(getInternalSerialization().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..3bdf9d90f 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(getInternalSerialization().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(getInternalSerialization().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 4962fa6fa..17ef9beb7 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -23,7 +23,6 @@ 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.*; @@ -77,9 +76,9 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio VPackSlice body; if (value instanceof String) { - body = util().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + body = getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { - body = util(Serializer.CUSTOM).serialize(value); + body = getUserSerialization().serialize(value); } request.setBody(body); return request; @@ -88,7 +87,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio 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 = getInternalSerialization().deserialize(body, VertexEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -112,7 +111,7 @@ 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 -> getUserSerialization().deserialize(response.getBody().get(VERTEX), type); } protected Request replaceVertexRequest(final String key, final T value, final VertexReplaceOptions options) { @@ -122,14 +121,14 @@ protected Request replaceVertexRequest(final String key, final T value, fina 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(getUserSerialization().serialize(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 = getInternalSerialization().deserialize(body, VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -147,14 +146,14 @@ protected Request updateVertexRequest(final String key, final T value, final 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))); + getUserSerialization().serialize(value, new ArangoSerializer.Options().serializeNullValues(true))); 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 = getInternalSerialization().deserialize(body, VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); diff --git a/src/main/java/com/arangodb/internal/InternalArangoView.java b/src/main/java/com/arangodb/internal/InternalArangoView.java index 1fa76f015..0257e3643 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoView.java +++ b/src/main/java/com/arangodb/internal/InternalArangoView.java @@ -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(getInternalSerialization().serialize(OptionsBuilder.build(new ViewRenameOptions(), newName))); return request; } diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java index b67ed820d..ff83bfbc4 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -25,7 +25,6 @@ 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 java.util.Iterator; @@ -76,7 +75,7 @@ public T next() { } protected R deserialize(final VPackSlice result, final Class type) { - return db.util(Serializer.CUSTOM).deserialize(result, type); + return db.getUserSerialization().deserialize(result, type); } @Override diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java b/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java index 035c2dc92..b015b59ec 100644 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java +++ b/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java @@ -27,27 +27,21 @@ */ public class ArangoSerializationFactory { - public enum Serializer { - INTERNAL, CUSTOM - } - - private final ArangoSerialization interal; - private final ArangoSerialization custom; + private final ArangoSerialization internal; + private final ArangoSerialization user; - public ArangoSerializationFactory(final ArangoSerialization interal, final ArangoSerialization custom) { + public ArangoSerializationFactory(final ArangoSerialization internal, final ArangoSerialization user) { super(); - this.interal = interal; - this.custom = custom; + this.internal = internal; + this.user = user; + } + + public ArangoSerialization getInternalSerialization() { + return internal; } - public ArangoSerialization get(final Serializer serializer) { - switch (serializer) { - case CUSTOM: - return custom; - case INTERNAL: - default: - return interal; - } + public ArangoSerialization getUserSerialization() { + return user; } } diff --git a/src/test/java/com/arangodb/JwtAuthTest.java b/src/test/java/com/arangodb/JwtAuthTest.java index 6c0c3029f..7ba60adbb 100644 --- a/src/test/java/com/arangodb/JwtAuthTest.java +++ b/src/test/java/com/arangodb/JwtAuthTest.java @@ -83,7 +83,7 @@ private ArangoDB.Builder getBuilder(Protocol protocol) { } private static String getJwt(ArangoDB arangoDB) { - ArangoSerialization serde = arangoDB.util(); + ArangoSerialization serde = arangoDB.getInternalSerialization(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/async/JwtAuthTest.java b/src/test/java/com/arangodb/async/JwtAuthTest.java index c9d0f40d1..ba119bcc7 100644 --- a/src/test/java/com/arangodb/async/JwtAuthTest.java +++ b/src/test/java/com/arangodb/async/JwtAuthTest.java @@ -90,7 +90,7 @@ private ArangoDBAsync.Builder getBuilder() { } private static String getJwt(ArangoDB arangoDB) { - ArangoSerialization serde = arangoDB.util(); + ArangoSerialization serde = arangoDB.getInternalSerialization(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index e5cd72078..790425c0a 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -51,7 +51,6 @@ import java.util.HashMap; 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; @@ -143,7 +142,7 @@ void customPersonDeserializer() { void manualCustomPersonDeserializer() { Person person = new Person(); person.name = "Joe"; - ArangoSerialization serialization = arangoDB.util(CUSTOM); + ArangoSerialization serialization = arangoDB.getUserSerialization(); VPackSlice serializedPerson = serialization.serialize(person); Person deserializedPerson = serialization.deserialize(serializedPerson, Person.class); assertThat(deserializedPerson.name).isEqualTo(PERSON_DESERIALIZER_ADDED_PREFIX + PERSON_SERIALIZER_ADDED_PREFIX + person.name); @@ -237,7 +236,7 @@ void getDocument() { @Test void parseNullString() { - final String json = arangoDB.util(CUSTOM).deserialize(new VPackBuilder().add((String) null).slice(), String.class); + final String json = arangoDB.getUserSerialization().deserialize(new VPackBuilder().add((String) null).slice(), String.class); assertThat(json).isNull(); } diff --git a/src/test/java/com/arangodb/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java index d17bd27c4..ebe7cec85 100644 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ b/src/test/java/com/arangodb/util/ArangoSerializationTest.java @@ -45,7 +45,7 @@ class ArangoSerializationTest { @BeforeAll static void setup() { final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); - util = arangoDB.util(); + util = arangoDB.getInternalSerialization(); } @Test From c146f38a62e50408808da50abf6a8c884e8cba25 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 5 Jul 2022 14:27:24 +0200 Subject: [PATCH 18/52] removed old ArangoSerialization --- src/main/java/com/arangodb/ArangoDB.java | 7 +- .../com/arangodb/async/ArangoDBAsync.java | 7 +- .../internal/InternalArangoDBBuilder.java | 6 - .../internal/InternalArangoDatabase.java | 8 +- .../InternalArangoEdgeCollection.java | 4 +- .../InternalArangoVertexCollection.java | 4 +- .../internal/http/HttpConnection.java | 8 +- .../internal/util/ArangoSerializerImpl.java | 86 ------------- .../util/DefaultArangoSerialization.java | 10 +- .../java/com/arangodb/mapping/ArangoJack.java | 6 - .../arangodb/util/ArangoSerialization.java | 5 +- .../com/arangodb/util/ArangoSerializer.java | 121 ------------------ .../util/ArangoSerializationTest.java | 22 ++-- 13 files changed, 27 insertions(+), 267 deletions(-) delete mode 100644 src/main/java/com/arangodb/internal/util/ArangoSerializerImpl.java delete mode 100644 src/main/java/com/arangodb/util/ArangoSerializer.java diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index ec3265318..e6056cf9f 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -30,7 +30,6 @@ 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.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; @@ -43,7 +42,6 @@ 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.velocystream.Request; @@ -360,14 +358,11 @@ public synchronized ArangoDB build() { 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 InternalSerde internalSerde = protocol == Protocol.HTTP_JSON ? InternalSerde.of(DataType.JSON) : InternalSerde.of(DataType.VPACK); - final DefaultArangoSerialization internal = new DefaultArangoSerialization(serializerTemp, - deserializerTemp, internalSerde); + final DefaultArangoSerialization internal = new DefaultArangoSerialization(deserializerTemp, internalSerde); final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 28dff5ee6..8075310b2 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -33,7 +33,6 @@ 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.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; @@ -45,7 +44,6 @@ import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.*; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; @@ -521,13 +519,10 @@ public synchronized ArangoDBAsync build() { 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 InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); - final DefaultArangoSerialization internal = new DefaultArangoSerialization(serializerTemp, - deserializerTemp, internalSerde); + final DefaultArangoSerialization internal = new DefaultArangoSerialization(deserializerTemp, internalSerde); final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); diff --git a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java index 6abc81bfa..07f741e5d 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java @@ -39,7 +39,6 @@ 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 org.apache.http.client.HttpRequestRetryHandler; @@ -96,7 +95,6 @@ public abstract class InternalArangoDBBuilder { 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; @@ -225,10 +223,6 @@ 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; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 294830a2e..422b4aba4 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -24,13 +24,11 @@ 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.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.velocystream.Request; @@ -169,7 +167,7 @@ protected Request queryRequest( final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR) .setBody(getInternalSerialization().serialize(OptionsBuilder .build(opt, query, bindVars != null ? - getUserSerialization().serialize(bindVars, new ArangoSerializer.Options().serializeNullValues(true)) : + getUserSerialization().serialize(bindVars) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); @@ -224,9 +222,7 @@ protected Request explainQueryRequest( .setBody(getInternalSerialization().serialize(OptionsBuilder.build( opt, query, - bindVars != null ? getUserSerialization().serialize( - bindVars, - new ArangoSerializer.Options().serializeNullValues(true)) : null))); + bindVars != null ? getUserSerialization().serialize(bindVars) : null))); } protected Request parseQueryRequest(final String query) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java index 6b6271c8b..0c84c3734 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -26,7 +26,6 @@ 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; @@ -133,8 +132,7 @@ protected Request updateEdgeRequest(final String key, final T value, final E request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody( - getUserSerialization().serialize(value, new ArangoSerializer.Options().serializeNullValues(true))); + request.setBody(getUserSerialization().serialize(value)); return request; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 17ef9beb7..5fabbe2b1 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -27,7 +27,6 @@ import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; import com.arangodb.serde.SerdeUtils; -import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -145,8 +144,7 @@ protected Request updateVertexRequest(final String key, final T value, final request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody( - getUserSerialization().serialize(value, new ArangoSerializer.Options().serializeNullValues(true))); + request.setBody(getUserSerialization().serialize(value)); return request; } diff --git a/src/main/java/com/arangodb/internal/http/HttpConnection.java b/src/main/java/com/arangodb/internal/http/HttpConnection.java index c74af9b2a..e10964990 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnection.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnection.java @@ -29,7 +29,7 @@ import com.arangodb.internal.util.ResponseUtils; import com.arangodb.serde.DataType; import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer.Options; +import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; @@ -356,6 +356,9 @@ private static void addHeader(final Request request, final HttpRequestBase httpR } } + // FIXME: remove + private final VPackParser parser = new VPackParser.Builder().build(); + public Response buildResponse(final CloseableHttpResponse httpResponse) throws UnsupportedOperationException, IOException { final Response response = new Response(dataType); @@ -370,8 +373,7 @@ public Response buildResponse(final CloseableHttpResponse httpResponse) } else { final String content = IOUtils.toString(entity.getContent()); if (!content.isEmpty()) { - response.setBody( - util.serialize(content, new Options().stringAsJson(true).serializeNullValues(true))); + response.setBody(parser.fromJson(content, true)); } } } 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 index 166f36644..fc258f2f3 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -25,7 +25,6 @@ import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; @@ -36,13 +35,11 @@ */ public class DefaultArangoSerialization implements ArangoSerialization { - private final ArangoSerializer serializer; private final ArangoDeserializer deserializer; private final InternalSerde serde; - public DefaultArangoSerialization(final ArangoSerializer serializer, final ArangoDeserializer deserializer, final InternalSerde serde) { + public DefaultArangoSerialization(final ArangoDeserializer deserializer, final InternalSerde serde) { super(); - this.serializer = serializer; this.deserializer = deserializer; this.serde = serde; } @@ -62,11 +59,6 @@ public VPackSlice serialize(final Object entity) throws ArangoDBException { } } - @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/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index e8c318232..d9c2b78a3 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -130,12 +130,6 @@ public VPackSlice serialize(final Object entity) throws ArangoDBException { } - @SuppressWarnings("unchecked") - @Override - public VPackSlice serialize(final Object entity, final Options options) throws ArangoDBException { - return serialize(entity); - } - @SuppressWarnings("unchecked") @Override public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index c6f710171..4d271d753 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -20,8 +20,11 @@ package com.arangodb.util; +import com.arangodb.velocypack.VPackSlice; + /** * @author Mark Vollmary */ -public interface ArangoSerialization extends ArangoSerializer, ArangoDeserializer { +public interface ArangoSerialization extends ArangoDeserializer { + VPackSlice serialize(final Object entity); } 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/test/java/com/arangodb/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java index ebe7cec85..26a5a8494 100644 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ b/src/test/java/com/arangodb/util/ArangoSerializationTest.java @@ -40,18 +40,20 @@ */ class ArangoSerializationTest { - private static ArangoSerialization util; + private static ArangoSerialization internalSer; + private static ArangoSerialization userSer; @BeforeAll static void setup() { final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); - util = arangoDB.getInternalSerialization(); + internalSer = arangoDB.getInternalSerialization(); + userSer = arangoDB.getUserSerialization(); } @Test void deserialize() { final VPackBuilder builder = new VPackBuilder().add(ValueType.OBJECT).add("foo", "bar").close(); - final BaseDocument doc = util.deserialize(builder.slice(), BaseDocument.class); + final BaseDocument doc = internalSer.deserialize(builder.slice(), BaseDocument.class); assertThat(doc.getAttribute("foo")).isEqualTo("bar"); } @@ -59,7 +61,7 @@ void deserialize() { void serialize() { final BaseDocument entity = new BaseDocument(); entity.addAttribute("foo", "bar"); - final VPackSlice vpack = util.serialize(entity); + final VPackSlice vpack = internalSer.serialize(entity); assertThat(vpack.get("foo").isString()).isTrue(); assertThat(vpack.get("foo").getAsString()).isEqualTo("bar"); } @@ -68,7 +70,7 @@ void serialize() { void serializeNullValues() { final BaseDocument entity = new BaseDocument(); entity.addAttribute("foo", null); - final VPackSlice vpack = util.serialize(entity, new ArangoSerializer.Options().serializeNullValues(true)); + final VPackSlice vpack = userSer.serialize(entity); assertThat(vpack.get("foo").isNull()).isTrue(); } @@ -76,7 +78,7 @@ void serializeNullValues() { void skipSerializeNullValues() { final BaseDocument entity = new BaseDocument(); entity.addAttribute("bar", null); - final VPackSlice vpack = util.serialize(entity); + final VPackSlice vpack = internalSer.serialize(entity); assertThat(vpack.get("bar").isNone()).isTrue(); } @@ -86,9 +88,7 @@ void serializeType() { list.add(new BaseDocument()); list.add(new BaseDocument()); - final VPackSlice vpack = util.serialize(list, - new ArangoSerializer.Options().type(new Type>() { - }.getType())); + final VPackSlice vpack = internalSer.serialize(list); assertThat(vpack.isArray()).isTrue(); assertThat(vpack.getLength()).isEqualTo(list.size()); } @@ -97,13 +97,13 @@ void serializeType() { 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); + final String json = internalSer.deserialize(internalSer.serialize(entity), String.class); assertThat(json).isEqualTo("{\"value\":[\"test\",null]}"); } @Test void parseNullString() { - final String json = util.deserialize(new VPackBuilder().add((String) null).slice(), String.class); + final String json = internalSer.deserialize(new VPackBuilder().add((String) null).slice(), String.class); assertThat(json).isNull(); } From 4fc2aa737a88b2cd6d878f1ba7e8bd34d0497a75 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 6 Jul 2022 14:23:14 +0200 Subject: [PATCH 19/52] refctored communication API using byte[] instead of VPackSlice for outgoing buffer --- .../internal/InternalArangoCollection.java | 10 ++++----- .../internal/InternalArangoDatabase.java | 6 ++--- .../InternalArangoVertexCollection.java | 2 +- .../arangodb/internal/http/CURLLogger.java | 2 +- .../internal/http/HttpConnection.java | 18 +++------------ .../util/DefaultArangoSerialization.java | 21 ++++++------------ .../velocystream/internal/Message.java | 6 ++--- .../velocystream/internal/VstConnection.java | 7 +++--- .../java/com/arangodb/mapping/ArangoJack.java | 22 ++++++------------- .../java/com/arangodb/serde/ArangoSerde.java | 2 +- .../arangodb/util/ArangoSerialization.java | 5 ++--- .../com/arangodb/velocystream/Request.java | 7 +++--- src/test/java/com/arangodb/BaseJunit5.java | 3 ++- .../annotations/ArangoAnnotationsTest.java | 10 ++++----- .../com/arangodb/serde/CustomSerdeTest.java | 3 +-- .../util/ArangoSerializationTest.java | 10 ++++----- 16 files changed, 53 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 8d9194dc2..298772824 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -91,7 +91,7 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - VPackSlice body; + byte[] body; if (value instanceof String) { body = getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { @@ -136,7 +136,7 @@ protected Request insertDocumentsRequest(final Collection values, final D request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) : getUserSerialization().serialize(values); request.setBody(body); return request; @@ -191,7 +191,7 @@ protected Request importDocumentsRequest(final String values, final DocumentImpo } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { - VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) : getUserSerialization().serialize(values); return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(body); } @@ -306,7 +306,7 @@ protected Request replaceDocumentsRequest(final Collection values, final request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) : getUserSerialization().serialize(values); request.setBody(body); return request; @@ -408,7 +408,7 @@ protected Request updateDocumentsRequest(final Collection values, final D request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - VPackSlice body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) + byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) : getUserSerialization().serialize(values); request.setBody(body); return request; diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 422b4aba4..f0ecd708e 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -98,7 +98,7 @@ protected Request getEngineRequest() { protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) { - VPackSlice body = getInternalSerialization() + byte[] body = getInternalSerialization() .serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)); return request(dbName, RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(body); @@ -167,7 +167,7 @@ protected Request queryRequest( final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR) .setBody(getInternalSerialization().serialize(OptionsBuilder .build(opt, query, bindVars != null ? - getUserSerialization().serialize(bindVars) : + new VPackSlice(getUserSerialization().serialize(bindVars)) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); @@ -222,7 +222,7 @@ protected Request explainQueryRequest( .setBody(getInternalSerialization().serialize(OptionsBuilder.build( opt, query, - bindVars != null ? getUserSerialization().serialize(bindVars) : null))); + bindVars != null ? new VPackSlice(getUserSerialization().serialize(bindVars)) : null))); } protected Request parseQueryRequest(final String query) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 5fabbe2b1..7bc503289 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -73,7 +73,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - VPackSlice body; + byte[] body; if (value instanceof String) { body = getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { diff --git a/src/main/java/com/arangodb/internal/http/CURLLogger.java b/src/main/java/com/arangodb/internal/http/CURLLogger.java index 941769fe4..4c6121330 100644 --- a/src/main/java/com/arangodb/internal/http/CURLLogger.java +++ b/src/main/java/com/arangodb/internal/http/CURLLogger.java @@ -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/HttpConnection.java b/src/main/java/com/arangodb/internal/http/HttpConnection.java index e10964990..eb1ea7d74 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnection.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnection.java @@ -48,7 +48,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; @@ -65,7 +64,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; @@ -83,9 +81,6 @@ 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; @@ -290,19 +285,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; diff --git a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java index fc258f2f3..c858c4bb7 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -21,11 +21,9 @@ package com.arangodb.internal.util; import com.arangodb.ArangoDBException; -import com.arangodb.serde.DataType; import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; import java.lang.reflect.Type; @@ -45,18 +43,13 @@ public DefaultArangoSerialization(final ArangoDeserializer deserializer, final I } @Override - public VPackSlice serialize(final Object entity) throws ArangoDBException { - DataType dataType = serde.getDataType(); - switch (dataType) { - case JSON: - String json = new String(serde.serialize(entity)); - VPackParser parser = new VPackParser.Builder().build(); - return parser.fromJson(json, true); - case VPACK: - return new VPackSlice(serde.serialize(entity)); - default: - throw new IllegalStateException("Unexpected value: " + dataType); - } + public byte[] serialize(final Object entity) throws ArangoDBException { + return serde.serialize(entity); + } + + @Override + public String toJsonString(byte[] content) { + return serde.toJsonString(content); } @Override 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 index d9c2b78a3..11dbb9739 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -28,7 +28,6 @@ import com.arangodb.serde.DataType; import com.arangodb.serde.JacksonSerde; import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -55,7 +54,6 @@ public interface ConfigureFunction { private final ObjectMapper vpackMapper; private final ObjectMapper vpackMapperNull; private final ObjectMapper jsonMapper; - private final VPackParser vpackParser; private final JacksonSerde serde; @@ -103,7 +101,6 @@ public ArangoJack(final VPackMapper mapper) { 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(); serde = JacksonSerde.of(DataType.VPACK, configureDefaultMapper(new VPackMapper())); } @@ -115,19 +112,14 @@ public void configure(final ArangoJack.ConfigureFunction f) { } @Override - public VPackSlice serialize(final Object entity) throws ArangoDBException { - DataType dataType = serde.getDataType(); - switch (dataType) { - case JSON: - String json = new String(serde.serialize(entity)); - VPackParser parser = new VPackParser.Builder().build(); - return parser.fromJson(json, true); - case VPACK: - return new VPackSlice(serde.serialize(entity)); - default: - throw new IllegalStateException("Unexpected value: " + dataType); - } + public byte[] serialize(final Object entity) throws ArangoDBException { + return serde.serialize(entity); + } + // FIXME: toJsonString should only be required for internal serialization + @Override + public String toJsonString(byte[] content) { + throw new UnsupportedOperationException(); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/arangodb/serde/ArangoSerde.java b/src/main/java/com/arangodb/serde/ArangoSerde.java index 3b310548c..ce56485d2 100644 --- a/src/main/java/com/arangodb/serde/ArangoSerde.java +++ b/src/main/java/com/arangodb/serde/ArangoSerde.java @@ -16,7 +16,7 @@ * This interface should not be directly implemented as an adapter to Jackson Databind. A more performant way to provide * custom implementations based on Jackson Databind is by extending {@link JacksonSerde}, which exposes additional * methods based on Jackson's types. - * Furthermore, existing implementations {@link JacksonSerde} can be instantiated providing a custom configured Jackson + * Furthermore, existing {@link JacksonSerde} implementations can be instantiated providing a custom configured Jackson * ObjectMapper, see {@link JacksonSerde#of(DataType, ObjectMapper)}. */ public interface ArangoSerde { diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index 4d271d753..6fee87692 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -20,11 +20,10 @@ package com.arangodb.util; -import com.arangodb.velocypack.VPackSlice; - /** * @author Mark Vollmary */ public interface ArangoSerialization extends ArangoDeserializer { - VPackSlice serialize(final Object entity); + byte[] serialize(final Object entity); + String toJsonString(byte[] content); } diff --git a/src/main/java/com/arangodb/velocystream/Request.java b/src/main/java/com/arangodb/velocystream/Request.java index cfa9eead7..872b01cf3 100644 --- a/src/main/java/com/arangodb/velocystream/Request.java +++ b/src/main/java/com/arangodb/velocystream/Request.java @@ -21,7 +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; @@ -40,7 +39,7 @@ public class 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 +103,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/test/java/com/arangodb/BaseJunit5.java b/src/test/java/com/arangodb/BaseJunit5.java index f6e9390ee..11ee86790 100644 --- a/src/test/java/com/arangodb/BaseJunit5.java +++ b/src/test/java/com/arangodb/BaseJunit5.java @@ -22,7 +22,8 @@ class BaseJunit5 { private static final List adbs = Arrays.stream(Protocol.values()) .map(p -> new ArangoDB.Builder() .useProtocol(p) - .serializer(new ArangoJack()) + // FIXME +// .serializer(new ArangoJack()) .build()) .collect(Collectors.toList()); diff --git a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java index 0aa1ace84..482d1287b 100644 --- a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java +++ b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java @@ -45,7 +45,7 @@ void documentFieldAnnotations() { e.setFrom("From"); e.setTo("To"); - VPackSlice slice = mapper.serialize(e); + VPackSlice slice = new VPackSlice(mapper.serialize(e)); System.out.println(slice); Map deserialized = mapper.deserialize(slice, Object.class); assertThat(deserialized) @@ -67,7 +67,7 @@ void serializedName() { e.setB("B"); e.setC("C"); - VPackSlice slice = mapper.serialize(e); + VPackSlice slice = new VPackSlice(mapper.serialize(e)); System.out.println(slice); Map deserialized = mapper.deserialize(slice, Object.class); assertThat(deserialized) @@ -87,7 +87,7 @@ void serializedNameParameter() { e.put(SerializedNameParameterEntity.SERIALIZED_NAME_B, "B"); e.put(SerializedNameParameterEntity.SERIALIZED_NAME_C, "C"); - VPackSlice slice = mapper.serialize(e); + VPackSlice slice = new VPackSlice(mapper.serialize(e)); SerializedNameParameterEntity deserializedEntity = mapper .deserialize(slice, SerializedNameParameterEntity.class); assertThat(deserializedEntity).isEqualTo(new SerializedNameParameterEntity("A", "B", "C")); @@ -101,7 +101,7 @@ void expose() { e.setWriteOnly("writeOnly"); e.setIgnored("ignored"); - VPackSlice serializedEntity = mapper.serialize(e); + VPackSlice serializedEntity = new VPackSlice(mapper.serialize(e)); Map deserializedEntity = mapper.deserialize(serializedEntity, Object.class); assertThat(deserializedEntity) .containsEntry("readWrite", "readWrite") @@ -114,7 +114,7 @@ void expose() { map.put("writeOnly", "writeOnly"); map.put("ignored", "ignored"); - VPackSlice serializedMap = mapper.serialize(map); + VPackSlice serializedMap = new VPackSlice(mapper.serialize(map)); ExposeEntity deserializedMap = mapper.deserialize(serializedMap, ExposeEntity.class); assertThat(deserializedMap.getIgnored()).isNull(); assertThat(deserializedMap.getReadOnly()).isNull(); diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index 790425c0a..e703ecae4 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -26,7 +26,6 @@ import com.arangodb.ArangoDatabase; import com.arangodb.DbName; import com.arangodb.entity.BaseDocument; -import com.arangodb.jackson.dataformat.velocypack.VPackMapper; import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; import com.arangodb.util.ArangoSerialization; @@ -143,7 +142,7 @@ void manualCustomPersonDeserializer() { Person person = new Person(); person.name = "Joe"; ArangoSerialization serialization = arangoDB.getUserSerialization(); - VPackSlice serializedPerson = serialization.serialize(person); + VPackSlice serializedPerson = new VPackSlice(serialization.serialize(person)); Person deserializedPerson = serialization.deserialize(serializedPerson, Person.class); assertThat(deserializedPerson.name).isEqualTo(PERSON_DESERIALIZER_ADDED_PREFIX + PERSON_SERIALIZER_ADDED_PREFIX + person.name); } diff --git a/src/test/java/com/arangodb/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java index 26a5a8494..28ed2612c 100644 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ b/src/test/java/com/arangodb/util/ArangoSerializationTest.java @@ -61,7 +61,7 @@ void deserialize() { void serialize() { final BaseDocument entity = new BaseDocument(); entity.addAttribute("foo", "bar"); - final VPackSlice vpack = internalSer.serialize(entity); + final VPackSlice vpack = new VPackSlice(internalSer.serialize(entity)); assertThat(vpack.get("foo").isString()).isTrue(); assertThat(vpack.get("foo").getAsString()).isEqualTo("bar"); } @@ -70,7 +70,7 @@ void serialize() { void serializeNullValues() { final BaseDocument entity = new BaseDocument(); entity.addAttribute("foo", null); - final VPackSlice vpack = userSer.serialize(entity); + final VPackSlice vpack = new VPackSlice(userSer.serialize(entity)); assertThat(vpack.get("foo").isNull()).isTrue(); } @@ -78,7 +78,7 @@ void serializeNullValues() { void skipSerializeNullValues() { final BaseDocument entity = new BaseDocument(); entity.addAttribute("bar", null); - final VPackSlice vpack = internalSer.serialize(entity); + final VPackSlice vpack = new VPackSlice(internalSer.serialize(entity)); assertThat(vpack.get("bar").isNone()).isTrue(); } @@ -88,7 +88,7 @@ void serializeType() { list.add(new BaseDocument()); list.add(new BaseDocument()); - final VPackSlice vpack = internalSer.serialize(list); + final VPackSlice vpack = new VPackSlice(internalSer.serialize(list)); assertThat(vpack.isArray()).isTrue(); assertThat(vpack.getLength()).isEqualTo(list.size()); } @@ -97,7 +97,7 @@ void serializeType() { void parseJsonIncludeNull() { final Map entity = new HashMap<>(); entity.put("value", new String[]{"test", null}); - final String json = internalSer.deserialize(internalSer.serialize(entity), String.class); + final String json = internalSer.deserialize(new VPackSlice(internalSer.serialize(entity)), String.class); assertThat(json).isEqualTo("{\"value\":[\"test\",null]}"); } From 93d5d438a681f8a2490d2c94f6c2efcbf8a3ff10 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 8 Jul 2022 09:32:51 +0200 Subject: [PATCH 20/52] serialize AQL bindvars as byte[] --- src/main/java/com/arangodb/ArangoDB.java | 11 ++----- .../com/arangodb/async/ArangoDBAsync.java | 8 ++--- .../internal/InternalArangoDatabase.java | 3 +- .../util/DefaultArangoSerialization.java | 13 ++++++-- .../java/com/arangodb/mapping/ArangoJack.java | 8 ++++- .../com/arangodb/model/AqlQueryOptions.java | 30 ++++++++++++++----- .../com/arangodb/model/OptionsBuilder.java | 2 +- .../java/com/arangodb/serde/DataType.java | 16 +++++++++- .../com/arangodb/serde/InternalSerde.java | 7 +++++ .../com/arangodb/serde/InternalSerdeImpl.java | 11 ++++++- .../arangodb/serde/InternalSerializers.java | 11 +++++++ .../arangodb/util/ArangoSerialization.java | 4 +++ .../java/com/arangodb/ArangoDatabaseTest.java | 8 +++-- 13 files changed, 100 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index e6056cf9f..b8aba440f 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -39,6 +39,7 @@ 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; @@ -347,11 +348,6 @@ 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); } @@ -360,10 +356,9 @@ public synchronized ArangoDB build() { final VPackParser vpackParser = vpackParserBuilder.build(); final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer : new ArangoDeserializerImpl(vpackerNull, vpackParser); - final InternalSerde internalSerde = protocol == Protocol.HTTP_JSON ? InternalSerde.of(DataType.JSON) - : InternalSerde.of(DataType.VPACK); + final InternalSerde internalSerde = InternalSerde.of(DataType.of(protocol)); final DefaultArangoSerialization internal = new DefaultArangoSerialization(deserializerTemp, internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; + final ArangoSerialization custom = customSerializer != null ? customSerializer : new DefaultArangoSerialization(deserializerTemp, JacksonSerde.of(DataType.of(protocol)));; final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); int protocolMaxConnections = protocol == Protocol.VST ? diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 8075310b2..17cdce649 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -42,6 +42,7 @@ import com.arangodb.model.UserUpdateOptions; import com.arangodb.serde.DataType; import com.arangodb.serde.InternalSerde; +import com.arangodb.serde.JacksonSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; import com.arangodb.velocypack.*; @@ -508,11 +509,6 @@ 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); } @@ -523,7 +519,7 @@ public synchronized ArangoDBAsync build() { : new ArangoDeserializerImpl(vpackerNull, vpackParser); final InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); final DefaultArangoSerialization internal = new DefaultArangoSerialization(deserializerTemp, internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : internal; + final ArangoSerialization custom = customSerializer != null ? customSerializer : new DefaultArangoSerialization(deserializerTemp, JacksonSerde.of(DataType.VPACK)); final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); final int max = maxConnections != null ? Math.max(1, maxConnections) diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index f0ecd708e..ba2ca8237 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -167,8 +167,7 @@ protected Request queryRequest( final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR) .setBody(getInternalSerialization().serialize(OptionsBuilder .build(opt, query, bindVars != null ? - new VPackSlice(getUserSerialization().serialize(bindVars)) : - null))); + getUserSerialization().serialize(bindVars) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } diff --git a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java index c858c4bb7..fba587c7b 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java @@ -21,10 +21,12 @@ package com.arangodb.internal.util; import com.arangodb.ArangoDBException; +import com.arangodb.serde.ArangoSerde; import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import java.lang.reflect.Type; @@ -34,9 +36,9 @@ public class DefaultArangoSerialization implements ArangoSerialization { private final ArangoDeserializer deserializer; - private final InternalSerde serde; + private final ArangoSerde serde; - public DefaultArangoSerialization(final ArangoDeserializer deserializer, final InternalSerde serde) { + public DefaultArangoSerialization(final ArangoDeserializer deserializer, final ArangoSerde serde) { super(); this.deserializer = deserializer; this.serde = serde; @@ -49,7 +51,12 @@ public byte[] serialize(final Object entity) throws ArangoDBException { @Override public String toJsonString(byte[] content) { - return serde.toJsonString(content); + return ((InternalSerde) serde).toJsonString(content); + } + + @Override + public JsonNode parse(byte[] content) { + return ((InternalSerde) serde).parse(content); } @Override diff --git a/src/main/java/com/arangodb/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index 11dbb9739..bb0cc271f 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -116,12 +116,18 @@ public byte[] serialize(final Object entity) throws ArangoDBException { return serde.serialize(entity); } - // FIXME: toJsonString should only be required for internal serialization + // FIXME: only required for internal serialization @Override public String toJsonString(byte[] content) { throw new UnsupportedOperationException(); } + // FIXME: only required for internal serialization + @Override + public JsonNode parse(byte[] content) { + throw new UnsupportedOperationException(); + } + @SuppressWarnings("unchecked") @Override public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 51e8494f7..a83b05cee 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -20,10 +20,13 @@ package com.arangodb.model; +import com.arangodb.serde.InternalSerializers; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.annotations.Expose; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -34,9 +37,7 @@ * @see API * Documentation */ -public class AqlQueryOptions implements Serializable { - - private static final long serialVersionUID = 1L; +public class AqlQueryOptions { private Boolean count; private Integer ttl; @@ -44,6 +45,7 @@ public class AqlQueryOptions implements Serializable { private Boolean cache; private Long memoryLimit; private VPackSlice bindVars; + private byte[] bindVarsBytes; private String query; private Options options; @Expose(serialize = false) @@ -151,10 +153,17 @@ public AqlQueryOptions fillBlockCache(final Boolean fillBlockCache) { return this; } + @JsonIgnore public VPackSlice getBindVars() { return bindVars; } + @JsonProperty("bindVars") + @JsonSerialize(using = InternalSerializers.AqlParamsSerializer.class) + public byte[] getBindVarsBytes() { + return bindVarsBytes; + } + /** * @param bindVars key/value pairs representing the bind parameters * @return options @@ -164,6 +173,15 @@ protected AqlQueryOptions bindVars(final VPackSlice bindVars) { return this; } + /** + * @param bindVarsBytes serialized bind parameters + * @return options + */ + protected AqlQueryOptions bindVars(final byte[] bindVarsBytes) { + this.bindVarsBytes = bindVarsBytes; + return this; + } + public String getQuery() { return query; } @@ -409,9 +427,7 @@ public Options getOptions() { return options; } - public static class Options implements Serializable { - - private static final long serialVersionUID = 1L; + public static class Options { private Boolean failOnWarning; private Boolean profile; diff --git a/src/main/java/com/arangodb/model/OptionsBuilder.java b/src/main/java/com/arangodb/model/OptionsBuilder.java index ab99ad37f..52c79b62e 100644 --- a/src/main/java/com/arangodb/model/OptionsBuilder.java +++ b/src/main/java/com/arangodb/model/OptionsBuilder.java @@ -83,7 +83,7 @@ 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 byte[] bindVars) { return options.query(query).bindVars(bindVars); } diff --git a/src/main/java/com/arangodb/serde/DataType.java b/src/main/java/com/arangodb/serde/DataType.java index 0b071915a..801e89234 100644 --- a/src/main/java/com/arangodb/serde/DataType.java +++ b/src/main/java/com/arangodb/serde/DataType.java @@ -19,6 +19,20 @@ */ package com.arangodb.serde; +import com.arangodb.Protocol; + public enum DataType { - JSON, VPACK + 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 IllegalStateException("Unexpected value: " + protocol); + } + } } diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 839c7e5f5..1d13abd2c 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -1,6 +1,7 @@ package com.arangodb.serde; import com.arangodb.jackson.dataformat.velocypack.VPackMapper; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public interface InternalSerde extends JacksonSerde { @@ -39,4 +40,10 @@ static InternalSerde of(final DataType dataType) { */ byte[] extract(byte[] content, String jsonPointer); + /** + * TODO + * @param content + * @return + */ + JsonNode parse(byte[] content); } diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 10b46c980..0dd204379 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -39,11 +39,20 @@ public String toJsonString(final byte[] content) { @Override public byte[] extract(final byte[] content, final String jsonPointer) { try { - JsonNode target = mapper.readTree(content).at(jsonPointer); + 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); + } + } + } diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 46514b8c3..635b35991 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -9,6 +9,7 @@ import com.arangodb.velocypack.VPackSlice; 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; @@ -19,6 +20,16 @@ public final class InternalSerializers { + public static class AqlParamsSerializer extends JsonSerializer { + @Override + public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + // TODO: find a way to append raw bytes directly + try (JsonParser parser = gen.getCodec().getFactory().createParser(value)) { + gen.writeTree(parser.readValueAsTree()); + } + } + } + public static class CollectionSchemaRuleSerializer extends JsonSerializer { @Override public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index 6fee87692..1786eef2e 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -20,10 +20,14 @@ package com.arangodb.util; +import com.fasterxml.jackson.databind.JsonNode; + /** * @author Mark Vollmary */ public interface ArangoSerialization extends ArangoDeserializer { byte[] serialize(final Object entity); String toJsonString(byte[] content); + JsonNode parse(byte[] content); + } diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 068107c5e..37b7e2efd 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -1259,12 +1259,16 @@ void transactionAllowImplicit(ArangoDatabase db) { .isEqualTo(400); } - static class TransactionTestEntity { + public static class TransactionTestEntity { private String value; - TransactionTestEntity() { + public TransactionTestEntity() { super(); } + + public String getValue() { + return value; + } } @ParameterizedTest(name = "{index}") From 055d266c402b03a8419cdbc9b973737af86f6ac6 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 8 Jul 2022 10:07:11 +0200 Subject: [PATCH 21/52] separated ArangoSerialization from InternalSerialization --- src/main/java/com/arangodb/ArangoDB.java | 8 ++-- .../arangodb/ArangoSerializationAccessor.java | 3 +- .../com/arangodb/async/ArangoDBAsync.java | 10 +++-- .../velocystream/VstCommunicationAsync.java | 6 +-- .../com/arangodb/internal/ArangoDBImpl.java | 8 ++-- .../arangodb/internal/ArangoExecuteable.java | 3 +- .../internal/InternalArangoDBBuilder.java | 13 +------ .../arangodb/internal/http/CURLLogger.java | 4 +- .../internal/http/HttpCommunication.java | 4 +- .../internal/http/HttpConnection.java | 10 ++--- .../internal/http/HttpConnectionFactory.java | 4 +- .../internal/net/ExtendedHostResolver.java | 6 +-- .../arangodb/internal/net/HostResolver.java | 4 +- .../internal/net/SimpleHostResolver.java | 4 +- .../util/ArangoSerializationFactory.java | 7 ++-- .../util/ArangoSerializationImpl.java | 32 ++++++++++++++++ ...on.java => InternalSerializationImpl.java} | 13 +++---- .../arangodb/internal/util/ResponseUtils.java | 4 +- .../velocystream/VstCommunication.java | 6 +-- .../velocystream/VstCommunicationSync.java | 6 +-- .../java/com/arangodb/mapping/ArangoJack.java | 12 ------ .../arangodb/util/ArangoSerialization.java | 38 +++---------------- .../arangodb/util/InternalSerialization.java | 33 ++++++++++++++++ src/test/java/com/arangodb/JwtAuthTest.java | 4 +- .../java/com/arangodb/async/JwtAuthTest.java | 4 +- .../arangodb/internal/HostHandlerTest.java | 6 +-- .../com/arangodb/serde/CustomSerdeTest.java | 1 + .../util/ArangoSerializationTest.java | 2 +- 28 files changed, 138 insertions(+), 117 deletions(-) create mode 100644 src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java rename src/main/java/com/arangodb/internal/util/{DefaultArangoSerialization.java => InternalSerializationImpl.java} (79%) create mode 100644 src/main/java/com/arangodb/util/InternalSerialization.java diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index b8aba440f..fa63cb244 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -30,7 +30,8 @@ import com.arangodb.internal.net.*; import com.arangodb.internal.util.ArangoDeserializerImpl; import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.DefaultArangoSerialization; +import com.arangodb.internal.util.ArangoSerializationImpl; +import com.arangodb.internal.util.InternalSerializationImpl; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; @@ -43,6 +44,7 @@ import com.arangodb.util.ArangoCursorInitializer; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; import com.arangodb.velocypack.VPack; import com.arangodb.velocypack.VPackParser; import com.arangodb.velocystream.Request; @@ -357,8 +359,8 @@ public synchronized ArangoDB build() { final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer : new ArangoDeserializerImpl(vpackerNull, vpackParser); final InternalSerde internalSerde = InternalSerde.of(DataType.of(protocol)); - final DefaultArangoSerialization internal = new DefaultArangoSerialization(deserializerTemp, internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : new DefaultArangoSerialization(deserializerTemp, JacksonSerde.of(DataType.of(protocol)));; + final InternalSerialization internal = new InternalSerializationImpl(deserializerTemp, internalSerde); + final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(deserializerTemp, JacksonSerde.of(DataType.of(protocol))); final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); int protocolMaxConnections = protocol == Protocol.VST ? diff --git a/src/main/java/com/arangodb/ArangoSerializationAccessor.java b/src/main/java/com/arangodb/ArangoSerializationAccessor.java index 1bd7dcfa4..0f811517c 100644 --- a/src/main/java/com/arangodb/ArangoSerializationAccessor.java +++ b/src/main/java/com/arangodb/ArangoSerializationAccessor.java @@ -21,6 +21,7 @@ package com.arangodb; import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; /** * @author Mark Vollmary @@ -32,7 +33,7 @@ public interface ArangoSerializationAccessor { * * @return ArangoSerialization */ - ArangoSerialization getInternalSerialization(); + InternalSerialization getInternalSerialization(); /** * Returns serialization implementation for serializing and deserializing user's classes. diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 17cdce649..aae9d3684 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -33,7 +33,8 @@ import com.arangodb.internal.net.HostResolver; import com.arangodb.internal.util.ArangoDeserializerImpl; import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.DefaultArangoSerialization; +import com.arangodb.internal.util.ArangoSerializationImpl; +import com.arangodb.internal.util.InternalSerializationImpl; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; @@ -45,7 +46,8 @@ import com.arangodb.serde.JacksonSerde; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.*; +import com.arangodb.velocypack.VPack; +import com.arangodb.velocypack.VPackParser; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -518,8 +520,8 @@ public synchronized ArangoDBAsync build() { final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer : new ArangoDeserializerImpl(vpackerNull, vpackParser); final InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); - final DefaultArangoSerialization internal = new DefaultArangoSerialization(deserializerTemp, internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : new DefaultArangoSerialization(deserializerTemp, JacksonSerde.of(DataType.VPACK)); + final InternalSerializationImpl internal = new InternalSerializationImpl(deserializerTemp, internalSerde); + final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(deserializerTemp, JacksonSerde.of(DataType.VPACK)); final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); final int max = maxConnections != null ? Math.max(1, maxConnections) 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..030ebc5f2 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.util.InternalSerialization; 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 VstCommunication hosts, final Integer maxConnections, @@ -69,7 +69,7 @@ public ExtendedHostResolver(final List hosts, final Integer maxConnections } @Override - public void init(ArangoExecutorSync executor, ArangoSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerialization arangoSerialization) { this.executor = executor; this.arangoSerialization = arangoSerialization; } diff --git a/src/main/java/com/arangodb/internal/net/HostResolver.java b/src/main/java/com/arangodb/internal/net/HostResolver.java index 85bdd2038..3dd9e6e1a 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.util.InternalSerialization; /** * @author Mark Vollmary */ public interface HostResolver { - void init(ArangoExecutorSync executorSync, ArangoSerialization arangoSerialization); + void init(ArangoExecutorSync executorSync, InternalSerialization 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..088189747 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.util.InternalSerialization; 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, InternalSerialization arangoSerialization) { } diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java b/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java index b015b59ec..c5c3558f9 100644 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java +++ b/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java @@ -21,22 +21,23 @@ package com.arangodb.internal.util; import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; /** * @author Mark Vollmary */ public class ArangoSerializationFactory { - private final ArangoSerialization internal; + private final InternalSerialization internal; private final ArangoSerialization user; - public ArangoSerializationFactory(final ArangoSerialization internal, final ArangoSerialization user) { + public ArangoSerializationFactory(final InternalSerialization internal, final ArangoSerialization user) { super(); this.internal = internal; this.user = user; } - public ArangoSerialization getInternalSerialization() { + public InternalSerialization getInternalSerialization() { return internal; } diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java b/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java new file mode 100644 index 000000000..e0048baea --- /dev/null +++ b/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java @@ -0,0 +1,32 @@ +package com.arangodb.internal.util; + +import com.arangodb.ArangoDBException; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.util.ArangoDeserializer; +import com.arangodb.util.ArangoSerialization; +import com.arangodb.velocypack.VPackSlice; + +import java.lang.reflect.Type; + +public class ArangoSerializationImpl implements ArangoSerialization { + + private final ArangoDeserializer deserializer; + private final ArangoSerde serde; + + public ArangoSerializationImpl(final ArangoDeserializer deserializer, final ArangoSerde serde) { + super(); + this.deserializer = deserializer; + this.serde = serde; + } + + @Override + public byte[] serialize(final Object entity) throws ArangoDBException { + return serde.serialize(entity); + } + + @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/DefaultArangoSerialization.java b/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java similarity index 79% rename from src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java rename to src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java index fba587c7b..05f249697 100644 --- a/src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java +++ b/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java @@ -21,10 +21,9 @@ package com.arangodb.internal.util; import com.arangodb.ArangoDBException; -import com.arangodb.serde.ArangoSerde; import com.arangodb.serde.InternalSerde; import com.arangodb.util.ArangoDeserializer; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.databind.JsonNode; @@ -33,12 +32,12 @@ /** * @author Mark Vollmary */ -public class DefaultArangoSerialization implements ArangoSerialization { +public class InternalSerializationImpl implements InternalSerialization { private final ArangoDeserializer deserializer; - private final ArangoSerde serde; + private final InternalSerde serde; - public DefaultArangoSerialization(final ArangoDeserializer deserializer, final ArangoSerde serde) { + public InternalSerializationImpl(final ArangoDeserializer deserializer, final InternalSerde serde) { super(); this.deserializer = deserializer; this.serde = serde; @@ -51,12 +50,12 @@ public byte[] serialize(final Object entity) throws ArangoDBException { @Override public String toJsonString(byte[] content) { - return ((InternalSerde) serde).toJsonString(content); + return serde.toJsonString(content); } @Override public JsonNode parse(byte[] content) { - return ((InternalSerde) serde).parse(content); + return serde.parse(content); } @Override diff --git a/src/main/java/com/arangodb/internal/util/ResponseUtils.java b/src/main/java/com/arangodb/internal/util/ResponseUtils.java index 0cc5e38cb..bd181ddb5 100644 --- a/src/main/java/com/arangodb/internal/util/ResponseUtils.java +++ b/src/main/java/com/arangodb/internal/util/ResponseUtils.java @@ -24,7 +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.util.InternalSerialization; import com.arangodb.velocypack.exception.VPackParserException; import com.arangodb.velocystream.Response; @@ -43,7 +43,7 @@ private ResponseUtils() { super(); } - public static void checkError(final ArangoSerialization util, final Response response) throws ArangoDBException { + public static void checkError(final InternalSerialization util, final Response response) throws ArangoDBException { try { final int responseCode = response.getResponseCode(); if (responseCode >= ERROR_STATUS) { diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java index 0cb2faea1..b76e1971c 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.util.InternalSerialization; 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 InternalSerialization 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 InternalSerialization util, final Integer chunksize, final HostHandler hostHandler) { this.user = user; this.password = password; diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java index e01e22bc2..140882367 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.util.InternalSerialization; 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 InternalSerialization 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 InternalSerialization 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/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index bb0cc271f..392548dd8 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -116,18 +116,6 @@ public byte[] serialize(final Object entity) throws ArangoDBException { return serde.serialize(entity); } - // FIXME: only required for internal serialization - @Override - public String toJsonString(byte[] content) { - throw new UnsupportedOperationException(); - } - - // FIXME: only required for internal serialization - @Override - public JsonNode parse(byte[] content) { - throw new UnsupportedOperationException(); - } - @SuppressWarnings("unchecked") @Override public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index 1786eef2e..8efa1b522 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -1,33 +1,5 @@ -/* - * 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.fasterxml.jackson.databind.JsonNode; - -/** - * @author Mark Vollmary - */ -public interface ArangoSerialization extends ArangoDeserializer { - byte[] serialize(final Object entity); - String toJsonString(byte[] content); - JsonNode parse(byte[] content); - -} +package com.arangodb.util; + +public interface ArangoSerialization extends ArangoDeserializer { + byte[] serialize(final Object entity); +} diff --git a/src/main/java/com/arangodb/util/InternalSerialization.java b/src/main/java/com/arangodb/util/InternalSerialization.java new file mode 100644 index 000000000..690d02a71 --- /dev/null +++ b/src/main/java/com/arangodb/util/InternalSerialization.java @@ -0,0 +1,33 @@ +/* + * 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.fasterxml.jackson.databind.JsonNode; + +/** + * @author Mark Vollmary + */ +public interface InternalSerialization extends ArangoDeserializer { + byte[] serialize(final Object entity); + String toJsonString(byte[] content); + JsonNode parse(byte[] content); + +} diff --git a/src/test/java/com/arangodb/JwtAuthTest.java b/src/test/java/com/arangodb/JwtAuthTest.java index 7ba60adbb..835c2cade 100644 --- a/src/test/java/com/arangodb/JwtAuthTest.java +++ b/src/test/java/com/arangodb/JwtAuthTest.java @@ -1,7 +1,7 @@ package com.arangodb; import com.arangodb.mapping.ArangoJack; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.arangodb.velocystream.Response; @@ -83,7 +83,7 @@ private ArangoDB.Builder getBuilder(Protocol protocol) { } private static String getJwt(ArangoDB arangoDB) { - ArangoSerialization serde = arangoDB.getInternalSerialization(); + InternalSerialization serde = arangoDB.getInternalSerialization(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/async/JwtAuthTest.java b/src/test/java/com/arangodb/async/JwtAuthTest.java index ba119bcc7..a55c23527 100644 --- a/src/test/java/com/arangodb/async/JwtAuthTest.java +++ b/src/test/java/com/arangodb/async/JwtAuthTest.java @@ -4,7 +4,7 @@ import com.arangodb.ArangoDBException; import com.arangodb.DbName; import com.arangodb.mapping.ArangoJack; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.arangodb.velocystream.Response; @@ -90,7 +90,7 @@ private ArangoDBAsync.Builder getBuilder() { } private static String getJwt(ArangoDB arangoDB) { - ArangoSerialization serde = arangoDB.getInternalSerialization(); + InternalSerialization serde = arangoDB.getInternalSerialization(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/internal/HostHandlerTest.java b/src/test/java/com/arangodb/internal/HostHandlerTest.java index 56b09ca5d..0fcc2bc92 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.util.InternalSerialization; 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, InternalSerialization 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, InternalSerialization arangoSerialization) { } diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index e703ecae4..06bbb18c8 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -29,6 +29,7 @@ import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; import com.arangodb.util.ArangoSerialization; +import com.arangodb.util.InternalSerialization; import com.arangodb.velocypack.VPackBuilder; import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.core.JsonGenerator; diff --git a/src/test/java/com/arangodb/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java index 28ed2612c..7f08a8d81 100644 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ b/src/test/java/com/arangodb/util/ArangoSerializationTest.java @@ -40,7 +40,7 @@ */ class ArangoSerializationTest { - private static ArangoSerialization internalSer; + private static InternalSerialization internalSer; private static ArangoSerialization userSer; @BeforeAll From d0bc5d4388325bdba53705e70bad8686c1f237d5 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 8 Jul 2022 12:38:01 +0200 Subject: [PATCH 22/52] deserializer refactoring --- src/main/java/com/arangodb/ArangoDB.java | 13 +- .../com/arangodb/async/ArangoDBAsync.java | 6 +- .../com/arangodb/entity/CursorEntity.java | 5 +- .../internal/ArangoResponseField.java | 4 +- .../internal/InternalArangoCollection.java | 122 +++++++------- .../arangodb/internal/InternalArangoDB.java | 34 ++-- .../internal/InternalArangoDatabase.java | 157 +++++------------- .../InternalArangoEdgeCollection.java | 12 +- .../internal/InternalArangoGraph.java | 10 +- .../InternalArangoVertexCollection.java | 12 +- .../internal/cursor/ArangoCursorIterator.java | 12 +- .../internal/http/HttpConnection.java | 16 +- .../internal/net/ExtendedHostResolver.java | 18 +- .../util/ArangoSerializationImpl.java | 10 +- .../util/InternalSerializationImpl.java | 30 +++- .../velocypack/VPackDeserializers.java | 27 +-- .../velocystream/VstCommunication.java | 4 +- .../java/com/arangodb/mapping/ArangoJack.java | 21 +-- .../arangodb/serde/InternalDeserializers.java | 49 ++++++ .../com/arangodb/serde/InternalModule.java | 7 + .../com/arangodb/serde/InternalSerde.java | 25 ++- .../com/arangodb/serde/InternalSerdeImpl.java | 12 ++ .../arangodb/util/ArangoSerialization.java | 5 +- .../arangodb/util/InternalSerialization.java | 16 +- .../com/arangodb/velocystream/Response.java | 26 +-- src/test/java/com/arangodb/ArangoDBTest.java | 2 +- .../java/com/arangodb/ArangoRouteTest.java | 2 +- src/test/java/com/arangodb/BaseJunit5.java | 1 - .../java/com/arangodb/async/ArangoDBTest.java | 4 +- .../annotations/ArangoAnnotationsTest.java | 14 +- .../com/arangodb/serde/CustomSerdeTest.java | 12 +- .../util/ArangoSerializationTest.java | 6 +- 32 files changed, 313 insertions(+), 381 deletions(-) create mode 100644 src/main/java/com/arangodb/serde/InternalDeserializers.java diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index fa63cb244..5efa9db1e 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -28,7 +28,6 @@ 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.ArangoSerializationImpl; import com.arangodb.internal.util.InternalSerializationImpl; @@ -42,11 +41,8 @@ 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.InternalSerialization; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackParser; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.apache.http.client.HttpRequestRetryHandler; @@ -353,14 +349,9 @@ public synchronized ArangoDB build() { 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 ArangoDeserializer deserializerTemp = deserializer != null ? deserializer - : new ArangoDeserializerImpl(vpackerNull, vpackParser); final InternalSerde internalSerde = InternalSerde.of(DataType.of(protocol)); - final InternalSerialization internal = new InternalSerializationImpl(deserializerTemp, internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(deserializerTemp, JacksonSerde.of(DataType.of(protocol))); + final InternalSerialization internal = new InternalSerializationImpl(internalSerde); + final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(JacksonSerde.of(DataType.of(protocol))); final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); int protocolMaxConnections = protocol == Protocol.VST ? diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index aae9d3684..275adf982 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -517,11 +517,9 @@ public synchronized ArangoDBAsync build() { final VPack vpacker = vpackBuilder.serializeNullValues(false).build(); final VPack vpackerNull = vpackBuilder.serializeNullValues(true).build(); final VPackParser vpackParser = vpackParserBuilder.build(); - final ArangoDeserializer deserializerTemp = deserializer != null ? deserializer - : new ArangoDeserializerImpl(vpackerNull, vpackParser); final InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); - final InternalSerializationImpl internal = new InternalSerializationImpl(deserializerTemp, internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(deserializerTemp, JacksonSerde.of(DataType.VPACK)); + final InternalSerializationImpl internal = new InternalSerializationImpl(internalSerde); + final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(JacksonSerde.of(DataType.VPACK)); final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); final int max = maxConnections != null ? Math.max(1, maxConnections) diff --git a/src/main/java/com/arangodb/entity/CursorEntity.java b/src/main/java/com/arangodb/entity/CursorEntity.java index 66a9a7010..5e73fbe9f 100644 --- a/src/main/java/com/arangodb/entity/CursorEntity.java +++ b/src/main/java/com/arangodb/entity/CursorEntity.java @@ -21,6 +21,7 @@ package com.arangodb.entity; import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import java.util.Collection; import java.util.Collections; @@ -38,7 +39,7 @@ public class CursorEntity implements Entity, MetaAware { private Extras extra = new Extras(); private Boolean cached; private Boolean hasMore; - private VPackSlice result; + private JsonNode result; private Map meta; @@ -83,7 +84,7 @@ public Boolean getHasMore() { /** * @return an vpack-array of result documents (might be empty if query has no results) */ - public VPackSlice getResult() { + public JsonNode getResult() { return result; } diff --git a/src/main/java/com/arangodb/internal/ArangoResponseField.java b/src/main/java/com/arangodb/internal/ArangoResponseField.java index 846774a3e..2a828cc03 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 = "/error"; + public static final String RESULT = "/result"; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 298772824..3bb982a51 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -29,7 +29,6 @@ import com.arangodb.model.*; import com.arangodb.serde.SerdeUtils; import com.arangodb.velocypack.Type; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.fasterxml.jackson.databind.JsonNode; @@ -105,15 +104,15 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO protected ResponseDeserializer> insertDocumentResponseDeserializer( final T value, final DocumentCreateOptions options) { return response -> { - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentCreateEntity doc = getInternalSerialization().deserialize(body, DocumentCreateEntity.class); - final VPackSlice newDoc = body.get(NEW); + final JsonNode newDoc = body.get(NEW); if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(newDoc, value.getClass())); + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), value.getClass())); } - final VPackSlice oldDoc = body.get(OLD); + final JsonNode oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, value.getClass())); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -156,23 +155,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).booleanValue()) { final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentCreateEntity doc = getInternalSerialization().deserialize(next, DocumentCreateEntity.class); - final VPackSlice newDoc = next.get(NEW); + final JsonNode newDoc = next.get(NEW); if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(newDoc, type)); + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); } - final VPackSlice oldDoc = next.get(OLD); + final JsonNode oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -238,15 +237,15 @@ 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 JsonNode body = getInternalSerialization().parse(response.getBody()); + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).booleanValue()) { final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final T doc = getUserSerialization().deserialize(next, type); + final T doc = getUserSerialization().deserialize(getInternalSerialization().serialize(next), type); docs.add(doc); documentsAndErrors.add(doc); } @@ -277,15 +276,15 @@ protected Request replaceDocumentRequest( protected ResponseDeserializer> replaceDocumentResponseDeserializer( final T value, final DocumentReplaceOptions options) { return response -> { - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); - final VPackSlice newDoc = body.get(NEW); + final JsonNode newDoc = body.get(NEW); if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(newDoc, value.getClass())); + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), value.getClass())); } - final VPackSlice oldDoc = body.get(OLD); + final JsonNode oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, value.getClass())); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -326,23 +325,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).booleanValue()) { final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); - final VPackSlice newDoc = next.get(NEW); + final JsonNode newDoc = next.get(NEW); if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(newDoc, type)); + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); } - final VPackSlice oldDoc = next.get(OLD); + final JsonNode oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -376,15 +375,15 @@ protected Request updateDocumentRequest(final String key, final T value, fin protected ResponseDeserializer> updateDocumentResponseDeserializer( final T value, final DocumentUpdateOptions options, final Class returnType) { return response -> { - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); - final VPackSlice newDoc = body.get(NEW); + final JsonNode newDoc = body.get(NEW); if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(newDoc, returnType)); + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); } - final VPackSlice oldDoc = body.get(OLD); + final JsonNode oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, returnType)); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -422,23 +421,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).booleanValue()) { final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); - final VPackSlice newDoc = next.get(NEW); + final JsonNode newDoc = next.get(NEW); if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(newDoc, returnType)); + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); } - final VPackSlice oldDoc = next.get(OLD); + final JsonNode oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, returnType)); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); } docs.add(doc); documentsAndErrors.add(doc); @@ -467,11 +466,11 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp protected ResponseDeserializer> deleteDocumentResponseDeserializer( final Class type) { return response -> { - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentDeleteEntity doc = getInternalSerialization().deserialize(body, DocumentDeleteEntity.class); - final VPackSlice oldDoc = body.get(OLD); + final JsonNode oldDoc = body.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); } return doc; }; @@ -495,19 +494,19 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final VPackSlice body = response.getBody(); + final JsonNode body = getInternalSerialization().parse(response.getBody()); if (body.isArray()) { - for (final Iterator iterator = body.arrayIterator(); iterator.hasNext(); ) { - final VPackSlice next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).isTrue()) { + for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { + final JsonNode next = iterator.next(); + if (next.get(ArangoResponseField.ERROR).booleanValue()) { final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentDeleteEntity doc = getInternalSerialization().deserialize(next, DocumentDeleteEntity.class); - final VPackSlice oldDoc = next.get(OLD); + final JsonNode oldDoc = next.get(OLD); if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(oldDoc, type)); + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -540,7 +539,7 @@ protected Request deleteIndexRequest(final String id) { } protected ResponseDeserializer deleteIndexResponseDeserializer() { - return response -> response.getBody().get("id").getAsString(); + return response -> getInternalSerialization().deserialize(response.getBody(), "id", String.class); } private String createIndexId(final String id) { @@ -622,7 +621,7 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("indexes"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "indexes", new Type>() { }.getType()); } @@ -690,16 +689,7 @@ 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 getInternalSerialization().deserialize(result, Permissions.class); - } - } - return null; - }; + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Permissions.class); } private boolean isStringCollection(final Collection values) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index e1ccaeef5..49c545c60 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -21,19 +21,20 @@ package com.arangodb.internal; import com.arangodb.DbName; -import com.arangodb.entity.*; +import com.arangodb.entity.LogLevelEntity; +import com.arangodb.entity.Permissions; +import com.arangodb.entity.ServerRole; +import com.arangodb.entity.UserEntity; 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.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 @@ -62,11 +63,11 @@ protected Request getServerIdRequest() { } protected ResponseDeserializer getRoleResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("role"), ServerRole.class); + return response -> getInternalSerialization().deserialize(response.getBody(), "/role", ServerRole.class); } protected ResponseDeserializer getServerIdResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("id"), String.class); + return response -> getInternalSerialization().deserialize(response.getBody(), "/id", String.class); } protected Request createDatabaseRequest(final DBCreateOptions options) { @@ -77,7 +78,7 @@ protected Request createDatabaseRequest(final DBCreateOptions options) { } protected ResponseDeserializer createDatabaseResponseDeserializer() { - return response -> response.getBody().get(ArangoResponseField.RESULT).getAsBoolean(); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Boolean.class); } protected Request getDatabasesRequest(final DbName dbName) { @@ -85,11 +86,8 @@ protected Request getDatabasesRequest(final DbName dbName) { } protected ResponseDeserializer> getDatabaseResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + }.getType()); } protected Request getAccessibleDatabasesForRequest(final DbName dbName, final String user) { @@ -98,11 +96,10 @@ protected Request getAccessibleDatabasesForRequest(final DbName dbName, final St protected ResponseDeserializer> getAccessibleDatabasesForResponseDeserializer() { return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); + Iterator names = getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT).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; }; @@ -133,11 +130,8 @@ protected Request getUserRequest(final DbName dbName, final String user) { } protected ResponseDeserializer> getUsersResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + }.getType()); } protected Request updateUserRequest(final DbName dbName, final String user, final UserUpdateOptions options) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index ba2ca8237..ba23a1c66 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -41,8 +41,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"; @@ -98,8 +97,7 @@ protected Request getEngineRequest() { protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) { - byte[] body = getInternalSerialization() - .serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)); + byte[] body = getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)); return request(dbName, RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(body); } @@ -113,11 +111,8 @@ protected Request getCollectionsRequest(final CollectionsReadOptions options) { } protected ResponseDeserializer> getCollectionsResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT), new Type>() { + }.getType()); } protected Request dropRequest() { @@ -125,49 +120,32 @@ protected Request dropRequest() { } protected ResponseDeserializer createDropResponseDeserializer() { - return response -> response.getBody().get(ArangoResponseField.RESULT).getAsBoolean(); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, 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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get()).setBody(getInternalSerialization().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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get(), "*").setBody(getInternalSerialization().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 getInternalSerialization().deserialize(result, Permissions.class); - } - } - return null; - }; - } - - protected Request queryRequest( - final String query, final Map bindVars, final AqlQueryOptions options) { + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Permissions.class); + } + + 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(getInternalSerialization().serialize(OptionsBuilder - .build(opt, query, bindVars != null ? - getUserSerialization().serialize(bindVars) : null))); + final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR).setBody(getInternalSerialization().serialize(OptionsBuilder.build(opt, query, bindVars != null ? getUserSerialization().serialize(bindVars) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } @@ -209,24 +187,15 @@ 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(getInternalSerialization().serialize(OptionsBuilder.build( - opt, - query, - bindVars != null ? new VPackSlice(getUserSerialization().serialize(bindVars)) : null))); + return request(dbName, RequestType.POST, PATH_API_EXPLAIN).setBody(getInternalSerialization().serialize(OptionsBuilder.build(opt, query, bindVars != null ? new VPackSlice(getUserSerialization().serialize(bindVars)) : null))); } protected Request parseQueryRequest(final String query) { - return request(dbName, RequestType.POST, PATH_API_QUERY) - .setBody(getInternalSerialization().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); + return request(dbName, RequestType.POST, PATH_API_QUERY).setBody(getInternalSerialization().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); } protected Request clearQueryCacheRequest() { @@ -265,10 +234,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(getInternalSerialization().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(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); } protected Request deleteAqlFunctionRequest(final String name, final AqlFunctionDeleteOptions options) { @@ -279,19 +246,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 -> getInternalSerialization().deserialize(response.getBody(), "/deletedCount", Integer.class); } protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { @@ -302,24 +257,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 getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + }.getType()); } - protected Request createGraphRequest( - final String name, final Collection edgeDefinitions, final GraphCreateOptions options) { - return request(dbName, RequestType.POST, InternalArangoGraph.PATH_API_GHARIAL).setBody(getInternalSerialization().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(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); } protected ResponseDeserializer createGraphResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("graph"), GraphEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), "/graph", GraphEntity.class); } protected Request getGraphsRequest() { @@ -327,31 +274,20 @@ protected Request getGraphsRequest() { } protected ResponseDeserializer> getGraphsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("graphs"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "/graphs", new Type>() { }.getType()); } protected Request transactionRequest(final String action, final TransactionOptions options) { - return request(dbName, RequestType.POST, PATH_API_TRANSACTION).setBody( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); + return request(dbName, RequestType.POST, PATH_API_TRANSACTION).setBody(getInternalSerialization().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 getUserSerialization().deserialize(result, type); - } - } - return null; - }; + return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), ArangoResponseField.RESULT), type); } protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { - return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION) - .setBody(getInternalSerialization().serialize(options != null ? options : new StreamTransactionOptions())); + return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION).setBody(getInternalSerialization().serialize(options != null ? options : new StreamTransactionOptions())); } protected Request abortStreamTransactionRequest(String id) { @@ -367,11 +303,8 @@ protected Request getStreamTransactionRequest(String id) { } protected ResponseDeserializer> transactionsResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get("transactions"); - return getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(response.getBody(), "/transactions", new Type>() { + }.getType()); } protected Request commitStreamTransactionRequest(String id) { @@ -379,8 +312,7 @@ protected Request commitStreamTransactionRequest(String id) { } protected ResponseDeserializer streamTransactionResponseDeserializer() { - return response -> getInternalSerialization() - .deserialize(response.getBody().get(ArangoResponseField.RESULT), StreamTransactionEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, StreamTransactionEntity.class); } protected Request getInfoRequest() { @@ -388,7 +320,7 @@ protected Request getInfoRequest() { } protected ResponseDeserializer getInfoResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get(ArangoResponseField.RESULT), DatabaseEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, DatabaseEntity.class); } protected Request reloadRoutingRequest() { @@ -400,21 +332,16 @@ protected Request getViewsRequest() { } protected ResponseDeserializer> getViewsResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + }.getType()); } protected Request createViewRequest(final String name, final ViewType type) { - return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW) - .setBody(getInternalSerialization().serialize(OptionsBuilder.build(new ViewCreateOptions(), name, type))); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getInternalSerialization().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(getInternalSerialization().serialize( - ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getInternalSerialization().serialize(ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); } protected Request getAnalyzerRequest(final String name) { @@ -426,16 +353,12 @@ protected Request getAnalyzersRequest() { } protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { - return response -> { - final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); - return getInternalSerialization().deserialize(result, new Type>() { - }.getType()); - }; + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + }.getType()); } protected Request createAnalyzerRequest(final SearchAnalyzer options) { - return request(dbName, RequestType.POST, InternalArangoView.PATH_API_ANALYZER) - .setBody(getInternalSerialization().serialize(options)); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_ANALYZER).setBody(getInternalSerialization().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 0c84c3734..cb24a0730 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -26,7 +26,6 @@ import com.arangodb.internal.util.DocumentUtil; import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -73,8 +72,7 @@ protected Request insertEdgeRequest(final T value, final EdgeCreateOptions o protected ResponseDeserializer insertEdgeResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(EDGE); - final EdgeEntity doc = getInternalSerialization().deserialize(body, EdgeEntity.class); + final EdgeEntity doc = getInternalSerialization().deserialize(response.getBody(), EDGE, EdgeEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -98,7 +96,7 @@ protected Request getEdgeRequest(final String key, final GraphDocumentReadOption } protected ResponseDeserializer getEdgeResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(response.getBody().get(EDGE), type); + return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), EDGE), type); } protected Request replaceEdgeRequest(final String key, final T value, final EdgeReplaceOptions options) { @@ -114,8 +112,7 @@ protected Request replaceEdgeRequest(final String key, final T value, final protected ResponseDeserializer replaceEdgeResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(EDGE); - final EdgeUpdateEntity doc = getInternalSerialization().deserialize(body, EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), EDGE, EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -138,8 +135,7 @@ protected Request updateEdgeRequest(final String key, final T value, final E protected ResponseDeserializer updateEdgeResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(EDGE); - final EdgeUpdateEntity doc = getInternalSerialization().deserialize(body, EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), EDGE, EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index 10059c705..e65d3a9cb 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoGraph.java +++ b/src/main/java/com/arangodb/internal/InternalArangoGraph.java @@ -84,7 +84,7 @@ protected Request getVertexCollectionsRequest() { } protected ResponseDeserializer> getVertexCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("collections"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "collections", new Type>() { }.getType()); } @@ -103,7 +103,7 @@ protected Request getEdgeDefinitionsRequest() { } protected ResponseDeserializer> getEdgeDefinitionsDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get("collections"), new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "collections", new Type>() { }.getType()); } @@ -114,7 +114,7 @@ protected Request addEdgeDefinitionRequest(final EdgeDefinition definition) { } protected ResponseDeserializer addEdgeDefinitionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), GRAPH, GraphEntity.class); } protected Request replaceEdgeDefinitionRequest(final EdgeDefinition definition) { @@ -125,7 +125,7 @@ protected Request replaceEdgeDefinitionRequest(final EdgeDefinition definition) } protected ResponseDeserializer replaceEdgeDefinitionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getInternalSerialization().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 -> getInternalSerialization().deserialize(response.getBody().get(GRAPH), GraphEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), GRAPH, GraphEntity.class); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 7bc503289..92e03d195 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -27,7 +27,6 @@ import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; import com.arangodb.serde.SerdeUtils; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -85,8 +84,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio protected ResponseDeserializer insertVertexResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(VERTEX); - final VertexEntity doc = getInternalSerialization().deserialize(body, VertexEntity.class); + final VertexEntity doc = getInternalSerialization().deserialize(response.getBody(), VERTEX, VertexEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -110,7 +108,7 @@ protected Request getVertexRequest(final String key, final GraphDocumentReadOpti } protected ResponseDeserializer getVertexResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(response.getBody().get(VERTEX), type); + return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), VERTEX), type); } protected Request replaceVertexRequest(final String key, final T value, final VertexReplaceOptions options) { @@ -126,8 +124,7 @@ protected Request replaceVertexRequest(final String key, final T value, fina protected ResponseDeserializer replaceVertexResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(VERTEX); - final VertexUpdateEntity doc = getInternalSerialization().deserialize(body, VertexUpdateEntity.class); + final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), VERTEX, VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -150,8 +147,7 @@ protected Request updateVertexRequest(final String key, final T value, final protected ResponseDeserializer updateVertexResponseDeserializer(final T value) { return response -> { - final VPackSlice body = response.getBody().get(VERTEX); - final VertexUpdateEntity doc = getInternalSerialization().deserialize(body, VertexUpdateEntity.class); + final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), VERTEX, VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java index ff83bfbc4..8b108f8ff 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -25,7 +25,7 @@ import com.arangodb.entity.CursorEntity; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; -import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import java.util.Iterator; import java.util.NoSuchElementException; @@ -37,7 +37,7 @@ public class ArangoCursorIterator implements ArangoIterator { private CursorEntity result; - private Iterator arrayIterator; + private Iterator arrayIterator; private final ArangoCursor cursor; private final InternalArangoDatabase db; @@ -50,7 +50,7 @@ protected ArangoCursorIterator(final ArangoCursor cursor, final ArangoCursorE this.execute = execute; this.db = db; this.result = result; - arrayIterator = result.getResult().arrayIterator(); + arrayIterator = result.getResult().iterator(); } public CursorEntity getResult() { @@ -66,15 +66,15 @@ 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.getInternalSerialization().serialize(arrayIterator.next()), cursor.getType()); } - protected R deserialize(final VPackSlice result, final Class type) { + protected R deserialize(final byte[] result, final Class type) { return db.getUserSerialization().deserialize(result, type); } diff --git a/src/main/java/com/arangodb/internal/http/HttpConnection.java b/src/main/java/com/arangodb/internal/http/HttpConnection.java index 789c0abfc..3f46c0bd7 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnection.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnection.java @@ -30,7 +30,6 @@ import com.arangodb.serde.DataType; import com.arangodb.util.InternalSerialization; import com.arangodb.velocypack.VPackParser; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.apache.http.*; @@ -349,20 +348,13 @@ private static void addHeader(final Request request, final HttpRequestBase httpR public Response buildResponse(final CloseableHttpResponse httpResponse) throws UnsupportedOperationException, IOException { - final Response response = new Response(dataType); + final Response response = new Response(); 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(parser.fromJson(content, 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/net/ExtendedHostResolver.java b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java index 6e300f6ba..e0bb05117 100644 --- a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java +++ b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java @@ -22,10 +22,11 @@ import com.arangodb.ArangoDBException; import com.arangodb.DbName; +import com.arangodb.entity.CollectionEntity; import com.arangodb.internal.ArangoExecutorSync; import com.arangodb.internal.util.HostUtils; import com.arangodb.util.InternalSerialization; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.velocypack.Type; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import org.slf4j.Logger; @@ -127,16 +128,11 @@ 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 Collection> tmp = arangoSerialization.deserialize(response1.getBody(), "/endpoints", new Type>() { + }.getType()); + 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/util/ArangoSerializationImpl.java b/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java index e0048baea..3cba46382 100644 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java +++ b/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java @@ -2,20 +2,16 @@ import com.arangodb.ArangoDBException; import com.arangodb.serde.ArangoSerde; -import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPackSlice; import java.lang.reflect.Type; public class ArangoSerializationImpl implements ArangoSerialization { - private final ArangoDeserializer deserializer; private final ArangoSerde serde; - public ArangoSerializationImpl(final ArangoDeserializer deserializer, final ArangoSerde serde) { + public ArangoSerializationImpl(final ArangoSerde serde) { super(); - this.deserializer = deserializer; this.serde = serde; } @@ -25,8 +21,8 @@ public byte[] serialize(final Object entity) throws ArangoDBException { } @Override - public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { - return deserializer.deserialize(vpack, type); + public T deserialize(byte[] content, Type type) { + return serde.deserialize(content, type); } } diff --git a/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java b/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java index 05f249697..681108497 100644 --- a/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java +++ b/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java @@ -22,9 +22,7 @@ import com.arangodb.ArangoDBException; import com.arangodb.serde.InternalSerde; -import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.InternalSerialization; -import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.databind.JsonNode; import java.lang.reflect.Type; @@ -34,12 +32,10 @@ */ public class InternalSerializationImpl implements InternalSerialization { - private final ArangoDeserializer deserializer; private final InternalSerde serde; - public InternalSerializationImpl(final ArangoDeserializer deserializer, final InternalSerde serde) { + public InternalSerializationImpl(final InternalSerde serde) { super(); - this.deserializer = deserializer; this.serde = serde; } @@ -59,8 +55,28 @@ public JsonNode parse(byte[] content) { } @Override - public T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { - return deserializer.deserialize(vpack, type); + public T deserialize(byte[] content, Type type) { + return serde.deserialize(content, type); + } + + @Override + public T deserialize(JsonNode node, Type type) { + return serde.deserialize(node, type); + } + + @Override + public JsonNode parse(byte[] content, String jsonPointer) { + return serde.parse(content, jsonPointer); + } + + @Override + public T deserialize(byte[] content, String jsonPointer, Type type) { + return serde.deserialize(content, jsonPointer, type); + } + + @Override + public byte[] extract(byte[] content, String jsonPointer) { + return serde.extract(content, jsonPointer); } } diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java index f2cad52d6..06b5e0878 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java @@ -20,32 +20,11 @@ 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.*; +import com.arangodb.entity.arangosearch.*; import com.arangodb.entity.arangosearch.analyzer.*; import com.arangodb.model.CollectionSchema; import com.arangodb.model.ZKDIndexOptions; -import com.arangodb.serde.DataType; import com.arangodb.velocypack.VPackDeserializer; import com.arangodb.velocypack.VPackParser; import com.arangodb.velocypack.VPackSlice; @@ -67,7 +46,7 @@ public class VPackDeserializers { 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(DataType.VPACK); + final Response response = new Response(); response.setVersion(vpack.get(0).getAsInt()); response.setType(vpack.get(1).getAsInt()); response.setResponseCode(vpack.get(2).getAsInt()); diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java index b76e1971c..81cec8572 100644 --- a/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java +++ b/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java @@ -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/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index 392548dd8..26f9fd5c4 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -33,14 +33,11 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.PropertyAccessor; 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; /** * @author Mark Vollmary @@ -116,23 +113,9 @@ public byte[] serialize(final Object entity) throws ArangoDBException { return serde.serialize(entity); } - @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); - } + public T deserialize(byte[] content, Type type) { + return serde.deserialize(content, type); } } 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..f2132a089 --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -0,0 +1,49 @@ +package com.arangodb.serde; + +import com.arangodb.entity.CollectionStatus; +import com.arangodb.entity.CollectionType; +import com.arangodb.velocystream.Response; +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.node.ArrayNode; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; + +public final class InternalDeserializers { + private InternalDeserializers() { + } + + 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 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(ctxt.readTreeAsValue(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 index 2c8d1442d..9f9e25a62 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -1,10 +1,12 @@ package com.arangodb.serde; +import com.arangodb.entity.CollectionStatus; import com.arangodb.entity.CollectionType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; +import com.arangodb.velocystream.Response; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -17,11 +19,16 @@ enum InternalModule implements Supplier { InternalModule() { module = new SimpleModule(); + module.addSerializer(VPackSlice.class, InternalSerializers.VPACK_SLICE_JSON_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(CollectionStatus.class, InternalDeserializers.COLLECTION_STATUS); + module.addDeserializer(CollectionType.class, InternalDeserializers.COLLECTION_TYPE); + module.addDeserializer(Response.class, InternalDeserializers.RESPONSE); } @Override diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 1d13abd2c..e67b4d811 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -1,9 +1,12 @@ package com.arangodb.serde; +import com.arangodb.internal.ArangoResponseField; import com.arangodb.jackson.dataformat.velocypack.VPackMapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import java.lang.reflect.Type; + public interface InternalSerde extends JacksonSerde { /** @@ -42,8 +45,26 @@ static InternalSerde of(final DataType dataType) { /** * TODO - * @param content - * @return */ JsonNode parse(byte[] content); + + /** + * TODO + */ + JsonNode parse(byte[] content, String jsonPointer); + + /** + * TODO + */ + default T deserialize(byte[] content, String jsonPointer, Class clazz){ + return deserialize(content, jsonPointer, (Type) clazz); + } + + /** + * TODO + */ + default T deserialize(byte[] content, String jsonPointer, Type type) { + return deserialize(parse(content, jsonPointer), type); + } + } diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 0dd204379..a779b5cf3 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -2,10 +2,12 @@ import com.arangodb.ArangoDBException; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; +import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { @@ -14,6 +16,7 @@ class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { super(dataType, mapper); mapper.registerModule(InternalModule.INSTANCE.get()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override @@ -55,4 +58,13 @@ public JsonNode parse(byte[] content) { } } + @Override + public JsonNode parse(byte[] content, String jsonPointer) { + try { + return mapper.readTree(content).at(jsonPointer); + } catch (IOException e) { + throw new ArangoDBException(e); + } + } + } diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java index 8efa1b522..d021c9bd7 100644 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ b/src/main/java/com/arangodb/util/ArangoSerialization.java @@ -1,5 +1,8 @@ package com.arangodb.util; -public interface ArangoSerialization extends ArangoDeserializer { +import java.lang.reflect.Type; + +public interface ArangoSerialization { byte[] serialize(final Object entity); + T deserialize(byte[] content, Type type); } diff --git a/src/main/java/com/arangodb/util/InternalSerialization.java b/src/main/java/com/arangodb/util/InternalSerialization.java index 690d02a71..d063a7d3a 100644 --- a/src/main/java/com/arangodb/util/InternalSerialization.java +++ b/src/main/java/com/arangodb/util/InternalSerialization.java @@ -22,12 +22,26 @@ import com.fasterxml.jackson.databind.JsonNode; +import java.lang.reflect.Type; + /** * @author Mark Vollmary */ -public interface InternalSerialization extends ArangoDeserializer { +public interface InternalSerialization { byte[] serialize(final Object entity); + + T deserialize(byte[] content, Type type); + + T deserialize(JsonNode node, Type type); + String toJsonString(byte[] content); + JsonNode parse(byte[] content); + JsonNode parse(byte[] content, String jsonPointer); + + T deserialize(byte[] content, String jsonPointer, Type type); + + byte[] extract(byte[] content, String jsonPointer); + } diff --git a/src/main/java/com/arangodb/velocystream/Response.java b/src/main/java/com/arangodb/velocystream/Response.java index 9c5869869..36021e1c5 100644 --- a/src/main/java/com/arangodb/velocystream/Response.java +++ b/src/main/java/com/arangodb/velocystream/Response.java @@ -20,11 +20,8 @@ package com.arangodb.velocystream; -import com.arangodb.serde.DataType; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.annotations.Expose; -import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -38,13 +35,10 @@ public class Response { private int responseCode; private Map meta; @Expose(deserialize = false) - private VPackSlice body = null; + private byte[] body = null; - private final DataType dataType; - - public Response(final DataType dataType) { + public Response() { super(); - this.dataType = dataType; meta = new HashMap<>(); } @@ -80,24 +74,12 @@ 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; } - public byte[] getBodyBytes() { - if (body == null) { - return new byte[0]; - } else if (dataType == DataType.JSON) { - return body.toString().getBytes(StandardCharsets.UTF_8); - } else if (dataType == DataType.VPACK) { - return body.toByteArray(); - } else { - throw new IllegalStateException("Unexpected value: " + dataType); - } - } - } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 284ae526e..cc80eacbf 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -395,7 +395,7 @@ void authenticationFailUser() { @MethodSource("arangos") void execute(ArangoDB arangoDB) throws VPackException { final Response response = arangoDB.execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")); - assertThat(response.getBody().get("version").isString()).isTrue(); + assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/ArangoRouteTest.java b/src/test/java/com/arangodb/ArangoRouteTest.java index 6bcd38f41..ba57d730c 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().getInternalSerialization().parse(res.getBody(), "version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/BaseJunit5.java b/src/test/java/com/arangodb/BaseJunit5.java index 11ee86790..140d52730 100644 --- a/src/test/java/com/arangodb/BaseJunit5.java +++ b/src/test/java/com/arangodb/BaseJunit5.java @@ -1,7 +1,6 @@ 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.util.TestUtils; diff --git a/src/test/java/com/arangodb/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 429f2c643..23732e8f0 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -441,7 +441,7 @@ void execute() throws VPackException, InterruptedException, ExecutionException { .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.getInternalSerialization().parse(response.getBody(), "version").isTextual()).isTrue(); }) .get(); } @@ -453,7 +453,7 @@ void execute_acquireHostList_enabled() throws VPackException, InterruptedExcepti .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.getInternalSerialization().parse(response.getBody(), "version").isTextual()).isTrue(); }) .get(); } diff --git a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java index 482d1287b..9484b7e30 100644 --- a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java +++ b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java @@ -47,7 +47,7 @@ void documentFieldAnnotations() { VPackSlice slice = new VPackSlice(mapper.serialize(e)); System.out.println(slice); - Map deserialized = mapper.deserialize(slice, Object.class); + Map deserialized = mapper.deserialize(slice.toByteArray(), Object.class); assertThat(deserialized) .containsEntry("_id", e.getId()) .containsEntry("_key", e.getKey()) @@ -56,7 +56,7 @@ void documentFieldAnnotations() { .containsEntry("_to", e.getTo()) .hasSize(5); - AnnotatedEntity deserializedEntity = mapper.deserialize(slice, AnnotatedEntity.class); + AnnotatedEntity deserializedEntity = mapper.deserialize(slice.toByteArray(), AnnotatedEntity.class); assertThat(deserializedEntity).isEqualTo(e); } @@ -69,14 +69,14 @@ void serializedName() { VPackSlice slice = new VPackSlice(mapper.serialize(e)); System.out.println(slice); - Map deserialized = mapper.deserialize(slice, Object.class); + Map deserialized = mapper.deserialize(slice.toByteArray(), 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); + SerializedNameEntity deserializedEntity = mapper.deserialize(slice.toByteArray(), SerializedNameEntity.class); assertThat(deserializedEntity).isEqualTo(e); } @@ -89,7 +89,7 @@ void serializedNameParameter() { VPackSlice slice = new VPackSlice(mapper.serialize(e)); SerializedNameParameterEntity deserializedEntity = mapper - .deserialize(slice, SerializedNameParameterEntity.class); + .deserialize(slice.toByteArray(), SerializedNameParameterEntity.class); assertThat(deserializedEntity).isEqualTo(new SerializedNameParameterEntity("A", "B", "C")); } @@ -102,7 +102,7 @@ void expose() { e.setIgnored("ignored"); VPackSlice serializedEntity = new VPackSlice(mapper.serialize(e)); - Map deserializedEntity = mapper.deserialize(serializedEntity, Object.class); + Map deserializedEntity = mapper.deserialize(serializedEntity.toByteArray(), Object.class); assertThat(deserializedEntity) .containsEntry("readWrite", "readWrite") .containsEntry("readOnly", "readOnly") @@ -115,7 +115,7 @@ void expose() { map.put("ignored", "ignored"); VPackSlice serializedMap = new VPackSlice(mapper.serialize(map)); - ExposeEntity deserializedMap = mapper.deserialize(serializedMap, ExposeEntity.class); + ExposeEntity deserializedMap = mapper.deserialize(serializedMap.toByteArray(), ExposeEntity.class); assertThat(deserializedMap.getIgnored()).isNull(); assertThat(deserializedMap.getReadOnly()).isNull(); assertThat(deserializedMap.getWriteOnly()).isEqualTo("writeOnly"); diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index 06bbb18c8..dd6b2d5d8 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -29,16 +29,11 @@ import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.InternalSerialization; 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; @@ -53,7 +48,6 @@ 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; @@ -144,7 +138,7 @@ void manualCustomPersonDeserializer() { person.name = "Joe"; ArangoSerialization serialization = arangoDB.getUserSerialization(); VPackSlice serializedPerson = new VPackSlice(serialization.serialize(person)); - Person deserializedPerson = serialization.deserialize(serializedPerson, Person.class); + Person deserializedPerson = serialization.deserialize(serializedPerson.toByteArray(), Person.class); assertThat(deserializedPerson.name).isEqualTo(PERSON_DESERIALIZER_ADDED_PREFIX + PERSON_SERIALIZER_ADDED_PREFIX + person.name); } @@ -236,7 +230,7 @@ void getDocument() { @Test void parseNullString() { - final String json = arangoDB.getUserSerialization().deserialize(new VPackBuilder().add((String) null).slice(), String.class); + final String json = arangoDB.getUserSerialization().deserialize(new VPackBuilder().add((String) null).slice().toByteArray(), String.class); assertThat(json).isNull(); } diff --git a/src/test/java/com/arangodb/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java index 7f08a8d81..fc64cd5c9 100644 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ b/src/test/java/com/arangodb/util/ArangoSerializationTest.java @@ -53,7 +53,7 @@ static void setup() { @Test void deserialize() { final VPackBuilder builder = new VPackBuilder().add(ValueType.OBJECT).add("foo", "bar").close(); - final BaseDocument doc = internalSer.deserialize(builder.slice(), BaseDocument.class); + final BaseDocument doc = internalSer.deserialize(builder.slice().toByteArray(), BaseDocument.class); assertThat(doc.getAttribute("foo")).isEqualTo("bar"); } @@ -97,13 +97,13 @@ void serializeType() { void parseJsonIncludeNull() { final Map entity = new HashMap<>(); entity.put("value", new String[]{"test", null}); - final String json = internalSer.deserialize(new VPackSlice(internalSer.serialize(entity)), String.class); + final String json = internalSer.deserialize(new VPackSlice(internalSer.serialize(entity)).toByteArray(), String.class); assertThat(json).isEqualTo("{\"value\":[\"test\",null]}"); } @Test void parseNullString() { - final String json = internalSer.deserialize(new VPackBuilder().add((String) null).slice(), String.class); + final String json = internalSer.deserialize(new VPackBuilder().add((String) null).slice().toByteArray(), String.class); assertThat(json).isNull(); } From 1f15b433a3917fc60ded4357351fc62cdd4ea83a Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Mon, 11 Jul 2022 21:28:31 +0200 Subject: [PATCH 23/52] deserializer refactoring: ArangoSearch --- .../java/com/arangodb/entity/License.java | 8 +- .../arangosearch/ArangoSearchProperties.java | 130 ------------------ .../ArangoSearchPropertiesEntity.java | 55 ++++---- .../entity/arangosearch/CollectionLink.java | 8 +- .../entity/arangosearch/FieldLink.java | 5 +- .../entity/arangosearch/StoredValue.java | 6 +- .../arangosearch/analyzer/SearchAnalyzer.java | 20 +++ .../InternalArangoEdgeCollection.java | 19 ++- .../InternalArangoVertexCollection.java | 21 ++- .../internal/net/ExtendedHostResolver.java | 6 +- .../velocypack/VPackDeserializers.java | 108 --------------- .../velocypack/VPackDriverModule.java | 6 - .../internal/velocypack/VPackSerializers.java | 85 ------------ .../model/VertexCollectionCreateOptions.java | 2 +- .../java/com/arangodb/serde/DataType.java | 2 +- .../arangodb/serde/InternalDeserializers.java | 57 ++++++++ .../com/arangodb/serde/InternalModule.java | 2 + .../com/arangodb/serde/InternalSerde.java | 2 +- .../com/arangodb/serde/InternalSerdeImpl.java | 2 +- .../java/com/arangodb/serde/JacksonSerde.java | 2 +- src/test/java/com/arangodb/ArangoDBTest.java | 2 +- .../java/com/arangodb/ArangoSearchTest.java | 6 +- .../velocypack/VPackSerializersTest.java | 5 +- 23 files changed, 163 insertions(+), 396 deletions(-) delete mode 100644 src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java 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/arangosearch/ArangoSearchProperties.java b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java deleted file mode 100644 index 443ac0dfe..000000000 --- a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java +++ /dev/null @@ -1,130 +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 com.arangodb.serde.InternalSerializers; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -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; - } - - @JsonSerialize(using = InternalSerializers.CollectionLinksSerializer.class) - 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..d33850aac 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; @@ -32,24 +33,14 @@ */ public 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 897119991..f6a471d14 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java @@ -20,8 +20,12 @@ package com.arangodb.entity.arangosearch; +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.ArrayList; @@ -53,7 +57,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); } @@ -99,6 +104,7 @@ 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)); return this; diff --git a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java index 4027498fe..e41f6cca7 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java @@ -1,7 +1,9 @@ package com.arangodb.entity.arangosearch; 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.ArrayList; @@ -30,7 +32,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); } diff --git a/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java b/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java index 5d3c2bd36..d6ffb95c9 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; /** @@ -33,7 +36,8 @@ public 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/SearchAnalyzer.java b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java index 2155a39a8..d826b50d3 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SearchAnalyzer.java @@ -24,6 +24,9 @@ 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,6 +36,22 @@ /** * @author Michele Rastelli */ +@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 implements Entity { private String name; private AnalyzerType type; @@ -52,6 +71,7 @@ public void setName(String name) { /** * @return The Analyzer type. */ + @JsonIgnore public AnalyzerType getType() { return type; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java index cb24a0730..725141dbd 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -39,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"; @@ -61,7 +60,7 @@ 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()); @@ -72,7 +71,7 @@ protected Request insertEdgeRequest(final T value, final EdgeCreateOptions o protected ResponseDeserializer insertEdgeResponseDeserializer(final T value) { return response -> { - final EdgeEntity doc = getInternalSerialization().deserialize(response.getBody(), EDGE, EdgeEntity.class); + final EdgeEntity doc = getInternalSerialization().deserialize(response.getBody(), "/edge", EdgeEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -83,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()); @@ -96,11 +95,11 @@ protected Request getEdgeRequest(final String key, final GraphDocumentReadOption } protected ResponseDeserializer getEdgeResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), EDGE), type); + return response -> getUserSerialization().deserialize(getInternalSerialization().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()); @@ -112,7 +111,7 @@ protected Request replaceEdgeRequest(final String key, final T value, final protected ResponseDeserializer replaceEdgeResponseDeserializer(final T value) { return response -> { - final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), EDGE, EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -122,7 +121,7 @@ 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()); @@ -135,7 +134,7 @@ protected Request updateEdgeRequest(final String key, final T value, final E protected ResponseDeserializer updateEdgeResponseDeserializer(final T value) { return response -> { - final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), EDGE, EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -144,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/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 92e03d195..bc9d1e0a4 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -40,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"; @@ -62,11 +61,11 @@ public String name() { } protected Request dropRequest() { - return request(graph.db().dbName(), RequestType.DELETE, PATH_API_GHARIAL, graph.name(), VERTEX, name); + return request(graph.db().dbName(), RequestType.DELETE, PATH_API_GHARIAL, graph.name(), "vertex", name); } protected 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()); @@ -84,7 +83,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio protected ResponseDeserializer insertVertexResponseDeserializer(final T value) { return response -> { - final VertexEntity doc = getInternalSerialization().deserialize(response.getBody(), VERTEX, VertexEntity.class); + final VertexEntity doc = getInternalSerialization().deserialize(response.getBody(), "/vertex", VertexEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -95,7 +94,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()); @@ -108,11 +107,11 @@ protected Request getVertexRequest(final String key, final GraphDocumentReadOpti } protected ResponseDeserializer getVertexResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), VERTEX), type); + return response -> getUserSerialization().deserialize(getInternalSerialization().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()); @@ -124,7 +123,7 @@ protected Request replaceVertexRequest(final String key, final T value, fina protected ResponseDeserializer replaceVertexResponseDeserializer(final T value) { return response -> { - final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), VERTEX, VertexUpdateEntity.class); + final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -134,7 +133,7 @@ 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()); @@ -147,7 +146,7 @@ protected Request updateVertexRequest(final String key, final T value, final protected ResponseDeserializer updateVertexResponseDeserializer(final T value) { return response -> { - final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), VERTEX, VertexUpdateEntity.class); + final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -156,7 +155,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/net/ExtendedHostResolver.java b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java index e0bb05117..42bb7273b 100644 --- a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java +++ b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java @@ -22,7 +22,6 @@ import com.arangodb.ArangoDBException; import com.arangodb.DbName; -import com.arangodb.entity.CollectionEntity; import com.arangodb.internal.ArangoExecutorSync; import com.arangodb.internal.util.HostUtils; import com.arangodb.util.InternalSerialization; @@ -128,8 +127,9 @@ private Collection resolveFromServer() throws ArangoDBException { response = executor.execute( new Request(DbName.SYSTEM, RequestType.GET, "/_api/cluster/endpoints"), response1 -> { - final Collection> tmp = arangoSerialization.deserialize(response1.getBody(), "/endpoints", new Type>() { - }.getType()); + final Collection> tmp = arangoSerialization.deserialize(response1.getBody(), "/endpoints", + new Type>>() { + }.getType()); Collection endpoints = new ArrayList<>(); for (final Map map : tmp) { endpoints.add(map.get("endpoint")); diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java index 06b5e0878..b7bbf5e31 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java @@ -130,107 +130,6 @@ public class VPackDeserializers { 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()); @@ -263,13 +162,6 @@ protected static FieldLink deserializeField(final Entry fiel 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()) { diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java index 5172f8e3a..cab5b226a 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java @@ -21,8 +21,6 @@ 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; @@ -31,7 +29,6 @@ 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; @@ -74,7 +71,6 @@ public > void setup(final C context) { context.registerSerializer(LogLevel.class, VPackSerializers.LOG_LEVEL); context.registerSerializer(Permissions.class, VPackSerializers.PERMISSIONS); context.registerSerializer(ViewType.class, VPackSerializers.VIEW_TYPE); - 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); @@ -92,8 +88,6 @@ public > void setup(final C context) { 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); diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java index 56494405f..29af7f6c6 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java @@ -109,91 +109,6 @@ public class VPackSerializers { builder.add(attribute, type); }; - 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); diff --git a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java index 2e4f97a9c..e7132fc64 100644 --- a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java @@ -29,7 +29,7 @@ public class VertexCollectionCreateOptions { private String collection; - private final Options options = new Options();; + private final Options options = new Options(); public VertexCollectionCreateOptions() { super(); diff --git a/src/main/java/com/arangodb/serde/DataType.java b/src/main/java/com/arangodb/serde/DataType.java index 801e89234..59fc96bcf 100644 --- a/src/main/java/com/arangodb/serde/DataType.java +++ b/src/main/java/com/arangodb/serde/DataType.java @@ -32,7 +32,7 @@ public static DataType of(Protocol protocol) { case VST: return DataType.VPACK; default: - throw new IllegalStateException("Unexpected value: " + protocol); + throw new IllegalArgumentException("Unexpected value: " + protocol); } } } diff --git a/src/main/java/com/arangodb/serde/InternalDeserializers.java b/src/main/java/com/arangodb/serde/InternalDeserializers.java index f2132a089..7f8971f87 100644 --- a/src/main/java/com/arangodb/serde/InternalDeserializers.java +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -2,18 +2,62 @@ 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.velocystream.Response; 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.ArrayNode; +import com.fasterxml.jackson.databind.node.NumericNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.Map; public final class InternalDeserializers { + + 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(ctxt.readTreeAsValue(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(ctxt.readTreeAsValue(v, FieldLink.class)); + } + return out.toArray(new FieldLink[0]); + } + } + private InternalDeserializers() { } @@ -30,6 +74,19 @@ public CollectionType deserialize(final JsonParser p, final DeserializationConte 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 { diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index 9f9e25a62..c606daecb 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -2,6 +2,7 @@ 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.velocypack.VPackSlice; @@ -28,6 +29,7 @@ enum InternalModule implements Supplier { 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); } diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index e67b4d811..70f531c86 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -21,7 +21,7 @@ static InternalSerde of(final DataType dataType) { } else if (dataType == DataType.VPACK) { return new InternalSerdeImpl(dataType, new VPackMapper()); } else { - throw new IllegalStateException("Unexpected value: " + dataType); + throw new IllegalArgumentException("Unexpected value: " + dataType); } } diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index a779b5cf3..b8e01d8bf 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -35,7 +35,7 @@ public String toJsonString(final byte[] content) { throw new ArangoDBException(e); } default: - throw new IllegalStateException("Unexpected value: " + dataType); + throw new IllegalArgumentException("Unexpected value: " + dataType); } } diff --git a/src/main/java/com/arangodb/serde/JacksonSerde.java b/src/main/java/com/arangodb/serde/JacksonSerde.java index 91d9ede18..901266c70 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerde.java +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -26,7 +26,7 @@ static JacksonSerde of(final DataType dataType) { } else if (dataType == DataType.VPACK) { return of(dataType, new VPackMapper()); } else { - throw new IllegalStateException("Unexpected value: " + dataType); + throw new IllegalArgumentException("Unexpected value: " + dataType); } } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index cc80eacbf..dfba5e9ce 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -395,7 +395,7 @@ void authenticationFailUser() { @MethodSource("arangos") void execute(ArangoDB arangoDB) throws VPackException { final Response response = arangoDB.execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")); - assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "version").isTextual()).isTrue(); + assertThat(arangoDB.getInternalSerialization().parse(response.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/internal/velocypack/VPackSerializersTest.java b/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java index 5c3880ba6..0b8658a65 100644 --- a/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java +++ b/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java @@ -22,7 +22,6 @@ 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; @@ -40,9 +39,7 @@ class VPackSerializersTest { @BeforeEach void init() { - vpack = new VPack.Builder() - .registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES) - .build(); + vpack = new VPack.Builder().build(); } @Test From 2b920503811be9c1dce57db58ba87450785f7e45 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 12 Jul 2022 17:30:22 +0200 Subject: [PATCH 24/52] deserializer refactoring: Collections API --- .../internal/ArangoCollectionAsyncImpl.java | 3 +- .../internal/ArangoCollectionImpl.java | 2 +- .../com/arangodb/internal/ArangoExecutor.java | 3 +- .../internal/ArangoResponseField.java | 4 +- .../internal/InternalArangoCollection.java | 186 ++++++++++-------- .../arangodb/internal/InternalArangoDB.java | 8 +- .../internal/InternalArangoDatabase.java | 18 +- .../internal/InternalArangoGraph.java | 6 +- .../com/arangodb/model/CollectionSchema.java | 3 + .../arangodb/serde/InternalDeserializers.java | 18 +- .../com/arangodb/ArangoCollectionTest.java | 4 +- .../graph/AQLActorsAndMoviesExampleTest.java | 19 +- .../graph/AQLActorsAndMoviesExampleTest.java | 24 +-- .../util/ArangoSerializationTest.java | 6 +- 14 files changed, 163 insertions(+), 141 deletions(-) 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/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 6dded7789..01fa6d99a 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java @@ -102,7 +102,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); diff --git a/src/main/java/com/arangodb/internal/ArangoExecutor.java b/src/main/java/com/arangodb/internal/ArangoExecutor.java index bbdd8d1b1..4c5b08443 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutor.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutor.java @@ -42,7 +42,8 @@ protected T createResult(final Type type, final Response response) { if (isInternal(type)) { return (T) util.getInternalSerialization().deserialize(response.getBody(), type); } else { - return (T) util.getUserSerialization().deserialize(response.getBody(), type); + throw new RuntimeException("FIXME: this should not never happen"); +// return (T) util.getUserSerialization().deserialize(response.getBody(), type); } } else { return null; diff --git a/src/main/java/com/arangodb/internal/ArangoResponseField.java b/src/main/java/com/arangodb/internal/ArangoResponseField.java index 2a828cc03..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/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 3bb982a51..8e0985314 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -107,12 +107,21 @@ protected ResponseDeserializer> insertDocumentRespon final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentCreateEntity doc = getInternalSerialization().deserialize(body, DocumentCreateEntity.class); final JsonNode newDoc = body.get(NEW); - if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), value.getClass())); + Class clazz = value.getClass(); + if (newDoc != null) { + if (String.class.isAssignableFrom(clazz)) { + doc.setNew((T) SerdeUtils.INSTANCE.writeJson(newDoc)); + } else { + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), clazz)); + } } final JsonNode oldDoc = body.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), value.getClass())); + if (oldDoc != null) { + if (String.class.isAssignableFrom(clazz)) { + doc.setOld((T) SerdeUtils.INSTANCE.writeJson(oldDoc)); + } else { + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), clazz)); + } } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -156,26 +165,25 @@ protected ResponseDeserializer>> final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); final JsonNode body = getInternalSerialization().parse(response.getBody()); - if (body.isArray()) { - for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { - final JsonNode next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).booleanValue()) { - final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentCreateEntity doc = getInternalSerialization().deserialize(next, DocumentCreateEntity.class); - final JsonNode newDoc = next.get(NEW); - if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); - } - final JsonNode oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); - } - docs.add(doc); - documentsAndErrors.add(doc); + 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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentCreateEntity doc = getInternalSerialization().deserialize(next, DocumentCreateEntity.class); + final JsonNode newDoc = next.get(NEW); + if (newDoc != null) { + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); } + final JsonNode oldDoc = next.get(OLD); + if (oldDoc != null) { + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); + } + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -217,6 +225,16 @@ protected Request getDocumentRequest(final String key, final DocumentReadOptions return request; } + protected ResponseDeserializer getDocumentResponseDeserializer(final Class type) { + return response -> { + if (String.class.isAssignableFrom(type)) { + return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerialization().parse(response.getBody())); + } else { + return getUserSerialization().deserialize(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) @@ -240,7 +258,8 @@ protected ResponseDeserializer> getDocumentsResponseD final JsonNode body = getInternalSerialization().parse(response.getBody()); for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { final JsonNode next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).booleanValue()) { + JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); + if (isError != null && isError.booleanValue()) { final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); @@ -279,11 +298,11 @@ protected ResponseDeserializer> replaceDocumentRespo final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); final JsonNode newDoc = body.get(NEW); - if (newDoc.isObject()) { + if (newDoc != null) { doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), value.getClass())); } final JsonNode oldDoc = body.get(OLD); - if (oldDoc.isObject()) { + if (oldDoc != null) { doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { @@ -326,26 +345,25 @@ protected ResponseDeserializer>> final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); final JsonNode body = getInternalSerialization().parse(response.getBody()); - if (body.isArray()) { - for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { - final JsonNode next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).booleanValue()) { - final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); - final JsonNode newDoc = next.get(NEW); - if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); - } - final JsonNode oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); - } - docs.add(doc); - documentsAndErrors.add(doc); + 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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); + final JsonNode newDoc = next.get(NEW); + if (newDoc != null) { + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); } + final JsonNode oldDoc = next.get(OLD); + if (oldDoc != null) { + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); + } + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -378,11 +396,11 @@ protected ResponseDeserializer> updateDocumentRes final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); final JsonNode newDoc = body.get(NEW); - if (newDoc.isObject()) { + if (newDoc != null) { doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); } final JsonNode oldDoc = body.get(OLD); - if (oldDoc.isObject()) { + if (oldDoc != null) { doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); } if (options == null || Boolean.TRUE != options.getSilent()) { @@ -422,26 +440,25 @@ protected ResponseDeserializer>> final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); final JsonNode body = getInternalSerialization().parse(response.getBody()); - if (body.isArray()) { - for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { - final JsonNode next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).booleanValue()) { - final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); - final JsonNode newDoc = next.get(NEW); - if (newDoc.isObject()) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); - } - final JsonNode oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); - } - docs.add(doc); - documentsAndErrors.add(doc); + 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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); + final JsonNode newDoc = next.get(NEW); + if (newDoc != null) { + doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); } + final JsonNode oldDoc = next.get(OLD); + if (oldDoc != null) { + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); + } + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -469,7 +486,7 @@ protected ResponseDeserializer> deleteDocumentRespon final JsonNode body = getInternalSerialization().parse(response.getBody()); final DocumentDeleteEntity doc = getInternalSerialization().deserialize(body, DocumentDeleteEntity.class); final JsonNode oldDoc = body.get(OLD); - if (oldDoc.isObject()) { + if (oldDoc != null) { doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); } return doc; @@ -495,22 +512,21 @@ protected ResponseDeserializer>> final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); final JsonNode body = getInternalSerialization().parse(response.getBody()); - if (body.isArray()) { - for (final Iterator iterator = body.iterator(); iterator.hasNext(); ) { - final JsonNode next = iterator.next(); - if (next.get(ArangoResponseField.ERROR).booleanValue()) { - final ErrorEntity error = getInternalSerialization().deserialize(next, ErrorEntity.class); - errors.add(error); - documentsAndErrors.add(error); - } else { - final DocumentDeleteEntity doc = getInternalSerialization().deserialize(next, DocumentDeleteEntity.class); - final JsonNode oldDoc = next.get(OLD); - if (oldDoc.isObject()) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); - } - docs.add(doc); - documentsAndErrors.add(doc); + 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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + errors.add(error); + documentsAndErrors.add(error); + } else { + final DocumentDeleteEntity doc = getInternalSerialization().deserialize(next, DocumentDeleteEntity.class); + final JsonNode oldDoc = next.get(OLD); + if (oldDoc != null) { + doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); } + docs.add(doc); + documentsAndErrors.add(doc); } } multiDocument.setDocuments(docs); @@ -539,7 +555,7 @@ protected Request deleteIndexRequest(final String id) { } protected ResponseDeserializer deleteIndexResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "id", String.class); + return response -> getInternalSerialization().deserialize(response.getBody(), "/id", String.class); } private String createIndexId(final String id) { @@ -621,7 +637,7 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "indexes", new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "/indexes", new Type>() { }.getType()); } @@ -689,7 +705,7 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Permissions.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } private boolean isStringCollection(final Collection values) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index 49c545c60..584449d30 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -78,7 +78,7 @@ protected Request createDatabaseRequest(final DBCreateOptions options) { } protected ResponseDeserializer createDatabaseResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Boolean.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); } protected Request getDatabasesRequest(final DbName dbName) { @@ -86,7 +86,7 @@ protected Request getDatabasesRequest(final DbName dbName) { } protected ResponseDeserializer> getDatabaseResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { }.getType()); } @@ -96,7 +96,7 @@ protected Request getAccessibleDatabasesForRequest(final DbName dbName, final St protected ResponseDeserializer> getAccessibleDatabasesForResponseDeserializer() { return response -> { - Iterator names = getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT).fieldNames(); + Iterator names = getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER).fieldNames(); final Collection dbs = new ArrayList<>(); while (names.hasNext()) { dbs.add(names.next()); @@ -130,7 +130,7 @@ protected Request getUserRequest(final DbName dbName, final String user) { } protected ResponseDeserializer> getUsersResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { }.getType()); } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index ba23a1c66..4d188d426 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -111,7 +111,7 @@ protected Request getCollectionsRequest(final CollectionsReadOptions options) { } protected ResponseDeserializer> getCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT), new Type>() { + return response -> getInternalSerialization().deserialize(getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), new Type>() { }.getType()); } @@ -120,7 +120,7 @@ protected Request dropRequest() { } protected ResponseDeserializer createDropResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Boolean.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); } protected Request grantAccessRequest(final String user, final Permissions permissions) { @@ -140,7 +140,7 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, Permissions.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } protected Request queryRequest(final String query, final Map bindVars, final AqlQueryOptions options) { @@ -257,7 +257,7 @@ protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { } protected ResponseDeserializer> getAqlFunctionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { }.getType()); } @@ -283,7 +283,7 @@ protected Request transactionRequest(final String action, final TransactionOptio } protected ResponseDeserializer transactionResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), ArangoResponseField.RESULT), type); + return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), type); } protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { @@ -312,7 +312,7 @@ protected Request commitStreamTransactionRequest(String id) { } protected ResponseDeserializer streamTransactionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, StreamTransactionEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, StreamTransactionEntity.class); } protected Request getInfoRequest() { @@ -320,7 +320,7 @@ protected Request getInfoRequest() { } protected ResponseDeserializer getInfoResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, DatabaseEntity.class); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, DatabaseEntity.class); } protected Request reloadRoutingRequest() { @@ -332,7 +332,7 @@ protected Request getViewsRequest() { } protected ResponseDeserializer> getViewsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { }.getType()); } @@ -353,7 +353,7 @@ protected Request getAnalyzersRequest() { } protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT, new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { }.getType()); } diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index e65d3a9cb..8108dd57a 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoGraph.java +++ b/src/main/java/com/arangodb/internal/InternalArangoGraph.java @@ -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"; @@ -84,7 +84,7 @@ protected Request getVertexCollectionsRequest() { } protected ResponseDeserializer> getVertexCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "collections", new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", new Type>() { }.getType()); } @@ -103,7 +103,7 @@ protected Request getEdgeDefinitionsRequest() { } protected ResponseDeserializer> getEdgeDefinitionsDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "collections", new Type>() { + return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", new Type>() { }.getType()); } diff --git a/src/main/java/com/arangodb/model/CollectionSchema.java b/src/main/java/com/arangodb/model/CollectionSchema.java index 8aa7bf098..395538c12 100644 --- a/src/main/java/com/arangodb/model/CollectionSchema.java +++ b/src/main/java/com/arangodb/model/CollectionSchema.java @@ -22,8 +22,10 @@ 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; /** @@ -53,6 +55,7 @@ public String getRule() { return rule; } + @JsonDeserialize(using = InternalDeserializers.CollectionSchemaRuleDeserializer.class) public CollectionSchema setRule(String rule) { this.rule = rule; return this; diff --git a/src/main/java/com/arangodb/serde/InternalDeserializers.java b/src/main/java/com/arangodb/serde/InternalDeserializers.java index 7f8971f87..b1666bb7f 100644 --- a/src/main/java/com/arangodb/serde/InternalDeserializers.java +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -6,11 +6,11 @@ import com.arangodb.entity.arangosearch.CollectionLink; import com.arangodb.entity.arangosearch.FieldLink; import com.arangodb.velocystream.Response; +import com.fasterxml.jackson.core.JacksonException; +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.*; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.NumericNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -31,7 +31,7 @@ public Collection deserialize(JsonParser p, DeserializationConte Collection out = new ArrayList<>(); ObjectNode tree = p.readValueAsTree(); Iterator> it = tree.fields(); - while (it.hasNext()){ + while (it.hasNext()) { Map.Entry e = it.next(); ObjectNode v = (ObjectNode) e.getValue(); v.put("name", e.getKey()); @@ -48,7 +48,7 @@ public FieldLink[] deserialize(JsonParser p, DeserializationContext ctxt) throws Collection out = new ArrayList<>(); ObjectNode tree = p.readValueAsTree(); Iterator> it = tree.fields(); - while (it.hasNext()){ + while (it.hasNext()) { Map.Entry e = it.next(); ObjectNode v = (ObjectNode) e.getValue(); v.put("name", e.getKey()); @@ -58,6 +58,14 @@ public FieldLink[] deserialize(JsonParser p, DeserializationContext ctxt) throws } } + public static class CollectionSchemaRuleDeserializer extends JsonDeserializer { + @Override + public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + return SerdeUtils.INSTANCE.writeJson(p.readValueAsTree()); + } + } + + private InternalDeserializers() { } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 2e6ef6278..b1cb16ac3 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -445,8 +445,8 @@ 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 String document = collection + .getDocument(doc.getKey(), String.class, new DocumentReadOptions().allowDirtyRead(true)); assertThat(document).isNotNull(); } 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..9667b542c 100644 --- a/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java @@ -31,6 +31,8 @@ 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; @@ -484,11 +486,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 +531,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/example/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java index f5283c5aa..ba9cb7cd4 100644 --- a/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java @@ -27,6 +27,8 @@ 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; @@ -219,14 +221,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 +267,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/util/ArangoSerializationTest.java b/src/test/java/com/arangodb/util/ArangoSerializationTest.java index fc64cd5c9..61c072a04 100644 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ b/src/test/java/com/arangodb/util/ArangoSerializationTest.java @@ -97,8 +97,10 @@ void serializeType() { void parseJsonIncludeNull() { final Map entity = new HashMap<>(); entity.put("value", new String[]{"test", null}); - final String json = internalSer.deserialize(new VPackSlice(internalSer.serialize(entity)).toByteArray(), String.class); - assertThat(json).isEqualTo("{\"value\":[\"test\",null]}"); + final Map res = userSer.deserialize(new VPackSlice(userSer.serialize(entity)).toByteArray(), Map.class); + assertThat(res.get("value")) + .asList() + .containsExactly("test", null); } @Test From e570506d2fab1ed2965225965f0a3aaaef60d66b Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 12 Jul 2022 20:15:14 +0200 Subject: [PATCH 25/52] deserializer refactoring: Database API --- .../arangodb/entity/QueryExecutionState.java | 24 +++++++++++++++++ .../com/arangodb/internal/DocumentCache.java | 2 +- .../internal/InternalArangoCollection.java | 6 ++--- .../internal/InternalArangoDatabase.java | 10 ++++++- .../java/com/arangodb/ArangoDatabaseTest.java | 27 ++++++++++--------- .../arangodb/async/ArangoDatabaseTest.java | 13 +++++---- 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/arangodb/entity/QueryExecutionState.java b/src/main/java/com/arangodb/entity/QueryExecutionState.java index 75e75df87..2e1988acb 100644 --- a/src/main/java/com/arangodb/entity/QueryExecutionState.java +++ b/src/main/java/com/arangodb/entity/QueryExecutionState.java @@ -20,19 +20,43 @@ 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/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 8e0985314..040186faf 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -109,7 +109,7 @@ protected ResponseDeserializer> insertDocumentRespon final JsonNode newDoc = body.get(NEW); Class clazz = value.getClass(); if (newDoc != null) { - if (String.class.isAssignableFrom(clazz)) { + if (String.class.equals(clazz)) { doc.setNew((T) SerdeUtils.INSTANCE.writeJson(newDoc)); } else { doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), clazz)); @@ -117,7 +117,7 @@ protected ResponseDeserializer> insertDocumentRespon } final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - if (String.class.isAssignableFrom(clazz)) { + if (String.class.equals(clazz)) { doc.setOld((T) SerdeUtils.INSTANCE.writeJson(oldDoc)); } else { doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), clazz)); @@ -227,7 +227,7 @@ protected Request getDocumentRequest(final String key, final DocumentReadOptions protected ResponseDeserializer getDocumentResponseDeserializer(final Class type) { return response -> { - if (String.class.isAssignableFrom(type)) { + if (String.class.equals(type)) { return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerialization().parse(response.getBody())); } else { return getUserSerialization().deserialize(response.getBody(), type); diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 4d188d426..49d5be7fb 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -29,6 +29,7 @@ import com.arangodb.model.arangosearch.AnalyzerDeleteOptions; import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; import com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder; +import com.arangodb.serde.SerdeUtils; import com.arangodb.velocypack.Type; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; @@ -283,7 +284,14 @@ protected Request transactionRequest(final String action, final TransactionOptio } protected ResponseDeserializer transactionResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), type); + return response -> { + byte[] userContent = getInternalSerialization().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); + if (String.class.equals(type)) { + return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerialization().parse(userContent)); + } else { + return getUserSerialization().deserialize(userContent, type); + } + }; } protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 37b7e2efd..d0f513b34 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -30,6 +30,7 @@ import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.ValueType; import com.arangodb.velocypack.exception.VPackException; +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; @@ -1137,7 +1138,7 @@ void getGraphs(ArangoDatabase db) { 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"); + assertThat(result).isEqualTo("\"test\""); } @ParameterizedTest(name = "{index}") @@ -1152,9 +1153,9 @@ void transactionNumber(ArangoDatabase db) { @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"); + final JsonNode result = db.transaction("function (params) {return params;}", JsonNode.class, options); + assertThat(result.isTextual()).isTrue(); + assertThat(result.asText()).isEqualTo("test"); } @ParameterizedTest(name = "{index}") @@ -1165,17 +1166,17 @@ void transactionVPackObject(ArangoDatabase db) throws VPackException { 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"); + assertThat(result).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionVPackArray(ArangoDatabase db) throws VPackException { + void transactionJsonArray(ArangoDatabase db) throws VPackException { final VPackSlice params = new VPackBuilder().add(ValueType.ARRAY).add("hello").add("world").close().slice(); 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"); + assertThat(result).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1185,7 +1186,7 @@ void transactionMap(ArangoDatabase db) { 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"); + assertThat(result).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1195,7 +1196,7 @@ void transactionArray(ArangoDatabase db) { 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"); + assertThat(result).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1207,7 +1208,7 @@ void transactionCollection(ArangoDatabase db) { 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"); + assertThat(result).isEqualTo("\"hello world\""); } @ParameterizedTest(name = "{index}") @@ -1240,7 +1241,7 @@ void transactionExclusiveWrite(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") void transactionEmpty(ArangoDatabase db) { - db.transaction("function () {}", null, null); + db.transaction("function () {}", Void.class, null); } @ParameterizedTest(name = "{index}") @@ -1250,9 +1251,9 @@ 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()) diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index 54df6dedb..206a54703 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -876,7 +876,7 @@ void getGraphs() throws InterruptedException, ExecutionException { 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")) + .whenComplete((result, ex) -> assertThat(result).isEqualTo("\"test\"")) .get(); } @@ -901,7 +901,7 @@ void transactionVPack() throws VPackException, InterruptedException, ExecutionEx @Test void transactionEmpty() throws InterruptedException, ExecutionException { - db.transaction("function () {}", null, null).get(); + db.transaction("function () {}", Void.class, null).get(); } @Test @@ -1008,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; + } } } From a5b2c4922463044548a252f86c6bb743c260d5d8 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 12 Jul 2022 20:38:45 +0200 Subject: [PATCH 26/52] deserializer refactoring: test fixes --- .../arangodb/entity/TransactionEntity.java | 2 +- .../com/arangodb/serde/InternalSerdeImpl.java | 1 - .../com/arangodb/serde/JacksonSerdeImpl.java | 2 + .../java/com/arangodb/ArangoCursorTest.java | 44 +++++++++---------- .../java/com/arangodb/ArangoRouteTest.java | 2 +- .../com/arangodb/StreamTransactionTest.java | 2 +- .../java/com/arangodb/async/ArangoDBTest.java | 4 +- .../arangodb/async/StreamTransactionTest.java | 2 +- .../arangodb/serde/CustomTypeHintTest.java | 5 +-- 9 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/arangodb/entity/TransactionEntity.java b/src/main/java/com/arangodb/entity/TransactionEntity.java index a700541f2..a517d7882 100644 --- a/src/main/java/com/arangodb/entity/TransactionEntity.java +++ b/src/main/java/com/arangodb/entity/TransactionEntity.java @@ -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/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index b8e01d8bf..500805004 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -16,7 +16,6 @@ class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { super(dataType, mapper); mapper.registerModule(InternalModule.INSTANCE.get()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override diff --git a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java index e6c373a04..ece832a30 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java @@ -2,6 +2,7 @@ import com.arangodb.ArangoDBException; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -17,6 +18,7 @@ class JacksonSerdeImpl implements JacksonSerde { JacksonSerdeImpl(final DataType dataType, final ObjectMapper mapper) { this.dataType = dataType; this.mapper = mapper; + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override 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/ArangoRouteTest.java b/src/test/java/com/arangodb/ArangoRouteTest.java index ba57d730c..212c654a4 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(db.arango().getInternalSerialization().parse(res.getBody(), "version").isTextual()).isTrue(); + assertThat(db.arango().getInternalSerialization().parse(res.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") 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/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 23732e8f0..7fb7497c0 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -441,7 +441,7 @@ void execute() throws VPackException, InterruptedException, ExecutionException { .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "version").isTextual()).isTrue(); + assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } @@ -453,7 +453,7 @@ void execute_acquireHostList_enabled() throws VPackException, InterruptedExcepti .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "version").isTextual()).isTrue(); + assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } 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/serde/CustomTypeHintTest.java b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java index f3e9bf046..178867aef 100644 --- a/src/test/java/com/arangodb/serde/CustomTypeHintTest.java +++ b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java @@ -21,10 +21,7 @@ package com.arangodb.serde; -import com.arangodb.ArangoCollection; -import com.arangodb.ArangoDB; -import com.arangodb.ArangoDatabase; -import com.arangodb.DbName; +import com.arangodb.*; import com.arangodb.entity.Key; import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; From 2ff9f3351b50d85a266f3e5f5d0edf7a58aa450d Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 12 Jul 2022 21:09:10 +0200 Subject: [PATCH 27/52] removed usages of VPackSlice --- .../com/arangodb/async/ArangoDBAsync.java | 7 - .../com/arangodb/entity/CursorEntity.java | 1 - .../internal/ArangoCollectionImpl.java | 4 +- .../internal/InternalArangoDBBuilder.java | 13 -- .../mapping/ArangoAnnotationIntrospector.java | 127 ------------ .../internal/mapping/VPackDeserializers.java | 96 --------- .../internal/mapping/VPackSerializers.java | 77 ------- .../internal/util/ArangoDeserializerImpl.java | 61 ------ .../velocypack/VPackDeserializers.java | 196 ------------------ .../velocypack/VPackDriverModule.java | 101 --------- .../internal/velocypack/VPackSerializers.java | 159 -------------- .../java/com/arangodb/mapping/ArangoJack.java | 43 +--- .../com/arangodb/model/AqlQueryOptions.java | 27 +-- .../com/arangodb/util/ArangoDeserializer.java | 43 ---- .../java/com/arangodb/BaseDocumentTest.java | 95 --------- 15 files changed, 8 insertions(+), 1042 deletions(-) delete mode 100644 src/main/java/com/arangodb/internal/mapping/ArangoAnnotationIntrospector.java delete mode 100644 src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java delete mode 100644 src/main/java/com/arangodb/internal/mapping/VPackSerializers.java delete mode 100644 src/main/java/com/arangodb/internal/util/ArangoDeserializerImpl.java delete mode 100644 src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java delete mode 100644 src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java delete mode 100644 src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java delete mode 100644 src/main/java/com/arangodb/util/ArangoDeserializer.java delete mode 100644 src/test/java/com/arangodb/BaseDocumentTest.java diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 275adf982..3bfa3d046 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -31,7 +31,6 @@ 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.ArangoSerializationImpl; import com.arangodb.internal.util.InternalSerializationImpl; @@ -44,10 +43,7 @@ import com.arangodb.serde.DataType; import com.arangodb.serde.InternalSerde; import com.arangodb.serde.JacksonSerde; -import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackParser; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -514,9 +510,6 @@ public synchronized ArangoDBAsync build() { 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 InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); final InternalSerializationImpl internal = new InternalSerializationImpl(internalSerde); final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(JacksonSerde.of(DataType.VPACK)); diff --git a/src/main/java/com/arangodb/entity/CursorEntity.java b/src/main/java/com/arangodb/entity/CursorEntity.java index 5e73fbe9f..e4aa9f32e 100644 --- a/src/main/java/com/arangodb/entity/CursorEntity.java +++ b/src/main/java/com/arangodb/entity/CursorEntity.java @@ -20,7 +20,6 @@ package com.arangodb.entity; -import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.databind.JsonNode; import java.util.Collection; diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 01fa6d99a..7212c2e91 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java @@ -25,7 +25,7 @@ import com.arangodb.entity.*; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; -import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -232,7 +232,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), JsonNode.class); return true; } catch (final ArangoDBException e) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java index 0aa1ed9cf..d262e1e12 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java @@ -25,8 +25,6 @@ import com.arangodb.entity.LoadBalancingStrategy; 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.velocypack.VPack; import com.arangodb.velocypack.VPackParser; @@ -82,9 +80,6 @@ public abstract class InternalArangoDBBuilder { protected Integer maxConnections; protected Long connectionTtl; protected Integer keepAliveInterval; - protected final VPack.Builder vpackBuilder; - protected final VPackParser.Builder vpackParserBuilder; - protected ArangoDeserializer deserializer; protected Boolean acquireHostList; protected Integer acquireHostListInterval; protected LoadBalancingStrategy loadBalancingStrategy; @@ -94,10 +89,6 @@ public abstract class InternalArangoDBBuilder { 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; @@ -212,10 +203,6 @@ protected void setResponseQueueTimeSamples(final Integer responseQueueTimeSample this.responseQueueTimeSamples = responseQueueTimeSamples; } - protected void deserializer(final ArangoDeserializer deserializer) { - this.deserializer = deserializer; - } - protected void setSerializer(final ArangoSerialization serializer) { this.customSerializer = serializer; } 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 6402a9e26..000000000 --- a/src/main/java/com/arangodb/internal/mapping/VPackDeserializers.java +++ /dev/null @@ -1,96 +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); - } - } - }; - -} 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 3f8f34577..000000000 --- a/src/main/java/com/arangodb/internal/mapping/VPackSerializers.java +++ /dev/null @@ -1,77 +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.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; - -/** - * @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)); - } - }; - -} 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/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java deleted file mode 100644 index b7bbf5e31..000000000 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ /dev/null @@ -1,196 +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.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) -> { - if (vpack.isString() && vpack.getAsString().equals("satellite")) { - return ReplicationFactor.ofSatellite(); - } else { - return ReplicationFactor.of(vpack.getAsInt()); - } - }; - - public static final VPackDeserializer VIEW_TYPE = (parent, vpack, context) -> "arangosearch".equals(vpack.getAsString()) ? ViewType.ARANGO_SEARCH - : ViewType.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH)); - - 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 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 cab5b226a..000000000 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.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.internal.velocypack; - -import com.arangodb.entity.*; -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.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(ViewType.class, VPackSerializers.VIEW_TYPE); - 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(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 29af7f6c6..000000000 --- a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java +++ /dev/null @@ -1,159 +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.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 VIEW_TYPE = (builder, attribute, value, context) -> { - final String type = value == ViewType.ARANGO_SEARCH ? "arangosearch" : value.name().toLowerCase(Locale.ENGLISH); - builder.add(attribute, type); - }; - - 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/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java index 26f9fd5c4..d195ad28d 100644 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ b/src/main/java/com/arangodb/mapping/ArangoJack.java @@ -21,21 +21,15 @@ package com.arangodb.mapping; import com.arangodb.ArangoDBException; -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.serde.DataType; import com.arangodb.serde.JacksonSerde; import com.arangodb.util.ArangoSerialization; -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.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.module.SimpleModule; import java.lang.reflect.Type; @@ -48,41 +42,13 @@ public interface ConfigureFunction { void configure(ObjectMapper mapper); } - private final ObjectMapper vpackMapper; - private final ObjectMapper vpackMapperNull; - private final ObjectMapper jsonMapper; - private final JacksonSerde serde; - 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); - return configureDefaultMapper(mapper); - } - - static VPackMapper configureDefaultMapper(final VPackMapper mapper) { - 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.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); - - mapper.registerModule(module); return mapper; } @@ -95,16 +61,11 @@ public ArangoJack() { */ 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); - serde = JacksonSerde.of(DataType.VPACK, configureDefaultMapper(new VPackMapper())); + VPackMapper m = mapper != null ? mapper.copy() : new VPackMapper(); + serde = JacksonSerde.of(DataType.VPACK, m); } public void configure(final ArangoJack.ConfigureFunction f) { - f.configure(vpackMapper); - f.configure(vpackMapperNull); - f.configure(jsonMapper); serde.configure(f::configure); } diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index a83b05cee..eabb084f6 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -21,10 +21,7 @@ package com.arangodb.model; import com.arangodb.serde.InternalSerializers; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.annotations.Expose; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.util.ArrayList; @@ -44,8 +41,7 @@ public class AqlQueryOptions { private Integer batchSize; private Boolean cache; private Long memoryLimit; - private VPackSlice bindVars; - private byte[] bindVarsBytes; + private byte[] bindVars; private String query; private Options options; @Expose(serialize = false) @@ -153,24 +149,9 @@ public AqlQueryOptions fillBlockCache(final Boolean fillBlockCache) { return this; } - @JsonIgnore - public VPackSlice getBindVars() { - return bindVars; - } - - @JsonProperty("bindVars") @JsonSerialize(using = InternalSerializers.AqlParamsSerializer.class) - public byte[] getBindVarsBytes() { - return bindVarsBytes; - } - - /** - * @param bindVars key/value pairs representing the bind parameters - * @return options - */ - protected AqlQueryOptions bindVars(final VPackSlice bindVars) { - this.bindVars = bindVars; - return this; + public byte[] getBindVars() { + return bindVars; } /** @@ -178,7 +159,7 @@ protected AqlQueryOptions bindVars(final VPackSlice bindVars) { * @return options */ protected AqlQueryOptions bindVars(final byte[] bindVarsBytes) { - this.bindVarsBytes = bindVarsBytes; + this.bindVars = bindVarsBytes; return this; } 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/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"); - } - -} From 013ca0ebf95715b620d48f25a51f187ef9bf97dd Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 12 Jul 2022 21:35:45 +0200 Subject: [PATCH 28/52] removed velocypack related code --- .../arangodb/entity/DocumentCreateEntity.java | 2 - .../arangodb/entity/DocumentDeleteEntity.java | 1 - .../arangodb/entity/DocumentUpdateEntity.java | 3 - .../com/arangodb/entity/EdgeUpdateEntity.java | 1 - .../arangodb/entity/VertexUpdateEntity.java | 1 - .../analyzer/NormAnalyzerProperties.java | 1 - .../SegmentationAnalyzerProperties.java | 2 - .../analyzer/TextAnalyzerProperties.java | 1 - .../com/arangodb/model/AqlQueryOptions.java | 1 - .../arangodb/model/DocumentReadOptions.java | 1 - .../model/GraphDocumentReadOptions.java | 1 - .../com/arangodb/velocystream/Request.java | 1 - .../com/arangodb/velocystream/Response.java | 1 - .../arangodb/async/ArangoDatabaseTest.java | 9 +- ...ueryWithSpecialReturnTypesExampleTest.java | 27 +- .../document/GetDocumentExampleTest.java | 7 +- .../document/InsertDocumentExampleTest.java | 14 +- ...ueryWithSpecialReturnTypesExampleTest.java | 27 +- .../document/GetDocumentExampleTest.java | 9 +- .../document/InsertDocumentExampleTest.java | 12 +- .../VPackSerializeDeserializeTest.java | 6560 +++++++++-------- .../annotations/ArangoAnnotationsTest.java | 63 - .../mapping/annotations/ExposeEntity.java | 101 - .../annotations/SerializedNameEntity.java | 89 - .../SerializedNameParameterEntity.java | 83 - 25 files changed, 3338 insertions(+), 3680 deletions(-) delete mode 100644 src/test/java/com/arangodb/mapping/annotations/ExposeEntity.java delete mode 100644 src/test/java/com/arangodb/mapping/annotations/SerializedNameEntity.java delete mode 100644 src/test/java/com/arangodb/mapping/annotations/SerializedNameParameterEntity.java diff --git a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java index 9469325bf..aa25d24a0 100644 --- a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java @@ -29,9 +29,7 @@ */ public class DocumentCreateEntity extends DocumentEntity { - @Expose(deserialize = false) private T newDocument; - @Expose(deserialize = false) private T oldDocument; public DocumentCreateEntity() { diff --git a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java index 336ec53c1..67de46e97 100644 --- a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java @@ -29,7 +29,6 @@ */ public class DocumentDeleteEntity extends DocumentEntity { - @Expose(deserialize = false) private T oldDocument; public DocumentDeleteEntity() { diff --git a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java index c2bacbf94..9475a6924 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -33,11 +33,8 @@ public class DocumentUpdateEntity extends DocumentEntity { @JsonProperty("_oldRev") - @SerializedName("_oldRev") private String oldRev; - @Expose(deserialize = false) private T newDocument; - @Expose(deserialize = false) private T oldDocument; public DocumentUpdateEntity() { diff --git a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java index ea26e50ed..26d16e468 100644 --- a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java @@ -30,7 +30,6 @@ public class EdgeUpdateEntity extends DocumentEntity { @JsonProperty("_oldRev") - @SerializedName("_oldRev") private String oldRev; public EdgeUpdateEntity() { diff --git a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java index 89be57062..f68163121 100644 --- a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java @@ -29,7 +29,6 @@ public class VertexUpdateEntity extends DocumentEntity { @JsonProperty("_oldRev") - @SerializedName("_oldRev") private String oldRev; public VertexUpdateEntity() { 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 ec0d7820c..96f848e75 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java @@ -36,7 +36,6 @@ public class NormAnalyzerProperties { private boolean accent; @JsonProperty("case") - @SerializedName("case") private SearchAnalyzerCase analyzerCase; /** 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 0140437c8..76080409e 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java @@ -33,11 +33,9 @@ public class SegmentationAnalyzerProperties { @JsonProperty("break") - @SerializedName("break") private BreakMode breakMode; @JsonProperty("case") - @SerializedName("case") private SearchAnalyzerCase analyzerCase; public BreakMode getBreakMode() { 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 5b68d0247..8dbb6057c 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java @@ -42,7 +42,6 @@ public TextAnalyzerProperties() { private boolean accent; @JsonProperty("case") - @SerializedName("case") private SearchAnalyzerCase analyzerCase; private boolean stemming; diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index eabb084f6..090d0c393 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -44,7 +44,6 @@ public class AqlQueryOptions { private byte[] bindVars; private String query; private Options options; - @Expose(serialize = false) private Boolean allowDirtyRead; private String streamTransactionId; diff --git a/src/main/java/com/arangodb/model/DocumentReadOptions.java b/src/main/java/com/arangodb/model/DocumentReadOptions.java index b808f6ed4..74c1af550 100644 --- a/src/main/java/com/arangodb/model/DocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/DocumentReadOptions.java @@ -33,7 +33,6 @@ public 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/GraphDocumentReadOptions.java b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java index 1e661f64d..bad03413e 100644 --- a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java @@ -30,7 +30,6 @@ public 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/velocystream/Request.java b/src/main/java/com/arangodb/velocystream/Request.java index 872b01cf3..a0ebb0941 100644 --- a/src/main/java/com/arangodb/velocystream/Request.java +++ b/src/main/java/com/arangodb/velocystream/Request.java @@ -38,7 +38,6 @@ public class Request { private final String request; private final Map queryParam; private final Map headerParam; - @Expose(serialize = false) private byte[] body; public Request(final DbName dbName, final RequestType requestType, final String path) { diff --git a/src/main/java/com/arangodb/velocystream/Response.java b/src/main/java/com/arangodb/velocystream/Response.java index 36021e1c5..4d8a27af4 100644 --- a/src/main/java/com/arangodb/velocystream/Response.java +++ b/src/main/java/com/arangodb/velocystream/Response.java @@ -34,7 +34,6 @@ public class Response { private int type = 2; private int responseCode; private Map meta; - @Expose(deserialize = false) private byte[] body = null; public Response() { diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index 206a54703..0ff4f81e8 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -30,6 +30,7 @@ import com.arangodb.velocypack.VPackBuilder; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.exception.VPackException; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -889,12 +890,12 @@ void transactionNumber() throws InterruptedException, ExecutionException { } @Test - void transactionVPack() throws VPackException, InterruptedException, ExecutionException { + void transactionJsonNode() throws VPackException, InterruptedException, ExecutionException { final TransactionOptions options = new TransactionOptions().params(new VPackBuilder().add("test").slice()); - db.transaction("function (params) {return params;}", VPackSlice.class, options) + 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(); } 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..b4e98bc16 100644 --- a/src/test/java/com/arangodb/async/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java +++ b/src/test/java/com/arangodb/async/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java @@ -23,7 +23,8 @@ 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; @@ -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); + 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); + 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(); } 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..e2cb01a76 100644 --- a/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/async/example/document/GetDocumentExampleTest.java @@ -24,6 +24,7 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -71,11 +72,11 @@ 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(); } 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..cd5a4b889 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,10 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; -import com.arangodb.velocypack.VPackBuilder; -import com.arangodb.velocypack.ValueType; +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,10 +53,11 @@ 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(); } diff --git a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java index 1a46d3a15..1172d4071 100644 --- a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java +++ b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java @@ -24,7 +24,8 @@ 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; @@ -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 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 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); } } diff --git a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java index 10df2972e..d7239a8f0 100644 --- a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java @@ -24,6 +24,7 @@ import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; import com.arangodb.velocypack.VPackSlice; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -72,11 +73,11 @@ 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 diff --git a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java index 016d7f2c3..8a4c38940 100644 --- a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java @@ -26,6 +26,9 @@ import com.arangodb.velocypack.VPackBuilder; import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.ValueType; +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,10 +54,11 @@ 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(); } diff --git a/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java b/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java index eed9a8052..ceefb66a0 100644 --- a/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java +++ b/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java @@ -21,3282 +21,3284 @@ 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); - } - - -} +// TODO: move these tests to velocypack-java project + +//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 9484b7e30..cfd5d8124 100644 --- a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java +++ b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java @@ -24,7 +24,6 @@ import com.arangodb.velocypack.VPackSlice; import org.junit.jupiter.api.Test; -import java.util.HashMap; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -60,66 +59,4 @@ void documentFieldAnnotations() { assertThat(deserializedEntity).isEqualTo(e); } - @Test - void serializedName() { - SerializedNameEntity e = new SerializedNameEntity(); - e.setA("A"); - e.setB("B"); - e.setC("C"); - - VPackSlice slice = new VPackSlice(mapper.serialize(e)); - System.out.println(slice); - Map deserialized = mapper.deserialize(slice.toByteArray(), 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.toByteArray(), 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 = new VPackSlice(mapper.serialize(e)); - SerializedNameParameterEntity deserializedEntity = mapper - .deserialize(slice.toByteArray(), 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 = new VPackSlice(mapper.serialize(e)); - Map deserializedEntity = mapper.deserialize(serializedEntity.toByteArray(), 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 = new VPackSlice(mapper.serialize(map)); - ExposeEntity deserializedMap = mapper.deserialize(serializedMap.toByteArray(), 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 + '\'' + '}'; - } -} From eceb7a7bd1b2a681306dbf1c3dd69446e0d4795e Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 19 Jul 2022 12:14:07 +0200 Subject: [PATCH 29/52] reviewed API changes in entity and model packages --- src/main/java/com/arangodb/entity/DocumentCreateEntity.java | 2 -- src/main/java/com/arangodb/entity/DocumentDeleteEntity.java | 2 -- src/main/java/com/arangodb/entity/DocumentUpdateEntity.java | 2 -- src/main/java/com/arangodb/entity/EdgeUpdateEntity.java | 1 - src/main/java/com/arangodb/entity/QueryExecutionState.java | 1 - src/main/java/com/arangodb/entity/VertexUpdateEntity.java | 1 - .../entity/arangosearch/analyzer/NormAnalyzerProperties.java | 1 - .../arangosearch/analyzer/SegmentationAnalyzerProperties.java | 1 - .../entity/arangosearch/analyzer/TextAnalyzerProperties.java | 1 - src/main/java/com/arangodb/model/AqlQueryOptions.java | 1 - src/main/java/com/arangodb/model/CollectionCreateOptions.java | 3 --- src/main/java/com/arangodb/model/GraphDocumentReadOptions.java | 2 -- .../model/arangosearch/ArangoSearchPropertiesOptions.java | 1 - 13 files changed, 19 deletions(-) diff --git a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java index aa25d24a0..6badc51cd 100644 --- a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java @@ -20,8 +20,6 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.Expose; - /** * @author Mark Vollmary * @see API diff --git a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java index 67de46e97..2f5a6f098 100644 --- a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java @@ -20,8 +20,6 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.Expose; - /** * @author Mark Vollmary * @see API diff --git a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java index 9475a6924..8393a7988 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -20,8 +20,6 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.Expose; -import com.arangodb.velocypack.annotations.SerializedName; import com.fasterxml.jackson.annotation.JsonProperty; /** diff --git a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java index 26d16e468..ad0a5777f 100644 --- a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java @@ -20,7 +20,6 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.SerializedName; import com.fasterxml.jackson.annotation.JsonProperty; /** diff --git a/src/main/java/com/arangodb/entity/QueryExecutionState.java b/src/main/java/com/arangodb/entity/QueryExecutionState.java index 2e1988acb..987044880 100644 --- a/src/main/java/com/arangodb/entity/QueryExecutionState.java +++ b/src/main/java/com/arangodb/entity/QueryExecutionState.java @@ -59,4 +59,3 @@ public enum QueryExecutionState { @JsonProperty("invalid") INVALID } - diff --git a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java index f68163121..b5148338f 100644 --- a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java @@ -20,7 +20,6 @@ package com.arangodb.entity; -import com.arangodb.velocypack.annotations.SerializedName; import com.fasterxml.jackson.annotation.JsonProperty; /** 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 96f848e75..92633f419 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java @@ -21,7 +21,6 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.velocypack.annotations.SerializedName; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; 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 76080409e..7c6ea73c4 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,6 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.velocypack.annotations.SerializedName; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; 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 8dbb6057c..566fe8a99 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,6 @@ package com.arangodb.entity.arangosearch.analyzer; -import com.arangodb.velocypack.annotations.SerializedName; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collections; diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 090d0c393..3b4fe5aee 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -21,7 +21,6 @@ package com.arangodb.model; import com.arangodb.serde.InternalSerializers; -import com.arangodb.velocypack.annotations.Expose; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.util.ArrayList; diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index 4f98a9dcd..b3433a3d4 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -25,8 +25,6 @@ import com.arangodb.entity.KeyType; import com.arangodb.entity.ReplicationFactor; -import java.util.Objects; - /** * @author Mark Vollmary * @see API @@ -163,7 +161,6 @@ public String[] getShardKeys() { * @return options */ public CollectionCreateOptions shardKeys(final String... shardKeys) { - Objects.requireNonNull(shardKeys); this.shardKeys = shardKeys; return this; } diff --git a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java index bad03413e..8a7fffa0a 100644 --- a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java @@ -20,8 +20,6 @@ package com.arangodb.model; -import com.arangodb.velocypack.annotations.Expose; - /** * @author Mark Vollmary */ diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java index 5283169d3..e4d142b1c 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Collections; /** * @author Mark Vollmary From 270e54f44590e5973e7f25b2236081616d1b8749 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 19 Jul 2022 14:53:20 +0200 Subject: [PATCH 30/52] remove dependencies on com.arangodb.velocypack --- .../internal/ArangoDatabaseAsyncImpl.java | 30 ++++----------- .../async/internal/ArangoExecutorAsync.java | 6 +-- .../arangodb/internal/ArangoDatabaseImpl.java | 11 +++--- .../com/arangodb/internal/ArangoExecutor.java | 37 ++----------------- .../arangodb/internal/ArangoExecutorSync.java | 23 ++++-------- .../internal/InternalArangoCollection.java | 5 +-- .../arangodb/internal/InternalArangoDB.java | 15 +++----- .../internal/InternalArangoDBBuilder.java | 2 - .../internal/InternalArangoDatabase.java | 35 +++++++++--------- .../internal/InternalArangoGraph.java | 10 ++--- .../internal/http/HttpConnection.java | 7 ---- .../internal/net/ExtendedHostResolver.java | 13 ++----- .../arangodb/internal/util/ResponseUtils.java | 31 +++++++--------- .../model/AqlQueryExplainOptions.java | 10 +++-- .../com/arangodb/model/AqlQueryOptions.java | 2 +- .../arangodb/model/DocumentReadOptions.java | 2 - .../com/arangodb/model/OptionsBuilder.java | 3 +- .../com/arangodb/serde/InternalModule.java | 2 - .../arangodb/serde/InternalSerializers.java | 14 +------ .../java/com/arangodb/serde/SerdeUtils.java | 15 +++++++- .../com/arangodb/velocystream/Request.java | 1 - .../com/arangodb/velocystream/Response.java | 2 - .../java/com/arangodb/ArangoDatabaseTest.java | 28 +++++++++++--- .../arangodb/async/ArangoDatabaseTest.java | 4 +- 24 files changed, 123 insertions(+), 185 deletions(-) diff --git a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java index 224d80d7c..629783023 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java @@ -22,13 +22,7 @@ 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; @@ -36,20 +30,10 @@ import com.arangodb.internal.InternalArangoDatabase; 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; @@ -296,14 +280,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..6a1cea3a1 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java +++ b/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java @@ -51,11 +51,11 @@ public ArangoExecutorAsync(final VstCommunicationAsync communication, final Aran } 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/internal/ArangoDatabaseImpl.java b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java index e73fa0fa0..2a834d948 100644 --- a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java @@ -29,12 +29,13 @@ 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; import java.util.Collections; +import java.util.List; import java.util.Map; /** @@ -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/ArangoExecutor.java b/src/main/java/com/arangodb/internal/ArangoExecutor.java index 4c5b08443..d9b0ef91a 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutor.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutor.java @@ -21,53 +21,22 @@ package com.arangodb.internal; import com.arangodb.QueueTimeMetrics; -import com.arangodb.entity.Entity; import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.velocypack.exception.VPackException; 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.getInternalSerialization().deserialize(response.getBody(), type); - } else { - throw new RuntimeException("FIXME: this should not never happen"); -// return (T) util.getUserSerialization().deserialize(response.getBody(), type); - } - } else { + if (response.getBody() == null) { 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 util.getInternalSerialization().deserialize(response.getBody(), type); } private final DocumentCache documentCache; @@ -89,7 +58,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..51c683e10 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java @@ -25,7 +25,6 @@ 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.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -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/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 040186faf..4bb014874 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -28,7 +28,6 @@ import com.arangodb.internal.util.RequestUtils; import com.arangodb.model.*; import com.arangodb.serde.SerdeUtils; -import com.arangodb.velocypack.Type; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import com.fasterxml.jackson.databind.JsonNode; @@ -637,8 +636,8 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/indexes", new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), "/indexes", + SerdeUtils.INSTANCE.constructListType(IndexEntity.class)); } protected Request truncateRequest(final CollectionTruncateOptions options) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index 584449d30..c1b6fcc0f 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -21,14 +21,11 @@ package com.arangodb.internal; import com.arangodb.DbName; -import com.arangodb.entity.LogLevelEntity; -import com.arangodb.entity.Permissions; -import com.arangodb.entity.ServerRole; -import com.arangodb.entity.UserEntity; +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.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -86,8 +83,8 @@ protected Request getDatabasesRequest(final DbName dbName) { } protected ResponseDeserializer> getDatabaseResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(String.class)); } protected Request getAccessibleDatabasesForRequest(final DbName dbName, final String user) { @@ -130,8 +127,8 @@ protected Request getUserRequest(final DbName dbName, final String user) { } protected ResponseDeserializer> getUsersResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(UserEntity.class)); } protected Request updateUserRequest(final DbName dbName, final String user, final UserUpdateOptions options) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java index d262e1e12..093e6428d 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java @@ -26,8 +26,6 @@ import com.arangodb.internal.net.*; import com.arangodb.internal.util.HostUtils; import com.arangodb.util.ArangoSerialization; -import com.arangodb.velocypack.VPack; -import com.arangodb.velocypack.VPackParser; import org.apache.http.client.HttpRequestRetryHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 49d5be7fb..5b3739cef 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -30,8 +30,6 @@ import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; import com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder; import com.arangodb.serde.SerdeUtils; -import com.arangodb.velocypack.Type; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -112,8 +110,8 @@ protected Request getCollectionsRequest(final CollectionsReadOptions options) { } protected ResponseDeserializer> getCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), + SerdeUtils.INSTANCE.constructListType(CollectionEntity.class)); } protected Request dropRequest() { @@ -146,7 +144,8 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() 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(getInternalSerialization().serialize(OptionsBuilder.build(opt, query, bindVars != null ? getUserSerialization().serialize(bindVars) : null))); + final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR).setBody(getInternalSerialization().serialize( + OptionsBuilder.build(opt, query, bindVars != null ? getUserSerialization().serialize(bindVars) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } @@ -189,10 +188,10 @@ protected Request queryCloseRequest(final String id, final AqlQueryOptions optio } 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(getInternalSerialization().serialize(OptionsBuilder.build(opt, query, bindVars != null ? new VPackSlice(getUserSerialization().serialize(bindVars)) : null))); + return request(dbName, RequestType.POST, PATH_API_EXPLAIN) + .setBody(getInternalSerialization().serialize( + OptionsBuilder.build(opt, query, bindVars != null ? getUserSerialization().serialize(bindVars) : null))); } protected Request parseQueryRequest(final String query) { @@ -258,8 +257,8 @@ protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { } protected ResponseDeserializer> getAqlFunctionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(AqlFunctionEntity.class)); } protected Request createGraphRequest(final String name, final Collection edgeDefinitions, final GraphCreateOptions options) { @@ -275,8 +274,8 @@ protected Request getGraphsRequest() { } protected ResponseDeserializer> getGraphsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/graphs", new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), "/graphs", + SerdeUtils.INSTANCE.constructListType(GraphEntity.class)); } protected Request transactionRequest(final String action, final TransactionOptions options) { @@ -311,8 +310,8 @@ protected Request getStreamTransactionRequest(String id) { } protected ResponseDeserializer> transactionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/transactions", new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), "/transactions", + SerdeUtils.INSTANCE.constructListType(TransactionEntity.class)); } protected Request commitStreamTransactionRequest(String id) { @@ -340,8 +339,8 @@ protected Request getViewsRequest() { } protected ResponseDeserializer> getViewsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(ViewEntity.class)); } protected Request createViewRequest(final String name, final ViewType type) { @@ -361,8 +360,8 @@ protected Request getAnalyzersRequest() { } protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + SerdeUtils.INSTANCE.constructListType(SearchAnalyzer.class)); } protected Request createAnalyzerRequest(final SearchAnalyzer options) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index 8108dd57a..f725539ba 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; @@ -84,8 +84,8 @@ protected Request getVertexCollectionsRequest() { } protected ResponseDeserializer> getVertexCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", + SerdeUtils.INSTANCE.constructListType(String.class)); } protected Request addVertexCollectionRequest(final String name, final VertexCollectionCreateOptions options) { @@ -103,8 +103,8 @@ protected Request getEdgeDefinitionsRequest() { } protected ResponseDeserializer> getEdgeDefinitionsDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", new Type>() { - }.getType()); + return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", + SerdeUtils.INSTANCE.constructListType(String.class)); } protected Request addEdgeDefinitionRequest(final EdgeDefinition definition) { diff --git a/src/main/java/com/arangodb/internal/http/HttpConnection.java b/src/main/java/com/arangodb/internal/http/HttpConnection.java index 3f46c0bd7..8dcfa001f 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.serde.DataType; import com.arangodb.util.InternalSerialization; -import com.arangodb.velocypack.VPackParser; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.apache.http.*; @@ -168,7 +166,6 @@ public HttpConnection build() { private final InternalSerialization util; private final Boolean useSsl; private final Protocol contentType; - private final DataType dataType; private final HostDescription host; private HttpConnection(final HostDescription host, final Integer timeout, final String user, final String password, @@ -181,7 +178,6 @@ private HttpConnection(final HostDescription host, final Integer timeout, final this.useSsl = useSsl; this.util = util; this.contentType = contentType; - dataType = contentType == Protocol.HTTP_JSON ? DataType.JSON : DataType.VPACK; final RegistryBuilder registryBuilder = RegistryBuilder .create(); if (Boolean.TRUE == useSsl) { @@ -343,9 +339,6 @@ private static void addHeader(final Request request, final HttpRequestBase httpR } } - // FIXME: remove - private final VPackParser parser = new VPackParser.Builder().build(); - public Response buildResponse(final CloseableHttpResponse httpResponse) throws UnsupportedOperationException, IOException { final Response response = new Response(); diff --git a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java index 42bb7273b..234c96dd0 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.serde.SerdeUtils; import com.arangodb.util.InternalSerialization; -import com.arangodb.velocypack.Type; 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 @@ -75,7 +70,6 @@ public void init(ArangoExecutorSync executor, InternalSerialization arangoSerial } @Override - public HostSet resolve(boolean initial, boolean closeConnections) { if (!initial && isExpired()) { @@ -128,8 +122,7 @@ private Collection resolveFromServer() throws ArangoDBException { new Request(DbName.SYSTEM, RequestType.GET, "/_api/cluster/endpoints"), response1 -> { final Collection> tmp = arangoSerialization.deserialize(response1.getBody(), "/endpoints", - new Type>>() { - }.getType()); + SerdeUtils.INSTANCE.constructMapType(String.class, String.class)); Collection endpoints = new ArrayList<>(); for (final Map map : tmp) { endpoints.add(map.get("endpoint")); diff --git a/src/main/java/com/arangodb/internal/util/ResponseUtils.java b/src/main/java/com/arangodb/internal/util/ResponseUtils.java index bd181ddb5..16bb4ce86 100644 --- a/src/main/java/com/arangodb/internal/util/ResponseUtils.java +++ b/src/main/java/com/arangodb/internal/util/ResponseUtils.java @@ -25,7 +25,6 @@ import com.arangodb.internal.ArangoErrors; import com.arangodb.internal.net.ArangoDBRedirectException; import com.arangodb.util.InternalSerialization; -import com.arangodb.velocypack.exception.VPackParserException; import com.arangodb.velocystream.Response; import java.util.concurrent.TimeoutException; @@ -44,25 +43,21 @@ private ResponseUtils() { } public static void checkError(final InternalSerialization 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); + 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/model/AqlQueryExplainOptions.java b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java index 7e453a4b7..91e59d9a8 100644 --- a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java @@ -20,7 +20,8 @@ package com.arangodb.model; -import com.arangodb.velocypack.VPackSlice; +import com.arangodb.serde.InternalSerializers; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.util.Collection; @@ -31,7 +32,7 @@ */ public class AqlQueryExplainOptions { - private VPackSlice bindVars; + private byte[] bindVars; private String query; private Options options; @@ -39,7 +40,8 @@ public AqlQueryExplainOptions() { super(); } - protected VPackSlice getBindVars() { + @JsonSerialize(using = InternalSerializers.AqlBindVarsSerializer.class) + public byte[] getBindVars() { return bindVars; } @@ -47,7 +49,7 @@ protected VPackSlice getBindVars() { * @param bindVars key/value pairs representing the bind parameters * @return options */ - protected AqlQueryExplainOptions bindVars(final VPackSlice bindVars) { + protected AqlQueryExplainOptions bindVars(final byte[] bindVars) { this.bindVars = bindVars; return this; } diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 3b4fe5aee..75e43d189 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -147,7 +147,7 @@ public AqlQueryOptions fillBlockCache(final Boolean fillBlockCache) { return this; } - @JsonSerialize(using = InternalSerializers.AqlParamsSerializer.class) + @JsonSerialize(using = InternalSerializers.AqlBindVarsSerializer.class) public byte[] getBindVars() { return bindVars; } diff --git a/src/main/java/com/arangodb/model/DocumentReadOptions.java b/src/main/java/com/arangodb/model/DocumentReadOptions.java index 74c1af550..2ad9d4dfa 100644 --- a/src/main/java/com/arangodb/model/DocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/DocumentReadOptions.java @@ -20,8 +20,6 @@ package com.arangodb.model; -import com.arangodb.velocypack.annotations.Expose; - /** * @author Mark Vollmary * @author Michele Rastelli diff --git a/src/main/java/com/arangodb/model/OptionsBuilder.java b/src/main/java/com/arangodb/model/OptionsBuilder.java index 52c79b62e..111bfcb1d 100644 --- a/src/main/java/com/arangodb/model/OptionsBuilder.java +++ b/src/main/java/com/arangodb/model/OptionsBuilder.java @@ -23,7 +23,6 @@ import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.Permissions; import com.arangodb.entity.ViewType; -import com.arangodb.velocypack.VPackSlice; import java.util.Collection; @@ -90,7 +89,7 @@ public static AqlQueryOptions build(final AqlQueryOptions options, final String public static AqlQueryExplainOptions build( final AqlQueryExplainOptions options, final String query, - final VPackSlice bindVars) { + final byte[] bindVars) { return options.query(query).bindVars(bindVars); } diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index c606daecb..fe7418f17 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -5,7 +5,6 @@ import com.arangodb.entity.ReplicationFactor; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import com.fasterxml.jackson.databind.Module; @@ -21,7 +20,6 @@ enum InternalModule implements Supplier { InternalModule() { module = new SimpleModule(); - module.addSerializer(VPackSlice.class, InternalSerializers.VPACK_SLICE_JSON_SERIALIZER); module.addSerializer(AuthenticationRequest.class, InternalSerializers.AUTHENTICATION_REQUEST); module.addSerializer(JwtAuthenticationRequest.class, InternalSerializers.JWT_AUTHENTICATION_REQUEST); module.addSerializer(Request.class, InternalSerializers.REQUEST); diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 635b35991..11aeb9a26 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -5,8 +5,6 @@ import com.arangodb.entity.arangosearch.FieldLink; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest; -import com.arangodb.jackson.dataformat.velocypack.VPackMapper; -import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocystream.Request; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -20,10 +18,11 @@ public final class InternalSerializers { - public static class AqlParamsSerializer extends JsonSerializer { + public static class AqlBindVarsSerializer extends JsonSerializer { @Override public void serialize(byte[] 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)) { gen.writeTree(parser.readValueAsTree()); } @@ -59,18 +58,9 @@ public void serialize(Collection value, JsonGenerator gen, Seria } } - private static final VPackMapper vPackMapper = new VPackMapper(); - private InternalSerializers() { } - static final JsonSerializer VPACK_SLICE_JSON_SERIALIZER = new JsonSerializer() { - @Override - public void serialize(VPackSlice value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeObject(vPackMapper.readTree(value.toByteArray())); - } - }; - static final JsonSerializer AUTHENTICATION_REQUEST = new JsonSerializer() { @Override public void serialize(AuthenticationRequest value, JsonGenerator gen, SerializerProvider serializers) throws IOException { diff --git a/src/main/java/com/arangodb/serde/SerdeUtils.java b/src/main/java/com/arangodb/serde/SerdeUtils.java index 27e0c9eae..52ec7a6b8 100644 --- a/src/main/java/com/arangodb/serde/SerdeUtils.java +++ b/src/main/java/com/arangodb/serde/SerdeUtils.java @@ -4,11 +4,16 @@ import com.fasterxml.jackson.core.JsonProcessingException; 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.List; +import java.util.Map; public enum SerdeUtils { INSTANCE; - private ObjectMapper jsonMapper = new ObjectMapper(); + private final ObjectMapper jsonMapper = new ObjectMapper(); /** * Parse a JSON string. @@ -36,4 +41,12 @@ public String writeJson(final JsonNode data) { } } + 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); + } + } diff --git a/src/main/java/com/arangodb/velocystream/Request.java b/src/main/java/com/arangodb/velocystream/Request.java index a0ebb0941..678808e59 100644 --- a/src/main/java/com/arangodb/velocystream/Request.java +++ b/src/main/java/com/arangodb/velocystream/Request.java @@ -21,7 +21,6 @@ package com.arangodb.velocystream; import com.arangodb.DbName; -import com.arangodb.velocypack.annotations.Expose; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/com/arangodb/velocystream/Response.java b/src/main/java/com/arangodb/velocystream/Response.java index 4d8a27af4..1f7b164bd 100644 --- a/src/main/java/com/arangodb/velocystream/Response.java +++ b/src/main/java/com/arangodb/velocystream/Response.java @@ -20,8 +20,6 @@ package com.arangodb.velocystream; -import com.arangodb.velocypack.annotations.Expose; - import java.util.HashMap; import java.util.Map; diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index d0f513b34..1afda7000 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -31,6 +31,9 @@ import com.arangodb.velocypack.ValueType; import com.arangodb.velocypack.exception.VPackException; 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; @@ -907,6 +910,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) { @@ -1152,7 +1171,7 @@ 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 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"); @@ -1160,9 +1179,8 @@ void transactionVPack(ArangoDatabase db) throws VPackException { @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) throws VPackException { + 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); @@ -1172,7 +1190,7 @@ void transactionVPackObject(ArangoDatabase db) throws VPackException { @ParameterizedTest(name = "{index}") @MethodSource("dbs") void transactionJsonArray(ArangoDatabase db) throws VPackException { - final VPackSlice params = new VPackBuilder().add(ValueType.ARRAY).add("hello").add("world").close().slice(); + 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); diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index 0ff4f81e8..be2fc3eef 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -31,6 +31,8 @@ import com.arangodb.velocypack.VPackSlice; import com.arangodb.velocypack.exception.VPackException; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -891,7 +893,7 @@ void transactionNumber() throws InterruptedException, ExecutionException { @Test void transactionJsonNode() throws VPackException, InterruptedException, ExecutionException { - final TransactionOptions options = new TransactionOptions().params(new VPackBuilder().add("test").slice()); + final TransactionOptions options = new TransactionOptions().params(JsonNodeFactory.instance.textNode("test")); db.transaction("function (params) {return params;}", JsonNode.class, options) .whenComplete((result, ex) -> { assertThat(result.isTextual()).isEqualTo(true); From abd5b250373b66b6d3c9188231f237e8145e6b10 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 20 Jul 2022 14:55:13 +0200 Subject: [PATCH 31/52] remove test dependencies on com.arangodb.velocypack --- .../com/arangodb/ArangoCollectionTest.java | 1 - src/test/java/com/arangodb/ArangoDBTest.java | 3 +- .../java/com/arangodb/ArangoDatabaseTest.java | 16 +-- .../java/com/arangodb/async/ArangoDBTest.java | 5 +- .../arangodb/async/ArangoDatabaseTest.java | 14 +-- .../document/GetDocumentExampleTest.java | 1 - .../example/velocypack/VPackExampleTest.java | 114 ------------------ .../com/arangodb/example/FirstProject.java | 14 +-- .../document/GetDocumentExampleTest.java | 1 - .../document/InsertDocumentExampleTest.java | 3 - .../example/velocypack/VPackExampleTest.java | 113 ----------------- .../velocypack/VPackSerializersTest.java | 76 ------------ .../annotations/ArangoAnnotationsTest.java | 22 ++-- .../com/arangodb/serde/CustomSerdeTest.java | 8 +- .../util/ArangoSerializationTest.java | 112 ----------------- 15 files changed, 36 insertions(+), 467 deletions(-) delete mode 100644 src/test/java/com/arangodb/async/example/velocypack/VPackExampleTest.java delete mode 100644 src/test/java/com/arangodb/example/velocypack/VPackExampleTest.java delete mode 100644 src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java delete mode 100644 src/test/java/com/arangodb/util/ArangoSerializationTest.java diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index b1cb16ac3..6cf12bb73 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -38,7 +38,6 @@ import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonIncludeProperties; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index dfba5e9ce..b2d70b92b 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -25,7 +25,6 @@ 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; @@ -393,7 +392,7 @@ 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(arangoDB.getInternalSerialization().parse(response.getBody(), "/version").isTextual()).isTrue(); } diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 1afda7000..a5996fc39 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -26,10 +26,6 @@ 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.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; @@ -843,9 +839,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(); } @@ -1170,7 +1166,7 @@ void transactionNumber(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionVPack(ArangoDatabase db) throws VPackException { + 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(); @@ -1179,7 +1175,7 @@ void transactionVPack(ArangoDatabase db) throws VPackException { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionJsonObject(ArangoDatabase db) throws VPackException { + 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 @@ -1189,7 +1185,7 @@ void transactionJsonObject(ArangoDatabase db) throws VPackException { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionJsonArray(ArangoDatabase db) throws VPackException { + void transactionJsonArray(ArangoDatabase db) { ArrayNode params = JsonNodeFactory.instance.arrayNode().add("hello").add("world"); final TransactionOptions options = new TransactionOptions().params(params); final String result = db @@ -1335,7 +1331,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/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 7fb7497c0..134189fa3 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -25,7 +25,6 @@ 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; @@ -436,7 +435,7 @@ 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) -> { @@ -447,7 +446,7 @@ void execute() throws VPackException, InterruptedException, ExecutionException { } @Test - void execute_acquireHostList_enabled() throws VPackException, InterruptedException, ExecutionException { + void execute_acquireHostList_enabled() throws InterruptedException, ExecutionException { final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().acquireHostList(true).serializer(new ArangoJack()).build(); arangoDB .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index be2fc3eef..65513d2dc 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -27,12 +27,8 @@ 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.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -892,7 +888,7 @@ void transactionNumber() throws InterruptedException, ExecutionException { } @Test - void transactionJsonNode() throws VPackException, InterruptedException, ExecutionException { + 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) -> { @@ -908,7 +904,7 @@ void transactionEmpty() throws InterruptedException, ExecutionException { } @Test - void transactionallowImplicit() throws InterruptedException, ExecutionException { + void transactionAllowImplicit() throws InterruptedException, ExecutionException { try { db.createCollection("someCollection", null).get(); db.createCollection("someOtherCollection", null).get(); @@ -916,10 +912,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); @@ -988,7 +984,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); 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 e2cb01a76..404422665 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,6 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; -import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; 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/example/FirstProject.java b/src/test/java/com/arangodb/example/FirstProject.java index 63bcf034e..8164c26a3 100644 --- a/src/test/java/com/arangodb/example/FirstProject.java +++ b/src/test/java/com/arangodb/example/FirstProject.java @@ -5,7 +5,7 @@ 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.Map; @@ -55,13 +55,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()); } diff --git a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java index d7239a8f0..50b8cceea 100644 --- a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java @@ -23,7 +23,6 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; -import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java index 8a4c38940..fbe81d69f 100644 --- a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java @@ -23,9 +23,6 @@ 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.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; 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/velocypack/VPackSerializersTest.java b/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java deleted file mode 100644 index 0b8658a65..000000000 --- a/src/test/java/com/arangodb/internal/velocypack/VPackSerializersTest.java +++ /dev/null @@ -1,76 +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.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().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/mapping/annotations/ArangoAnnotationsTest.java b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java index cfd5d8124..1e1389b9c 100644 --- a/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java +++ b/src/test/java/com/arangodb/mapping/annotations/ArangoAnnotationsTest.java @@ -20,9 +20,11 @@ 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.Map; @@ -33,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"); @@ -44,9 +47,8 @@ void documentFieldAnnotations() { e.setFrom("From"); e.setTo("To"); - VPackSlice slice = new VPackSlice(mapper.serialize(e)); - System.out.println(slice); - Map deserialized = mapper.deserialize(slice.toByteArray(), Object.class); + byte[] serialized = mapper.serialize(e); + Map deserialized = mapper.deserialize(serialized, Map.class); assertThat(deserialized) .containsEntry("_id", e.getId()) .containsEntry("_key", e.getKey()) @@ -55,7 +57,7 @@ void documentFieldAnnotations() { .containsEntry("_to", e.getTo()) .hasSize(5); - AnnotatedEntity deserializedEntity = mapper.deserialize(slice.toByteArray(), AnnotatedEntity.class); + AnnotatedEntity deserializedEntity = mapper.deserialize(serialized, AnnotatedEntity.class); assertThat(deserializedEntity).isEqualTo(e); } diff --git a/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index dd6b2d5d8..94812aac4 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -29,8 +29,6 @@ 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.*; @@ -137,8 +135,8 @@ void manualCustomPersonDeserializer() { Person person = new Person(); person.name = "Joe"; ArangoSerialization serialization = arangoDB.getUserSerialization(); - VPackSlice serializedPerson = new VPackSlice(serialization.serialize(person)); - Person deserializedPerson = serialization.deserialize(serializedPerson.toByteArray(), Person.class); + 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); } @@ -230,7 +228,7 @@ void getDocument() { @Test void parseNullString() { - final String json = arangoDB.getUserSerialization().deserialize(new VPackBuilder().add((String) null).slice().toByteArray(), String.class); + final String json = arangoDB.getUserSerialization().deserialize(arangoDB.getUserSerialization().serialize(null), String.class); assertThat(json).isNull(); } 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 61c072a04..000000000 --- a/src/test/java/com/arangodb/util/ArangoSerializationTest.java +++ /dev/null @@ -1,112 +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 InternalSerialization internalSer; - private static ArangoSerialization userSer; - - @BeforeAll - static void setup() { - final ArangoDB arangoDB = new ArangoDB.Builder().serializer(new ArangoJack()).build(); - internalSer = arangoDB.getInternalSerialization(); - userSer = arangoDB.getUserSerialization(); - } - - @Test - void deserialize() { - final VPackBuilder builder = new VPackBuilder().add(ValueType.OBJECT).add("foo", "bar").close(); - final BaseDocument doc = internalSer.deserialize(builder.slice().toByteArray(), BaseDocument.class); - assertThat(doc.getAttribute("foo")).isEqualTo("bar"); - } - - @Test - void serialize() { - final BaseDocument entity = new BaseDocument(); - entity.addAttribute("foo", "bar"); - final VPackSlice vpack = new VPackSlice(internalSer.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 = new VPackSlice(userSer.serialize(entity)); - assertThat(vpack.get("foo").isNull()).isTrue(); - } - - @Test - void skipSerializeNullValues() { - final BaseDocument entity = new BaseDocument(); - entity.addAttribute("bar", null); - final VPackSlice vpack = new VPackSlice(internalSer.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 = new VPackSlice(internalSer.serialize(list)); - 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 Map res = userSer.deserialize(new VPackSlice(userSer.serialize(entity)).toByteArray(), Map.class); - assertThat(res.get("value")) - .asList() - .containsExactly("test", null); - } - - @Test - void parseNullString() { - final String json = internalSer.deserialize(new VPackBuilder().add((String) null).slice().toByteArray(), String.class); - assertThat(json).isNull(); - } - -} From 5f5f32309e89213cef3d6ad0c82307d12901d751 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 20 Jul 2022 15:38:22 +0200 Subject: [PATCH 32/52] removed old serialization classes --- .../java/com/arangodb/ArangoCollection.java | 2 +- src/main/java/com/arangodb/ArangoDB.java | 19 +-- .../java/com/arangodb/ArangoDatabase.java | 2 +- .../com/arangodb/ArangoEdgeCollection.java | 2 +- src/main/java/com/arangodb/ArangoGraph.java | 2 +- src/main/java/com/arangodb/ArangoRoute.java | 2 +- ...Accessor.java => ArangoSerdeAccessor.java} | 14 +- .../com/arangodb/ArangoVertexCollection.java | 2 +- src/main/java/com/arangodb/ArangoView.java | 2 +- .../arangodb/async/ArangoCollectionAsync.java | 4 +- .../com/arangodb/async/ArangoDBAsync.java | 17 +-- .../arangodb/async/ArangoDatabaseAsync.java | 4 +- .../async/ArangoEdgeCollectionAsync.java | 4 +- .../com/arangodb/async/ArangoGraphAsync.java | 4 +- .../com/arangodb/async/ArangoRouteAsync.java | 4 +- .../async/ArangoVertexCollectionAsync.java | 4 +- .../com/arangodb/async/ArangoViewAsync.java | 4 +- .../async/internal/ArangoDBAsyncImpl.java | 12 +- .../async/internal/ArangoExecutorAsync.java | 4 +- .../velocystream/VstCommunicationAsync.java | 6 +- .../com/arangodb/internal/ArangoDBImpl.java | 18 +-- .../arangodb/internal/ArangoExecuteable.java | 20 +-- .../com/arangodb/internal/ArangoExecutor.java | 8 +- .../arangodb/internal/ArangoExecutorSync.java | 4 +- .../internal/InternalArangoCollection.java | 139 +++++++++--------- .../arangodb/internal/InternalArangoDB.java | 30 ++-- .../internal/InternalArangoDBBuilder.java | 6 +- .../internal/InternalArangoDatabase.java | 64 ++++---- .../InternalArangoEdgeCollection.java | 14 +- .../internal/InternalArangoGraph.java | 16 +- .../internal/InternalArangoRoute.java | 2 +- .../internal/InternalArangoSearch.java | 4 +- .../InternalArangoVertexCollection.java | 16 +- .../arangodb/internal/InternalArangoView.java | 2 +- .../internal/cursor/ArangoCursorIterator.java | 4 +- .../arangodb/internal/http/CURLLogger.java | 4 +- .../internal/http/HttpCommunication.java | 4 +- .../internal/http/HttpConnection.java | 10 +- .../internal/http/HttpConnectionFactory.java | 4 +- .../internal/net/ExtendedHostResolver.java | 6 +- .../arangodb/internal/net/HostResolver.java | 4 +- .../internal/net/SimpleHostResolver.java | 4 +- ...onFactory.java => ArangoSerdeFactory.java} | 16 +- .../util/ArangoSerializationImpl.java | 28 ---- .../util/InternalSerializationImpl.java | 82 ----------- .../arangodb/internal/util/ResponseUtils.java | 4 +- .../velocystream/VstCommunication.java | 6 +- .../velocystream/VstCommunicationSync.java | 6 +- .../java/com/arangodb/mapping/ArangoJack.java | 82 ----------- .../arangodb/util/ArangoSerialization.java | 8 - .../arangodb/util/InternalSerialization.java | 47 ------ src/test/java/com/arangodb/ArangoDBTest.java | 11 +- .../java/com/arangodb/ArangoRouteTest.java | 2 +- src/test/java/com/arangodb/ArangoSslTest.java | 5 +- src/test/java/com/arangodb/BaseJunit5.java | 2 - .../java/com/arangodb/ConcurrencyTests.java | 3 +- src/test/java/com/arangodb/JwtAuthTest.java | 9 +- .../java/com/arangodb/async/ArangoDBTest.java | 17 +-- .../java/com/arangodb/async/BaseTest.java | 3 +- .../com/arangodb/async/CommunicationTest.java | 3 +- .../com/arangodb/async/ConcurrencyTest.java | 3 +- .../com/arangodb/async/ConcurrencyTests.java | 3 +- .../java/com/arangodb/async/JwtAuthTest.java | 9 +- .../debug/ConsolidationIntervalMsecTest.java | 2 - .../arangodb/async/example/ExampleBase.java | 3 +- ...ueryWithSpecialReturnTypesExampleTest.java | 10 +- .../graph/AQLActorsAndMoviesExampleTest.java | 3 +- .../async/example/graph/BaseGraphTest.java | 3 +- .../async/example/ssl/SslExampleTest.java | 3 +- .../arangodb/async/serde/CustomSerdeTest.java | 9 +- .../com/arangodb/example/ExampleBase.java | 3 +- .../com/arangodb/example/FirstProject.java | 9 +- ...ueryWithSpecialReturnTypesExampleTest.java | 10 +- .../graph/AQLActorsAndMoviesExampleTest.java | 3 +- .../arangodb/example/graph/BaseGraphTest.java | 3 +- .../arangodb/example/ssl/SslExampleTest.java | 5 +- .../arangodb/internal/HostHandlerTest.java | 6 +- .../velocystream/CommunicationTest.java | 11 +- .../com/arangodb/serde/CustomSerdeTest.java | 12 +- .../arangodb/serde/CustomTypeHintTest.java | 5 +- .../java/com/arangodb/util/MapBuilder.java | 92 ++++++------ src/test/java/perf/SimpleSyncPerfTest.java | 3 +- 82 files changed, 380 insertions(+), 661 deletions(-) rename src/main/java/com/arangodb/{ArangoSerializationAccessor.java => ArangoSerdeAccessor.java} (76%) rename src/main/java/com/arangodb/internal/util/{ArangoSerializationFactory.java => ArangoSerdeFactory.java} (66%) delete mode 100644 src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java delete mode 100644 src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java delete mode 100644 src/main/java/com/arangodb/mapping/ArangoJack.java delete mode 100644 src/main/java/com/arangodb/util/ArangoSerialization.java delete mode 100644 src/main/java/com/arangodb/util/InternalSerialization.java rename src/{main => test}/java/com/arangodb/util/MapBuilder.java (96%) diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index 2073ff689..3af131403 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 diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index 5efa9db1e..3ac79ee8d 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -28,9 +28,7 @@ import com.arangodb.internal.http.HttpCommunication; import com.arangodb.internal.http.HttpConnectionFactory; import com.arangodb.internal.net.*; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationImpl; -import com.arangodb.internal.util.InternalSerializationImpl; +import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; @@ -41,8 +39,8 @@ import com.arangodb.serde.InternalSerde; import com.arangodb.serde.JacksonSerde; import com.arangodb.util.ArangoCursorInitializer; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.InternalSerialization; +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; @@ -72,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}. @@ -335,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; } @@ -349,10 +347,9 @@ public synchronized ArangoDB build() { if (hosts.isEmpty()) { hosts.add(host); } - final InternalSerde internalSerde = InternalSerde.of(DataType.of(protocol)); - final InternalSerialization internal = new InternalSerializationImpl(internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(JacksonSerde.of(DataType.of(protocol))); - final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); + final InternalSerde internal = InternalSerde.of(DataType.of(protocol)); + final ArangoSerde custom = customSerializer != null ? customSerializer : JacksonSerde.of(DataType.of(protocol)); + final ArangoSerdeFactory util = new ArangoSerdeFactory(internal, custom); int protocolMaxConnections = protocol == Protocol.VST ? ArangoDefaults.MAX_CONNECTIONS_VST_DEFAULT : diff --git a/src/main/java/com/arangodb/ArangoDatabase.java b/src/main/java/com/arangodb/ArangoDatabase.java index 24146626c..826d301fd 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 diff --git a/src/main/java/com/arangodb/ArangoEdgeCollection.java b/src/main/java/com/arangodb/ArangoEdgeCollection.java index 17d6d054b..702728e99 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 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..a32e09f70 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 diff --git a/src/main/java/com/arangodb/ArangoSerializationAccessor.java b/src/main/java/com/arangodb/ArangoSerdeAccessor.java similarity index 76% rename from src/main/java/com/arangodb/ArangoSerializationAccessor.java rename to src/main/java/com/arangodb/ArangoSerdeAccessor.java index 0f811517c..4c73ef488 100644 --- a/src/main/java/com/arangodb/ArangoSerializationAccessor.java +++ b/src/main/java/com/arangodb/ArangoSerdeAccessor.java @@ -20,26 +20,26 @@ package com.arangodb; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.InternalSerialization; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.InternalSerde; /** * @author Mark Vollmary */ -public interface ArangoSerializationAccessor { +public interface ArangoSerdeAccessor { /** * Returns driver internal serialization implementation for serializing and deserializing driver's classes. * - * @return ArangoSerialization + * @return ArangoSerde */ - InternalSerialization getInternalSerialization(); + InternalSerde getInternalSerde(); /** * Returns serialization implementation for serializing and deserializing user's classes. * - * @return ArangoSerialization + * @return ArangoSerde */ - ArangoSerialization getUserSerialization(); + ArangoSerde getUserSerde(); } diff --git a/src/main/java/com/arangodb/ArangoVertexCollection.java b/src/main/java/com/arangodb/ArangoVertexCollection.java index e34705cf4..ffc1a39f0 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 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..8d2194f43 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 diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 3bfa3d046..44a01a679 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -31,9 +31,7 @@ import com.arangodb.internal.net.ConnectionFactory; import com.arangodb.internal.net.HostHandler; import com.arangodb.internal.net.HostResolver; -import com.arangodb.internal.util.ArangoSerializationFactory; -import com.arangodb.internal.util.ArangoSerializationImpl; -import com.arangodb.internal.util.InternalSerializationImpl; +import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; @@ -43,7 +41,7 @@ import com.arangodb.serde.DataType; import com.arangodb.serde.InternalSerde; import com.arangodb.serde.JacksonSerde; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.ArangoSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -68,7 +66,7 @@ * * @author Mark Vollmary */ -public interface ArangoDBAsync extends ArangoSerializationAccessor { +public interface ArangoDBAsync extends ArangoSerdeAccessor { void shutdown() throws ArangoDBException; @@ -496,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; } @@ -510,10 +508,9 @@ public synchronized ArangoDBAsync build() { if (hosts.isEmpty()) { hosts.add(host); } - final InternalSerde internalSerde = InternalSerde.of(DataType.VPACK); - final InternalSerializationImpl internal = new InternalSerializationImpl(internalSerde); - final ArangoSerialization custom = customSerializer != null ? customSerializer : new ArangoSerializationImpl(JacksonSerde.of(DataType.VPACK)); - final ArangoSerializationFactory util = new ArangoSerializationFactory(internal, custom); + final InternalSerde internal = InternalSerde.of(DataType.VPACK); + final ArangoSerde custom = customSerializer != null ? customSerializer : JacksonSerde.of(DataType.VPACK); + final ArangoSerdeFactory util = new ArangoSerdeFactory(internal, custom); final int max = maxConnections != null ? Math.max(1, maxConnections) : ArangoDefaults.MAX_CONNECTIONS_VST_DEFAULT; diff --git a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java index d3ed12c32..0a7648967 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 diff --git a/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java index 2dea8807c..f87d1f4c7 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 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..2605cbf53 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 diff --git a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java index b610a9796..ed3f98629 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 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/ArangoDBAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java index 70c2ef595..f670e839e 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java @@ -31,7 +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.ArangoSerdeFactory; import com.arangodb.internal.velocystream.VstCommunication; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; @@ -62,7 +62,7 @@ public class ArangoDBAsyncImpl extends InternalArangoDB imp public ArangoDBAsyncImpl( final VstCommunicationAsync.Builder asyncCommBuilder, - final ArangoSerializationFactory util, + final ArangoSerdeFactory util, final VstCommunicationSync.Builder syncCommBuilder, final HostResolver asyncHostResolver, final HostResolver syncHostResolver, @@ -73,10 +73,10 @@ public ArangoDBAsyncImpl( final int timeoutMs ) { - super(new ArangoExecutorAsync(asyncCommBuilder.build(util.getInternalSerialization()), util, new DocumentCache(), + super(new ArangoExecutorAsync(asyncCommBuilder.build(util.getInternalSerde()), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, context); - final VstCommunication cacheCom = syncCommBuilder.build(util.getInternalSerialization()); + final VstCommunication cacheCom = syncCommBuilder.build(util.getInternalSerde()); cp = new VstProtocol(cacheCom); this.asyncHostHandler = asyncHostHandler; @@ -84,8 +84,8 @@ public ArangoDBAsyncImpl( ArangoExecutorSync arangoExecutorSync = new ArangoExecutorSync(cp, util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs); - asyncHostResolver.init(arangoExecutorSync, util.getInternalSerialization()); - syncHostResolver.init(arangoExecutorSync, util.getInternalSerialization()); + asyncHostResolver.init(arangoExecutorSync, util.getInternalSerde()); + syncHostResolver.init(arangoExecutorSync, util.getInternalSerde()); } diff --git a/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java b/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java index 6a1cea3a1..ab8ac57e0 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.internal.util.ArangoSerdeFactory; import com.arangodb.velocystream.Request; import java.io.IOException; @@ -44,7 +44,7 @@ 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 ArangoSerdeFactory util, final DocumentCache documentCache, final QueueTimeMetricsImpl qtMetrics, final int timeoutMs) { super(util, documentCache, qtMetrics, timeoutMs); this.communication = communication; 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 030ebc5f2..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.InternalSerialization; +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 VstCommunication 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 ArangoSerdeFactory 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.getInternalSerialization(), protocol), + createProtocol(vstBuilder, httpBuilder, util.getInternalSerde(), protocol), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, @@ -72,11 +72,11 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom cp = createProtocol( new VstCommunicationSync.Builder(vstBuilder).maxConnections(1), new HttpCommunication.Builder(httpBuilder), - util.getInternalSerialization(), + util.getInternalSerde(), protocol); this.hostHandler = hostHandler; - hostResolver.init(this.executor(), getInternalSerialization()); + hostResolver.init(this.executor(), getInternalSerde()); LOGGER.debug("ArangoDB Client is ready to use"); @@ -85,7 +85,7 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom private static CommunicationProtocol createProtocol( final VstCommunicationSync.Builder vstBuilder, final HttpCommunication.Builder httpBuilder, - final InternalSerialization util, + final InternalSerde util, final Protocol protocol) { return (protocol == null || Protocol.VST == protocol) ? createVST(vstBuilder, util) @@ -94,13 +94,13 @@ private static CommunicationProtocol createProtocol( private static CommunicationProtocol createVST( final VstCommunicationSync.Builder builder, - final InternalSerialization util) { + final InternalSerde util) { return new VstProtocol(builder.build(util)); } private static CommunicationProtocol createHTTP( final HttpCommunication.Builder builder, - final InternalSerialization util) { + final InternalSerde util) { return new HttpProtocol(builder.build(util)); } diff --git a/src/main/java/com/arangodb/internal/ArangoExecuteable.java b/src/main/java/com/arangodb/internal/ArangoExecuteable.java index 2410da540..b3b6d958e 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecuteable.java +++ b/src/main/java/com/arangodb/internal/ArangoExecuteable.java @@ -20,12 +20,12 @@ package com.arangodb.internal; -import com.arangodb.ArangoSerializationAccessor; +import com.arangodb.ArangoSerdeAccessor; import com.arangodb.DbName; -import com.arangodb.internal.util.ArangoSerializationFactory; +import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.internal.util.EncodeUtils; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.InternalSerialization; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -34,15 +34,15 @@ /** * @author Mark Vollmary */ -public abstract class ArangoExecuteable implements ArangoSerializationAccessor { +public abstract class ArangoExecuteable implements ArangoSerdeAccessor { private static final String SLASH = "/"; protected final E executor; - protected final ArangoSerializationFactory util; + protected final ArangoSerdeFactory util; protected final ArangoContext context; - protected ArangoExecuteable(final E executor, final ArangoSerializationFactory util, final ArangoContext context) { + protected ArangoExecuteable(final E executor, final ArangoSerdeFactory util, final ArangoContext context) { super(); this.executor = executor; this.util = util; @@ -54,12 +54,12 @@ protected E executor() { } @Override - public InternalSerialization getInternalSerialization() { - return util.getInternalSerialization(); + public InternalSerde getInternalSerde() { + return util.getInternalSerde(); } @Override - public ArangoSerialization getUserSerialization() { + public ArangoSerde getUserSerde() { return util.getUserSerialization(); } diff --git a/src/main/java/com/arangodb/internal/ArangoExecutor.java b/src/main/java/com/arangodb/internal/ArangoExecutor.java index d9b0ef91a..c3fb99c40 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutor.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutor.java @@ -21,7 +21,7 @@ package com.arangodb.internal; import com.arangodb.QueueTimeMetrics; -import com.arangodb.internal.util.ArangoSerializationFactory; +import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; @@ -36,15 +36,15 @@ protected T createResult(final Type type, final Response response) { if (response.getBody() == null) { return null; } - return util.getInternalSerialization().deserialize(response.getBody(), type); + return util.getInternalSerde().deserialize(response.getBody(), type); } private final DocumentCache documentCache; private final QueueTimeMetricsImpl qtMetrics; - private final ArangoSerializationFactory util; + private final ArangoSerdeFactory util; private final String timeoutS; - protected ArangoExecutor(final ArangoSerializationFactory util, final DocumentCache documentCache, + protected ArangoExecutor(final ArangoSerdeFactory util, final DocumentCache documentCache, final QueueTimeMetricsImpl qtMetrics, final int timeoutMs) { super(); this.documentCache = documentCache; diff --git a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java index 51c683e10..e74037140 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java @@ -24,7 +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.internal.util.ArangoSerdeFactory; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -42,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 ArangoSerdeFactory util, final DocumentCache documentCache, final QueueTimeMetricsImpl qtMetrics, final int timeoutMs) { super(util, documentCache, qtMetrics, timeoutMs); this.protocol = protocol; diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 4bb014874..2e6e397e3 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -91,9 +91,9 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO byte[] body; if (value instanceof String) { - body = getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + body = getInternalSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { - body = getUserSerialization().serialize(value); + body = getUserSerde().serialize(value); } request.setBody(body); @@ -103,15 +103,15 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO protected ResponseDeserializer> insertDocumentResponseDeserializer( final T value, final DocumentCreateOptions options) { return response -> { - final JsonNode body = getInternalSerialization().parse(response.getBody()); - final DocumentCreateEntity doc = getInternalSerialization().deserialize(body, DocumentCreateEntity.class); + final JsonNode body = getInternalSerde().parse(response.getBody()); + final DocumentCreateEntity doc = getInternalSerde().deserialize(body, DocumentCreateEntity.class); final JsonNode newDoc = body.get(NEW); - Class clazz = value.getClass(); + Class clazz = (Class) value.getClass(); if (newDoc != null) { if (String.class.equals(clazz)) { doc.setNew((T) SerdeUtils.INSTANCE.writeJson(newDoc)); } else { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), clazz)); + doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), clazz)); } } final JsonNode oldDoc = body.get(OLD); @@ -119,7 +119,7 @@ protected ResponseDeserializer> insertDocumentRespon if (String.class.equals(clazz)) { doc.setOld((T) SerdeUtils.INSTANCE.writeJson(oldDoc)); } else { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), clazz)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), clazz)); } } if (options == null || Boolean.TRUE != options.getSilent()) { @@ -143,8 +143,8 @@ protected Request insertDocumentsRequest(final Collection values, final D request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerialization().serialize(values); + byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerde().serialize(values); request.setBody(body); return request; } @@ -163,23 +163,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerialization().parse(response.getBody()); + final JsonNode body = getInternalSerde().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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getInternalSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentCreateEntity doc = getInternalSerialization().deserialize(next, DocumentCreateEntity.class); + final DocumentCreateEntity doc = getInternalSerde().deserialize(next, DocumentCreateEntity.class); final JsonNode newDoc = next.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); + doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), type)); } final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -193,12 +193,12 @@ protected ResponseDeserializer>> } protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson(values))); + return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getInternalSerde().serialize(SerdeUtils.INSTANCE.parseJson(values))); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { - byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerialization().serialize(values); + byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerde().serialize(values); return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(body); } @@ -227,9 +227,9 @@ protected Request getDocumentRequest(final String key, final DocumentReadOptions protected ResponseDeserializer getDocumentResponseDeserializer(final Class type) { return response -> { if (String.class.equals(type)) { - return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerialization().parse(response.getBody())); + return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerde().parse(response.getBody())); } else { - return getUserSerialization().deserialize(response.getBody(), type); + return getUserSerde().deserialize(response.getBody(), type); } }; } @@ -239,7 +239,7 @@ protected Request getDocumentsRequest(final Collection keys, final Docum 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(getInternalSerialization().serialize(keys)) + .putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()).setBody(getInternalSerde().serialize(keys)) .putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); if (params.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); @@ -254,16 +254,16 @@ protected ResponseDeserializer> getDocumentsResponseD final Collection docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerialization().parse(response.getBody()); + final JsonNode body = getInternalSerde().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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getInternalSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final T doc = getUserSerialization().deserialize(getInternalSerialization().serialize(next), type); + final T doc = getUserSerde().deserialize(getInternalSerde().serialize(next), type); docs.add(doc); documentsAndErrors.add(doc); } @@ -287,22 +287,23 @@ protected Request replaceDocumentRequest( request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer> replaceDocumentResponseDeserializer( final T value, final DocumentReplaceOptions options) { return response -> { - final JsonNode body = getInternalSerialization().parse(response.getBody()); - final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); + final JsonNode body = getInternalSerde().parse(response.getBody()); + final DocumentUpdateEntity doc = getInternalSerde().deserialize(body, DocumentUpdateEntity.class); final JsonNode newDoc = body.get(NEW); + Class clazz = (Class) value.getClass(); if (newDoc != null) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), value.getClass())); + doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), clazz)); } final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), value.getClass())); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), clazz)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -323,8 +324,8 @@ protected Request replaceDocumentsRequest(final Collection values, final request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerialization().serialize(values); + byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerde().serialize(values); request.setBody(body); return request; } @@ -343,23 +344,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerialization().parse(response.getBody()); + final JsonNode body = getInternalSerde().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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getInternalSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getInternalSerde().deserialize(next, DocumentUpdateEntity.class); final JsonNode newDoc = next.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), type)); + doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), type)); } final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -385,22 +386,22 @@ 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(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer> updateDocumentResponseDeserializer( final T value, final DocumentUpdateOptions options, final Class returnType) { return response -> { - final JsonNode body = getInternalSerialization().parse(response.getBody()); - final DocumentUpdateEntity doc = getInternalSerialization().deserialize(body, DocumentUpdateEntity.class); + final JsonNode body = getInternalSerde().parse(response.getBody()); + final DocumentUpdateEntity doc = getInternalSerde().deserialize(body, DocumentUpdateEntity.class); final JsonNode newDoc = body.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); + doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), returnType)); } final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), returnType)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -424,8 +425,8 @@ protected Request updateDocumentsRequest(final Collection values, final D request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - byte[] body = isStringCollection(values) ? getInternalSerialization().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerialization().serialize(values); + byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getUserSerde().serialize(values); request.setBody(body); return request; } @@ -438,23 +439,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerialization().parse(response.getBody()); + final JsonNode body = getInternalSerde().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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getInternalSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = getInternalSerialization().deserialize(next, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getInternalSerde().deserialize(next, DocumentUpdateEntity.class); final JsonNode newDoc = next.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerialization().deserialize(getInternalSerialization().serialize(newDoc), returnType)); + doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), returnType)); } final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), returnType)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), returnType)); } docs.add(doc); documentsAndErrors.add(doc); @@ -482,11 +483,11 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp protected ResponseDeserializer> deleteDocumentResponseDeserializer( final Class type) { return response -> { - final JsonNode body = getInternalSerialization().parse(response.getBody()); - final DocumentDeleteEntity doc = getInternalSerialization().deserialize(body, DocumentDeleteEntity.class); + final JsonNode body = getInternalSerde().parse(response.getBody()); + final DocumentDeleteEntity doc = getInternalSerde().deserialize(body, DocumentDeleteEntity.class); final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); } return doc; }; @@ -499,7 +500,7 @@ 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(getInternalSerialization().serialize(keys)); + request.setBody(getInternalSerde().serialize(keys)); return request; } @@ -510,19 +511,19 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerialization().parse(response.getBody()); + final JsonNode body = getInternalSerde().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 = getInternalSerialization().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getInternalSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentDeleteEntity doc = getInternalSerialization().deserialize(next, DocumentDeleteEntity.class); + final DocumentDeleteEntity doc = getInternalSerde().deserialize(next, DocumentDeleteEntity.class); final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerialization().deserialize(getInternalSerialization().serialize(oldDoc), type)); + doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -554,7 +555,7 @@ protected Request deleteIndexRequest(final String id) { } protected ResponseDeserializer deleteIndexResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/id", String.class); + return response -> getInternalSerde().deserialize(response.getBody(), "/id", String.class); } private String createIndexId(final String id) { @@ -574,7 +575,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( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); + getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); return request; } @@ -583,7 +584,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( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); + getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); return request; } @@ -591,7 +592,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(getInternalSerialization().serialize( + request.setBody(getInternalSerde().serialize( OptionsBuilder.build(options != null ? options : new PersistentIndexOptions(), fields))); return request; } @@ -600,7 +601,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( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); + getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); return request; } @@ -608,7 +609,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( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); + getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); return request; } @@ -616,7 +617,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( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); + getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); return request; } @@ -624,7 +625,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(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : + request.setBody(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new ZKDIndexOptions().fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE), fields))); return request; } @@ -636,7 +637,7 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/indexes", + return response -> getInternalSerde().deserialize(response.getBody(), "/indexes", SerdeUtils.INSTANCE.constructListType(IndexEntity.class)); } @@ -668,19 +669,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(getInternalSerialization().serialize(options != null ? options : new CollectionPropertiesOptions())); + request.setBody(getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(new CollectionRenameOptions(), newName))); + request.setBody(getInternalSerde().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(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } @@ -690,7 +691,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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + db.dbName().get(), name).setBody(getInternalSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { @@ -704,7 +705,7 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); + return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } private boolean isStringCollection(final Collection values) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index c1b6fcc0f..eb63cb9cb 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -23,7 +23,7 @@ import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerializationFactory; +import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.model.*; import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; @@ -47,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 ArangoSerdeFactory util, final ArangoContext context) { super(executor, util, context); } @@ -60,22 +60,22 @@ protected Request getServerIdRequest() { } protected ResponseDeserializer getRoleResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/role", ServerRole.class); + return response -> getInternalSerde().deserialize(response.getBody(), "/role", ServerRole.class); } protected ResponseDeserializer getServerIdResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/id", String.class); + return response -> getInternalSerde().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(getInternalSerialization().serialize(options)); + request.setBody(getInternalSerde().serialize(options)); return request; } protected ResponseDeserializer createDatabaseResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); + return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); } protected Request getDatabasesRequest(final DbName dbName) { @@ -83,7 +83,7 @@ protected Request getDatabasesRequest(final DbName dbName) { } protected ResponseDeserializer> getDatabaseResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, SerdeUtils.INSTANCE.constructListType(String.class)); } @@ -93,7 +93,7 @@ protected Request getAccessibleDatabasesForRequest(final DbName dbName, final St protected ResponseDeserializer> getAccessibleDatabasesForResponseDeserializer() { return response -> { - Iterator names = getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER).fieldNames(); + Iterator names = getInternalSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER).fieldNames(); final Collection dbs = new ArrayList<>(); while (names.hasNext()) { dbs.add(names.next()); @@ -110,7 +110,7 @@ protected Request createUserRequest( final Request request; request = request(dbName, RequestType.POST, PATH_API_USER); request.setBody( - getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); + getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); return request; } @@ -127,32 +127,32 @@ protected Request getUserRequest(final DbName dbName, final String user) { } protected ResponseDeserializer> getUsersResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + return response -> getInternalSerde().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(getInternalSerialization().serialize(options != null ? options : new UserUpdateOptions())); + request.setBody(getInternalSerde().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(getInternalSerialization().serialize(options != null ? options : new UserUpdateOptions())); + request.setBody(getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + "*").setBody(getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + "*", "*").setBody(getInternalSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getLogEntriesRequest(final LogOptions options) { @@ -173,7 +173,7 @@ protected Request getLogLevelRequest() { protected Request setLogLevelRequest(final LogLevelEntity entity) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_ADMIN_LOG_LEVEL) - .setBody(getInternalSerialization().serialize(entity)); + .setBody(getInternalSerde().serialize(entity)); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java index 093e6428d..9b8821057 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java @@ -25,7 +25,7 @@ import com.arangodb.entity.LoadBalancingStrategy; import com.arangodb.internal.net.*; import com.arangodb.internal.util.HostUtils; -import com.arangodb.util.ArangoSerialization; +import com.arangodb.serde.ArangoSerde; import org.apache.http.client.HttpRequestRetryHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,7 +81,7 @@ public abstract class InternalArangoDBBuilder { protected Boolean acquireHostList; protected Integer acquireHostListInterval; protected LoadBalancingStrategy loadBalancingStrategy; - protected ArangoSerialization customSerializer; + protected ArangoSerde customSerializer; protected Integer responseQueueTimeSamples; @@ -201,7 +201,7 @@ protected void setResponseQueueTimeSamples(final Integer responseQueueTimeSample this.responseQueueTimeSamples = responseQueueTimeSamples; } - 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 5b3739cef..8943e5d34 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -96,7 +96,7 @@ protected Request getEngineRequest() { protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) { - byte[] body = getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)); + byte[] body = getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)); return request(dbName, RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(body); } @@ -110,7 +110,7 @@ protected Request getCollectionsRequest(final CollectionsReadOptions options) { } protected ResponseDeserializer> getCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(getInternalSerialization().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), + return response -> getInternalSerde().deserialize(getInternalSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), SerdeUtils.INSTANCE.constructListType(CollectionEntity.class)); } @@ -119,11 +119,11 @@ protected Request dropRequest() { } protected ResponseDeserializer createDropResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); + return response -> getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get()).setBody(getInternalSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { @@ -131,7 +131,7 @@ protected Request resetAccessRequest(final String user) { } protected Request updateUserDefaultCollectionAccessRequest(final String user, final Permissions permissions) { - return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get(), "*").setBody(getInternalSerialization().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get(), "*").setBody(getInternalSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getPermissionsRequest(final String user) { @@ -139,13 +139,13 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); + return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } 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(getInternalSerialization().serialize( - OptionsBuilder.build(opt, query, bindVars != null ? getUserSerialization().serialize(bindVars) : null))); + final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR).setBody(getInternalSerde().serialize( + OptionsBuilder.build(opt, query, bindVars != null ? getUserSerde().serialize(bindVars) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } @@ -190,12 +190,12 @@ protected Request queryCloseRequest(final String id, final AqlQueryOptions optio 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(getInternalSerialization().serialize( - OptionsBuilder.build(opt, query, bindVars != null ? getUserSerialization().serialize(bindVars) : null))); + .setBody(getInternalSerde().serialize( + OptionsBuilder.build(opt, query, bindVars != null ? getUserSerde().serialize(bindVars) : null))); } protected Request parseQueryRequest(final String query) { - return request(dbName, RequestType.POST, PATH_API_QUERY).setBody(getInternalSerialization().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); + return request(dbName, RequestType.POST, PATH_API_QUERY).setBody(getInternalSerde().serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); } protected Request clearQueryCacheRequest() { @@ -207,7 +207,7 @@ protected Request getQueryCachePropertiesRequest() { } protected Request setQueryCachePropertiesRequest(final QueryCachePropertiesEntity properties) { - return request(dbName, RequestType.PUT, PATH_API_QUERY_CACHE_PROPERTIES).setBody(getInternalSerialization().serialize(properties)); + return request(dbName, RequestType.PUT, PATH_API_QUERY_CACHE_PROPERTIES).setBody(getInternalSerde().serialize(properties)); } protected Request getQueryTrackingPropertiesRequest() { @@ -215,7 +215,7 @@ protected Request getQueryTrackingPropertiesRequest() { } protected Request setQueryTrackingPropertiesRequest(final QueryTrackingPropertiesEntity properties) { - return request(dbName, RequestType.PUT, PATH_API_QUERY_PROPERTIES).setBody(getInternalSerialization().serialize(properties)); + return request(dbName, RequestType.PUT, PATH_API_QUERY_PROPERTIES).setBody(getInternalSerde().serialize(properties)); } protected Request getCurrentlyRunningQueriesRequest() { @@ -235,7 +235,7 @@ protected Request killQueryRequest(final String id) { } protected Request createAqlFunctionRequest(final String name, final String code, final AqlFunctionCreateOptions options) { - return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); + return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); } protected Request deleteAqlFunctionRequest(final String name, final AqlFunctionDeleteOptions options) { @@ -246,7 +246,7 @@ protected Request deleteAqlFunctionRequest(final String name, final AqlFunctionD } protected ResponseDeserializer deleteAqlFunctionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/deletedCount", Integer.class); + return response -> getInternalSerde().deserialize(response.getBody(), "/deletedCount", Integer.class); } protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { @@ -257,16 +257,16 @@ protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { } protected ResponseDeserializer> getAqlFunctionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + return response -> getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); + return request(dbName, RequestType.POST, InternalArangoGraph.PATH_API_GHARIAL).setBody(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); } protected ResponseDeserializer createGraphResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/graph", GraphEntity.class); + return response -> getInternalSerde().deserialize(response.getBody(), "/graph", GraphEntity.class); } protected Request getGraphsRequest() { @@ -274,27 +274,27 @@ protected Request getGraphsRequest() { } protected ResponseDeserializer> getGraphsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/graphs", + return response -> getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); + return request(dbName, RequestType.POST, PATH_API_TRANSACTION).setBody(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); } protected ResponseDeserializer transactionResponseDeserializer(final Class type) { return response -> { - byte[] userContent = getInternalSerialization().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); + byte[] userContent = getInternalSerde().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); if (String.class.equals(type)) { - return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerialization().parse(userContent)); + return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerde().parse(userContent)); } else { - return getUserSerialization().deserialize(userContent, type); + return getUserSerde().deserialize(userContent, type); } }; } protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { - return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION).setBody(getInternalSerialization().serialize(options != null ? options : new StreamTransactionOptions())); + return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION).setBody(getInternalSerde().serialize(options != null ? options : new StreamTransactionOptions())); } protected Request abortStreamTransactionRequest(String id) { @@ -310,7 +310,7 @@ protected Request getStreamTransactionRequest(String id) { } protected ResponseDeserializer> transactionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/transactions", + return response -> getInternalSerde().deserialize(response.getBody(), "/transactions", SerdeUtils.INSTANCE.constructListType(TransactionEntity.class)); } @@ -319,7 +319,7 @@ protected Request commitStreamTransactionRequest(String id) { } protected ResponseDeserializer streamTransactionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, StreamTransactionEntity.class); + return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, StreamTransactionEntity.class); } protected Request getInfoRequest() { @@ -327,7 +327,7 @@ protected Request getInfoRequest() { } protected ResponseDeserializer getInfoResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, DatabaseEntity.class); + return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, DatabaseEntity.class); } protected Request reloadRoutingRequest() { @@ -339,16 +339,16 @@ protected Request getViewsRequest() { } protected ResponseDeserializer> getViewsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + return response -> getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(new ViewCreateOptions(), name, type))); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getInternalSerde().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(getInternalSerialization().serialize(ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(getInternalSerde().serialize(ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); } protected Request getAnalyzerRequest(final String name) { @@ -360,12 +360,12 @@ protected Request getAnalyzersRequest() { } protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + return response -> getInternalSerde().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(getInternalSerialization().serialize(options)); + return request(dbName, RequestType.POST, InternalArangoView.PATH_API_ANALYZER).setBody(getInternalSerde().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 725141dbd..ae4b357bf 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -65,13 +65,13 @@ protected Request insertEdgeRequest(final T value, final EdgeCreateOptions o final EdgeCreateOptions params = (options != null ? options : new EdgeCreateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.setBody(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer insertEdgeResponseDeserializer(final T value) { return response -> { - final EdgeEntity doc = getInternalSerialization().deserialize(response.getBody(), "/edge", EdgeEntity.class); + final EdgeEntity doc = getInternalSerde().deserialize(response.getBody(), "/edge", EdgeEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -95,7 +95,7 @@ protected Request getEdgeRequest(final String key, final GraphDocumentReadOption } protected ResponseDeserializer getEdgeResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), "/edge"), type); + return response -> getUserSerde().deserialize(getInternalSerde().extract(response.getBody(), "/edge"), type); } protected Request replaceEdgeRequest(final String key, final T value, final EdgeReplaceOptions options) { @@ -105,13 +105,13 @@ protected Request replaceEdgeRequest(final String key, final T value, final request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer replaceEdgeResponseDeserializer(final T value) { return response -> { - final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -128,13 +128,13 @@ protected Request updateEdgeRequest(final String key, final T value, final E request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer updateEdgeResponseDeserializer(final T value) { return response -> { - final EdgeUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); + final EdgeUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/edge", EdgeUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index f725539ba..4e74bcf25 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoGraph.java +++ b/src/main/java/com/arangodb/internal/InternalArangoGraph.java @@ -84,13 +84,13 @@ protected Request getVertexCollectionsRequest() { } protected ResponseDeserializer> getVertexCollectionsResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", + return response -> getInternalSerde().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(getInternalSerialization().serialize(OptionsBuilder.build(options, name))); + request.setBody(getInternalSerde().serialize(OptionsBuilder.build(options, name))); return request; } @@ -103,29 +103,29 @@ protected Request getEdgeDefinitionsRequest() { } protected ResponseDeserializer> getEdgeDefinitionsDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), "/collections", + return response -> getInternalSerde().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(getInternalSerialization().serialize(definition)); + request.setBody(getInternalSerde().serialize(definition)); return request; } protected ResponseDeserializer addEdgeDefinitionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), GRAPH, GraphEntity.class); + return response -> getInternalSerde().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(getInternalSerialization().serialize(definition)); + request.setBody(getInternalSerde().serialize(definition)); return request; } protected ResponseDeserializer replaceEdgeDefinitionResponseDeserializer() { - return response -> getInternalSerialization().deserialize(response.getBody(), GRAPH, GraphEntity.class); + return response -> getInternalSerde().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 -> getInternalSerialization().deserialize(response.getBody(), GRAPH, GraphEntity.class); + return response -> getInternalSerde().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 f0936eb87..f053c19ce 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoRoute.java +++ b/src/main/java/com/arangodb/internal/InternalArangoRoute.java @@ -74,7 +74,7 @@ protected Request createRequest(final RequestType requestType) { request.putQueryParam(param.getKey(), param.getValue()); } if (body != null) { - request.setBody(getInternalSerialization().serialize(body)); + request.setBody(getInternalSerde().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 3bdf9d90f..8e09b414f 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(getInternalSerialization().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); + request.setBody(getInternalSerde().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(getInternalSerialization().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); + request.setBody(getInternalSerde().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 bc9d1e0a4..f74214086 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -73,9 +73,9 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio byte[] body; if (value instanceof String) { - body = getInternalSerialization().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + body = getInternalSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { - body = getUserSerialization().serialize(value); + body = getUserSerde().serialize(value); } request.setBody(body); return request; @@ -83,7 +83,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio protected ResponseDeserializer insertVertexResponseDeserializer(final T value) { return response -> { - final VertexEntity doc = getInternalSerialization().deserialize(response.getBody(), "/vertex", VertexEntity.class); + final VertexEntity doc = getInternalSerde().deserialize(response.getBody(), "/vertex", VertexEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); values.put(DocumentFields.KEY, doc.getKey()); @@ -107,7 +107,7 @@ protected Request getVertexRequest(final String key, final GraphDocumentReadOpti } protected ResponseDeserializer getVertexResponseDeserializer(final Class type) { - return response -> getUserSerialization().deserialize(getInternalSerialization().extract(response.getBody(), "/vertex"), type); + return response -> getUserSerde().deserialize(getInternalSerde().extract(response.getBody(), "/vertex"), type); } protected Request replaceVertexRequest(final String key, final T value, final VertexReplaceOptions options) { @@ -117,13 +117,13 @@ protected Request replaceVertexRequest(final String key, final T value, fina request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer replaceVertexResponseDeserializer(final T value) { return response -> { - final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); + final VertexUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); @@ -140,13 +140,13 @@ protected Request updateVertexRequest(final String key, final T value, final request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerialization().serialize(value)); + request.setBody(getUserSerde().serialize(value)); return request; } protected ResponseDeserializer updateVertexResponseDeserializer(final T value) { return response -> { - final VertexUpdateEntity doc = getInternalSerialization().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); + final VertexUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/vertex", VertexUpdateEntity.class); final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); executor.documentCache().setValues(value, values); diff --git a/src/main/java/com/arangodb/internal/InternalArangoView.java b/src/main/java/com/arangodb/internal/InternalArangoView.java index 0257e3643..0f4e821e6 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoView.java +++ b/src/main/java/com/arangodb/internal/InternalArangoView.java @@ -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(getInternalSerialization().serialize(OptionsBuilder.build(new ViewRenameOptions(), newName))); + request.setBody(getInternalSerde().serialize(OptionsBuilder.build(new ViewRenameOptions(), newName))); return request; } diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java index 8b108f8ff..ad9afbac0 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -71,11 +71,11 @@ public T next() { if (!hasNext()) { throw new NoSuchElementException(); } - return deserialize(db.getInternalSerialization().serialize(arrayIterator.next()), cursor.getType()); + return deserialize(db.getInternalSerde().serialize(arrayIterator.next()), cursor.getType()); } protected R deserialize(final byte[] result, final Class type) { - return db.getUserSerialization().deserialize(result, type); + return db.getUserSerde().deserialize(result, type); } @Override diff --git a/src/main/java/com/arangodb/internal/http/CURLLogger.java b/src/main/java/com/arangodb/internal/http/CURLLogger.java index f60039a19..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.InternalSerialization; +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 InternalSerialization 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; diff --git a/src/main/java/com/arangodb/internal/http/HttpCommunication.java b/src/main/java/com/arangodb/internal/http/HttpCommunication.java index 2d7137128..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.InternalSerialization; +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 InternalSerialization 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 8dcfa001f..1544839dc 100644 --- a/src/main/java/com/arangodb/internal/http/HttpConnection.java +++ b/src/main/java/com/arangodb/internal/http/HttpConnection.java @@ -27,7 +27,7 @@ import com.arangodb.internal.net.HostDescription; import com.arangodb.internal.util.IOUtils; import com.arangodb.internal.util.ResponseUtils; -import com.arangodb.util.InternalSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.apache.http.*; @@ -81,7 +81,7 @@ public class HttpConnection implements Connection { public static class Builder { private String user; private String password; - private InternalSerialization util; + private InternalSerde util; private Boolean useSsl; private String httpCookieSpec; private Protocol contentType; @@ -102,7 +102,7 @@ public Builder password(final String password) { return this; } - public Builder serializationUtil(final InternalSerialization util) { + public Builder serializationUtil(final InternalSerde util) { this.util = util; return this; } @@ -163,13 +163,13 @@ public HttpConnection build() { private final String user; private final String password; private volatile String jwt = null; - private final InternalSerialization 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 InternalSerialization 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; diff --git a/src/main/java/com/arangodb/internal/http/HttpConnectionFactory.java b/src/main/java/com/arangodb/internal/http/HttpConnectionFactory.java index 6ed7bbefb..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.InternalSerialization; +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 InternalSerialization 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/net/ExtendedHostResolver.java b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java index 234c96dd0..7f4e6a9fa 100644 --- a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java +++ b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java @@ -25,7 +25,7 @@ import com.arangodb.internal.ArangoExecutorSync; import com.arangodb.internal.util.HostUtils; import com.arangodb.serde.SerdeUtils; -import com.arangodb.util.InternalSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; import org.slf4j.Logger; @@ -49,7 +49,7 @@ public class ExtendedHostResolver implements HostResolver { private final Integer acquireHostListInterval; private ArangoExecutorSync executor; - private InternalSerialization arangoSerialization; + private InternalSerde arangoSerialization; public ExtendedHostResolver(final List hosts, final Integer maxConnections, @@ -64,7 +64,7 @@ public ExtendedHostResolver(final List hosts, final Integer maxConnections } @Override - public void init(ArangoExecutorSync executor, InternalSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { this.executor = executor; this.arangoSerialization = arangoSerialization; } diff --git a/src/main/java/com/arangodb/internal/net/HostResolver.java b/src/main/java/com/arangodb/internal/net/HostResolver.java index 3dd9e6e1a..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.InternalSerialization; +import com.arangodb.serde.InternalSerde; /** * @author Mark Vollmary */ public interface HostResolver { - void init(ArangoExecutorSync executorSync, InternalSerialization 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 088189747..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.InternalSerialization; +import com.arangodb.serde.InternalSerde; import java.util.List; @@ -38,7 +38,7 @@ public SimpleHostResolver(final List hosts) { } @Override - public void init(ArangoExecutorSync executor, InternalSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { } diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java b/src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java similarity index 66% rename from src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java rename to src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java index c5c3558f9..5edfef0b3 100644 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializationFactory.java +++ b/src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java @@ -20,28 +20,28 @@ package com.arangodb.internal.util; -import com.arangodb.util.ArangoSerialization; -import com.arangodb.util.InternalSerialization; +import com.arangodb.serde.ArangoSerde; +import com.arangodb.serde.InternalSerde; /** * @author Mark Vollmary */ -public class ArangoSerializationFactory { +public class ArangoSerdeFactory { - private final InternalSerialization internal; - private final ArangoSerialization user; + private final InternalSerde internal; + private final ArangoSerde user; - public ArangoSerializationFactory(final InternalSerialization internal, final ArangoSerialization user) { + public ArangoSerdeFactory(final InternalSerde internal, final ArangoSerde user) { super(); this.internal = internal; this.user = user; } - public InternalSerialization getInternalSerialization() { + public InternalSerde getInternalSerde() { return internal; } - public ArangoSerialization getUserSerialization() { + public ArangoSerde getUserSerialization() { return user; } diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java b/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java deleted file mode 100644 index 3cba46382..000000000 --- a/src/main/java/com/arangodb/internal/util/ArangoSerializationImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.arangodb.internal.util; - -import com.arangodb.ArangoDBException; -import com.arangodb.serde.ArangoSerde; -import com.arangodb.util.ArangoSerialization; - -import java.lang.reflect.Type; - -public class ArangoSerializationImpl implements ArangoSerialization { - - private final ArangoSerde serde; - - public ArangoSerializationImpl(final ArangoSerde serde) { - super(); - this.serde = serde; - } - - @Override - public byte[] serialize(final Object entity) throws ArangoDBException { - return serde.serialize(entity); - } - - @Override - public T deserialize(byte[] content, Type type) { - return serde.deserialize(content, type); - } - -} diff --git a/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java b/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java deleted file mode 100644 index 681108497..000000000 --- a/src/main/java/com/arangodb/internal/util/InternalSerializationImpl.java +++ /dev/null @@ -1,82 +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.serde.InternalSerde; -import com.arangodb.util.InternalSerialization; -import com.fasterxml.jackson.databind.JsonNode; - -import java.lang.reflect.Type; - -/** - * @author Mark Vollmary - */ -public class InternalSerializationImpl implements InternalSerialization { - - private final InternalSerde serde; - - public InternalSerializationImpl(final InternalSerde serde) { - super(); - this.serde = serde; - } - - @Override - public byte[] serialize(final Object entity) throws ArangoDBException { - return serde.serialize(entity); - } - - @Override - public String toJsonString(byte[] content) { - return serde.toJsonString(content); - } - - @Override - public JsonNode parse(byte[] content) { - return serde.parse(content); - } - - @Override - public T deserialize(byte[] content, Type type) { - return serde.deserialize(content, type); - } - - @Override - public T deserialize(JsonNode node, Type type) { - return serde.deserialize(node, type); - } - - @Override - public JsonNode parse(byte[] content, String jsonPointer) { - return serde.parse(content, jsonPointer); - } - - @Override - public T deserialize(byte[] content, String jsonPointer, Type type) { - return serde.deserialize(content, jsonPointer, type); - } - - @Override - public byte[] extract(byte[] content, String jsonPointer) { - return serde.extract(content, jsonPointer); - } - -} diff --git a/src/main/java/com/arangodb/internal/util/ResponseUtils.java b/src/main/java/com/arangodb/internal/util/ResponseUtils.java index 16bb4ce86..ea70a9272 100644 --- a/src/main/java/com/arangodb/internal/util/ResponseUtils.java +++ b/src/main/java/com/arangodb/internal/util/ResponseUtils.java @@ -24,7 +24,7 @@ import com.arangodb.entity.ErrorEntity; import com.arangodb.internal.ArangoErrors; import com.arangodb.internal.net.ArangoDBRedirectException; -import com.arangodb.util.InternalSerialization; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Response; import java.util.concurrent.TimeoutException; @@ -42,7 +42,7 @@ private ResponseUtils() { super(); } - public static void checkError(final InternalSerialization util, final Response response) throws ArangoDBException { + 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)) { diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunication.java index 81cec8572..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.InternalSerialization; +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 InternalSerialization 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 InternalSerialization util, + final Boolean useSsl, final SSLContext sslContext, final InternalSerde util, final Integer chunksize, final HostHandler hostHandler) { this.user = user; this.password = password; diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunicationSync.java index 140882367..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.InternalSerialization; +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 InternalSerialization 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 InternalSeriali protected VstCommunicationSync(final HostHandler hostHandler, final Integer timeout, final String user, final String password, final String jwt, final Boolean useSsl, - final SSLContext sslContext, final InternalSerialization 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/mapping/ArangoJack.java b/src/main/java/com/arangodb/mapping/ArangoJack.java deleted file mode 100644 index d195ad28d..000000000 --- a/src/main/java/com/arangodb/mapping/ArangoJack.java +++ /dev/null @@ -1,82 +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.jackson.dataformat.velocypack.VPackMapper; -import com.arangodb.serde.DataType; -import com.arangodb.serde.JacksonSerde; -import com.arangodb.util.ArangoSerialization; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.PropertyAccessor; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -import java.lang.reflect.Type; - -/** - * @author Mark Vollmary - */ -public class ArangoJack implements ArangoSerialization { - - public interface ConfigureFunction { - void configure(ObjectMapper mapper); - } - - private final JacksonSerde serde; - - 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); - 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 m = mapper != null ? mapper.copy() : new VPackMapper(); - serde = JacksonSerde.of(DataType.VPACK, m); - } - - public void configure(final ArangoJack.ConfigureFunction f) { - serde.configure(f::configure); - } - - @Override - public byte[] serialize(final Object entity) throws ArangoDBException { - return serde.serialize(entity); - } - - @Override - public T deserialize(byte[] content, Type type) { - return serde.deserialize(content, type); - } - -} diff --git a/src/main/java/com/arangodb/util/ArangoSerialization.java b/src/main/java/com/arangodb/util/ArangoSerialization.java deleted file mode 100644 index d021c9bd7..000000000 --- a/src/main/java/com/arangodb/util/ArangoSerialization.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.arangodb.util; - -import java.lang.reflect.Type; - -public interface ArangoSerialization { - byte[] serialize(final Object entity); - T deserialize(byte[] content, Type type); -} diff --git a/src/main/java/com/arangodb/util/InternalSerialization.java b/src/main/java/com/arangodb/util/InternalSerialization.java deleted file mode 100644 index d063a7d3a..000000000 --- a/src/main/java/com/arangodb/util/InternalSerialization.java +++ /dev/null @@ -1,47 +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.fasterxml.jackson.databind.JsonNode; - -import java.lang.reflect.Type; - -/** - * @author Mark Vollmary - */ -public interface InternalSerialization { - byte[] serialize(final Object entity); - - T deserialize(byte[] content, Type type); - - T deserialize(JsonNode node, Type type); - - String toJsonString(byte[] content); - - JsonNode parse(byte[] content); - - JsonNode parse(byte[] content, String jsonPointer); - - T deserialize(byte[] content, String jsonPointer, Type type); - - byte[] extract(byte[] content, String jsonPointer); - -} diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index b2d70b92b..5762bf915 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -21,7 +21,6 @@ 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; @@ -213,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(); @@ -375,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); @@ -384,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,7 +393,7 @@ void authenticationFailUser() { @MethodSource("arangos") void execute(ArangoDB arangoDB) { final Response response = arangoDB.execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")); - assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "/version").isTextual()).isTrue(); + assertThat(arangoDB.getInternalSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") @@ -555,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(); } diff --git a/src/test/java/com/arangodb/ArangoRouteTest.java b/src/test/java/com/arangodb/ArangoRouteTest.java index 212c654a4..b6866fbea 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(db.arango().getInternalSerialization().parse(res.getBody(), "/version").isTextual()).isTrue(); + assertThat(db.arango().getInternalSerde().parse(res.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") 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/BaseJunit5.java b/src/test/java/com/arangodb/BaseJunit5.java index 140d52730..b231b4a58 100644 --- a/src/test/java/com/arangodb/BaseJunit5.java +++ b/src/test/java/com/arangodb/BaseJunit5.java @@ -21,8 +21,6 @@ class BaseJunit5 { private static final List adbs = Arrays.stream(Protocol.values()) .map(p -> new ArangoDB.Builder() .useProtocol(p) - // FIXME -// .serializer(new ArangoJack()) .build()) .collect(Collectors.toList()); 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/JwtAuthTest.java b/src/test/java/com/arangodb/JwtAuthTest.java index 835c2cade..59d12df67 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.InternalSerialization; +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) { - InternalSerialization serde = arangoDB.getInternalSerialization(); + InternalSerde serde = arangoDB.getInternalSerde(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 134189fa3..743b7cc28 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -22,7 +22,6 @@ import com.arangodb.*; import com.arangodb.entity.*; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.*; import com.arangodb.util.TestUtils; import com.arangodb.velocystream.Request; @@ -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))); @@ -414,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(); @@ -425,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(); @@ -440,19 +439,19 @@ void execute() throws InterruptedException, ExecutionException { .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(arangoDB.getInternalSerialization().parse(response.getBody(), "/version").isTextual()).isTrue(); + assertThat(arangoDB.getInternalSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } @Test void execute_acquireHostList_enabled() throws InterruptedException, ExecutionException { - final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().acquireHostList(true).serializer(new ArangoJack()).build(); + 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(arangoDB.getInternalSerialization().parse(response.getBody(), "/version").isTextual()).isTrue(); + assertThat(arangoDB.getInternalSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } 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 a55c23527..640c7a0ee 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.InternalSerialization; +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) { - InternalSerialization serde = arangoDB.getInternalSerialization(); + InternalSerde serde = arangoDB.getInternalSerde(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); 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 b4e98bc16..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,12 +22,12 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; -import com.arangodb.util.MapBuilder; 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; @@ -59,7 +59,7 @@ private static void createExamples() throws InterruptedException, ExecutionExcep 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(); + 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"); @@ -73,7 +73,7 @@ void aqlWithLimitQueryAsJsonObject() throws InterruptedException, ExecutionExcep 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(); + 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"); @@ -87,7 +87,7 @@ void aqlWithLimitQueryAsArrayNode() throws InterruptedException, ExecutionExcept 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(); @@ -104,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/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/async/example/graph/AQLActorsAndMoviesExampleTest.java index 9667b542c..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,7 +29,6 @@ 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; @@ -57,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(); } 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/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java index 90022a845..2546334bd 100644 --- a/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java @@ -26,8 +26,9 @@ 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; @@ -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); diff --git a/src/test/java/com/arangodb/example/ExampleBase.java b/src/test/java/com/arangodb/example/ExampleBase.java index b903a31d5..6267026d5 100644 --- a/src/test/java/com/arangodb/example/ExampleBase.java +++ b/src/test/java/com/arangodb/example/ExampleBase.java @@ -21,7 +21,6 @@ package com.arangodb.example; import com.arangodb.*; -import com.arangodb.mapping.ArangoJack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -39,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 8164c26a3..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.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"); @@ -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 1172d4071..f820cdd09 100644 --- a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java +++ b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExampleTest.java @@ -23,12 +23,12 @@ import com.arangodb.ArangoCursor; import com.arangodb.entity.BaseDocument; import com.arangodb.example.ExampleBase; -import com.arangodb.util.MapBuilder; 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; @@ -63,7 +63,7 @@ private static void createExamples() { 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 Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); final ArangoCursor cursor = db.query(query, bindVars, null, ObjectNode.class); assertThat((Object) cursor).isNotNull(); while (cursor.hasNext()) { @@ -79,7 +79,7 @@ void aqlWithLimitQueryAsJsonObject() { 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 Map bindVars = Collections.singletonMap("gender", Gender.FEMALE); final ArangoCursor cursor = db.query(query, bindVars, null, ArrayNode.class); assertThat((Object) cursor).isNotNull(); while (cursor.hasNext()) { @@ -96,7 +96,7 @@ void aqlWithLimitQueryAsJsonArray() { 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()) { @@ -116,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/graph/AQLActorsAndMoviesExampleTest.java b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java index ba9cb7cd4..0bd9b57a3 100644 --- a/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java +++ b/src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExampleTest.java @@ -25,7 +25,6 @@ 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; @@ -49,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); 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/internal/HostHandlerTest.java b/src/test/java/com/arangodb/internal/HostHandlerTest.java index 0fcc2bc92..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.InternalSerialization; +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, InternalSerialization 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, InternalSerialization arangoSerialization) { + public void init(ArangoExecutorSync executor, InternalSerde arangoSerialization) { } 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/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index 94812aac4..f00656d43 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -26,9 +26,7 @@ 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.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.*; @@ -92,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()) { @@ -134,7 +132,7 @@ void customPersonDeserializer() { void manualCustomPersonDeserializer() { Person person = new Person(); person.name = "Joe"; - ArangoSerialization serialization = arangoDB.getUserSerialization(); + 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); @@ -228,7 +226,7 @@ void getDocument() { @Test void parseNullString() { - final String json = arangoDB.getUserSerialization().deserialize(arangoDB.getUserSerialization().serialize(null), 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 178867aef..d2144e0ee 100644 --- a/src/test/java/com/arangodb/serde/CustomTypeHintTest.java +++ b/src/test/java/com/arangodb/serde/CustomTypeHintTest.java @@ -23,7 +23,6 @@ import com.arangodb.*; import com.arangodb.entity.Key; -import com.arangodb.mapping.ArangoJack; import com.arangodb.model.DocumentCreateOptions; import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.junit.jupiter.api.AfterEach; @@ -87,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/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/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); From 9d9e46d62923f31cfc347aaf7571cbd68fdd17d3 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 21 Jul 2022 10:04:47 +0200 Subject: [PATCH 33/52] made data definition classes final --- .../entity/AqlExecutionExplainEntity.java | 14 +++++----- .../arangodb/entity/AqlFunctionEntity.java | 2 +- .../com/arangodb/entity/AqlParseEntity.java | 4 +-- .../com/arangodb/entity/ArangoDBEngine.java | 2 +- .../com/arangodb/entity/ArangoDBVersion.java | 2 +- .../com/arangodb/entity/BaseEdgeDocument.java | 2 +- .../com/arangodb/entity/CollectionEntity.java | 2 +- .../entity/CollectionPropertiesEntity.java | 2 +- .../entity/CollectionRevisionEntity.java | 2 +- .../com/arangodb/entity/CursorEntity.java | 8 +++--- .../com/arangodb/entity/DatabaseEntity.java | 2 +- .../arangodb/entity/DocumentCreateEntity.java | 2 +- .../arangodb/entity/DocumentDeleteEntity.java | 2 +- .../com/arangodb/entity/DocumentEntity.java | 2 +- .../arangodb/entity/DocumentImportEntity.java | 2 +- .../arangodb/entity/DocumentUpdateEntity.java | 2 +- .../com/arangodb/entity/EdgeDefinition.java | 4 +-- .../java/com/arangodb/entity/EdgeEntity.java | 2 +- .../com/arangodb/entity/EdgeUpdateEntity.java | 2 +- src/main/java/com/arangodb/entity/Entity.java | 28 ------------------- .../java/com/arangodb/entity/ErrorEntity.java | 2 +- .../java/com/arangodb/entity/GraphEntity.java | 2 +- .../java/com/arangodb/entity/IndexEntity.java | 2 +- .../java/com/arangodb/entity/KeyOptions.java | 2 +- .../com/arangodb/entity/LogEntriesEntity.java | 4 +-- .../com/arangodb/entity/LogLevelEntity.java | 2 +- .../arangodb/entity/MultiDocumentEntity.java | 2 +- .../entity/QueryCachePropertiesEntity.java | 2 +- .../java/com/arangodb/entity/QueryEntity.java | 2 +- .../entity/QueryTrackingPropertiesEntity.java | 2 +- .../arangodb/entity/ReplicationFactor.java | 2 +- .../java/com/arangodb/entity/ShardEntity.java | 2 +- .../entity/StreamTransactionEntity.java | 2 +- .../arangodb/entity/TransactionEntity.java | 2 +- .../java/com/arangodb/entity/UserEntity.java | 2 +- .../com/arangodb/entity/VertexEntity.java | 2 +- .../arangodb/entity/VertexUpdateEntity.java | 2 +- .../java/com/arangodb/entity/ViewEntity.java | 2 +- .../ArangoSearchPropertiesEntity.java | 2 +- .../entity/arangosearch/CollectionLink.java | 2 +- .../arangosearch/ConsolidationPolicy.java | 2 +- .../entity/arangosearch/FieldLink.java | 2 +- .../entity/arangosearch/PrimarySort.java | 2 +- .../entity/arangosearch/StoredValue.java | 2 +- .../arangosearch/analyzer/AQLAnalyzer.java | 2 +- .../analyzer/AQLAnalyzerProperties.java | 2 +- .../analyzer/CollationAnalyzer.java | 2 +- .../analyzer/CollationAnalyzerProperties.java | 2 +- .../analyzer/DelimiterAnalyzer.java | 2 +- .../analyzer/DelimiterAnalyzerProperties.java | 2 +- .../arangosearch/analyzer/EdgeNgram.java | 2 +- .../analyzer/GeoAnalyzerOptions.java | 2 +- .../analyzer/GeoJSONAnalyzer.java | 2 +- .../analyzer/GeoJSONAnalyzerProperties.java | 2 +- .../analyzer/GeoPointAnalyzer.java | 2 +- .../analyzer/GeoPointAnalyzerProperties.java | 2 +- .../analyzer/IdentityAnalyzer.java | 2 +- .../arangosearch/analyzer/NGramAnalyzer.java | 2 +- .../analyzer/NGramAnalyzerProperties.java | 2 +- .../arangosearch/analyzer/NormAnalyzer.java | 2 +- .../analyzer/NormAnalyzerProperties.java | 2 +- .../analyzer/PipelineAnalyzer.java | 2 +- .../analyzer/PipelineAnalyzerProperties.java | 2 +- .../arangosearch/analyzer/SearchAnalyzer.java | 3 +- .../analyzer/SegmentationAnalyzer.java | 2 +- .../SegmentationAnalyzerProperties.java | 2 +- .../arangosearch/analyzer/StemAnalyzer.java | 2 +- .../analyzer/StemAnalyzerProperties.java | 2 +- .../analyzer/StopwordsAnalyzer.java | 2 +- .../analyzer/StopwordsAnalyzerProperties.java | 2 +- .../arangosearch/analyzer/TextAnalyzer.java | 2 +- .../analyzer/TextAnalyzerProperties.java | 2 +- .../model/AqlFunctionCreateOptions.java | 6 ++-- .../model/AqlFunctionDeleteOptions.java | 2 +- .../arangodb/model/AqlFunctionGetOptions.java | 2 +- .../model/AqlQueryExplainOptions.java | 10 +++---- .../com/arangodb/model/AqlQueryOptions.java | 8 +++--- .../arangodb/model/AqlQueryParseOptions.java | 4 +-- .../model/CollectionCountOptions.java | 2 +- .../model/CollectionCreateOptions.java | 4 +-- .../model/CollectionPropertiesOptions.java | 2 +- .../model/CollectionRenameOptions.java | 4 +-- .../com/arangodb/model/CollectionSchema.java | 2 +- .../model/CollectionTruncateOptions.java | 2 +- .../model/CollectionsReadOptions.java | 2 +- .../com/arangodb/model/DBCreateOptions.java | 2 +- .../com/arangodb/model/DatabaseOptions.java | 2 +- .../arangodb/model/DatabaseUsersOptions.java | 2 +- .../arangodb/model/DocumentCreateOptions.java | 2 +- .../arangodb/model/DocumentDeleteOptions.java | 2 +- .../arangodb/model/DocumentExistsOptions.java | 2 +- .../arangodb/model/DocumentImportOptions.java | 2 +- .../arangodb/model/DocumentReadOptions.java | 2 +- .../model/DocumentReplaceOptions.java | 2 +- .../arangodb/model/DocumentUpdateOptions.java | 2 +- .../com/arangodb/model/EdgeCreateOptions.java | 2 +- .../com/arangodb/model/EdgeDeleteOptions.java | 2 +- .../arangodb/model/EdgeReplaceOptions.java | 2 +- .../com/arangodb/model/EdgeUpdateOptions.java | 2 +- .../arangodb/model/FulltextIndexOptions.java | 6 ++-- .../com/arangodb/model/GeoIndexOptions.java | 6 ++-- .../arangodb/model/GraphCreateOptions.java | 8 +++--- .../model/GraphDocumentReadOptions.java | 2 +- .../com/arangodb/model/HashIndexOptions.java | 6 ++-- .../java/com/arangodb/model/IndexOptions.java | 4 +-- .../java/com/arangodb/model/LogOptions.java | 2 +- .../com/arangodb/model/OptionsBuilder.java | 2 +- .../model/PersistentIndexOptions.java | 6 ++-- .../com/arangodb/model/QueueTimeSample.java | 2 +- .../arangodb/model/SkiplistIndexOptions.java | 6 ++-- .../model/StreamTransactionOptions.java | 2 +- .../model/TransactionCollectionOptions.java | 2 +- .../arangodb/model/TransactionOptions.java | 4 +-- .../com/arangodb/model/TtlIndexOptions.java | 6 ++-- .../com/arangodb/model/UserAccessOptions.java | 4 +-- .../com/arangodb/model/UserCreateOptions.java | 6 ++-- .../com/arangodb/model/UserUpdateOptions.java | 2 +- .../model/VertexCollectionCreateOptions.java | 6 ++-- .../arangodb/model/VertexCreateOptions.java | 2 +- .../arangodb/model/VertexDeleteOptions.java | 2 +- .../arangodb/model/VertexReplaceOptions.java | 2 +- .../arangodb/model/VertexUpdateOptions.java | 2 +- .../com/arangodb/model/ViewCreateOptions.java | 6 ++-- .../com/arangodb/model/ViewRenameOptions.java | 4 +-- .../com/arangodb/model/ZKDIndexOptions.java | 8 +++--- .../arangosearch/AnalyzerDeleteOptions.java | 2 +- .../ArangoSearchCreateOptions.java | 4 +-- .../ArangoSearchPropertiesOptions.java | 2 +- 128 files changed, 180 insertions(+), 209 deletions(-) delete mode 100644 src/main/java/com/arangodb/entity/Entity.java diff --git a/src/main/java/com/arangodb/entity/AqlExecutionExplainEntity.java b/src/main/java/com/arangodb/entity/AqlExecutionExplainEntity.java index b913a267c..c95613764 100644 --- a/src/main/java/com/arangodb/entity/AqlExecutionExplainEntity.java +++ b/src/main/java/com/arangodb/entity/AqlExecutionExplainEntity.java @@ -26,9 +26,9 @@ * @author Mark Vollmary * @see API 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/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 050104ffe..9e9388bc3 100644 --- a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java @@ -27,7 +27,7 @@ * @see API * Documentation */ -public class CollectionPropertiesEntity extends CollectionEntity { +public final class CollectionPropertiesEntity extends CollectionEntity { private KeyOptions keyOptions; private Long count; 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/CursorEntity.java b/src/main/java/com/arangodb/entity/CursorEntity.java index e4aa9f32e..e205a2d79 100644 --- a/src/main/java/com/arangodb/entity/CursorEntity.java +++ b/src/main/java/com/arangodb/entity/CursorEntity.java @@ -31,7 +31,7 @@ * @see API * Documentation */ -public class CursorEntity implements Entity, MetaAware { +public final class CursorEntity implements MetaAware { private String id; private Integer count; @@ -105,7 +105,7 @@ public void setMeta(Map meta) { this.meta = cleanupMeta(meta); } - public static class Warning { + public static final class Warning { private Integer code; private String message; @@ -120,7 +120,7 @@ public String getMessage() { } - public static class Extras { + public static final class Extras { private Stats stats; private Collection warnings = Collections.emptyList(); @@ -134,7 +134,7 @@ public Collection getWarnings() { } - public static class Stats { + public static final class Stats { private Long writesExecuted; private Long writesIgnored; private Long scannedFull; diff --git a/src/main/java/com/arangodb/entity/DatabaseEntity.java b/src/main/java/com/arangodb/entity/DatabaseEntity.java index 524db2c63..3b996d033 100644 --- a/src/main/java/com/arangodb/entity/DatabaseEntity.java +++ b/src/main/java/com/arangodb/entity/DatabaseEntity.java @@ -24,7 +24,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class DatabaseEntity implements Entity { +public final class DatabaseEntity { private String id; private String name; diff --git a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java index 6badc51cd..64c8a53af 100644 --- a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class DocumentCreateEntity extends DocumentEntity { +public final class DocumentCreateEntity extends DocumentEntity { private T newDocument; private T oldDocument; diff --git a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java index 2f5a6f098..612494d66 100644 --- a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java @@ -25,7 +25,7 @@ * @see API * Documentation */ -public class DocumentDeleteEntity extends DocumentEntity { +public final class DocumentDeleteEntity extends DocumentEntity { private T 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 8393a7988..3567bd10e 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -28,7 +28,7 @@ * @see API * Documentation */ -public class DocumentUpdateEntity extends DocumentEntity { +public final class DocumentUpdateEntity extends DocumentEntity { @JsonProperty("_oldRev") private String oldRev; diff --git a/src/main/java/com/arangodb/entity/EdgeDefinition.java b/src/main/java/com/arangodb/entity/EdgeDefinition.java index 8fc808428..cd39c9a3b 100644 --- a/src/main/java/com/arangodb/entity/EdgeDefinition.java +++ b/src/main/java/com/arangodb/entity/EdgeDefinition.java @@ -28,7 +28,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class EdgeDefinition { +public final class EdgeDefinition { private String collection; private Collection from; @@ -82,7 +82,7 @@ public EdgeDefinition satellites(final String... satellites) { return this; } - public static class Options { + public static final class Options { private Collection satellites = Collections.emptyList(); public Collection getSatellites() { 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 ad0a5777f..67b72e76b 100644 --- a/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/EdgeUpdateEntity.java @@ -26,7 +26,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class EdgeUpdateEntity extends DocumentEntity { +public final class EdgeUpdateEntity extends DocumentEntity { @JsonProperty("_oldRev") private String oldRev; diff --git a/src/main/java/com/arangodb/entity/Entity.java b/src/main/java/com/arangodb/entity/Entity.java deleted file mode 100644 index 146e561ae..000000000 --- a/src/main/java/com/arangodb/entity/Entity.java +++ /dev/null @@ -1,28 +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; - -/** - * @author Mark Vollmary - */ -public interface Entity { - -} 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/GraphEntity.java b/src/main/java/com/arangodb/entity/GraphEntity.java index 858a60acd..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; /** 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/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/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 1801d0cea..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 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/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/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 9b84bbf4f..853aad4bb 100644 --- a/src/main/java/com/arangodb/entity/ReplicationFactor.java +++ b/src/main/java/com/arangodb/entity/ReplicationFactor.java @@ -35,7 +35,7 @@ static SatelliteReplicationFactor ofSatellite() { @JsonValue Object getValue(); - class NumericReplicationFactor implements ReplicationFactor { + final class NumericReplicationFactor implements ReplicationFactor { private Integer value; 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/TransactionEntity.java b/src/main/java/com/arangodb/entity/TransactionEntity.java index a517d7882..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; 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 b5148338f..c5e8f0ff2 100644 --- a/src/main/java/com/arangodb/entity/VertexUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/VertexUpdateEntity.java @@ -25,7 +25,7 @@ /** * @author Mark Vollmary */ -public class VertexUpdateEntity extends DocumentEntity { +public final class VertexUpdateEntity extends DocumentEntity { @JsonProperty("_oldRev") private String oldRev; 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/arangosearch/ArangoSearchPropertiesEntity.java b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java index d33850aac..4c5f3073b 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java @@ -31,7 +31,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class ArangoSearchPropertiesEntity extends ViewEntity { +public final class ArangoSearchPropertiesEntity extends ViewEntity { private Long consolidationIntervalMsec; private Long commitIntervalMsec; diff --git a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java index f6a471d14..0e8b3c2d9 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java @@ -35,7 +35,7 @@ /** * @author Mark Vollmary */ -public class CollectionLink { +public final class CollectionLink { private final String name; private final Collection analyzers; 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/FieldLink.java b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java index e41f6cca7..f4374f52e 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java @@ -10,7 +10,7 @@ import java.util.Arrays; import java.util.Collection; -public class FieldLink { +public final class FieldLink { private final String name; private final Collection analyzers; 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/StoredValue.java b/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java index d6ffb95c9..d44df7a6d 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java +++ b/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java @@ -31,7 +31,7 @@ * @see API Documentation * @since ArangoDB 3.7 */ -public class StoredValue { +public final class StoredValue { private final List fields; private final ArangoSearchCompression 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 92633f419..72258ea83 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/NormAnalyzerProperties.java @@ -28,7 +28,7 @@ /** * @author Michele Rastelli */ -public class NormAnalyzerProperties { +public final class NormAnalyzerProperties { private String locale; 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 d826b50d3..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,7 +21,6 @@ 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; @@ -52,7 +51,7 @@ @JsonSubTypes.Type(name = "segmentation", value = SegmentationAnalyzer.class), @JsonSubTypes.Type(name = "collation", value = CollationAnalyzer.class) }) -public abstract class SearchAnalyzer implements Entity { +public abstract class SearchAnalyzer { private String name; private AnalyzerType type; private Collection features; 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 7c6ea73c4..a98b39b76 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/SegmentationAnalyzerProperties.java @@ -29,7 +29,7 @@ * @author Michele Rastelli * @since ArangoDB 3.9 */ -public class SegmentationAnalyzerProperties { +public final class SegmentationAnalyzerProperties { @JsonProperty("break") private BreakMode breakMode; 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 d00809337..b6f570267 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/StopwordsAnalyzerProperties.java @@ -31,7 +31,7 @@ /** * @author Michele Rastelli */ -public class StopwordsAnalyzerProperties { +public final class StopwordsAnalyzerProperties { private static String stringToHex(String str) { final StringBuilder hex = new StringBuilder(); 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 566fe8a99..38cbebe89 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java +++ b/src/main/java/com/arangodb/entity/arangosearch/analyzer/TextAnalyzerProperties.java @@ -30,7 +30,7 @@ /** * @author Michele Rastelli */ -public class TextAnalyzerProperties { +public final class TextAnalyzerProperties { public TextAnalyzerProperties() { stopwords = Collections.emptyList(); diff --git a/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java b/src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java index d9c578804..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,7 +39,7 @@ 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; } @@ -52,7 +52,7 @@ public 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; } 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 91e59d9a8..45cb189a6 100644 --- a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java @@ -30,7 +30,7 @@ * @author Michele Rastelli * @see API Documentation */ -public class AqlQueryExplainOptions { +public final class AqlQueryExplainOptions { private byte[] bindVars; private String query; @@ -49,7 +49,7 @@ public byte[] getBindVars() { * @param bindVars key/value pairs representing the bind parameters * @return options */ - protected AqlQueryExplainOptions bindVars(final byte[] bindVars) { + AqlQueryExplainOptions bindVars(final byte[] bindVars) { this.bindVars = bindVars; return this; } @@ -62,7 +62,7 @@ public 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; } @@ -116,7 +116,7 @@ private Options getOptions() { return options; } - public static class Options { + public static final class Options { private Optimizer optimizer; private Integer maxNumberOfPlans; private Boolean allPlans; @@ -129,7 +129,7 @@ public 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 75e43d189..7d646b700 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -33,7 +33,7 @@ * @see API * Documentation */ -public class AqlQueryOptions { +public final class AqlQueryOptions { private Boolean count; private Integer ttl; @@ -156,7 +156,7 @@ public byte[] getBindVars() { * @param bindVarsBytes serialized bind parameters * @return options */ - protected AqlQueryOptions bindVars(final byte[] bindVarsBytes) { + AqlQueryOptions bindVars(final byte[] bindVarsBytes) { this.bindVars = bindVarsBytes; return this; } @@ -406,7 +406,7 @@ public Options getOptions() { return options; } - public static class Options { + public static final class Options { private Boolean failOnWarning; private Boolean profile; @@ -492,7 +492,7 @@ public Collection getShardIds() { } - public static class Optimizer { + public static final class Optimizer { private Collection rules; public Collection getRules() { diff --git a/src/main/java/com/arangodb/model/AqlQueryParseOptions.java b/src/main/java/com/arangodb/model/AqlQueryParseOptions.java index 2059415e2..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; @@ -40,7 +40,7 @@ public 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 b3433a3d4..4acf37754 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -30,7 +30,7 @@ * @see API * Documentation */ -public class CollectionCreateOptions { +public final class CollectionCreateOptions { private String name; private ReplicationFactor replicationFactor; @@ -60,7 +60,7 @@ public 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; } 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 395538c12..231d19616 100644 --- a/src/main/java/com/arangodb/model/CollectionSchema.java +++ b/src/main/java/com/arangodb/model/CollectionSchema.java @@ -33,7 +33,7 @@ * @see API Documentation * @since ArangoDB 3.7 */ -public class CollectionSchema { +public final class CollectionSchema { /** * Value to unset the collection schema on properties update {@link com.arangodb.ArangoCollection#changeProperties(CollectionPropertiesOptions)}. 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 df5cca03b..68cfd83d0 100644 --- a/src/main/java/com/arangodb/model/DatabaseOptions.java +++ b/src/main/java/com/arangodb/model/DatabaseOptions.java @@ -26,7 +26,7 @@ * @author Michele Rastelli * @since ArangoDB 3.6.0 */ -public class DatabaseOptions { +public final class DatabaseOptions { private ReplicationFactor replicationFactor; private Integer writeConcern; 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 2ad9d4dfa..1041b786c 100644 --- a/src/main/java/com/arangodb/model/DocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/DocumentReadOptions.java @@ -26,7 +26,7 @@ * @see API * Documentation */ -public class DocumentReadOptions { +public final class DocumentReadOptions { private String ifNoneMatch; private String ifMatch; 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 4ca261670..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; 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 607e1b908..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,7 +38,7 @@ public FulltextIndexOptions() { } @Override - protected FulltextIndexOptions getThis() { + FulltextIndexOptions getThis() { return this; } @@ -50,7 +50,7 @@ public 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; } diff --git a/src/main/java/com/arangodb/model/GeoIndexOptions.java b/src/main/java/com/arangodb/model/GeoIndexOptions.java index c55ba0c70..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,7 +37,7 @@ public GeoIndexOptions() { } @Override - protected GeoIndexOptions getThis() { + GeoIndexOptions getThis() { return this; } @@ -49,7 +49,7 @@ public 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; } diff --git a/src/main/java/com/arangodb/model/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index f6453a4e1..7261065b7 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -31,7 +31,7 @@ * @author Mark Vollmary * @see API Documentation */ -public class GraphCreateOptions { +public final class GraphCreateOptions { private String name; private Collection edgeDefinitions = Collections.emptyList(); @@ -51,7 +51,7 @@ public 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; } @@ -64,7 +64,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; } @@ -206,7 +206,7 @@ public SmartOptions getOptions() { return options; } - public static class SmartOptions { + public static final class SmartOptions { private ReplicationFactor replicationFactor; private Integer writeConcern; private Integer numberOfShards; diff --git a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java index 8a7fffa0a..7277b10df 100644 --- a/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java +++ b/src/main/java/com/arangodb/model/GraphDocumentReadOptions.java @@ -23,7 +23,7 @@ /** * @author Mark Vollmary */ -public class GraphDocumentReadOptions { +public final class GraphDocumentReadOptions { private String ifNoneMatch; private String ifMatch; diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 6268a3718..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,7 +43,7 @@ public HashIndexOptions() { } @Override - protected HashIndexOptions getThis() { + HashIndexOptions getThis() { return this; } @@ -55,7 +55,7 @@ public 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; } diff --git a/src/main/java/com/arangodb/model/IndexOptions.java b/src/main/java/com/arangodb/model/IndexOptions.java index 7cafad173..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 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 111bfcb1d..6bf13ae4e 100644 --- a/src/main/java/com/arangodb/model/OptionsBuilder.java +++ b/src/main/java/com/arangodb/model/OptionsBuilder.java @@ -30,7 +30,7 @@ * @author Mark Vollmary * @author Michele Rastelli */ -public class OptionsBuilder { +public final class OptionsBuilder { private OptionsBuilder() { super(); diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index d7a752cd2..598054551 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -27,7 +27,7 @@ * @see API * Documentation */ -public class PersistentIndexOptions extends IndexOptions { +public final class PersistentIndexOptions extends IndexOptions { private Iterable fields; private final IndexType type = IndexType.persistent; @@ -41,7 +41,7 @@ public PersistentIndexOptions() { } @Override - protected PersistentIndexOptions getThis() { + PersistentIndexOptions getThis() { return this; } @@ -53,7 +53,7 @@ public 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; } 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 981d7fa62..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,7 +43,7 @@ public SkiplistIndexOptions() { } @Override - protected SkiplistIndexOptions getThis() { + SkiplistIndexOptions getThis() { return this; } @@ -55,7 +55,7 @@ public 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; } diff --git a/src/main/java/com/arangodb/model/StreamTransactionOptions.java b/src/main/java/com/arangodb/model/StreamTransactionOptions.java index 52cae19d2..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; diff --git a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java index e16060a33..ade09ba96 100644 --- a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java @@ -28,7 +28,7 @@ * @author Mark Vollmary * @author Michele Rastelli */ -public class TransactionCollectionOptions { +public final class TransactionCollectionOptions { private Collection read = Collections.emptyList(); private Collection write = Collections.emptyList(); diff --git a/src/main/java/com/arangodb/model/TransactionOptions.java b/src/main/java/com/arangodb/model/TransactionOptions.java index ebe31c7d9..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; @@ -52,7 +52,7 @@ public 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 a12e45ceb..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,7 +37,7 @@ public TtlIndexOptions() { } @Override - protected TtlIndexOptions getThis() { + TtlIndexOptions getThis() { return this; } @@ -49,7 +49,7 @@ public 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; } diff --git a/src/main/java/com/arangodb/model/UserAccessOptions.java b/src/main/java/com/arangodb/model/UserAccessOptions.java index 12355c642..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; @@ -37,7 +37,7 @@ 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 f4808da27..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; @@ -45,7 +45,7 @@ public 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; } @@ -58,7 +58,7 @@ public 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 e7132fc64..86fa34067 100644 --- a/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/VertexCollectionCreateOptions.java @@ -26,7 +26,7 @@ /** * @author Mark Vollmary */ -public class VertexCollectionCreateOptions { +public final class VertexCollectionCreateOptions { private String collection; private final Options options = new Options(); @@ -43,7 +43,7 @@ public 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; } @@ -68,7 +68,7 @@ public VertexCollectionCreateOptions satellites(final String... satellites) { return this; } - public static class Options { + public static final class Options { private Collection satellites; public Collection getSatellites() { 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 0fa34d0aa..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,12 +36,12 @@ 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; } 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 6f17e5b87..aad739d86 100644 --- a/src/main/java/com/arangodb/model/ZKDIndexOptions.java +++ b/src/main/java/com/arangodb/model/ZKDIndexOptions.java @@ -28,10 +28,10 @@ * @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; @@ -40,7 +40,7 @@ public ZKDIndexOptions() { } @Override - protected ZKDIndexOptions getThis() { + ZKDIndexOptions getThis() { return this; } @@ -52,7 +52,7 @@ public 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; } 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 66653bd5d..5d810507a 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java @@ -31,7 +31,7 @@ /** * @author Mark Vollmary */ -public class ArangoSearchCreateOptions { +public final class ArangoSearchCreateOptions { @SuppressWarnings("unused") private String name; @@ -51,7 +51,7 @@ public ArangoSearchCreateOptions() { type = ViewType.ARANGO_SEARCH; } - protected ArangoSearchCreateOptions name(final String name) { + ArangoSearchCreateOptions name(final String name) { this.name = name; return this; } diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java index e4d142b1c..7be061b87 100644 --- a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java @@ -32,7 +32,7 @@ /** * @author Mark Vollmary */ -public class ArangoSearchPropertiesOptions { +public final class ArangoSearchPropertiesOptions { private Long consolidationIntervalMsec; private Long cleanupIntervalStep; From 567988fb8c892288d0c88099106514f7683bea0f Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 21 Jul 2022 10:16:43 +0200 Subject: [PATCH 34/52] removed VPackSlice from javadoc --- .../java/com/arangodb/ArangoCollection.java | 40 +++++++++---------- .../java/com/arangodb/ArangoDatabase.java | 16 ++++---- .../com/arangodb/ArangoEdgeCollection.java | 16 ++++---- src/main/java/com/arangodb/ArangoRoute.java | 2 +- .../com/arangodb/ArangoVertexCollection.java | 16 ++++---- .../arangodb/async/ArangoCollectionAsync.java | 40 +++++++++---------- .../arangodb/async/ArangoDatabaseAsync.java | 16 ++++---- .../async/ArangoEdgeCollectionAsync.java | 8 ++-- .../com/arangodb/async/ArangoRouteAsync.java | 2 +- .../async/ArangoVertexCollectionAsync.java | 8 ++-- .../java/com/arangodb/serde/ArangoSerde.java | 4 +- .../arangodb/serde/InternalDeserializers.java | 2 - .../com/arangodb/serde/InternalSerde.java | 1 - .../com/arangodb/serde/InternalSerdeImpl.java | 2 - 14 files changed, 83 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index 3af131403..ebd00fad5 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -55,7 +55,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO or String for JSON) * @return information about the document * @throws ArangoDBException * @see API @@ -67,7 +67,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO, VPackSlice or String for JSON) + * @param value A representation of a single document (POJO or String for JSON) * @param options Additional options, can be null * @return information about the document * @throws ArangoDBException @@ -83,7 +83,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 or String for JSON) * @return information about the documents * @throws ArangoDBException * @see API @@ -98,7 +98,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * 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 or String for JSON) * @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 class or String for JSON) * @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 class or String for JSON) * @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 class or String for JSON) * @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 class or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 or String for JSON) * @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 class or String for JSON). 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 class or String for JSON). 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/ArangoDatabase.java b/src/main/java/com/arangodb/ArangoDatabase.java index 826d301fd..6aaf3ff26 100644 --- a/src/main/java/com/arangodb/ArangoDatabase.java +++ b/src/main/java/com/arangodb/ArangoDatabase.java @@ -260,7 +260,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * @param query An AQL query string * @param bindVars key/value pairs defining the variables to bind the query to * @param options Additional options that will be passed to the query API, can be null - * @param type The type of the result (POJO class, VPackSlice, String for JSON, or Collection/List/Map) + * @param type The type of the result (POJO class, String for JSON, or Collection/List/Map) * @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 class, String for JSON, or Collection/List/Map) * @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 class, String for JSON, or Collection/List/Map) * @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 class, String for JSON, or Collection/List/Map) * @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 class, String for JSON, or Collection/List/Map) * @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 class or String for JSON) * @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 class or String for JSON) * @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 class or String for JSON) * @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 702728e99..569d5d561 100644 --- a/src/main/java/com/arangodb/ArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/ArangoEdgeCollection.java @@ -50,7 +50,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { /** * 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 or String for JSON) * @return information about the edge * @throws ArangoDBException * @see API Documentation @@ -60,7 +60,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { /** * 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 or String for JSON) * @param options Additional options, can be null * @return information about the edge * @throws ArangoDBException @@ -72,7 +72,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param type The type of the edge-document (POJO class or String for JSON) * @return the edge identified by the key * @throws ArangoDBException * @see API Documentation @@ -83,7 +83,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param type The type of the edge-document (POJO class or String for JSON) * @param options Additional options, can be null * @return the edge identified by the key * @throws ArangoDBException @@ -96,7 +96,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * 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 class or String for JSON) * @return information about the edge * @throws ArangoDBException * @see API Documentation @@ -108,7 +108,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * 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 class or String for JSON) * @param options Additional options, can be null * @return information about the edge * @throws ArangoDBException @@ -122,7 +122,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the edge - * @param The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param The type of the edge-document (POJO class or String for JSON) * @return information about the edge * @throws ArangoDBException * @see API Documentation @@ -135,7 +135,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the edge - * @param The type of the edge-document (POJO class, VPackSlice or String for JSON) + * @param The type of the edge-document (POJO class or String for JSON) * @param options Additional options, can be null * @return information about the edge * @throws ArangoDBException diff --git a/src/main/java/com/arangodb/ArangoRoute.java b/src/main/java/com/arangodb/ArangoRoute.java index a32e09f70..b9a393add 100644 --- a/src/main/java/com/arangodb/ArangoRoute.java +++ b/src/main/java/com/arangodb/ArangoRoute.java @@ -57,7 +57,7 @@ public interface ArangoRoute extends ArangoSerdeAccessor { 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/ArangoVertexCollection.java b/src/main/java/com/arangodb/ArangoVertexCollection.java index ffc1a39f0..a8f5b5727 100644 --- a/src/main/java/com/arangodb/ArangoVertexCollection.java +++ b/src/main/java/com/arangodb/ArangoVertexCollection.java @@ -59,7 +59,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { /** * 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 or String for JSON) * @return information about the vertex * @throws ArangoDBException * @see API Documentation @@ -69,7 +69,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { /** * 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 or String for JSON) * @param options Additional options, can be null * @return information about the vertex * @throws ArangoDBException @@ -81,7 +81,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * Retrieves the vertex document with the given {@code key} from the collection. * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class, VPackSlice or String for JSON) + * @param type The type of the vertex-document (POJO class or String for JSON) * @return the vertex identified by the key * @throws ArangoDBException * @see API Documentation @@ -92,7 +92,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * Retrieves the vertex document with the given {@code key} from the collection. * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class, VPackSlice or String for JSON) + * @param type The type of the vertex-document (POJO class or String for JSON) * @param options Additional options, can be null * @return the vertex identified by the key * @throws ArangoDBException @@ -105,7 +105,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * 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 or String for JSON) * @return information about the vertex * @throws ArangoDBException * @see API @@ -118,7 +118,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * 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 or String for JSON) * @param options Additional options, can be null * @return information about the vertex * @throws ArangoDBException @@ -133,7 +133,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the vertex - * @param The type of the vertex-document (POJO class, VPackSlice or String for JSON) + * @param The type of the vertex-document (POJO class or String for JSON) * @return information about the vertex * @throws ArangoDBException * @see API Documentation @@ -146,7 +146,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { * do not yet exist, and overwritten in the existing document if they do exist there. * * @param key The key of the vertex - * @param The type of the vertex-document (POJO class, VPackSlice or String for JSON) + * @param The type of the vertex-document (POJO class or String for JSON) * @param options Additional options, can be null * @return information about the vertex * @throws ArangoDBException diff --git a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index 8d2194f43..d2da44236 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -56,7 +56,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO, VPackSlice or String for Json) + * @param value A representation of a single document (POJO or String for Json) * @return information about the document * @see API * Documentation @@ -67,7 +67,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO, VPackSlice or String for Json) + * @param value A representation of a single document (POJO or String for Json) * @param options Additional options, can be null * @return information about the document * @see API @@ -79,7 +79,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param values A List of documents (POJO, VPackSlice or String for Json) + * @param values A List of documents (POJO or String for Json) * @return information about the documents * @see API * Documentation @@ -90,7 +90,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param values A List of documents (POJO, VPackSlice or String for Json) + * @param values A List of documents (POJO or String for Json) * @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 class or String for Json) * @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 class or String for Json) * @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 class or String for Json) * @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 class or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 or String for Json) * @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 class or String for Json). 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 class or String for Json). 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/ArangoDatabaseAsync.java b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java index 0a7648967..4531c7cba 100644 --- a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java @@ -249,7 +249,7 @@ public interface ArangoDatabaseAsync extends ArangoSerdeAccessor { * @param query contains the query string to be executed * @param bindVars key/value pairs representing the bind parameters * @param options Additional options, can be null - * @param type The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) + * @param type The type of the result (POJO class, String for Json, or Collection/List/Map) * @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 class, String for Json, or Collection/List/Map) * @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 class, String for Json, or Collection/List/Map) * @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 class, String for Json, or Collection/List/Map) * @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 class, String for Json, or Collection/List/Map) * @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 class or String for Json) * @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 class or String for Json) * @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 class or String for Json) * @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 f87d1f4c7..cff6747f0 100644 --- a/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java @@ -53,7 +53,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { /** * 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 or String for Json) * @return information about the edge * @see API Documentation */ @@ -62,7 +62,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { /** * 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 or String for Json) * @param options Additional options, can be null * @return information about the edge * @see API Documentation @@ -73,7 +73,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for Json) + * @param type The type of the edge-document (POJO class or String for Json) * @return the edge identified by the key * @see API Documentation */ @@ -83,7 +83,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class, VPackSlice or String for Json) + * @param type The type of the edge-document (POJO class or String for Json) * @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/ArangoRouteAsync.java b/src/main/java/com/arangodb/async/ArangoRouteAsync.java index 2605cbf53..e79d9ca13 100644 --- a/src/main/java/com/arangodb/async/ArangoRouteAsync.java +++ b/src/main/java/com/arangodb/async/ArangoRouteAsync.java @@ -61,7 +61,7 @@ public interface ArangoRouteAsync extends ArangoSerdeAccessor { 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 ed3f98629..e9ad701de 100644 --- a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java @@ -63,7 +63,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { /** * 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 or String for Json) * @return information about the vertex * @see API Documentation */ @@ -72,7 +72,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { /** * 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 or String for Json) * @param options Additional options, can be null * @return information about the vertex * @see API Documentation @@ -83,7 +83,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class, VPackSlice or String for Json) + * @param type The type of the vertex-document (POJO class or String for Json) * @return the vertex identified by the key * @see API Documentation */ @@ -93,7 +93,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class, VPackSlice or String for Json) + * @param type The type of the vertex-document (POJO class or String for Json) * @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/serde/ArangoSerde.java b/src/main/java/com/arangodb/serde/ArangoSerde.java index ce56485d2..211d55422 100644 --- a/src/main/java/com/arangodb/serde/ArangoSerde.java +++ b/src/main/java/com/arangodb/serde/ArangoSerde.java @@ -1,7 +1,5 @@ package com.arangodb.serde; -import com.fasterxml.jackson.databind.ObjectMapper; - import java.lang.reflect.Type; /** @@ -17,7 +15,7 @@ * custom implementations based on Jackson Databind is by extending {@link JacksonSerde}, which exposes additional * methods based on Jackson's types. * Furthermore, existing {@link JacksonSerde} implementations can be instantiated providing a custom configured Jackson - * ObjectMapper, see {@link JacksonSerde#of(DataType, ObjectMapper)}. + * ObjectMapper, see {@link JacksonSerde#of(DataType, com.fasterxml.jackson.databind.ObjectMapper)}. */ public interface ArangoSerde { diff --git a/src/main/java/com/arangodb/serde/InternalDeserializers.java b/src/main/java/com/arangodb/serde/InternalDeserializers.java index b1666bb7f..e364988ca 100644 --- a/src/main/java/com/arangodb/serde/InternalDeserializers.java +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -6,8 +6,6 @@ import com.arangodb.entity.arangosearch.CollectionLink; import com.arangodb.entity.arangosearch.FieldLink; import com.arangodb.velocystream.Response; -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.databind.*; diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 70f531c86..ace96b5fe 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -1,6 +1,5 @@ package com.arangodb.serde; -import com.arangodb.internal.ArangoResponseField; import com.arangodb.jackson.dataformat.velocypack.VPackMapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 500805004..53de21719 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -2,12 +2,10 @@ import com.arangodb.ArangoDBException; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; -import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { From 02f3de4c7dbd51d6c0a6bf145dc575beb92355b9 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 21 Jul 2022 15:32:17 +0200 Subject: [PATCH 35/52] simplified serde API --- .../java/com/arangodb/serde/ArangoSerde.java | 20 +++---- .../com/arangodb/serde/InternalSerde.java | 55 ++++++++++++++++--- .../com/arangodb/serde/InternalSerdeImpl.java | 36 ++++++------ .../java/com/arangodb/serde/JacksonSerde.java | 33 ++--------- .../com/arangodb/serde/JacksonSerdeImpl.java | 19 +------ 5 files changed, 76 insertions(+), 87 deletions(-) diff --git a/src/main/java/com/arangodb/serde/ArangoSerde.java b/src/main/java/com/arangodb/serde/ArangoSerde.java index 211d55422..f682ec35a 100644 --- a/src/main/java/com/arangodb/serde/ArangoSerde.java +++ b/src/main/java/com/arangodb/serde/ArangoSerde.java @@ -1,29 +1,23 @@ 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 other than Jackson Databind, like: + * 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 databinding code generation) - * - lower level libraries without support to data binding + * - high performance serialization libraries (e.g. supporting compile-time data binding code generation) + * - low-level libraries without support to data binding *

- * This interface should not be directly implemented as an adapter to Jackson Databind. A more performant way to provide - * custom implementations based on Jackson Databind is by extending {@link JacksonSerde}, which exposes additional - * methods based on Jackson's types. - * Furthermore, existing {@link JacksonSerde} implementations can be instantiated providing a custom configured Jackson - * ObjectMapper, see {@link JacksonSerde#of(DataType, com.fasterxml.jackson.databind.ObjectMapper)}. + * To create a custom serde based on Jackson, existing {@link JacksonSerde} can be reused and instantiated providing a + * custom configured ObjectMapper ({@link JacksonSerde#of(com.fasterxml.jackson.databind.ObjectMapper)}) or configured + * after creation through {@link JacksonSerde#configure(Consumer)}. */ public interface ArangoSerde { - /** - * @return the data type supported by this implementation - */ - DataType getDataType(); - /** * 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. diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index ace96b5fe..d7f161b29 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -16,9 +16,9 @@ public interface InternalSerde extends JacksonSerde { */ static InternalSerde of(final DataType dataType) { if (dataType == DataType.JSON) { - return new InternalSerdeImpl(dataType, new ObjectMapper()); + return new InternalSerdeImpl(new ObjectMapper()); } else if (dataType == DataType.VPACK) { - return new InternalSerdeImpl(dataType, new VPackMapper()); + return new InternalSerdeImpl(new VPackMapper()); } else { throw new IllegalArgumentException("Unexpected value: " + dataType); } @@ -37,30 +37,69 @@ static InternalSerde of(final DataType dataType) { * Used for extracting nested user data. * * @param content byte array - * @param jsonPointer location of user data + * @param jsonPointer location of data to be extracted * @return byte array */ byte[] extract(byte[] content, String jsonPointer); /** - * TODO + * 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); /** - * TODO + * 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); /** - * TODO + * 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){ + default T deserialize(byte[] content, String jsonPointer, Class clazz) { return deserialize(content, jsonPointer, (Type) clazz); } /** - * TODO + * 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); diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 53de21719..996c9a373 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -6,33 +6,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; -import java.nio.charset.StandardCharsets; +import java.lang.reflect.Type; -class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { +final class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { - InternalSerdeImpl(DataType dataType, ObjectMapper mapper) { - super(dataType, mapper); + InternalSerdeImpl(ObjectMapper mapper) { + super(mapper); mapper.registerModule(InternalModule.INSTANCE.get()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Override - // FIXME: refactor to: - // return SerdeUtils.INSTANCE.writeJson(mapper.readTree(content)); - // afterwards dataType should not be needed anymore public String toJsonString(final byte[] content) { - switch (dataType) { - case JSON: - return new String(content, StandardCharsets.UTF_8); - case VPACK: - try { - JsonNode tree = mapper.readTree(content); - return SerdeUtils.INSTANCE.writeJson(tree); - } catch (IOException e) { - throw new ArangoDBException(e); - } - default: - throw new IllegalArgumentException("Unexpected value: " + dataType); + try { + return SerdeUtils.INSTANCE.writeJson(mapper.readTree(content)); + } catch (IOException e) { + throw new ArangoDBException(e); } } @@ -64,4 +53,13 @@ public JsonNode parse(byte[] content, String jsonPointer) { } } + @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); + } + } + } diff --git a/src/main/java/com/arangodb/serde/JacksonSerde.java b/src/main/java/com/arangodb/serde/JacksonSerde.java index 901266c70..c7c0ae2f0 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerde.java +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -1,16 +1,12 @@ package com.arangodb.serde; import com.arangodb.jackson.dataformat.velocypack.VPackMapper; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import java.lang.reflect.Type; import java.util.function.Consumer; /** * Contract for serialization/deserialization of user data, based on Jackson Databind. - * In comparison to {@link ArangoSerde}, this API improves the deserialization performance by allowing reusing the JSON - * tree already parsed by the root deserializer. */ public interface JacksonSerde extends ArangoSerde { @@ -22,9 +18,9 @@ public interface JacksonSerde extends ArangoSerde { */ static JacksonSerde of(final DataType dataType) { if (dataType == DataType.JSON) { - return of(dataType, new ObjectMapper()); + return of(new ObjectMapper()); } else if (dataType == DataType.VPACK) { - return of(dataType, new VPackMapper()); + return of(new VPackMapper()); } else { throw new IllegalArgumentException("Unexpected value: " + dataType); } @@ -33,12 +29,11 @@ static JacksonSerde of(final DataType dataType) { /** * Creates a new JacksonSerde using the provided ObjectMapper. * - * @param dataType serialization target data type * @param mapper Jackson ObjectMapper to use * @return the created JacksonSerde */ - static JacksonSerde of(final DataType dataType, final ObjectMapper mapper) { - return new JacksonSerdeImpl(dataType, mapper); + static JacksonSerde of(final ObjectMapper mapper) { + return new JacksonSerdeImpl(mapper); } /** @@ -47,24 +42,4 @@ static JacksonSerde of(final DataType dataType, final ObjectMapper mapper) { */ void configure(final Consumer configureFunction); - /** - * 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); - } diff --git a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java index ece832a30..11f56ab1f 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/JacksonSerdeImpl.java @@ -3,7 +3,6 @@ import com.arangodb.ArangoDBException; 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 java.io.IOException; @@ -12,20 +11,13 @@ class JacksonSerdeImpl implements JacksonSerde { - protected final DataType dataType; protected final ObjectMapper mapper; - JacksonSerdeImpl(final DataType dataType, final ObjectMapper mapper) { - this.dataType = dataType; + JacksonSerdeImpl(final ObjectMapper mapper) { this.mapper = mapper; mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } - @Override - public DataType getDataType() { - return dataType; - } - @Override public byte[] serialize(final Object value) { try { @@ -49,13 +41,4 @@ public void configure(Consumer configureFunction) { configureFunction.accept(mapper); } - @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); - } - } - } From a61f84ecbd54399803acdc788b9b12a99de11af3 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 22 Jul 2022 10:17:00 +0200 Subject: [PATCH 36/52] removed CursorEntity from public API --- src/main/java/com/arangodb/ArangoCursor.java | 8 +- .../async/internal/ArangoCursorAsyncImpl.java | 4 +- .../internal/ArangoDatabaseAsyncImpl.java | 13 ++-- .../java/com/arangodb/entity/CursorStats.java | 44 +++++++++++ .../com/arangodb/entity/CursorWarning.java | 16 ++++ .../internal/ArangoCursorExecute.java | 4 +- .../arangodb/internal/ArangoDatabaseImpl.java | 14 ++-- .../internal/cursor/ArangoCursorImpl.java | 15 ++-- .../internal/cursor/ArangoCursorIterator.java | 7 +- .../cursor/InternalCursorEntity.java} | 75 +++---------------- .../util/ArangoCursorInitializer.java | 4 +- .../java/com/arangodb/ArangoDatabaseTest.java | 3 +- 12 files changed, 106 insertions(+), 101 deletions(-) create mode 100644 src/main/java/com/arangodb/entity/CursorStats.java create mode 100644 src/main/java/com/arangodb/entity/CursorWarning.java rename src/main/java/com/arangodb/{entity/CursorEntity.java => internal/cursor/InternalCursorEntity.java} (66%) 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/async/internal/ArangoCursorAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java index 14988eca3..f2ac9c93b 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.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/ArangoDatabaseAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java index 629783023..22f300325 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java @@ -28,6 +28,7 @@ import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.ArangoErrors; import com.arangodb.internal.InternalArangoDatabase; +import com.arangodb.internal.cursor.InternalCursorEntity; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; @@ -178,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)); } @@ -206,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) { 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/internal/ArangoCursorExecute.java b/src/main/java/com/arangodb/internal/ArangoCursorExecute.java index 455844113..b9462b076 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.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/ArangoDatabaseImpl.java b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java index 2a834d948..3c1ad65e2 100644 --- a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java @@ -24,6 +24,7 @@ import com.arangodb.entity.*; import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; import com.arangodb.internal.cursor.ArangoCursorImpl; +import com.arangodb.internal.cursor.InternalCursorEntity; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; @@ -35,7 +36,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -168,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); @@ -194,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 diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java index 1de76a083..40ece0f7d 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java @@ -22,10 +22,9 @@ 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.InternalCursorEntity.Extras; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; @@ -44,7 +43,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 +55,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 +75,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 ad9afbac0..a89191cb8 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -22,7 +22,6 @@ 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.fasterxml.jackson.databind.JsonNode; @@ -36,7 +35,7 @@ */ public class ArangoCursorIterator implements ArangoIterator { - private CursorEntity result; + private InternalCursorEntity result; private Iterator arrayIterator; private final ArangoCursor cursor; @@ -44,7 +43,7 @@ public class ArangoCursorIterator implements ArangoIterator { 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; @@ -53,7 +52,7 @@ protected ArangoCursorIterator(final ArangoCursor cursor, final ArangoCursorE arrayIterator = result.getResult().iterator(); } - public CursorEntity getResult() { + public InternalCursorEntity getResult() { return result; } diff --git a/src/main/java/com/arangodb/entity/CursorEntity.java b/src/main/java/com/arangodb/internal/cursor/InternalCursorEntity.java similarity index 66% rename from src/main/java/com/arangodb/entity/CursorEntity.java rename to src/main/java/com/arangodb/internal/cursor/InternalCursorEntity.java index e205a2d79..a85999902 100644 --- a/src/main/java/com/arangodb/entity/CursorEntity.java +++ b/src/main/java/com/arangodb/internal/cursor/InternalCursorEntity.java @@ -18,8 +18,11 @@ * Copyright holder is ArangoDB GmbH, Cologne, Germany */ -package com.arangodb.entity; +package com.arangodb.internal.cursor; +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; @@ -31,7 +34,7 @@ * @see API * Documentation */ -public final class CursorEntity implements MetaAware { +public final class InternalCursorEntity implements MetaAware { private String id; private Integer count; @@ -81,7 +84,7 @@ 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 JsonNode getResult() { return result; @@ -105,75 +108,19 @@ public void setMeta(Map meta) { this.meta = cleanupMeta(meta); } - public static final class Warning { - - private Integer code; - private String message; - - public Integer getCode() { - return code; - } - - public String getMessage() { - return message; - } - - } - public static final class Extras { - private Stats stats; - private Collection warnings = Collections.emptyList(); + private CursorStats stats; + private Collection warnings = Collections.emptyList(); - public Stats getStats() { + public CursorStats getStats() { return stats; } - public Collection getWarnings() { + public Collection getWarnings() { return warnings; } } - public static final 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/util/ArangoCursorInitializer.java b/src/main/java/com/arangodb/util/ArangoCursorInitializer.java index bc2da8378..9d0b2169c 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.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/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index a5996fc39..da017d860 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -22,7 +22,6 @@ 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; @@ -751,7 +750,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(); } From d71a14ec3fd1459246e11f3aac6ce20de9c12af6 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 22 Jul 2022 12:17:56 +0200 Subject: [PATCH 37/52] RawJson and RawBytes --- .../arangodb/serde/InternalDeserializers.java | 24 ++++++++++ .../com/arangodb/serde/InternalModule.java | 6 +++ .../arangodb/serde/InternalSerializers.java | 20 ++++++++ src/main/java/com/arangodb/util/RawBytes.java | 47 +++++++++++++++++++ src/main/java/com/arangodb/util/RawJson.java | 41 ++++++++++++++++ .../java/com/arangodb/serde/SerdeTest.java | 38 +++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 src/main/java/com/arangodb/util/RawBytes.java create mode 100644 src/main/java/com/arangodb/util/RawJson.java create mode 100644 src/test/java/com/arangodb/serde/SerdeTest.java diff --git a/src/main/java/com/arangodb/serde/InternalDeserializers.java b/src/main/java/com/arangodb/serde/InternalDeserializers.java index e364988ca..0a33aa444 100644 --- a/src/main/java/com/arangodb/serde/InternalDeserializers.java +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -5,7 +5,10 @@ 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.*; @@ -14,6 +17,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -67,6 +71,26 @@ public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx 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 { diff --git a/src/main/java/com/arangodb/serde/InternalModule.java b/src/main/java/com/arangodb/serde/InternalModule.java index fe7418f17..407590d7a 100644 --- a/src/main/java/com/arangodb/serde/InternalModule.java +++ b/src/main/java/com/arangodb/serde/InternalModule.java @@ -5,6 +5,8 @@ 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; @@ -20,11 +22,15 @@ enum InternalModule implements Supplier { 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); diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 11aeb9a26..6d951e2d5 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -5,6 +5,8 @@ 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; @@ -61,6 +63,24 @@ public void serialize(Collection value, JsonGenerator gen, Seria 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 { 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/test/java/com/arangodb/serde/SerdeTest.java b/src/test/java/com/arangodb/serde/SerdeTest.java new file mode 100644 index 000000000..d1e315ff6 --- /dev/null +++ b/src/test/java/com/arangodb/serde/SerdeTest.java @@ -0,0 +1,38 @@ +package com.arangodb.serde; + +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; +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 static org.assertj.core.api.Assertions.assertThat; + + +class SerdeTest { + + @ParameterizedTest + @EnumSource(DataType.class) + void rawJsonSerde(DataType type) { + InternalSerde s = InternalSerde.of(type); + 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); + 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); + } + +} From cabc5a8196d8f5a2192f64e99df5ef2f13ec550e Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 22 Jul 2022 14:30:22 +0200 Subject: [PATCH 38/52] refactoring: user serde inside internal serde --- src/main/java/com/arangodb/ArangoDB.java | 11 +- .../com/arangodb/ArangoSerdeAccessor.java | 2 +- .../com/arangodb/async/ArangoDBAsync.java | 9 +- .../async/internal/ArangoDBAsyncImpl.java | 12 +- .../async/internal/ArangoExecutorAsync.java | 4 +- .../com/arangodb/internal/ArangoDBImpl.java | 10 +- .../arangodb/internal/ArangoExecuteable.java | 13 +- .../com/arangodb/internal/ArangoExecutor.java | 13 +- .../arangodb/internal/ArangoExecutorSync.java | 4 +- .../internal/InternalArangoCollection.java | 138 +++++++++--------- .../arangodb/internal/InternalArangoDB.java | 30 ++-- .../internal/InternalArangoDatabase.java | 66 ++++----- .../InternalArangoEdgeCollection.java | 16 +- .../internal/InternalArangoGraph.java | 18 +-- .../internal/InternalArangoRoute.java | 4 +- .../internal/InternalArangoSearch.java | 4 +- .../InternalArangoVertexCollection.java | 18 +-- .../arangodb/internal/InternalArangoView.java | 4 +- .../internal/cursor/ArangoCursorIterator.java | 4 +- .../internal/util/ArangoSerdeFactory.java | 48 ------ .../com/arangodb/serde/InternalSerde.java | 38 ++++- .../com/arangodb/serde/InternalSerdeImpl.java | 38 ++++- src/test/java/com/arangodb/ArangoDBTest.java | 2 +- .../java/com/arangodb/ArangoRouteTest.java | 2 +- src/test/java/com/arangodb/JwtAuthTest.java | 2 +- .../java/com/arangodb/async/ArangoDBTest.java | 4 +- .../java/com/arangodb/async/JwtAuthTest.java | 2 +- .../java/com/arangodb/serde/SerdeTest.java | 4 +- 28 files changed, 267 insertions(+), 253 deletions(-) delete mode 100644 src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index 3ac79ee8d..9b112c97e 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -28,7 +28,7 @@ import com.arangodb.internal.http.HttpCommunication; import com.arangodb.internal.http.HttpConnectionFactory; import com.arangodb.internal.net.*; -import com.arangodb.internal.util.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; @@ -347,9 +347,8 @@ public synchronized ArangoDB build() { if (hosts.isEmpty()) { hosts.add(host); } - final InternalSerde internal = InternalSerde.of(DataType.of(protocol)); - final ArangoSerde custom = customSerializer != null ? customSerializer : JacksonSerde.of(DataType.of(protocol)); - final ArangoSerdeFactory util = new ArangoSerdeFactory(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 : @@ -358,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, internal, + : new HttpConnectionFactory(timeout, user, password, useSsl, sslContext, hostnameVerifier, serde, protocol, connectionTtl, httpCookieSpec, httpRequestRetryHandler); final Collection hostList = createHostList(max, connectionFactory); @@ -371,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/ArangoSerdeAccessor.java b/src/main/java/com/arangodb/ArangoSerdeAccessor.java index 4c73ef488..c3075a1b4 100644 --- a/src/main/java/com/arangodb/ArangoSerdeAccessor.java +++ b/src/main/java/com/arangodb/ArangoSerdeAccessor.java @@ -33,7 +33,7 @@ public interface ArangoSerdeAccessor { * * @return ArangoSerde */ - InternalSerde getInternalSerde(); + InternalSerde getSerde(); /** * Returns serialization implementation for serializing and deserializing user's classes. diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 44a01a679..77a3bdabd 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -31,7 +31,7 @@ import com.arangodb.internal.net.ConnectionFactory; import com.arangodb.internal.net.HostHandler; import com.arangodb.internal.net.HostResolver; -import com.arangodb.internal.util.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; import com.arangodb.model.DBCreateOptions; @@ -508,9 +508,8 @@ public synchronized ArangoDBAsync build() { if (hosts.isEmpty()) { hosts.add(host); } - final InternalSerde internal = InternalSerde.of(DataType.VPACK); - final ArangoSerde custom = customSerializer != null ? customSerializer : JacksonSerde.of(DataType.VPACK); - final ArangoSerdeFactory util = new ArangoSerdeFactory(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; @@ -526,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/internal/ArangoDBAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java index f670e839e..e6a56e137 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java @@ -31,7 +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.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunication; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; @@ -62,7 +62,7 @@ public class ArangoDBAsyncImpl extends InternalArangoDB imp public ArangoDBAsyncImpl( final VstCommunicationAsync.Builder asyncCommBuilder, - final ArangoSerdeFactory util, + final InternalSerde util, final VstCommunicationSync.Builder syncCommBuilder, final HostResolver asyncHostResolver, final HostResolver syncHostResolver, @@ -73,10 +73,10 @@ public ArangoDBAsyncImpl( final int timeoutMs ) { - super(new ArangoExecutorAsync(asyncCommBuilder.build(util.getInternalSerde()), util, new DocumentCache(), + super(new ArangoExecutorAsync(asyncCommBuilder.build(util), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, context); - final VstCommunication cacheCom = syncCommBuilder.build(util.getInternalSerde()); + final VstCommunication cacheCom = syncCommBuilder.build(util); cp = new VstProtocol(cacheCom); this.asyncHostHandler = asyncHostHandler; @@ -84,8 +84,8 @@ public ArangoDBAsyncImpl( ArangoExecutorSync arangoExecutorSync = new ArangoExecutorSync(cp, util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs); - asyncHostResolver.init(arangoExecutorSync, util.getInternalSerde()); - syncHostResolver.init(arangoExecutorSync, util.getInternalSerde()); + asyncHostResolver.init(arangoExecutorSync, util); + syncHostResolver.init(arangoExecutorSync, util); } diff --git a/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java b/src/main/java/com/arangodb/async/internal/ArangoExecutorAsync.java index ab8ac57e0..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.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import java.io.IOException; @@ -44,7 +44,7 @@ public class ArangoExecutorAsync extends ArangoExecutor { private final VstCommunicationAsync communication; private final ExecutorService outgoingExecutor = Executors.newSingleThreadExecutor(); - public ArangoExecutorAsync(final VstCommunicationAsync communication, final ArangoSerdeFactory 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; diff --git a/src/main/java/com/arangodb/internal/ArangoDBImpl.java b/src/main/java/com/arangodb/internal/ArangoDBImpl.java index cfdeff208..cdefb0d3a 100644 --- a/src/main/java/com/arangodb/internal/ArangoDBImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDBImpl.java @@ -28,7 +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.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; import com.arangodb.model.DBCreateOptions; @@ -59,11 +59,11 @@ public class ArangoDBImpl extends InternalArangoDB implement private final HostHandler hostHandler; public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCommunication.Builder httpBuilder, - final ArangoSerdeFactory 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.getInternalSerde(), protocol), + createProtocol(vstBuilder, httpBuilder, util, protocol), util, new DocumentCache(), new QueueTimeMetricsImpl(responseQueueTimeSamples), timeoutMs), util, @@ -72,11 +72,11 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom cp = createProtocol( new VstCommunicationSync.Builder(vstBuilder).maxConnections(1), new HttpCommunication.Builder(httpBuilder), - util.getInternalSerde(), + util, protocol); this.hostHandler = hostHandler; - hostResolver.init(this.executor(), getInternalSerde()); + hostResolver.init(this.executor(), getSerde()); LOGGER.debug("ArangoDB Client is ready to use"); diff --git a/src/main/java/com/arangodb/internal/ArangoExecuteable.java b/src/main/java/com/arangodb/internal/ArangoExecuteable.java index b3b6d958e..e56d0bc51 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecuteable.java +++ b/src/main/java/com/arangodb/internal/ArangoExecuteable.java @@ -22,7 +22,6 @@ import com.arangodb.ArangoSerdeAccessor; import com.arangodb.DbName; -import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.internal.util.EncodeUtils; import com.arangodb.serde.ArangoSerde; import com.arangodb.serde.InternalSerde; @@ -39,13 +38,13 @@ public abstract class ArangoExecuteable implements Ara private static final String SLASH = "/"; protected final E executor; - protected final ArangoSerdeFactory util; + protected final InternalSerde serde; protected final ArangoContext context; - protected ArangoExecuteable(final E executor, final ArangoSerdeFactory 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; } @@ -54,13 +53,13 @@ protected E executor() { } @Override - public InternalSerde getInternalSerde() { - return util.getInternalSerde(); + public InternalSerde getSerde() { + return serde; } @Override public ArangoSerde getUserSerde() { - return util.getUserSerialization(); + 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 c3fb99c40..8a0555009 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutor.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutor.java @@ -21,7 +21,7 @@ package com.arangodb.internal; import com.arangodb.QueueTimeMetrics; -import com.arangodb.internal.util.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; @@ -33,23 +33,20 @@ public abstract class ArangoExecutor { protected T createResult(final Type type, final Response response) { - if (response.getBody() == null) { - return null; - } - return util.getInternalSerde().deserialize(response.getBody(), type); + return serde.deserialize(response.getBody(), type); } private final DocumentCache documentCache; private final QueueTimeMetricsImpl qtMetrics; - private final ArangoSerdeFactory util; + private final InternalSerde serde; private final String timeoutS; - protected ArangoExecutor(final ArangoSerdeFactory 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; } diff --git a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java index e74037140..4d9d5875d 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutorSync.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutorSync.java @@ -24,7 +24,7 @@ import com.arangodb.entity.MetaAware; import com.arangodb.internal.net.CommunicationProtocol; import com.arangodb.internal.net.HostHandle; -import com.arangodb.internal.util.ArangoSerdeFactory; +import com.arangodb.serde.InternalSerde; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; import org.slf4j.Logger; @@ -42,7 +42,7 @@ public class ArangoExecutorSync extends ArangoExecutor { private final CommunicationProtocol protocol; - public ArangoExecutorSync(final CommunicationProtocol protocol, final ArangoSerdeFactory 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; diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 2e6e397e3..5655cbafa 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -65,7 +65,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; } @@ -91,9 +91,9 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO byte[] body; if (value instanceof String) { - body = getInternalSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + body = getSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { - body = getUserSerde().serialize(value); + body = getSerde().serializeUserData(value); } request.setBody(body); @@ -103,15 +103,15 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO protected ResponseDeserializer> insertDocumentResponseDeserializer( final T value, final DocumentCreateOptions options) { return response -> { - final JsonNode body = getInternalSerde().parse(response.getBody()); - final DocumentCreateEntity doc = getInternalSerde().deserialize(body, DocumentCreateEntity.class); + final JsonNode body = getSerde().parse(response.getBody()); + final DocumentCreateEntity doc = getSerde().deserialize(body, DocumentCreateEntity.class); final JsonNode newDoc = body.get(NEW); Class clazz = (Class) value.getClass(); if (newDoc != null) { if (String.class.equals(clazz)) { doc.setNew((T) SerdeUtils.INSTANCE.writeJson(newDoc)); } else { - doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), clazz)); + doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), clazz)); } } final JsonNode oldDoc = body.get(OLD); @@ -119,7 +119,7 @@ protected ResponseDeserializer> insertDocumentRespon if (String.class.equals(clazz)) { doc.setOld((T) SerdeUtils.INSTANCE.writeJson(oldDoc)); } else { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), clazz)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), clazz)); } } if (options == null || Boolean.TRUE != options.getSilent()) { @@ -143,8 +143,8 @@ protected Request insertDocumentsRequest(final Collection values, final D request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); - byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerde().serialize(values); + byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getSerde().serializeUserData(values); request.setBody(body); return request; } @@ -163,23 +163,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerde().parse(response.getBody()); + 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 = getInternalSerde().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentCreateEntity doc = getInternalSerde().deserialize(next, DocumentCreateEntity.class); + final DocumentCreateEntity doc = getSerde().deserialize(next, DocumentCreateEntity.class); final JsonNode newDoc = next.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), type)); + doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), type)); } final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -193,12 +193,12 @@ protected ResponseDeserializer>> } protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) { - return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getInternalSerde().serialize(SerdeUtils.INSTANCE.parseJson(values))); + return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(getSerde().serialize(SerdeUtils.INSTANCE.parseJson(values))); } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { - byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerde().serialize(values); + byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getSerde().serializeUserData(values); return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(body); } @@ -227,9 +227,9 @@ protected Request getDocumentRequest(final String key, final DocumentReadOptions protected ResponseDeserializer getDocumentResponseDeserializer(final Class type) { return response -> { if (String.class.equals(type)) { - return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerde().parse(response.getBody())); + return (T) SerdeUtils.INSTANCE.writeJson(getSerde().parse(response.getBody())); } else { - return getUserSerde().deserialize(response.getBody(), type); + return getSerde().deserializeUserData(response.getBody(), type); } }; } @@ -239,7 +239,7 @@ protected Request getDocumentsRequest(final Collection keys, final Docum 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(getInternalSerde().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); @@ -254,16 +254,16 @@ protected ResponseDeserializer> getDocumentsResponseD final Collection docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerde().parse(response.getBody()); + 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 = getInternalSerde().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final T doc = getUserSerde().deserialize(getInternalSerde().serialize(next), type); + final T doc = getSerde().deserializeUserData(getSerde().serialize(next), type); docs.add(doc); documentsAndErrors.add(doc); } @@ -287,23 +287,23 @@ protected Request replaceDocumentRequest( request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - request.setBody(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer> replaceDocumentResponseDeserializer( final T value, final DocumentReplaceOptions options) { return response -> { - final JsonNode body = getInternalSerde().parse(response.getBody()); - final DocumentUpdateEntity doc = getInternalSerde().deserialize(body, DocumentUpdateEntity.class); + final JsonNode body = getSerde().parse(response.getBody()); + final DocumentUpdateEntity doc = getSerde().deserialize(body, DocumentUpdateEntity.class); final JsonNode newDoc = body.get(NEW); Class clazz = (Class) value.getClass(); if (newDoc != null) { - doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), clazz)); + doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), clazz)); } final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), clazz)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), clazz)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -324,8 +324,8 @@ protected Request replaceDocumentsRequest(final Collection values, final request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerde().serialize(values); + byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getSerde().serializeUserData(values); request.setBody(body); return request; } @@ -344,23 +344,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerde().parse(response.getBody()); + 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 = getInternalSerde().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = getInternalSerde().deserialize(next, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getSerde().deserialize(next, DocumentUpdateEntity.class); final JsonNode newDoc = next.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), type)); + doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), type)); } final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -386,22 +386,22 @@ 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(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer> updateDocumentResponseDeserializer( final T value, final DocumentUpdateOptions options, final Class returnType) { return response -> { - final JsonNode body = getInternalSerde().parse(response.getBody()); - final DocumentUpdateEntity doc = getInternalSerde().deserialize(body, DocumentUpdateEntity.class); + final JsonNode body = getSerde().parse(response.getBody()); + final DocumentUpdateEntity doc = getSerde().deserialize(body, DocumentUpdateEntity.class); final JsonNode newDoc = body.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), returnType)); + doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), returnType)); } final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), returnType)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), returnType)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -425,8 +425,8 @@ protected Request updateDocumentsRequest(final Collection values, final D request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - byte[] body = isStringCollection(values) ? getInternalSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getUserSerde().serialize(values); + byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) + : getSerde().serializeUserData(values); request.setBody(body); return request; } @@ -439,23 +439,23 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerde().parse(response.getBody()); + 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 = getInternalSerde().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = getInternalSerde().deserialize(next, DocumentUpdateEntity.class); + final DocumentUpdateEntity doc = getSerde().deserialize(next, DocumentUpdateEntity.class); final JsonNode newDoc = next.get(NEW); if (newDoc != null) { - doc.setNew(getUserSerde().deserialize(getInternalSerde().serialize(newDoc), returnType)); + doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), returnType)); } final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), returnType)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), returnType)); } docs.add(doc); documentsAndErrors.add(doc); @@ -483,11 +483,11 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp protected ResponseDeserializer> deleteDocumentResponseDeserializer( final Class type) { return response -> { - final JsonNode body = getInternalSerde().parse(response.getBody()); - final DocumentDeleteEntity doc = getInternalSerde().deserialize(body, DocumentDeleteEntity.class); + final JsonNode body = getSerde().parse(response.getBody()); + final DocumentDeleteEntity doc = getSerde().deserialize(body, DocumentDeleteEntity.class); final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); } return doc; }; @@ -500,7 +500,7 @@ 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(getInternalSerde().serialize(keys)); + request.setBody(getSerde().serialize(keys)); return request; } @@ -511,19 +511,19 @@ protected ResponseDeserializer>> final Collection> docs = new ArrayList<>(); final Collection errors = new ArrayList<>(); final Collection documentsAndErrors = new ArrayList<>(); - final JsonNode body = getInternalSerde().parse(response.getBody()); + 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 = getInternalSerde().deserialize(next, ErrorEntity.class); + final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { - final DocumentDeleteEntity doc = getInternalSerde().deserialize(next, DocumentDeleteEntity.class); + final DocumentDeleteEntity doc = getSerde().deserialize(next, DocumentDeleteEntity.class); final JsonNode oldDoc = next.get(OLD); if (oldDoc != null) { - doc.setOld(getUserSerde().deserialize(getInternalSerde().serialize(oldDoc), type)); + doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); } docs.add(doc); documentsAndErrors.add(doc); @@ -555,7 +555,7 @@ protected Request deleteIndexRequest(final String id) { } protected ResponseDeserializer deleteIndexResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/id", String.class); + return response -> getSerde().deserialize(response.getBody(), "/id", String.class); } private String createIndexId(final String id) { @@ -575,7 +575,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( - getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields))); return request; } @@ -584,7 +584,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( - getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields))); return request; } @@ -592,7 +592,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(getInternalSerde().serialize( + request.setBody(getSerde().serialize( OptionsBuilder.build(options != null ? options : new PersistentIndexOptions(), fields))); return request; } @@ -601,7 +601,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( - getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields))); return request; } @@ -609,7 +609,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( - getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields))); return request; } @@ -617,7 +617,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( - getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new TtlIndexOptions(), fields))); return request; } @@ -625,7 +625,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(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : + request.setBody(getSerde().serialize(OptionsBuilder.build(options != null ? options : new ZKDIndexOptions().fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE), fields))); return request; } @@ -637,7 +637,7 @@ protected Request getIndexesRequest() { } protected ResponseDeserializer> getIndexesResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/indexes", + return response -> getSerde().deserialize(response.getBody(), "/indexes", SerdeUtils.INSTANCE.constructListType(IndexEntity.class)); } @@ -669,19 +669,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(getInternalSerde().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(getInternalSerde().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(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } @@ -691,7 +691,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(getInternalSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + db.dbName().get(), name).setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request resetAccessRequest(final String user) { @@ -705,7 +705,7 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } private boolean isStringCollection(final Collection values) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index eb63cb9cb..862c4d90c 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -23,8 +23,8 @@ import com.arangodb.DbName; import com.arangodb.entity.*; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; -import com.arangodb.internal.util.ArangoSerdeFactory; import com.arangodb.model.*; +import com.arangodb.serde.InternalSerde; import com.arangodb.serde.SerdeUtils; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.RequestType; @@ -47,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 ArangoSerdeFactory util, final ArangoContext context) { + protected InternalArangoDB(final E executor, final InternalSerde util, final ArangoContext context) { super(executor, util, context); } @@ -60,22 +60,22 @@ protected Request getServerIdRequest() { } protected ResponseDeserializer getRoleResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/role", ServerRole.class); + return response -> getSerde().deserialize(response.getBody(), "/role", ServerRole.class); } protected ResponseDeserializer getServerIdResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/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(getInternalSerde().serialize(options)); + request.setBody(getSerde().serialize(options)); return request; } protected ResponseDeserializer createDatabaseResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); } protected Request getDatabasesRequest(final DbName dbName) { @@ -83,7 +83,7 @@ protected Request getDatabasesRequest(final DbName dbName) { } protected ResponseDeserializer> getDatabaseResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, SerdeUtils.INSTANCE.constructListType(String.class)); } @@ -93,7 +93,7 @@ protected Request getAccessibleDatabasesForRequest(final DbName dbName, final St protected ResponseDeserializer> getAccessibleDatabasesForResponseDeserializer() { return response -> { - Iterator names = getInternalSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER).fieldNames(); + Iterator names = getSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER).fieldNames(); final Collection dbs = new ArrayList<>(); while (names.hasNext()) { dbs.add(names.next()); @@ -110,7 +110,7 @@ protected Request createUserRequest( final Request request; request = request(dbName, RequestType.POST, PATH_API_USER); request.setBody( - getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); + getSerde().serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd))); return request; } @@ -127,32 +127,32 @@ protected Request getUserRequest(final DbName dbName, final String user) { } protected ResponseDeserializer> getUsersResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + 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(getInternalSerde().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(getInternalSerde().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(getInternalSerde().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(getInternalSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); + "*", "*").setBody(getSerde().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions))); } protected Request getLogEntriesRequest(final LogOptions options) { @@ -173,7 +173,7 @@ protected Request getLogLevelRequest() { protected Request setLogLevelRequest(final LogLevelEntity entity) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_ADMIN_LOG_LEVEL) - .setBody(getInternalSerde().serialize(entity)); + .setBody(getSerde().serialize(entity)); } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 8943e5d34..a94042aab 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -65,7 +65,7 @@ public abstract class InternalArangoDatabase> getCollectionsResponseDeserializer() { - return response -> getInternalSerde().deserialize(getInternalSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), + return response -> getSerde().deserialize(getSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), SerdeUtils.INSTANCE.constructListType(CollectionEntity.class)); } @@ -119,11 +119,11 @@ protected Request dropRequest() { } protected ResponseDeserializer createDropResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Boolean.class); + 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(getInternalSerde().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) { @@ -131,7 +131,7 @@ protected Request resetAccessRequest(final String user) { } protected Request updateUserDefaultCollectionAccessRequest(final String user, final Permissions permissions) { - return request(DbName.SYSTEM, RequestType.PUT, PATH_API_USER, user, ArangoRequestParam.DATABASE, dbName.get(), "*").setBody(getInternalSerde().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) { @@ -139,13 +139,13 @@ protected Request getPermissionsRequest(final String user) { } protected ResponseDeserializer getPermissionsResponseDeserialzer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } 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(getInternalSerde().serialize( - OptionsBuilder.build(opt, query, bindVars != null ? getUserSerde().serialize(bindVars) : null))); + final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR).setBody(getSerde().serialize( + OptionsBuilder.build(opt, query, bindVars != null ? getSerde().serializeUserData(bindVars) : null))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } @@ -190,12 +190,12 @@ protected Request queryCloseRequest(final String id, final AqlQueryOptions optio 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(getInternalSerde().serialize( - OptionsBuilder.build(opt, query, bindVars != null ? getUserSerde().serialize(bindVars) : null))); + .setBody(getSerde().serialize( + OptionsBuilder.build(opt, query, bindVars != null ? getSerde().serializeUserData(bindVars) : null))); } protected Request parseQueryRequest(final String query) { - return request(dbName, RequestType.POST, PATH_API_QUERY).setBody(getInternalSerde().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() { @@ -207,7 +207,7 @@ protected Request getQueryCachePropertiesRequest() { } protected Request setQueryCachePropertiesRequest(final QueryCachePropertiesEntity properties) { - return request(dbName, RequestType.PUT, PATH_API_QUERY_CACHE_PROPERTIES).setBody(getInternalSerde().serialize(properties)); + return request(dbName, RequestType.PUT, PATH_API_QUERY_CACHE_PROPERTIES).setBody(getSerde().serialize(properties)); } protected Request getQueryTrackingPropertiesRequest() { @@ -215,7 +215,7 @@ protected Request getQueryTrackingPropertiesRequest() { } protected Request setQueryTrackingPropertiesRequest(final QueryTrackingPropertiesEntity properties) { - return request(dbName, RequestType.PUT, PATH_API_QUERY_PROPERTIES).setBody(getInternalSerde().serialize(properties)); + return request(dbName, RequestType.PUT, PATH_API_QUERY_PROPERTIES).setBody(getSerde().serialize(properties)); } protected Request getCurrentlyRunningQueriesRequest() { @@ -235,7 +235,7 @@ protected Request killQueryRequest(final String id) { } protected Request createAqlFunctionRequest(final String name, final String code, final AqlFunctionCreateOptions options) { - return request(dbName, RequestType.POST, PATH_API_AQLFUNCTION).setBody(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); + 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) { @@ -246,7 +246,7 @@ protected Request deleteAqlFunctionRequest(final String name, final AqlFunctionD } protected ResponseDeserializer deleteAqlFunctionResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/deletedCount", Integer.class); + return response -> getSerde().deserialize(response.getBody(), "/deletedCount", Integer.class); } protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { @@ -257,16 +257,16 @@ protected Request getAqlFunctionsRequest(final AqlFunctionGetOptions options) { } protected ResponseDeserializer> getAqlFunctionsResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + 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(getInternalSerde().serialize(OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); + 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 -> getInternalSerde().deserialize(response.getBody(), "/graph", GraphEntity.class); + return response -> getSerde().deserialize(response.getBody(), "/graph", GraphEntity.class); } protected Request getGraphsRequest() { @@ -274,27 +274,27 @@ protected Request getGraphsRequest() { } protected ResponseDeserializer> getGraphsResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/graphs", + 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(getInternalSerde().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 -> { - byte[] userContent = getInternalSerde().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); + byte[] userContent = getSerde().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); if (String.class.equals(type)) { - return (T) SerdeUtils.INSTANCE.writeJson(getInternalSerde().parse(userContent)); + return (T) SerdeUtils.INSTANCE.writeJson(getSerde().parse(userContent)); } else { - return getUserSerde().deserialize(userContent, type); + return getSerde().deserializeUserData(userContent, type); } }; } protected Request beginStreamTransactionRequest(final StreamTransactionOptions options) { - return request(dbName, RequestType.POST, PATH_API_BEGIN_STREAM_TRANSACTION).setBody(getInternalSerde().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) { @@ -310,7 +310,7 @@ protected Request getStreamTransactionRequest(String id) { } protected ResponseDeserializer> transactionsResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), "/transactions", + return response -> getSerde().deserialize(response.getBody(), "/transactions", SerdeUtils.INSTANCE.constructListType(TransactionEntity.class)); } @@ -319,7 +319,7 @@ protected Request commitStreamTransactionRequest(String id) { } protected ResponseDeserializer streamTransactionResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, StreamTransactionEntity.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, StreamTransactionEntity.class); } protected Request getInfoRequest() { @@ -327,7 +327,7 @@ protected Request getInfoRequest() { } protected ResponseDeserializer getInfoResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, DatabaseEntity.class); + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, DatabaseEntity.class); } protected Request reloadRoutingRequest() { @@ -339,16 +339,16 @@ protected Request getViewsRequest() { } protected ResponseDeserializer> getViewsResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + 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(getInternalSerde().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(getInternalSerde().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) { @@ -360,12 +360,12 @@ protected Request getAnalyzersRequest() { } protected ResponseDeserializer> getSearchAnalyzersResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, + 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(getInternalSerde().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 ae4b357bf..01e6b5e68 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java @@ -46,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; } @@ -65,13 +65,13 @@ protected Request insertEdgeRequest(final T value, final EdgeCreateOptions o final EdgeCreateOptions params = (options != null ? options : new EdgeCreateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - request.setBody(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer insertEdgeResponseDeserializer(final T value) { return response -> { - final EdgeEntity doc = getInternalSerde().deserialize(response.getBody(), "/edge", 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()); @@ -95,7 +95,7 @@ protected Request getEdgeRequest(final String key, final GraphDocumentReadOption } protected ResponseDeserializer getEdgeResponseDeserializer(final Class type) { - return response -> getUserSerde().deserialize(getInternalSerde().extract(response.getBody(), "/edge"), type); + return response -> getSerde().deserializeUserData(getSerde().extract(response.getBody(), "/edge"), type); } protected Request replaceEdgeRequest(final String key, final T value, final EdgeReplaceOptions options) { @@ -105,13 +105,13 @@ protected Request replaceEdgeRequest(final String key, final T value, final request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer replaceEdgeResponseDeserializer(final T value) { return response -> { - final EdgeUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/edge", 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); @@ -128,13 +128,13 @@ protected Request updateEdgeRequest(final String key, final T value, final E request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer updateEdgeResponseDeserializer(final T value) { return response -> { - final EdgeUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/edge", 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); diff --git a/src/main/java/com/arangodb/internal/InternalArangoGraph.java b/src/main/java/com/arangodb/internal/InternalArangoGraph.java index 4e74bcf25..46e3ff8d1 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoGraph.java +++ b/src/main/java/com/arangodb/internal/InternalArangoGraph.java @@ -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 -> getInternalSerde().deserialize(response.getBody(), "/collections", + 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(getInternalSerde().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 -> getInternalSerde().deserialize(response.getBody(), "/collections", + 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(getInternalSerde().serialize(definition)); + request.setBody(getSerde().serialize(definition)); return request; } protected ResponseDeserializer addEdgeDefinitionResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), 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(getInternalSerde().serialize(definition)); + request.setBody(getSerde().serialize(definition)); return request; } protected ResponseDeserializer replaceEdgeDefinitionResponseDeserializer() { - return response -> getInternalSerde().deserialize(response.getBody(), 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 -> getInternalSerde().deserialize(response.getBody(), 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 f053c19ce..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(getInternalSerde().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 8e09b414f..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(getInternalSerde().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(getInternalSerde().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 f74214086..6cd10c0d7 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -47,7 +47,7 @@ public abstract class InternalArangoVertexCollection Request insertVertexRequest(final T value, final VertexCreateOptio byte[] body; if (value instanceof String) { - body = getInternalSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); + body = getSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); } else { - body = getUserSerde().serialize(value); + body = getSerde().serializeUserData(value); } request.setBody(body); return request; @@ -83,7 +83,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio protected ResponseDeserializer insertVertexResponseDeserializer(final T value) { return response -> { - final VertexEntity doc = getInternalSerde().deserialize(response.getBody(), "/vertex", 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()); @@ -107,7 +107,7 @@ protected Request getVertexRequest(final String key, final GraphDocumentReadOpti } protected ResponseDeserializer getVertexResponseDeserializer(final Class type) { - return response -> getUserSerde().deserialize(getInternalSerde().extract(response.getBody(), "/vertex"), type); + return response -> getSerde().deserializeUserData(getSerde().extract(response.getBody(), "/vertex"), type); } protected Request replaceVertexRequest(final String key, final T value, final VertexReplaceOptions options) { @@ -117,13 +117,13 @@ protected Request replaceVertexRequest(final String key, final T value, fina request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer replaceVertexResponseDeserializer(final T value) { return response -> { - final VertexUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/vertex", 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); @@ -140,13 +140,13 @@ protected Request updateVertexRequest(final String key, final T value, final request.putQueryParam(ArangoRequestParam.KEEP_NULL, params.getKeepNull()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch()); - request.setBody(getUserSerde().serialize(value)); + request.setBody(getSerde().serializeUserData(value)); return request; } protected ResponseDeserializer updateVertexResponseDeserializer(final T value) { return response -> { - final VertexUpdateEntity doc = getInternalSerde().deserialize(response.getBody(), "/vertex", 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); diff --git a/src/main/java/com/arangodb/internal/InternalArangoView.java b/src/main/java/com/arangodb/internal/InternalArangoView.java index 0f4e821e6..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(getInternalSerde().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/ArangoCursorIterator.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java index a89191cb8..b3b048158 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -70,11 +70,11 @@ public T next() { if (!hasNext()) { throw new NoSuchElementException(); } - return deserialize(db.getInternalSerde().serialize(arrayIterator.next()), cursor.getType()); + return deserialize(db.getSerde().serialize(arrayIterator.next()), cursor.getType()); } protected R deserialize(final byte[] result, final Class type) { - return db.getUserSerde().deserialize(result, type); + return db.getSerde().deserializeUserData(result, type); } @Override diff --git a/src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java b/src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java deleted file mode 100644 index 5edfef0b3..000000000 --- a/src/main/java/com/arangodb/internal/util/ArangoSerdeFactory.java +++ /dev/null @@ -1,48 +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.serde.ArangoSerde; -import com.arangodb.serde.InternalSerde; - -/** - * @author Mark Vollmary - */ -public class ArangoSerdeFactory { - - private final InternalSerde internal; - private final ArangoSerde user; - - public ArangoSerdeFactory(final InternalSerde internal, final ArangoSerde user) { - super(); - this.internal = internal; - this.user = user; - } - - public InternalSerde getInternalSerde() { - return internal; - } - - public ArangoSerde getUserSerialization() { - return user; - } - -} diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index d7f161b29..fb7e0626b 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -14,11 +14,11 @@ public interface InternalSerde extends JacksonSerde { * @param dataType serialization target data type * @return the created InternalSerde */ - static InternalSerde of(final DataType dataType) { + static InternalSerde of(final DataType dataType, ArangoSerde userSerde) { if (dataType == DataType.JSON) { - return new InternalSerdeImpl(new ObjectMapper()); + return new InternalSerdeImpl(new ObjectMapper(), userSerde); } else if (dataType == DataType.VPACK) { - return new InternalSerdeImpl(new VPackMapper()); + return new InternalSerdeImpl(new VPackMapper(), userSerde); } else { throw new IllegalArgumentException("Unexpected value: " + dataType); } @@ -105,4 +105,36 @@ 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); + + /** + * 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 + */ + default T deserializeUserData(byte[] content, Class clazz) { + return deserializeUserData(content, (Type) 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); + + /** + * @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 index 996c9a373..b5b9f01d3 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -1,6 +1,8 @@ package com.arangodb.serde; import com.arangodb.ArangoDBException; +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; @@ -10,8 +12,11 @@ final class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde { - InternalSerdeImpl(ObjectMapper mapper) { + private final ArangoSerde userSerde; + + InternalSerdeImpl(final ObjectMapper mapper, final ArangoSerde userSerde) { super(mapper); + this.userSerde = userSerde; mapper.registerModule(InternalModule.INSTANCE.get()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @@ -53,6 +58,29 @@ public JsonNode parse(byte[] content, String jsonPointer) { } } + @Override + public byte[] serializeUserData(Object value) { + if (RawJson.class.equals(value.getClass()) || RawBytes.class.equals(value.getClass())) { + return serialize(value); + } else { + return userSerde.serialize(value); + } + } + + @Override + public T deserializeUserData(byte[] content, Type type) { + if (RawJson.class.equals(type) || RawBytes.class.equals(type)) { + return deserialize(content, type); + } else { + return userSerde.deserialize(content, type); + } + } + + @Override + public ArangoSerde getUserSerde() { + return userSerde; + } + @Override public T deserialize(final JsonNode node, final Type type) { try { @@ -62,4 +90,12 @@ public T deserialize(final JsonNode node, final Type type) { } } + @Override + public T deserialize(final byte[] content, final Type type) { + if (content == null) { + return null; + } + return super.deserialize(content, type); + } + } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 5762bf915..c51a12272 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -393,7 +393,7 @@ void authenticationFailUser() { @MethodSource("arangos") void execute(ArangoDB arangoDB) { final Response response = arangoDB.execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")); - assertThat(arangoDB.getInternalSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); + assertThat(arangoDB.getSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/ArangoRouteTest.java b/src/test/java/com/arangodb/ArangoRouteTest.java index b6866fbea..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(db.arango().getInternalSerde().parse(res.getBody(), "/version").isTextual()).isTrue(); + assertThat(db.arango().getSerde().parse(res.getBody(), "/version").isTextual()).isTrue(); } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/JwtAuthTest.java b/src/test/java/com/arangodb/JwtAuthTest.java index 59d12df67..71bf4da0e 100644 --- a/src/test/java/com/arangodb/JwtAuthTest.java +++ b/src/test/java/com/arangodb/JwtAuthTest.java @@ -82,7 +82,7 @@ private ArangoDB.Builder getBuilder(Protocol protocol) { } private static String getJwt(ArangoDB arangoDB) { - InternalSerde serde = arangoDB.getInternalSerde(); + 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/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 743b7cc28..2169914d4 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -439,7 +439,7 @@ void execute() throws InterruptedException, ExecutionException { .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(arangoDB.getInternalSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); + assertThat(arangoDB.getSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } @@ -451,7 +451,7 @@ void execute_acquireHostList_enabled() throws InterruptedException, ExecutionEx .execute(new Request(DbName.SYSTEM, RequestType.GET, "/_api/version")) .whenComplete((response, ex) -> { assertThat(response.getBody()).isNotNull(); - assertThat(arangoDB.getInternalSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); + assertThat(arangoDB.getSerde().parse(response.getBody(), "/version").isTextual()).isTrue(); }) .get(); } diff --git a/src/test/java/com/arangodb/async/JwtAuthTest.java b/src/test/java/com/arangodb/async/JwtAuthTest.java index 640c7a0ee..13ac28bc6 100644 --- a/src/test/java/com/arangodb/async/JwtAuthTest.java +++ b/src/test/java/com/arangodb/async/JwtAuthTest.java @@ -89,7 +89,7 @@ private ArangoDBAsync.Builder getBuilder() { } private static String getJwt(ArangoDB arangoDB) { - InternalSerde serde = arangoDB.getInternalSerde(); + InternalSerde serde = arangoDB.getSerde(); Map reqBody = new HashMap<>(); reqBody.put("username", "root"); reqBody.put("password", "test"); diff --git a/src/test/java/com/arangodb/serde/SerdeTest.java b/src/test/java/com/arangodb/serde/SerdeTest.java index d1e315ff6..6e924e4fb 100644 --- a/src/test/java/com/arangodb/serde/SerdeTest.java +++ b/src/test/java/com/arangodb/serde/SerdeTest.java @@ -16,7 +16,7 @@ class SerdeTest { @ParameterizedTest @EnumSource(DataType.class) void rawJsonSerde(DataType type) { - InternalSerde s = InternalSerde.of(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); @@ -27,7 +27,7 @@ void rawJsonSerde(DataType type) { @ParameterizedTest @EnumSource(DataType.class) void rawBytesSerde(DataType type) { - InternalSerde s = InternalSerde.of(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); From e69fa80f1996786912196b9af02e8089bbdb468c Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 22 Jul 2022 23:32:56 +0200 Subject: [PATCH 39/52] removed support for raw json strings in favor of RawJson and RawBytes wrappers --- .../java/com/arangodb/ArangoCollection.java | 40 +- .../java/com/arangodb/ArangoDatabase.java | 16 +- .../com/arangodb/ArangoEdgeCollection.java | 16 +- .../com/arangodb/ArangoVertexCollection.java | 16 +- .../arangodb/async/ArangoCollectionAsync.java | 40 +- .../arangodb/async/ArangoDatabaseAsync.java | 16 +- .../async/ArangoEdgeCollectionAsync.java | 8 +- .../async/ArangoVertexCollectionAsync.java | 8 +- .../internal/InternalArangoCollection.java | 30 +- .../internal/InternalArangoDatabase.java | 6 +- .../InternalArangoVertexCollection.java | 9 +- .../com/arangodb/serde/InternalSerde.java | 20 + .../com/arangodb/serde/InternalSerdeImpl.java | 5 + .../com/arangodb/ArangoCollectionTest.java | 708 ++++++------------ .../java/com/arangodb/ArangoDatabaseTest.java | 39 +- .../arangodb/ArangoVertexCollectionTest.java | 5 +- src/test/java/com/arangodb/DocumentTest.java | 8 +- .../arangodb/async/ArangoCollectionTest.java | 27 +- .../arangodb/async/ArangoDatabaseTest.java | 5 +- .../document/GetDocumentExampleTest.java | 10 +- .../document/InsertDocumentExampleTest.java | 3 +- .../document/GetDocumentExampleTest.java | 18 +- .../document/InsertDocumentExampleTest.java | 3 +- 23 files changed, 406 insertions(+), 650 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index ebd00fad5..c77a228f4 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -55,7 +55,7 @@ public interface ArangoCollection extends ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO 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 ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO 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 ArangoSerdeAccessor { * Limitations: * - the fields having {@code null} value are always removed during serialization * - * @param values A List of documents (POJO 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 ArangoSerdeAccessor { * Limitations: * - the fields having {@code null} value are always removed during serialization * - * @param values A List of documents (POJO 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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/ArangoDatabase.java b/src/main/java/com/arangodb/ArangoDatabase.java index 6aaf3ff26..58d055418 100644 --- a/src/main/java/com/arangodb/ArangoDatabase.java +++ b/src/main/java/com/arangodb/ArangoDatabase.java @@ -260,7 +260,7 @@ public interface ArangoDatabase extends ArangoSerdeAccessor { * @param query An AQL query string * @param bindVars key/value pairs defining the variables to bind the query to * @param options Additional options that will be passed to the query API, can be null - * @param type The type of the result (POJO class, 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, 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, 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, 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, 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 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 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 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 569d5d561..0c8bbc45d 100644 --- a/src/main/java/com/arangodb/ArangoEdgeCollection.java +++ b/src/main/java/com/arangodb/ArangoEdgeCollection.java @@ -50,7 +50,7 @@ public interface ArangoEdgeCollection extends ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO 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 ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO 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 ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class 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 ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class 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 ArangoSerdeAccessor { * violated * * @param key The key of the edge - * @param The type of the edge-document (POJO class 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 ArangoSerdeAccessor { * violated * * @param key The key of the edge - * @param The type of the edge-document (POJO class 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 ArangoSerdeAccessor { * 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 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 ArangoSerdeAccessor { * 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 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/ArangoVertexCollection.java b/src/main/java/com/arangodb/ArangoVertexCollection.java index a8f5b5727..0d514a9fc 100644 --- a/src/main/java/com/arangodb/ArangoVertexCollection.java +++ b/src/main/java/com/arangodb/ArangoVertexCollection.java @@ -59,7 +59,7 @@ public interface ArangoVertexCollection extends ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO 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 ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO 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 ArangoSerdeAccessor { * Retrieves the vertex document with the given {@code key} from the collection. * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class 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 ArangoSerdeAccessor { * Retrieves the vertex document with the given {@code key} from the collection. * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class 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 ArangoSerdeAccessor { * violated * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO 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 ArangoSerdeAccessor { * violated * * @param key The key of the vertex - * @param value A representation of a single vertex (POJO 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 ArangoSerdeAccessor { * 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 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 ArangoSerdeAccessor { * 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 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/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index d2da44236..1df9efcd3 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -56,7 +56,7 @@ public interface ArangoCollectionAsync extends ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO 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 ArangoSerdeAccessor { * Creates a new document from the given document, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param value A representation of a single document (POJO 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 ArangoSerdeAccessor { * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param values A List of documents (POJO 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 ArangoSerdeAccessor { * Creates new documents from the given documents, unless there is already a document with the _key given. If no * _key is given, a new unique _key is generated automatically. * - * @param values A List of documents (POJO 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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/ArangoDatabaseAsync.java b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java index 4531c7cba..4f525c838 100644 --- a/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDatabaseAsync.java @@ -249,7 +249,7 @@ public interface ArangoDatabaseAsync extends ArangoSerdeAccessor { * @param query contains the query string to be executed * @param bindVars key/value pairs representing the bind parameters * @param options Additional options, can be null - * @param type The type of the result (POJO class, 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, 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, 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, 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, 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 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 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 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 cff6747f0..39a8a3a0d 100644 --- a/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoEdgeCollectionAsync.java @@ -53,7 +53,7 @@ public interface ArangoEdgeCollectionAsync extends ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO 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 ArangoSerdeAccessor { /** * Creates a new edge in the collection * - * @param value A representation of a single edge (POJO 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 ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class 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 ArangoSerdeAccessor { * Fetches an existing edge * * @param key The key of the edge - * @param type The type of the edge-document (POJO class 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/ArangoVertexCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java index e9ad701de..38eb462cd 100644 --- a/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoVertexCollectionAsync.java @@ -63,7 +63,7 @@ public interface ArangoVertexCollectionAsync extends ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO 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 ArangoSerdeAccessor { /** * Creates a new vertex in the collection * - * @param value A representation of a single vertex (POJO 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 ArangoSerdeAccessor { * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class 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 ArangoSerdeAccessor { * Fetches an existing vertex * * @param key The key of the vertex - * @param type The type of the vertex-document (POJO class 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/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 5655cbafa..2016b4373 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -88,15 +88,7 @@ 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()); - - byte[] body; - if (value instanceof String) { - body = getSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); - } else { - body = getSerde().serializeUserData(value); - } - request.setBody(body); - + request.setBody(getSerde().serializeUserData(value)); return request; } @@ -108,19 +100,11 @@ protected ResponseDeserializer> insertDocumentRespon final JsonNode newDoc = body.get(NEW); Class clazz = (Class) value.getClass(); if (newDoc != null) { - if (String.class.equals(clazz)) { - doc.setNew((T) SerdeUtils.INSTANCE.writeJson(newDoc)); - } else { - doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), clazz)); - } + doc.setNew(getSerde().deserializeUserData(newDoc, clazz)); } final JsonNode oldDoc = body.get(OLD); if (oldDoc != null) { - if (String.class.equals(clazz)) { - doc.setOld((T) SerdeUtils.INSTANCE.writeJson(oldDoc)); - } else { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), clazz)); - } + doc.setOld(getSerde().deserializeUserData(oldDoc, clazz)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); @@ -225,13 +209,7 @@ protected Request getDocumentRequest(final String key, final DocumentReadOptions } protected ResponseDeserializer getDocumentResponseDeserializer(final Class type) { - return response -> { - if (String.class.equals(type)) { - return (T) SerdeUtils.INSTANCE.writeJson(getSerde().parse(response.getBody())); - } else { - return getSerde().deserializeUserData(response.getBody(), type); - } - }; + return response -> getSerde().deserializeUserData(response.getBody(), type); } protected Request getDocumentsRequest(final Collection keys, final DocumentReadOptions options) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index a94042aab..9a8761600 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -285,11 +285,7 @@ protected Request transactionRequest(final String action, final TransactionOptio protected ResponseDeserializer transactionResponseDeserializer(final Class type) { return response -> { byte[] userContent = getSerde().extract(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER); - if (String.class.equals(type)) { - return (T) SerdeUtils.INSTANCE.writeJson(getSerde().parse(userContent)); - } else { - return getSerde().deserializeUserData(userContent, type); - } + return getSerde().deserializeUserData(userContent, type); }; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java index 6cd10c0d7..d7c9ebb8d 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java @@ -70,14 +70,7 @@ protected Request insertVertexRequest(final T value, final VertexCreateOptio final VertexCreateOptions params = (options != null ? options : new VertexCreateOptions()); request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); - - byte[] body; - if (value instanceof String) { - body = getSerde().serialize(SerdeUtils.INSTANCE.parseJson((String) value)); - } else { - body = getSerde().serializeUserData(value); - } - request.setBody(body); + request.setBody(getSerde().serializeUserData(value)); return request; } diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index fb7e0626b..be850da3f 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -133,6 +133,26 @@ default T deserializeUserData(byte[] content, Class clazz) { */ 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 */ diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index b5b9f01d3..d321f3743 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -76,6 +76,11 @@ public T deserializeUserData(byte[] content, Type type) { } } + @Override + public T deserializeUserData(JsonNode node, Type type) { + return deserializeUserData(serialize(node), type); + } + @Override public ArangoSerde getUserSerde() { return userSerde; diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 6cf12bb73..a23f182af 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -38,6 +38,8 @@ import com.arangodb.model.*; import com.arangodb.model.DocumentImportOptions.OnDuplicate; import com.arangodb.util.MapBuilder; +import com.arangodb.util.RawBytes; +import com.arangodb.util.RawJson; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonIncludeProperties; import com.fasterxml.jackson.core.JsonProcessingException; @@ -92,8 +94,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(); @@ -112,8 +113,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(); @@ -131,8 +131,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(); @@ -145,8 +144,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()); } @@ -154,8 +152,7 @@ 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(); @@ -175,8 +172,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()); @@ -193,8 +189,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); @@ -213,8 +208,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()); @@ -232,8 +226,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()); @@ -253,11 +246,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()); @@ -268,8 +257,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(); @@ -281,20 +269,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(); @@ -308,8 +314,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); @@ -319,9 +324,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(); @@ -331,11 +334,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()); } @@ -343,12 +344,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()); } @@ -356,24 +355,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()); } @@ -381,12 +376,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(); } @@ -394,11 +387,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}") @@ -411,8 +403,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(); } @@ -426,8 +417,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); } @@ -444,8 +434,7 @@ void getDocumentDirtyRead(ArangoCollection collection) throws InterruptedExcepti final BaseDocument doc = new BaseDocument(); collection.insertDocument(doc, new DocumentCreateOptions()); Thread.sleep(2000); - final String document = collection - .getDocument(doc.getKey(), String.class, new DocumentReadOptions().allowDirtyRead(true)); + final RawJson document = collection.getDocument(doc.getKey(), RawJson.class, new DocumentReadOptions().allowDirtyRead(true)); assertThat(document).isNotNull(); } @@ -457,8 +446,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()) { @@ -470,24 +458,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); } @@ -500,9 +480,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()) { @@ -513,8 +491,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); @@ -523,8 +500,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); @@ -536,13 +512,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(); @@ -550,8 +524,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"); @@ -569,8 +542,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(); @@ -583,11 +555,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()); } @@ -597,21 +567,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"); @@ -627,8 +594,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); @@ -643,13 +609,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()); @@ -667,13 +631,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()); @@ -690,19 +652,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"); } @@ -712,19 +671,16 @@ 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(); @@ -768,13 +724,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"); @@ -789,13 +743,11 @@ void updateDocumentSerializeNullFalse(ArangoCollection collection) { final DocumentCreateEntity createResult = collection.insertDocument(doc); final TestUpdateEntitySerializeNullFalse patchDoc = new TestUpdateEntitySerializeNullFalse(); patchDoc.a = "bar"; - final DocumentUpdateEntity updateResult = collection - .updateDocument(createResult.getKey(), patchDoc); + final DocumentUpdateEntity updateResult = collection.updateDocument(createResult.getKey(), patchDoc); assertThat(updateResult).isNotNull(); assertThat(updateResult.getKey()).isEqualTo(createResult.getKey()); - 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"); @@ -810,21 +762,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); @@ -840,21 +789,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); @@ -868,8 +814,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"); @@ -882,10 +827,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(); @@ -896,11 +839,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(); @@ -926,15 +866,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); @@ -948,12 +886,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(); @@ -961,8 +897,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"); @@ -974,11 +909,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()); } @@ -987,20 +920,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"); @@ -1013,8 +943,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"); @@ -1029,8 +958,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"); @@ -1045,13 +973,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()); @@ -1068,13 +994,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()); @@ -1090,10 +1014,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(); @@ -1108,8 +1030,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); } @@ -1118,11 +1039,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(); @@ -1133,11 +1051,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(); } @@ -1146,11 +1062,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(); @@ -1161,12 +1075,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(); } @@ -1174,8 +1086,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); @@ -1185,10 +1096,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(); @@ -1199,11 +1108,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(); @@ -1530,9 +1436,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(); @@ -1718,10 +1622,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); } @@ -1747,14 +1648,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(); } @@ -1762,19 +1661,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(); } @@ -1788,9 +1688,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(); @@ -1798,9 +1699,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(); @@ -1808,9 +1710,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(); @@ -1818,9 +1721,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(); @@ -1829,14 +1733,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 MultiDocumentEntity> docs = collection - .insertDocuments(values, null); + final Collection values = Arrays.asList(new BaseDocument(), new BaseDocument(), new BaseDocument()); + + final MultiDocumentEntity> docs = collection.insertDocuments(values, null); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1860,9 +1759,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(); @@ -1881,8 +1778,7 @@ void insertDocumentsJson(ArangoCollection collection) { values.add("{}"); values.add("{}"); values.add("{}"); - final MultiDocumentEntity> docs = collection - .insertDocuments(values); + final MultiDocumentEntity> docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(3); @@ -1895,8 +1791,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); @@ -1908,8 +1803,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(); @@ -1925,8 +1819,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); @@ -1945,14 +1838,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 MultiDocumentEntity> docs = collection - .insertDocuments(values); + final Collection values = Arrays.asList(new BaseDocument(k1), new BaseDocument(k2), new BaseDocument(k2)); + + final MultiDocumentEntity> docs = collection.insertDocuments(values); assertThat(docs).isNotNull(); assertThat(docs.getDocuments()).isNotNull(); assertThat(docs.getDocuments()).hasSize(2); @@ -1964,11 +1852,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(); @@ -1983,11 +1867,7 @@ void importDocuments(ArangoCollection collection) { @ParameterizedTest(name = "{index}") @MethodSource("cols") void importDocumentsJsonList(ArangoCollection collection) { - final Collection values = Arrays.asList( - "{}", - "{}", - "{}" - ); + final Collection values = Arrays.asList("{}", "{}", "{}"); final DocumentImportEntity docs = collection.importDocuments(values); assertThat(docs).isNotNull(); @@ -2005,11 +1885,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(); @@ -2027,14 +1903,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(); @@ -2050,14 +1921,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(); @@ -2073,14 +1939,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(); @@ -2096,14 +1957,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(); @@ -2119,11 +1975,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); @@ -2137,14 +1989,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(); @@ -2184,17 +2031,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) { @@ -2208,10 +2051,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(); @@ -2229,11 +2069,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(); @@ -2251,14 +2087,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(); @@ -2274,13 +2105,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(); @@ -2296,14 +2122,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(); @@ -2319,14 +2140,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(); @@ -2352,14 +2168,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(); @@ -2376,10 +2187,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); } @@ -2389,10 +2197,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); } @@ -2405,21 +2210,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) { @@ -2448,8 +2241,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()) { @@ -2473,8 +2265,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()) { @@ -2495,8 +2286,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()) { @@ -2515,8 +2305,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()) { @@ -2531,8 +2320,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(); @@ -2543,13 +2331,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); @@ -2569,8 +2353,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); @@ -2579,15 +2362,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(); } @@ -2596,32 +2375,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}") @@ -2638,8 +2407,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(); } @@ -2648,8 +2416,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(); } @@ -2668,8 +2435,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); } @@ -2685,8 +2451,7 @@ void updateDocumentsJson(ArangoCollection collection) { final Collection updatedValues = new ArrayList<>(); updatedValues.add("{\"_key\":\"1\", \"foo\":\"bar\"}"); updatedValues.add("{\"_key\":\"2\", \"foo\":\"bar\"}"); - final MultiDocumentEntity> updateResult = collection - .updateDocuments(updatedValues); + final MultiDocumentEntity> updateResult = collection.updateDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2705,8 +2470,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(); } @@ -2725,8 +2489,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(); } @@ -2735,8 +2498,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(); } @@ -2755,8 +2517,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); } @@ -2772,8 +2533,7 @@ void replaceDocumentsJson(ArangoCollection collection) { final Collection updatedValues = new ArrayList<>(); updatedValues.add("{\"_key\":\"1\", \"foo\":\"bar\"}"); updatedValues.add("{\"_key\":\"2\", \"foo\":\"bar\"}"); - final MultiDocumentEntity> updateResult = collection - .replaceDocuments(updatedValues); + final MultiDocumentEntity> updateResult = collection.replaceDocuments(updatedValues); assertThat(updateResult.getDocuments()).hasSize(2); assertThat(updateResult.getErrors()).isEmpty(); } @@ -2802,23 +2562,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(); @@ -2831,10 +2578,7 @@ void changeProperties(ArangoCollection collection) { } // revert changes - CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions() - .waitForSync(properties.getWaitForSync()) - .schema(CollectionSchema.NULL_SCHEMA) - ); + CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions().waitForSync(properties.getWaitForSync()).schema(CollectionSchema.NULL_SCHEMA)); if (isAtLeastVersion(3, 7)) { assertThat(revertedProperties.getSchema()).isNull(); } diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index da017d860..beb25d244 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -25,6 +25,7 @@ import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.model.*; import com.arangodb.util.MapBuilder; +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; @@ -1151,8 +1152,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}") @@ -1177,9 +1178,9 @@ void transactionVPack(ArangoDatabase db) { 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}") @@ -1187,9 +1188,9 @@ void transactionJsonObject(ArangoDatabase db) { 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}") @@ -1197,9 +1198,9 @@ void transactionJsonArray(ArangoDatabase db) { 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}") @@ -1207,9 +1208,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}") @@ -1219,9 +1220,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}") @@ -1234,7 +1235,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}") @@ -1248,7 +1249,7 @@ 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}") 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/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/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/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index 65513d2dc..565185563 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -27,6 +27,7 @@ import com.arangodb.entity.AqlParseEntity.AstNode; import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.model.*; +import com.arangodb.util.RawJson; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import org.junit.jupiter.api.Disabled; @@ -874,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(); } 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 404422665..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,6 +23,7 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; +import com.arangodb.util.RawJson; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -82,11 +83,12 @@ void getAsVPack() throws InterruptedException, ExecutionException { @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 cd5a4b889..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,6 +22,7 @@ import com.arangodb.async.example.ExampleBase; import com.arangodb.entity.BaseDocument; +import com.arangodb.util.RawJson; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; @@ -64,7 +65,7 @@ void insertJsonNode() throws ExecutionException, InterruptedException { @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/example/document/GetDocumentExampleTest.java b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java index 50b8cceea..51cd6f9f3 100644 --- a/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/GetDocumentExampleTest.java @@ -23,6 +23,8 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; +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; @@ -81,10 +83,18 @@ void getAsJsonNode() { @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 fbe81d69f..e12949537 100644 --- a/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java +++ b/src/test/java/com/arangodb/example/document/InsertDocumentExampleTest.java @@ -23,6 +23,7 @@ import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.example.ExampleBase; +import com.arangodb.util.RawJson; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -61,7 +62,7 @@ void insertJsonNode() { @Test void insertJson() { - final DocumentCreateEntity doc = collection.insertDocument("{\"foo\":\"bar\"}"); + final DocumentCreateEntity doc = collection.insertDocument(RawJson.of("{\"foo\":\"bar\"}")); assertThat(doc.getKey()).isNotNull(); } From 1b34f41ccfb6d7a08f10638f524ff166d90a6b93 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Mon, 25 Jul 2022 13:49:03 +0200 Subject: [PATCH 40/52] @UserData and @UserDataInside annotations --- .../arangodb/entity/DocumentCreateEntity.java | 4 ++ .../arangodb/entity/DocumentDeleteEntity.java | 3 ++ .../arangodb/entity/DocumentUpdateEntity.java | 3 ++ .../internal/InternalArangoCollection.java | 28 +++--------- .../internal/InternalArangoDatabase.java | 7 ++- .../model/AqlQueryExplainOptions.java | 12 ++--- .../com/arangodb/model/AqlQueryOptions.java | 12 ++--- .../com/arangodb/model/OptionsBuilder.java | 5 ++- .../serde/InternalAnnotationIntrospector.java | 32 ++++++++++++++ .../com/arangodb/serde/InternalSerde.java | 9 ++++ .../com/arangodb/serde/InternalSerdeImpl.java | 15 ++++++- .../arangodb/serde/InternalSerializers.java | 11 ----- .../java/com/arangodb/serde/UserData.java | 14 ++++++ .../com/arangodb/serde/UserDataInside.java | 19 ++++++++ .../arangodb/serde/UserDataSerializer.java | 25 +++++++++++ .../com/arangodb/ArangoCollectionTest.java | 44 ++++++++++--------- .../java/com/arangodb/ArangoDatabaseTest.java | 20 +++++++-- 17 files changed, 187 insertions(+), 76 deletions(-) create mode 100644 src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java create mode 100644 src/main/java/com/arangodb/serde/UserData.java create mode 100644 src/main/java/com/arangodb/serde/UserDataInside.java create mode 100644 src/main/java/com/arangodb/serde/UserDataSerializer.java diff --git a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java index 64c8a53af..e857c5179 100644 --- a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java @@ -20,6 +20,8 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Mark Vollmary * @see API @@ -41,6 +43,7 @@ public T getNew() { return newDocument; } + @JsonIgnore public void setNew(final T newDocument) { this.newDocument = newDocument; } @@ -53,6 +56,7 @@ public T getOld() { return oldDocument; } + @JsonIgnore 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 612494d66..7a91b6b95 100644 --- a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java @@ -20,6 +20,8 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * @author Mark Vollmary * @see API @@ -41,6 +43,7 @@ public T getOld() { return oldDocument; } + @JsonIgnore public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java index 3567bd10e..593b62a90 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -20,6 +20,7 @@ package com.arangodb.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -50,6 +51,7 @@ public T getNew() { return newDocument; } + @JsonIgnore public void setNew(final T newDocument) { this.newDocument = newDocument; } @@ -62,6 +64,7 @@ public T getOld() { return oldDocument; } + @JsonIgnore public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 2016b4373..b9048da21 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -126,10 +126,7 @@ 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()); - - byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getSerde().serializeUserData(values); - request.setBody(body); + request.setBody(getSerde().serializeCollectionUserData(values)); return request; } @@ -181,9 +178,8 @@ protected Request importDocumentsRequest(final String values, final DocumentImpo } protected Request importDocumentsRequest(final Collection values, final DocumentImportOptions options) { - byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getSerde().serializeUserData(values); - return importDocumentsRequest(options).putQueryParam("type", ImportType.list).setBody(body); + return importDocumentsRequest(options).putQueryParam("type", ImportType.list) + .setBody(getSerde().serializeCollectionUserData(values)); } protected Request importDocumentsRequest(final DocumentImportOptions options) { @@ -301,10 +297,7 @@ protected Request replaceDocumentsRequest(final Collection values, final request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); - - byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getSerde().serializeUserData(values); - request.setBody(body); + request.setBody(getSerde().serializeCollectionUserData(values)); return request; } @@ -402,10 +395,7 @@ 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()); - - byte[] body = isStringCollection(values) ? getSerde().serialize(stringCollectionToJsonArray((Collection) values)) - : getSerde().serializeUserData(values); - request.setBody(body); + request.setBody(getSerde().serializeCollectionUserData(values)); return request; } @@ -686,12 +676,4 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class); } - private boolean isStringCollection(final Collection values) { - return values.stream().allMatch(String.class::isInstance); - } - - private JsonNode stringCollectionToJsonArray(final Collection values) { - return SerdeUtils.INSTANCE.parseJson("[" + String.join(",", values) + "]"); - } - } diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 9a8761600..2f36609cb 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -144,8 +144,8 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() 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(getSerde().serialize( - OptionsBuilder.build(opt, query, bindVars != null ? getSerde().serializeUserData(bindVars) : null))); + final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR) + .setBody(getSerde().serialize(OptionsBuilder.build(opt, query, bindVars))); if (opt.getAllowDirtyRead() == Boolean.TRUE) { RequestUtils.allowDirtyRead(request); } @@ -190,8 +190,7 @@ protected Request queryCloseRequest(final String id, final AqlQueryOptions optio 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(getSerde().serialize( - OptionsBuilder.build(opt, query, bindVars != null ? getSerde().serializeUserData(bindVars) : null))); + .setBody(getSerde().serialize(OptionsBuilder.build(opt, query, bindVars))); } protected Request parseQueryRequest(final String query) { diff --git a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java index 45cb189a6..7a1b9b448 100644 --- a/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryExplainOptions.java @@ -20,10 +20,10 @@ package com.arangodb.model; -import com.arangodb.serde.InternalSerializers; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.arangodb.serde.UserDataInside; import java.util.Collection; +import java.util.Map; /** * @author Mark Vollmary @@ -32,7 +32,7 @@ */ public final class AqlQueryExplainOptions { - private byte[] bindVars; + private Map bindVars; private String query; private Options options; @@ -40,8 +40,8 @@ public AqlQueryExplainOptions() { super(); } - @JsonSerialize(using = InternalSerializers.AqlBindVarsSerializer.class) - public byte[] getBindVars() { + @UserDataInside + public Map getBindVars() { return bindVars; } @@ -49,7 +49,7 @@ public byte[] getBindVars() { * @param bindVars key/value pairs representing the bind parameters * @return options */ - AqlQueryExplainOptions bindVars(final byte[] bindVars) { + AqlQueryExplainOptions bindVars(final Map bindVars) { this.bindVars = bindVars; return this; } diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index 7d646b700..dd85a40b1 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -20,12 +20,12 @@ package com.arangodb.model; -import com.arangodb.serde.InternalSerializers; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.arangodb.serde.UserDataInside; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Map; /** * @author Mark Vollmary @@ -40,7 +40,7 @@ public final class AqlQueryOptions { private Integer batchSize; private Boolean cache; private Long memoryLimit; - private byte[] bindVars; + private Map bindVars; private String query; private Options options; private Boolean allowDirtyRead; @@ -147,8 +147,8 @@ public AqlQueryOptions fillBlockCache(final Boolean fillBlockCache) { return this; } - @JsonSerialize(using = InternalSerializers.AqlBindVarsSerializer.class) - public byte[] getBindVars() { + @UserDataInside + public Map getBindVars() { return bindVars; } @@ -156,7 +156,7 @@ public byte[] getBindVars() { * @param bindVarsBytes serialized bind parameters * @return options */ - AqlQueryOptions bindVars(final byte[] bindVarsBytes) { + AqlQueryOptions bindVars(final Map bindVarsBytes) { this.bindVars = bindVarsBytes; return this; } diff --git a/src/main/java/com/arangodb/model/OptionsBuilder.java b/src/main/java/com/arangodb/model/OptionsBuilder.java index 6bf13ae4e..f62a45d19 100644 --- a/src/main/java/com/arangodb/model/OptionsBuilder.java +++ b/src/main/java/com/arangodb/model/OptionsBuilder.java @@ -25,6 +25,7 @@ import com.arangodb.entity.ViewType; import java.util.Collection; +import java.util.Map; /** * @author Mark Vollmary @@ -82,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 byte[] 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 byte[] bindVars) { + final Map bindVars) { return options.query(query).bindVars(bindVars); } 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..92b1e2fdd --- /dev/null +++ b/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java @@ -0,0 +1,32 @@ +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; + + InternalAnnotationIntrospector(final UserDataSerializer userDataSerializer) { + this.userDataSerializer = userDataSerializer; + } + + @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); + } + } + +} diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index be850da3f..04215e6ee 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.lang.reflect.Type; +import java.util.Collection; public interface InternalSerde extends JacksonSerde { @@ -113,6 +114,14 @@ default T deserialize(byte[] content, String jsonPointer, Type type) { */ 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. * diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index d321f3743..f27f7164b 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -9,6 +9,9 @@ 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 { @@ -19,6 +22,7 @@ final class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde this.userSerde = userSerde; mapper.registerModule(InternalModule.INSTANCE.get()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.setAnnotationIntrospector(new InternalAnnotationIntrospector(new UserDataSerializer(this))); } @Override @@ -60,13 +64,22 @@ public JsonNode parse(byte[] content, String jsonPointer) { @Override public byte[] serializeUserData(Object value) { - if (RawJson.class.equals(value.getClass()) || RawBytes.class.equals(value.getClass())) { + if (value != null && (RawJson.class.equals(value.getClass()) || RawBytes.class.equals(value.getClass()))) { 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, Type type) { if (RawJson.class.equals(type) || RawBytes.class.equals(type)) { diff --git a/src/main/java/com/arangodb/serde/InternalSerializers.java b/src/main/java/com/arangodb/serde/InternalSerializers.java index 6d951e2d5..454b1a4bc 100644 --- a/src/main/java/com/arangodb/serde/InternalSerializers.java +++ b/src/main/java/com/arangodb/serde/InternalSerializers.java @@ -20,17 +20,6 @@ public final class InternalSerializers { - public static class AqlBindVarsSerializer extends JsonSerializer { - @Override - public void serialize(byte[] 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)) { - gen.writeTree(parser.readValueAsTree()); - } - } - } - public static class CollectionSchemaRuleSerializer extends JsonSerializer { @Override public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { 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/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/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index a23f182af..843bd6c18 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -1774,11 +1774,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); @@ -1867,7 +1867,11 @@ 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); assertThat(docs).isNotNull(); @@ -2443,15 +2447,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(); } @@ -2525,15 +2529,15 @@ 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(); } diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index beb25d244..1e4054984 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -25,6 +25,7 @@ import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.model.*; import com.arangodb.util.MapBuilder; +import com.arangodb.util.RawBytes; import com.arangodb.util.RawJson; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -826,6 +827,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) { @@ -1166,7 +1180,7 @@ void transactionNumber(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionVPack(ArangoDatabase db) { + 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(); @@ -1175,7 +1189,7 @@ void transactionVPack(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionJsonObject(ArangoDatabase db) { + void transactionJsonObject(ArangoDatabase db) { ObjectNode params = JsonNodeFactory.instance.objectNode().put("foo", "hello").put("bar", "world"); final TransactionOptions options = new TransactionOptions().params(params); final RawJson result = db @@ -1185,7 +1199,7 @@ void transactionJsonObject(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void transactionJsonArray(ArangoDatabase db) { + void transactionJsonArray(ArangoDatabase db) { ArrayNode params = JsonNodeFactory.instance.arrayNode().add("hello").add("world"); final TransactionOptions options = new TransactionOptions().params(params); final RawJson result = db From 4eb2886b0b7043dd6a4e11970abb0eea23ebb905 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 26 Jul 2022 13:46:09 +0200 Subject: [PATCH 41/52] @UserData and @UserDataInside deserialization --- .../arangodb/entity/DocumentCreateEntity.java | 6 +- .../arangodb/entity/DocumentDeleteEntity.java | 4 +- .../arangodb/entity/DocumentUpdateEntity.java | 6 +- .../internal/InternalArangoCollection.java | 118 +++++------------- .../serde/InternalAnnotationIntrospector.java | 25 +++- .../serde/InternalParameterizedType.java | 31 +++++ .../com/arangodb/serde/InternalSerdeImpl.java | 5 +- .../java/com/arangodb/serde/SerdeUtils.java | 19 +++ .../arangodb/serde/UserDataDeserializer.java | 42 +++++++ 9 files changed, 160 insertions(+), 96 deletions(-) create mode 100644 src/main/java/com/arangodb/serde/InternalParameterizedType.java create mode 100644 src/main/java/com/arangodb/serde/UserDataDeserializer.java diff --git a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java index e857c5179..c2d07bc8c 100644 --- a/src/main/java/com/arangodb/entity/DocumentCreateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentCreateEntity.java @@ -20,7 +20,7 @@ package com.arangodb.entity; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.arangodb.serde.UserData; /** * @author Mark Vollmary @@ -43,7 +43,7 @@ public T getNew() { return newDocument; } - @JsonIgnore + @UserData public void setNew(final T newDocument) { this.newDocument = newDocument; } @@ -56,7 +56,7 @@ public T getOld() { return oldDocument; } - @JsonIgnore + @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 7a91b6b95..46fa34c56 100644 --- a/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentDeleteEntity.java @@ -20,7 +20,7 @@ package com.arangodb.entity; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.arangodb.serde.UserData; /** * @author Mark Vollmary @@ -43,7 +43,7 @@ public T getOld() { return oldDocument; } - @JsonIgnore + @UserData public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java index 593b62a90..61b9b1f62 100644 --- a/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java +++ b/src/main/java/com/arangodb/entity/DocumentUpdateEntity.java @@ -20,7 +20,7 @@ package com.arangodb.entity; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.arangodb.serde.UserData; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -51,7 +51,7 @@ public T getNew() { return newDocument; } - @JsonIgnore + @UserData public void setNew(final T newDocument) { this.newDocument = newDocument; } @@ -64,7 +64,7 @@ public T getOld() { return oldDocument; } - @JsonIgnore + @UserData public void setOld(final T oldDocument) { this.oldDocument = oldDocument; } diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index b9048da21..3bfd2d792 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -32,6 +32,7 @@ import com.arangodb.velocystream.RequestType; import com.fasterxml.jackson.databind.JsonNode; +import java.lang.reflect.Type; import java.util.*; /** @@ -96,16 +97,8 @@ protected ResponseDeserializer> insertDocumentRespon final T value, final DocumentCreateOptions options) { return response -> { final JsonNode body = getSerde().parse(response.getBody()); - final DocumentCreateEntity doc = getSerde().deserialize(body, DocumentCreateEntity.class); - final JsonNode newDoc = body.get(NEW); - Class clazz = (Class) value.getClass(); - if (newDoc != null) { - doc.setNew(getSerde().deserializeUserData(newDoc, clazz)); - } - final JsonNode oldDoc = body.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(oldDoc, clazz)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, value.getClass()); + final DocumentCreateEntity doc = getSerde().deserialize(body, type); if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); values.put(DocumentFields.ID, doc.getId()); @@ -130,16 +123,10 @@ protected Request insertDocumentsRequest(final Collection values, final D 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<>(); @@ -153,15 +140,8 @@ protected ResponseDeserializer>> errors.add(error); documentsAndErrors.add(error); } else { - final DocumentCreateEntity doc = getSerde().deserialize(next, DocumentCreateEntity.class); - final JsonNode newDoc = next.get(NEW); - if (newDoc != null) { - doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), type)); - } - final JsonNode oldDoc = next.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, userDataClass); + final DocumentCreateEntity doc = getSerde().deserialize(next, type); docs.add(doc); documentsAndErrors.add(doc); } @@ -269,16 +249,8 @@ protected ResponseDeserializer> replaceDocumentRespo final T value, final DocumentReplaceOptions options) { return response -> { final JsonNode body = getSerde().parse(response.getBody()); - final DocumentUpdateEntity doc = getSerde().deserialize(body, DocumentUpdateEntity.class); - final JsonNode newDoc = body.get(NEW); - Class clazz = (Class) value.getClass(); - if (newDoc != null) { - doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), clazz)); - } - final JsonNode oldDoc = body.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), clazz)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, value.getClass()); + final DocumentUpdateEntity doc = getSerde().deserialize(body, type); if (options == null || Boolean.TRUE != options.getSilent()) { final Map values = new HashMap<>(); values.put(DocumentFields.REV, doc.getRev()); @@ -301,16 +273,10 @@ protected Request replaceDocumentsRequest(final Collection values, final 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<>(); @@ -324,15 +290,8 @@ protected ResponseDeserializer>> errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = getSerde().deserialize(next, DocumentUpdateEntity.class); - final JsonNode newDoc = next.get(NEW); - if (newDoc != null) { - doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), type)); - } - final JsonNode oldDoc = next.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, userDataClass); + final DocumentUpdateEntity doc = getSerde().deserialize(next, type); docs.add(doc); documentsAndErrors.add(doc); } @@ -364,16 +323,8 @@ protected Request updateDocumentRequest(final String key, final T value, fin protected ResponseDeserializer> updateDocumentResponseDeserializer( final T value, final DocumentUpdateOptions options, final Class returnType) { return response -> { - final JsonNode body = getSerde().parse(response.getBody()); - final DocumentUpdateEntity doc = getSerde().deserialize(body, DocumentUpdateEntity.class); - final JsonNode newDoc = body.get(NEW); - if (newDoc != null) { - doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), returnType)); - } - final JsonNode oldDoc = body.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(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()); @@ -399,7 +350,6 @@ protected Request updateDocumentsRequest(final Collection values, final D return request; } - @SuppressWarnings("unchecked") protected ResponseDeserializer>> updateDocumentsResponseDeserializer( final Class returnType) { return response -> { @@ -416,15 +366,8 @@ protected ResponseDeserializer>> errors.add(error); documentsAndErrors.add(error); } else { - final DocumentUpdateEntity doc = getSerde().deserialize(next, DocumentUpdateEntity.class); - final JsonNode newDoc = next.get(NEW); - if (newDoc != null) { - doc.setNew(getSerde().deserializeUserData(getSerde().serialize(newDoc), returnType)); - } - final JsonNode oldDoc = next.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), returnType)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, returnType); + final DocumentUpdateEntity doc = getSerde().deserialize(next, type); docs.add(doc); documentsAndErrors.add(doc); } @@ -449,15 +392,10 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp } protected ResponseDeserializer> deleteDocumentResponseDeserializer( - final Class type) { + final Class userDataClass) { return response -> { - final JsonNode body = getSerde().parse(response.getBody()); - final DocumentDeleteEntity doc = getSerde().deserialize(body, DocumentDeleteEntity.class); - final JsonNode oldDoc = body.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); - } - return doc; + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentDeleteEntity.class, userDataClass); + return getSerde().deserialize(response.getBody(), type); }; } @@ -473,7 +411,7 @@ protected Request deleteDocumentsRequest(final Collection keys, final Doc } protected ResponseDeserializer>> deleteDocumentsResponseDeserializer( - final Class type) { + final Class userDataClass) { return response -> { final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>(); final Collection> docs = new ArrayList<>(); @@ -488,11 +426,8 @@ protected ResponseDeserializer>> errors.add(error); documentsAndErrors.add(error); } else { - final DocumentDeleteEntity doc = getSerde().deserialize(next, DocumentDeleteEntity.class); - final JsonNode oldDoc = next.get(OLD); - if (oldDoc != null) { - doc.setOld(getSerde().deserializeUserData(getSerde().serialize(oldDoc), type)); - } + Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentDeleteEntity.class, userDataClass); + final DocumentDeleteEntity doc = getSerde().deserialize(next, type); docs.add(doc); documentsAndErrors.add(doc); } @@ -676,4 +611,15 @@ protected ResponseDeserializer getPermissionsResponseDeserialzer() 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/serde/InternalAnnotationIntrospector.java b/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java index 92b1e2fdd..cfaa5b417 100644 --- a/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java +++ b/src/main/java/com/arangodb/serde/InternalAnnotationIntrospector.java @@ -6,9 +6,14 @@ class InternalAnnotationIntrospector extends JacksonAnnotationIntrospector { private final UserDataSerializer userDataSerializer; + private final UserDataDeserializer userDataDeserializer; - InternalAnnotationIntrospector(final UserDataSerializer userDataSerializer) { + InternalAnnotationIntrospector( + final UserDataSerializer userDataSerializer, + final UserDataDeserializer userDataDeserializer + ) { this.userDataSerializer = userDataSerializer; + this.userDataDeserializer = userDataDeserializer; } @Override @@ -29,4 +34,22 @@ public Object findContentSerializer(Annotated 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/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/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index f27f7164b..ae978c7fd 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -22,7 +22,10 @@ final class InternalSerdeImpl extends JacksonSerdeImpl implements InternalSerde this.userSerde = userSerde; mapper.registerModule(InternalModule.INSTANCE.get()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.setAnnotationIntrospector(new InternalAnnotationIntrospector(new UserDataSerializer(this))); + mapper.setAnnotationIntrospector(new InternalAnnotationIntrospector( + new UserDataSerializer(this), + new UserDataDeserializer(this) + )); } @Override diff --git a/src/main/java/com/arangodb/serde/SerdeUtils.java b/src/main/java/com/arangodb/serde/SerdeUtils.java index 52ec7a6b8..c93677825 100644 --- a/src/main/java/com/arangodb/serde/SerdeUtils.java +++ b/src/main/java/com/arangodb/serde/SerdeUtils.java @@ -2,11 +2,13 @@ import com.arangodb.ArangoDBException; 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.List; import java.util.Map; @@ -49,4 +51,21 @@ 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])); + } + } 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); + } +} From a567a65d1e4f95d2618b5553e14f1d54bed22b42 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 26 Jul 2022 21:58:19 +0200 Subject: [PATCH 42/52] fix cluster tests --- .../java/com/arangodb/internal/ArangoCollectionImpl.java | 3 +-- .../com/arangodb/internal/InternalArangoCollection.java | 6 ++---- .../java/com/arangodb/internal/InternalArangoDatabase.java | 2 +- .../com/arangodb/internal/net/ExtendedHostResolver.java | 5 +++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionImpl.java index 7212c2e91..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.fasterxml.jackson.databind.JsonNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -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), JsonNode.class); + executor.execute(documentExistsRequest(key, options), Void.class); return true; } catch (final ArangoDBException e) { diff --git a/src/main/java/com/arangodb/internal/InternalArangoCollection.java b/src/main/java/com/arangodb/internal/InternalArangoCollection.java index 3bfd2d792..3840fd7a2 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoCollection.java +++ b/src/main/java/com/arangodb/internal/InternalArangoCollection.java @@ -96,9 +96,8 @@ protected Request insertDocumentRequest(final T value, final DocumentCreateO protected ResponseDeserializer> insertDocumentResponseDeserializer( final T value, final DocumentCreateOptions options) { return response -> { - final JsonNode body = getSerde().parse(response.getBody()); Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, value.getClass()); - final DocumentCreateEntity doc = getSerde().deserialize(body, type); + 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()); @@ -248,9 +247,8 @@ protected Request replaceDocumentRequest( protected ResponseDeserializer> replaceDocumentResponseDeserializer( final T value, final DocumentReplaceOptions options) { return response -> { - final JsonNode body = getSerde().parse(response.getBody()); Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, value.getClass()); - final DocumentUpdateEntity doc = getSerde().deserialize(body, type); + 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()); diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 2f36609cb..97d9707af 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -110,7 +110,7 @@ protected Request getCollectionsRequest(final CollectionsReadOptions options) { } protected ResponseDeserializer> getCollectionsResponseDeserializer() { - return response -> getSerde().deserialize(getSerde().parse(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER), + return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, SerdeUtils.INSTANCE.constructListType(CollectionEntity.class)); } diff --git a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java index 7f4e6a9fa..5d617c942 100644 --- a/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java +++ b/src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java @@ -121,8 +121,9 @@ private Collection resolveFromServer() throws ArangoDBException { response = executor.execute( new Request(DbName.SYSTEM, RequestType.GET, "/_api/cluster/endpoints"), response1 -> { - final Collection> tmp = arangoSerialization.deserialize(response1.getBody(), "/endpoints", - SerdeUtils.INSTANCE.constructMapType(String.class, String.class)); + 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")); From 453a38ea1ed1f32fd1ed36f397934dce7c471ae7 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 27 Jul 2022 10:25:33 +0200 Subject: [PATCH 43/52] replaced model arrays with collections --- .../entity/arangosearch/CollectionLink.java | 11 +++--- .../entity/arangosearch/FieldLink.java | 11 +++--- .../com/arangodb/model/AqlQueryOptions.java | 34 ++++++++----------- .../model/CollectionCreateOptions.java | 9 +++-- .../com/arangodb/model/CollectionSchema.java | 8 ----- .../arangodb/model/GraphCreateOptions.java | 5 ++- .../model/TransactionCollectionOptions.java | 7 ++-- .../com/arangodb/ArangoCollectionTest.java | 3 +- 8 files changed, 36 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java index 0e8b3c2d9..d358e24d0 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java @@ -28,7 +28,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -38,17 +37,15 @@ 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<>(); } /** @@ -67,7 +64,7 @@ public static CollectionLink on(@JsonProperty("name") final String name) { * @return link */ public CollectionLink analyzers(final String... analyzers) { - this.analyzers.addAll(Arrays.asList(analyzers)); + this.analyzers = Arrays.asList(analyzers); return this; } @@ -106,7 +103,7 @@ public CollectionLink storeValues(final StoreValuesType storeValues) { */ @JsonDeserialize(using = InternalDeserializers.FieldLinksDeserializer.class) public CollectionLink fields(final FieldLink... fields) { - this.fields.addAll(Arrays.asList(fields)); + this.fields = Arrays.asList(fields); return this; } diff --git a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java index f4374f52e..cb3a851dc 100644 --- a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java +++ b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java @@ -6,24 +6,21 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; 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<>(); } /** @@ -42,7 +39,7 @@ public static FieldLink on(@JsonProperty("name") final String name) { * @return link */ public FieldLink analyzers(final String... analyzers) { - this.analyzers.addAll(Arrays.asList(analyzers)); + this.analyzers = Arrays.asList(analyzers); return this; } @@ -80,7 +77,7 @@ 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; } diff --git a/src/main/java/com/arangodb/model/AqlQueryOptions.java b/src/main/java/com/arangodb/model/AqlQueryOptions.java index dd85a40b1..9fe1e4a65 100644 --- a/src/main/java/com/arangodb/model/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/model/AqlQueryOptions.java @@ -22,7 +22,6 @@ import com.arangodb.serde.UserDataInside; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -128,7 +127,7 @@ public AqlQueryOptions cache(final Boolean cache) { } public Boolean getFillBlockCache() { - return options != null ? options.fillBlockCache : null; + return getOptions().fillBlockCache; } /** @@ -175,7 +174,7 @@ public AqlQueryOptions query(final String query) { } public Boolean getFailOnWarning() { - return options != null ? options.failOnWarning : null; + return getOptions().failOnWarning; } /** @@ -206,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; } /** @@ -220,7 +219,7 @@ public AqlQueryOptions profile(final Boolean profile) { } public Long getMaxTransactionSize() { - return options != null ? options.maxTransactionSize : null; + return getOptions().maxTransactionSize; } /** @@ -234,7 +233,7 @@ public AqlQueryOptions maxTransactionSize(final Long maxTransactionSize) { } public Long getMaxWarningCount() { - return options != null ? options.maxWarningCount : null; + return getOptions().maxWarningCount; } /** @@ -249,7 +248,7 @@ public AqlQueryOptions maxWarningCount(final Long maxWarningCount) { } public Long getIntermediateCommitCount() { - return options != null ? options.intermediateCommitCount : null; + return getOptions().intermediateCommitCount; } /** @@ -264,7 +263,7 @@ public AqlQueryOptions intermediateCommitCount(final Long intermediateCommitCoun } public Long getIntermediateCommitSize() { - return options != null ? options.intermediateCommitSize : null; + return getOptions().intermediateCommitSize; } /** @@ -279,7 +278,7 @@ public AqlQueryOptions intermediateCommitSize(final Long intermediateCommitSize) } public Double getSatelliteSyncWait() { - return options != null ? options.satelliteSyncWait : null; + return getOptions().satelliteSyncWait; } /** @@ -295,7 +294,7 @@ public AqlQueryOptions satelliteSyncWait(final Double satelliteSyncWait) { } public Boolean getSkipInaccessibleCollections() { - return options != null ? options.skipInaccessibleCollections : null; + return getOptions().skipInaccessibleCollections; } /** @@ -314,7 +313,7 @@ public AqlQueryOptions skipInaccessibleCollections(final Boolean skipInaccessibl } public Boolean getFullCount() { - return options != null ? options.fullCount : null; + return getOptions().fullCount; } /** @@ -335,7 +334,7 @@ public AqlQueryOptions fullCount(final Boolean fullCount) { } public Integer getMaxPlans() { - return options != null ? options.maxPlans : null; + return getOptions().maxPlans; } /** @@ -348,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; } /** @@ -363,7 +362,7 @@ public AqlQueryOptions rules(final Collection rules) { } public Boolean getStream() { - return options != null ? options.stream : null; + return getOptions().stream; } /** @@ -385,7 +384,7 @@ public AqlQueryOptions stream(final Boolean stream) { } public Collection getShardIds() { - return options != null ? options.shardIds : null; + return getOptions().shardIds; } /** @@ -395,7 +394,7 @@ public Collection getShardIds() { * @return options */ public AqlQueryOptions shardIds(final String... shardIds) { - getOptions().getShardIds().addAll(Arrays.asList(shardIds)); + getOptions().shardIds = Arrays.asList(shardIds); return this; } @@ -484,9 +483,6 @@ public Optimizer getOptimizer() { } public Collection getShardIds() { - if (shardIds == null) { - shardIds = new ArrayList<>(); - } return shardIds; } diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index 4acf37754..fa7ebc9db 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -25,6 +25,9 @@ import com.arangodb.entity.KeyType; import com.arangodb.entity.ReplicationFactor; +import java.util.Arrays; +import java.util.Collection; + /** * @author Mark Vollmary * @see API @@ -37,7 +40,7 @@ public final class CollectionCreateOptions { private Integer writeConcern; private KeyOptions keyOptions; private Boolean waitForSync; - private String[] shardKeys = new String[]{}; + private Collection shardKeys; private Integer numberOfShards; private Boolean isSystem; private CollectionType type; @@ -148,7 +151,7 @@ public CollectionCreateOptions waitForSync(final Boolean waitForSync) { return this; } - public String[] getShardKeys() { + public Collection getShardKeys() { return shardKeys; } @@ -161,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/CollectionSchema.java b/src/main/java/com/arangodb/model/CollectionSchema.java index 231d19616..40c5c539b 100644 --- a/src/main/java/com/arangodb/model/CollectionSchema.java +++ b/src/main/java/com/arangodb/model/CollectionSchema.java @@ -35,14 +35,6 @@ */ public final 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); - private String rule; private Level level; private String message; diff --git a/src/main/java/com/arangodb/model/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index 7261065b7..83cb05363 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Collections; /** * @author Mark Vollmary @@ -34,8 +33,8 @@ public final class GraphCreateOptions { private String name; - private Collection edgeDefinitions = Collections.emptyList(); - private Collection orphanCollections = Collections.emptyList(); + private Collection edgeDefinitions; + private Collection orphanCollections; private Boolean isSmart; private SmartOptions options; diff --git a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java index ade09ba96..ce1d4e466 100644 --- a/src/main/java/com/arangodb/model/TransactionCollectionOptions.java +++ b/src/main/java/com/arangodb/model/TransactionCollectionOptions.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Collections; /** * @author Mark Vollmary @@ -30,9 +29,9 @@ */ public final class TransactionCollectionOptions { - private Collection read = Collections.emptyList(); - private Collection write = Collections.emptyList(); - private Collection exclusive = Collections.emptyList(); + private Collection read; + private Collection write; + private Collection exclusive; private Boolean allowImplicit; public Collection getRead() { diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 843bd6c18..8e58b4c8b 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -2582,7 +2582,8 @@ void changeProperties(ArangoCollection collection) { } // revert changes - CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions().waitForSync(properties.getWaitForSync()).schema(CollectionSchema.NULL_SCHEMA)); + CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions() + .waitForSync(properties.getWaitForSync()).schema(new CollectionSchema())); if (isAtLeastVersion(3, 7)) { assertThat(revertedProperties.getSchema()).isNull(); } From 870736134bcb4978320a915898d5e84c9855f8b7 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 27 Jul 2022 13:48:50 +0200 Subject: [PATCH 44/52] native image support --- pom.xml | 3 +- .../async/internal/ArangoCursorAsyncImpl.java | 2 +- .../internal/ArangoDatabaseAsyncImpl.java | 2 +- .../internal/ArangoCursorExecute.java | 2 +- .../arangodb/internal/ArangoDatabaseImpl.java | 2 +- .../internal/cursor/ArangoCursorImpl.java | 3 +- .../internal/cursor/ArangoCursorIterator.java | 1 + .../{ => entity}/InternalCursorEntity.java | 2 +- .../util/ArangoCursorInitializer.java | 2 +- .../arangodb-java-driver/reflect-config.json | 1558 +++++++---------- src/test/java/helper/NativeImageHelper.java | 54 +- .../META-INF/native-image/reflect-config.json | 351 +--- 12 files changed, 683 insertions(+), 1299 deletions(-) rename src/main/java/com/arangodb/internal/cursor/{ => entity}/InternalCursorEntity.java (98%) diff --git a/pom.xml b/pom.xml index 649739b52..fa82b22d5 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.11 + 0.9.13 true @@ -102,6 +102,7 @@ + true false --no-fallback diff --git a/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoCursorAsyncImpl.java index f2ac9c93b..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.internal.cursor.InternalCursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; import com.arangodb.internal.cursor.ArangoCursorImpl; diff --git a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java index 22f300325..0e390e736 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java @@ -28,7 +28,7 @@ import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.ArangoErrors; import com.arangodb.internal.InternalArangoDatabase; -import com.arangodb.internal.cursor.InternalCursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; diff --git a/src/main/java/com/arangodb/internal/ArangoCursorExecute.java b/src/main/java/com/arangodb/internal/ArangoCursorExecute.java index b9462b076..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.internal.cursor.InternalCursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import java.util.Map; diff --git a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java index 3c1ad65e2..f02e8c516 100644 --- a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java @@ -24,7 +24,7 @@ import com.arangodb.entity.*; import com.arangodb.entity.arangosearch.analyzer.SearchAnalyzer; import com.arangodb.internal.cursor.ArangoCursorImpl; -import com.arangodb.internal.cursor.InternalCursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; import com.arangodb.model.*; diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java index 40ece0f7d..1af8097fb 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java @@ -24,7 +24,8 @@ import com.arangodb.ArangoIterator; import com.arangodb.entity.CursorStats; import com.arangodb.entity.CursorWarning; -import com.arangodb.internal.cursor.InternalCursorEntity.Extras; +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; diff --git a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java index b3b048158..f34f3203a 100644 --- a/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java +++ b/src/main/java/com/arangodb/internal/cursor/ArangoCursorIterator.java @@ -24,6 +24,7 @@ import com.arangodb.ArangoIterator; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.fasterxml.jackson.databind.JsonNode; import java.util.Iterator; diff --git a/src/main/java/com/arangodb/internal/cursor/InternalCursorEntity.java b/src/main/java/com/arangodb/internal/cursor/entity/InternalCursorEntity.java similarity index 98% rename from src/main/java/com/arangodb/internal/cursor/InternalCursorEntity.java rename to src/main/java/com/arangodb/internal/cursor/entity/InternalCursorEntity.java index a85999902..56f428f67 100644 --- a/src/main/java/com/arangodb/internal/cursor/InternalCursorEntity.java +++ b/src/main/java/com/arangodb/internal/cursor/entity/InternalCursorEntity.java @@ -18,7 +18,7 @@ * Copyright holder is ArangoDB GmbH, Cologne, Germany */ -package com.arangodb.internal.cursor; +package com.arangodb.internal.cursor.entity; import com.arangodb.entity.CursorStats; import com.arangodb.entity.CursorWarning; diff --git a/src/main/java/com/arangodb/util/ArangoCursorInitializer.java b/src/main/java/com/arangodb/util/ArangoCursorInitializer.java index 9d0b2169c..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.internal.cursor.InternalCursorEntity; +import com.arangodb.internal.cursor.entity.InternalCursorEntity; import com.arangodb.internal.ArangoCursorExecute; import com.arangodb.internal.InternalArangoDatabase; 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/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/resources/META-INF/native-image/reflect-config.json b/src/test/resources/META-INF/native-image/reflect-config.json index f3181a2c9..717f0a566 100644 --- a/src/test/resources/META-INF/native-image/reflect-config.json +++ b/src/test/resources/META-INF/native-image/reflect-config.json @@ -74,12 +74,16 @@ ] }, { - "name": "com.arangodb.ArangoCollectionTest$TestUpdateEntity", - "allDeclaredFields": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredConstructors": true, - "allDeclaredClasses": true + "name":"com.arangodb.ArangoCollectionTest$TestUpdateEntity", + "allDeclaredFields":true, + "allDeclaredMethods":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,11 @@ "name": "java.util.HashSet", "allDeclaredMethods": true, "allDeclaredConstructors": true + }, + { + "name":"com.arangodb.mapping.annotations.AnnotatedEntity", + "allDeclaredFields":true, + "allDeclaredMethods":true, + "allDeclaredConstructors":true } ] From 18a3e8d9c10094789de12543ccdcc7dc78338fb3 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 28 Jul 2022 10:04:10 +0200 Subject: [PATCH 45/52] removed VPack tests --- .../VPackSerializeDeserializeTest.java | 3304 ----------------- 1 file changed, 3304 deletions(-) delete mode 100644 src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java 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 ceefb66a0..000000000 --- a/src/test/java/com/arangodb/mapping/VPackSerializeDeserializeTest.java +++ /dev/null @@ -1,3304 +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; - -// TODO: move these tests to velocypack-java project - -//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); -// } -// -// -//} From f32d1b665db697704aab1973274f379166b9bd54 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 28 Jul 2022 10:06:56 +0200 Subject: [PATCH 46/52] removed dep on velocypack --- pom.xml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pom.xml b/pom.xml index fa82b22d5..a7893e292 100644 --- a/pom.xml +++ b/pom.xml @@ -234,10 +234,6 @@ - - com.arangodb - velocypack - org.slf4j slf4j-api @@ -318,11 +314,6 @@ commons-logging 1.2 - - com.arangodb - velocypack - 2.5.4 - org.slf4j slf4j-api From c00dc6fc7569c92fbea0b9d929dfa93244257ebc Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 28 Jul 2022 13:46:13 +0200 Subject: [PATCH 47/52] implemented MapperProvider to isolate references to optional VPackMapper --- .../java/com/arangodb/serde/InternalSerde.java | 10 +--------- .../java/com/arangodb/serde/JacksonSerde.java | 9 +-------- .../com/arangodb/serde/JsonMapperProvider.java | 12 ++++++++++++ .../java/com/arangodb/serde/MapperProvider.java | 17 +++++++++++++++++ .../com/arangodb/serde/VPackMapperProvider.java | 13 +++++++++++++ 5 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/arangodb/serde/JsonMapperProvider.java create mode 100644 src/main/java/com/arangodb/serde/MapperProvider.java create mode 100644 src/main/java/com/arangodb/serde/VPackMapperProvider.java diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 04215e6ee..05b175276 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -1,8 +1,6 @@ package com.arangodb.serde; -import com.arangodb.jackson.dataformat.velocypack.VPackMapper; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import java.lang.reflect.Type; import java.util.Collection; @@ -16,13 +14,7 @@ public interface InternalSerde extends JacksonSerde { * @return the created InternalSerde */ static InternalSerde of(final DataType dataType, ArangoSerde userSerde) { - if (dataType == DataType.JSON) { - return new InternalSerdeImpl(new ObjectMapper(), userSerde); - } else if (dataType == DataType.VPACK) { - return new InternalSerdeImpl(new VPackMapper(), userSerde); - } else { - throw new IllegalArgumentException("Unexpected value: " + dataType); - } + return new InternalSerdeImpl(MapperProvider.of(dataType), userSerde); } /** diff --git a/src/main/java/com/arangodb/serde/JacksonSerde.java b/src/main/java/com/arangodb/serde/JacksonSerde.java index c7c0ae2f0..c6fe4b1ed 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerde.java +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -1,6 +1,5 @@ package com.arangodb.serde; -import com.arangodb.jackson.dataformat.velocypack.VPackMapper; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.function.Consumer; @@ -17,13 +16,7 @@ public interface JacksonSerde extends ArangoSerde { * @return the created JacksonSerde */ static JacksonSerde of(final DataType dataType) { - if (dataType == DataType.JSON) { - return of(new ObjectMapper()); - } else if (dataType == DataType.VPACK) { - return of(new VPackMapper()); - } else { - throw new IllegalArgumentException("Unexpected value: " + dataType); - } + return of(MapperProvider.of(dataType)); } /** 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/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/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(); + } +} From 949022aa73b07442e752f756ef2a7e6e6104d5e7 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 28 Jul 2022 14:31:20 +0200 Subject: [PATCH 48/52] serialize/deserialize JsonNode with internal serde --- .../java/com/arangodb/serde/InternalSerde.java | 4 +--- .../com/arangodb/serde/InternalSerdeImpl.java | 16 +++++++++++++--- .../java/com/arangodb/ArangoDatabaseTest.java | 8 ++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/arangodb/serde/InternalSerde.java b/src/main/java/com/arangodb/serde/InternalSerde.java index 05b175276..2fcafb358 100644 --- a/src/main/java/com/arangodb/serde/InternalSerde.java +++ b/src/main/java/com/arangodb/serde/InternalSerde.java @@ -121,9 +121,7 @@ default T deserialize(byte[] content, String jsonPointer, Type type) { * @param clazz class of target data type * @return deserialized object */ - default T deserializeUserData(byte[] content, Class clazz) { - return deserializeUserData(content, (Type) clazz); - } + T deserializeUserData(byte[] content, Class clazz); /** * Deserializes the content and binds it to the target data type, using the user serde. diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index ae978c7fd..f5f1b097a 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -67,7 +67,8 @@ public JsonNode parse(byte[] content, String jsonPointer) { @Override public byte[] serializeUserData(Object value) { - if (value != null && (RawJson.class.equals(value.getClass()) || RawBytes.class.equals(value.getClass()))) { + Class clazz = value.getClass(); + if (RawJson.class.equals(clazz) || RawBytes.class.equals(clazz) || JsonNode.class.isAssignableFrom(clazz)) { return serialize(value); } else { return userSerde.serialize(value); @@ -83,10 +84,19 @@ public byte[] serializeCollectionUserData(Collection value) { return serialize(jsonNodeCollection); } + @Override + public T deserializeUserData(byte[] content, Class clazz) { + if (RawJson.class.isAssignableFrom(clazz) || RawBytes.class.isAssignableFrom(clazz) || JsonNode.class.isAssignableFrom(clazz)) { + return deserialize(content, clazz); + } else { + return userSerde.deserialize(content, clazz); + } + } + @Override public T deserializeUserData(byte[] content, Type type) { - if (RawJson.class.equals(type) || RawBytes.class.equals(type)) { - return deserialize(content, type); + if (type instanceof Class) { + return deserializeUserData(content, (Class) type); } else { return userSerde.deserialize(content, type); } diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 1e4054984..ce781e18e 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -536,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) { From fd3d5fbd16384f9a0fdbd2ca6e84ff659dd8ee63 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 28 Jul 2022 14:49:24 +0200 Subject: [PATCH 49/52] date serde tests --- .../java/com/arangodb/serde/SerdeTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/com/arangodb/serde/SerdeTest.java b/src/test/java/com/arangodb/serde/SerdeTest.java index 6e924e4fb..75c374659 100644 --- a/src/test/java/com/arangodb/serde/SerdeTest.java +++ b/src/test/java/com/arangodb/serde/SerdeTest.java @@ -2,12 +2,15 @@ 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; @@ -35,4 +38,32 @@ void rawBytesSerde(DataType type) { 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); + } + } From 99ff26d6cccf4ad7cfbb6457ccc78e39adf95e9c Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 28 Jul 2022 17:42:52 +0200 Subject: [PATCH 50/52] test with different jackson versions --- .github/workflows/maven.yml | 43 +++++++++++++++++++ pom.xml | 20 +++++++++ .../arangodb/serde/InternalDeserializers.java | 22 ++++++---- .../com/arangodb/serde/InternalSerdeImpl.java | 4 ++ .../java/com/arangodb/serde/SerdeUtils.java | 18 ++++++++ .../com/arangodb/ArangoCollectionTest.java | 1 - 6 files changed, 99 insertions(+), 9 deletions(-) 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 a7893e292..1f59e16d8 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ UTF-8 + 2.13.3 @@ -242,6 +243,18 @@ 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 @@ -289,6 +302,13 @@ + + com.fasterxml.jackson + jackson-bom + ${jackson.version} + import + pom + com.arangodb jackson-dataformat-velocypack diff --git a/src/main/java/com/arangodb/serde/InternalDeserializers.java b/src/main/java/com/arangodb/serde/InternalDeserializers.java index 0a33aa444..f571b5f5b 100644 --- a/src/main/java/com/arangodb/serde/InternalDeserializers.java +++ b/src/main/java/com/arangodb/serde/InternalDeserializers.java @@ -11,11 +11,10 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.TreeNode; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.NumericNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.TextNode; +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; @@ -26,6 +25,13 @@ 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 @@ -37,7 +43,7 @@ public Collection deserialize(JsonParser p, DeserializationConte Map.Entry e = it.next(); ObjectNode v = (ObjectNode) e.getValue(); v.put("name", e.getKey()); - out.add(ctxt.readTreeAsValue(v, CollectionLink.class)); + out.add(readTreeAsValue(p, ctxt, v, CollectionLink.class)); } return out; } @@ -54,7 +60,7 @@ public FieldLink[] deserialize(JsonParser p, DeserializationContext ctxt) throws Map.Entry e = it.next(); ObjectNode v = (ObjectNode) e.getValue(); v.put("name", e.getKey()); - out.add(ctxt.readTreeAsValue(v, FieldLink.class)); + out.add(readTreeAsValue(p, ctxt, v, FieldLink.class)); } return out.toArray(new FieldLink[0]); } @@ -126,7 +132,7 @@ public Response deserialize(final JsonParser p, final DeserializationContext ctx response.setType(it.next().intValue()); response.setResponseCode(it.next().intValue()); if (it.hasNext()) { - response.setMeta(ctxt.readTreeAsValue(it.next(), Map.class)); + response.setMeta(readTreeAsValue(p, ctxt, it.next(), Map.class)); } return response; } diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index f5f1b097a..68fa1a1d3 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -17,6 +17,10 @@ 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; diff --git a/src/main/java/com/arangodb/serde/SerdeUtils.java b/src/main/java/com/arangodb/serde/SerdeUtils.java index c93677825..87eb13d3d 100644 --- a/src/main/java/com/arangodb/serde/SerdeUtils.java +++ b/src/main/java/com/arangodb/serde/SerdeUtils.java @@ -1,6 +1,7 @@ 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; @@ -9,8 +10,11 @@ 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; @@ -68,4 +72,18 @@ public Type convertToType(final JavaType javaType) { 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/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 8e58b4c8b..07e173e79 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -41,7 +41,6 @@ import com.arangodb.util.RawBytes; import com.arangodb.util.RawJson; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonIncludeProperties; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeAll; From 40c2c59e89fbd71d6bb93e1c42a5b9616b9dc6da Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Fri, 29 Jul 2022 14:29:40 +0200 Subject: [PATCH 51/52] JSON-B serde --- pom.xml | 11 +++ .../com/arangodb/entity/BaseDocument.java | 3 + src/main/java/com/arangodb/entity/From.java | 4 + src/main/java/com/arangodb/entity/Id.java | 4 + src/main/java/com/arangodb/entity/Key.java | 4 + src/main/java/com/arangodb/entity/Rev.java | 4 + src/main/java/com/arangodb/entity/To.java | 4 + .../java/com/arangodb/serde/ArangoSerde.java | 2 +- .../com/arangodb/serde/InternalSerdeImpl.java | 13 +++- .../java/com/arangodb/serde/JacksonSerde.java | 6 +- .../java/com/arangodb/serde/JsonbSerde.java | 29 +++++++ .../com/arangodb/serde/JsonbSerdeImpl.java | 32 ++++++++ .../com/arangodb/ArangoCollectionTest.java | 4 +- .../java/com/arangodb/ArangoDatabaseTest.java | 8 +- src/test/java/com/arangodb/BaseJunit5.java | 13 ++-- .../arangodb/async/serde/CustomSerdeTest.java | 76 ++++++++++--------- .../com/arangodb/serde/CustomSerdeTest.java | 76 ++++++++++--------- 17 files changed, 203 insertions(+), 90 deletions(-) create mode 100644 src/main/java/com/arangodb/serde/JsonbSerde.java create mode 100644 src/main/java/com/arangodb/serde/JsonbSerdeImpl.java diff --git a/pom.xml b/pom.xml index 1f59e16d8..355b4c4dc 100644 --- a/pom.xml +++ b/pom.xml @@ -260,6 +260,11 @@ jackson-dataformat-velocypack true + + jakarta.json.bind + jakarta.json.bind-api + 3.0.0 + ch.qos.logback logback-classic @@ -298,6 +303,12 @@ 22.1.0 test + + org.eclipse + yasson + 3.0.0 + test + diff --git a/src/main/java/com/arangodb/entity/BaseDocument.java b/src/main/java/com/arangodb/entity/BaseDocument.java index 72ea06cdc..1946afda1 100644 --- a/src/main/java/com/arangodb/entity/BaseDocument.java +++ b/src/main/java/com/arangodb/entity/BaseDocument.java @@ -23,6 +23,7 @@ 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; @@ -94,6 +95,7 @@ public void setRevision(final String revision) { this.revision = revision; } + @JsonInclude @JsonAnyGetter public Map getProperties() { return properties; @@ -103,6 +105,7 @@ 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/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/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/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/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/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/serde/ArangoSerde.java b/src/main/java/com/arangodb/serde/ArangoSerde.java index f682ec35a..f09e1d2f6 100644 --- a/src/main/java/com/arangodb/serde/ArangoSerde.java +++ b/src/main/java/com/arangodb/serde/ArangoSerde.java @@ -13,7 +13,7 @@ * - 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#of(com.fasterxml.jackson.databind.ObjectMapper)}) or configured + * custom configured ObjectMapper ({@link JacksonSerde#create(com.fasterxml.jackson.databind.ObjectMapper)}) or configured * after creation through {@link JacksonSerde#configure(Consumer)}. */ public interface ArangoSerde { diff --git a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java index 68fa1a1d3..2922c6544 100644 --- a/src/main/java/com/arangodb/serde/InternalSerdeImpl.java +++ b/src/main/java/com/arangodb/serde/InternalSerdeImpl.java @@ -1,6 +1,7 @@ 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; @@ -72,7 +73,11 @@ public JsonNode parse(byte[] content, String jsonPointer) { @Override public byte[] serializeUserData(Object value) { Class clazz = value.getClass(); - if (RawJson.class.equals(clazz) || RawBytes.class.equals(clazz) || JsonNode.class.isAssignableFrom(clazz)) { + 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); @@ -90,7 +95,11 @@ public byte[] serializeCollectionUserData(Collection value) { @Override public T deserializeUserData(byte[] content, Class clazz) { - if (RawJson.class.isAssignableFrom(clazz) || RawBytes.class.isAssignableFrom(clazz) || JsonNode.class.isAssignableFrom(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); diff --git a/src/main/java/com/arangodb/serde/JacksonSerde.java b/src/main/java/com/arangodb/serde/JacksonSerde.java index c6fe4b1ed..122601dcf 100644 --- a/src/main/java/com/arangodb/serde/JacksonSerde.java +++ b/src/main/java/com/arangodb/serde/JacksonSerde.java @@ -5,7 +5,7 @@ import java.util.function.Consumer; /** - * Contract for serialization/deserialization of user data, based on Jackson Databind. + * User data serde based on Jackson Databind. */ public interface JacksonSerde extends ArangoSerde { @@ -16,7 +16,7 @@ public interface JacksonSerde extends ArangoSerde { * @return the created JacksonSerde */ static JacksonSerde of(final DataType dataType) { - return of(MapperProvider.of(dataType)); + return create(MapperProvider.of(dataType)); } /** @@ -25,7 +25,7 @@ static JacksonSerde of(final DataType dataType) { * @param mapper Jackson ObjectMapper to use * @return the created JacksonSerde */ - static JacksonSerde of(final ObjectMapper mapper) { + static JacksonSerde create(final ObjectMapper mapper) { return new JacksonSerdeImpl(mapper); } 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/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 07e173e79..ad980df47 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -686,7 +686,7 @@ void updateDocumentKeepNullFalse(ArangoCollection collection) { assertThat(readResult.getProperties().keySet()).doesNotContain("a"); } - static class TestUpdateEntity { + public static class TestUpdateEntity { @SuppressWarnings("unused") private String a, b; @@ -699,7 +699,7 @@ public String getB() { } } - static class TestUpdateEntitySerializeNullFalse { + public static class TestUpdateEntitySerializeNullFalse { @SuppressWarnings("unused") private String a, b; diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index ce781e18e..a63eefd24 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -1299,13 +1299,13 @@ void transactionAllowImplicit(ArangoDatabase db) { public static class TransactionTestEntity { private String value; - public TransactionTestEntity() { - super(); - } - public String getValue() { return value; } + + public void setValue(String value) { + this.value = value; + } } @ParameterizedTest(name = "{index}") diff --git a/src/test/java/com/arangodb/BaseJunit5.java b/src/test/java/com/arangodb/BaseJunit5.java index b231b4a58..506bba0ef 100644 --- a/src/test/java/com/arangodb/BaseJunit5.java +++ b/src/test/java/com/arangodb/BaseJunit5.java @@ -3,6 +3,7 @@ import com.arangodb.entity.*; 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; @@ -12,17 +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) - .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/async/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java index 2546334bd..16816ec0b 100644 --- a/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/async/serde/CustomSerdeTest.java @@ -25,7 +25,6 @@ import com.arangodb.async.ArangoCollectionAsync; import com.arangodb.async.ArangoDBAsync; import com.arangodb.async.ArangoDatabaseAsync; -import com.arangodb.entity.BaseDocument; import com.arangodb.model.DocumentCreateOptions; import com.arangodb.serde.DataType; import com.arangodb.serde.JacksonSerde; @@ -37,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; @@ -85,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/serde/CustomSerdeTest.java b/src/test/java/com/arangodb/serde/CustomSerdeTest.java index f00656d43..5fae2ba2f 100644 --- a/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -25,7 +25,6 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDatabase; import com.arangodb.DbName; -import com.arangodb.entity.BaseDocument; import com.arangodb.model.DocumentCreateOptions; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -40,6 +39,7 @@ import java.math.BigInteger; import java.util.Collections; import java.util.HashMap; +import java.util.Map; import java.util.UUID; import static com.fasterxml.jackson.databind.DeserializationFeature.USE_BIG_INTEGER_FOR_INTS; @@ -142,86 +142,90 @@ 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 From 88367ec2d5463180a74aa5c0938c882d376f98c3 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Mon, 1 Aug 2022 11:59:21 +0200 Subject: [PATCH 52/52] fixed native tests --- .../META-INF/native-image/reflect-config.json | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) 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 717f0a566..a7c217b64 100644 --- a/src/test/resources/META-INF/native-image/reflect-config.json +++ b/src/test/resources/META-INF/native-image/reflect-config.json @@ -74,16 +74,16 @@ ] }, { - "name":"com.arangodb.ArangoCollectionTest$TestUpdateEntity", - "allDeclaredFields":true, - "allDeclaredMethods":true, - "allDeclaredConstructors":true + "name": "com.arangodb.ArangoCollectionTest$TestUpdateEntity", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { - "name":"com.arangodb.ArangoCollectionTest$TestUpdateEntitySerializeNullFalse", - "allDeclaredFields":true, - "allDeclaredMethods":true, - "allDeclaredConstructors":true + "name": "com.arangodb.ArangoCollectionTest$TestUpdateEntitySerializeNullFalse", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true }, { "name": "com.arangodb.ArangoDatabaseTest$TransactionTestEntity", @@ -264,9 +264,27 @@ "allDeclaredConstructors": true }, { - "name":"com.arangodb.mapping.annotations.AnnotatedEntity", - "allDeclaredFields":true, - "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": [] + } + ] } ]