From 806747a7952a09c99b235026d3b0a71e47c83a4b Mon Sep 17 00:00:00 2001 From: datomo Date: Fri, 6 Oct 2023 00:20:19 +0200 Subject: [PATCH] fixes for jdbs output --- .../db/functions/CrossModelFunctions.java | 2 +- .../org/polypheny/db/functions/Functions.java | 3 +- .../db/type/entity/PolyBigDecimal.java | 33 +--- .../polypheny/db/type/entity/PolyBinary.java | 23 --- .../polypheny/db/type/entity/PolyBoolean.java | 28 +-- .../polypheny/db/type/entity/PolyDate.java | 23 --- .../polypheny/db/type/entity/PolyDouble.java | 24 --- .../polypheny/db/type/entity/PolyFloat.java | 23 --- .../polypheny/db/type/entity/PolyInteger.java | 28 +-- .../db/type/entity/PolyInterval.java | 32 ---- .../polypheny/db/type/entity/PolyList.java | 75 +------- .../polypheny/db/type/entity/PolyLong.java | 23 --- .../polypheny/db/type/entity/PolyNull.java | 29 --- .../polypheny/db/type/entity/PolyString.java | 34 +--- .../polypheny/db/type/entity/PolySymbol.java | 36 ---- .../polypheny/db/type/entity/PolyTime.java | 24 --- .../db/type/entity/PolyTimeStamp.java | 24 --- .../polypheny/db/type/entity/PolyValue.java | 166 +++++++++--------- .../db/type/entity/category/PolyBlob.java | 10 -- .../db/type/entity/category/PolyNumber.java | 5 - .../db/type/entity/document/PolyDocument.java | 40 ----- .../db/type/entity/graph/GraphObject.java | 4 - .../entity/graph/GraphPropertyHolder.java | 7 +- .../db/type/entity/graph/PolyDictionary.java | 38 +--- .../db/type/entity/graph/PolyEdge.java | 39 ---- .../db/type/entity/graph/PolyGraph.java | 32 ---- .../db/type/entity/graph/PolyNode.java | 33 ---- .../java/org/polypheny/db/util/BsonUtil.java | 4 +- .../org/polypheny/db/util/LimitIterator.java | 10 +- .../java/org/polypheny/db/TestHelper.java | 2 +- .../db/cypher/CypherTestTemplate.java | 79 +-------- .../db/cypher/helper/TestGraphObject.java | 4 +- .../polypheny/db/cypher/helper/TestPath.java | 4 +- .../org/polypheny/db/avatica/DbmsMeta.java | 39 ++-- .../avatica/PolyphenyDbStatementHandle.java | 6 +- .../db/adapter/jdbc/ResultSetEnumerable.java | 2 +- .../adapter/jdbc/rel2sql/SqlImplementor.java | 2 +- .../mongodb/rules/MongoDocumentModify.java | 2 +- .../mongodb/rules/MongoTableModify.java | 2 +- .../db/adapter/neo4j/util/NeoUtil.java | 2 +- .../java/org/polypheny/db/webui/Crud.java | 2 +- .../org/polypheny/db/webui/WebSocket.java | 2 +- .../polypheny/db/webui/crud/LanguageCrud.java | 2 +- .../models/results/RelationalResult.java | 1 - 44 files changed, 162 insertions(+), 841 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/functions/CrossModelFunctions.java b/core/src/main/java/org/polypheny/db/functions/CrossModelFunctions.java index fdc64eadb0..4c211341e6 100644 --- a/core/src/main/java/org/polypheny/db/functions/CrossModelFunctions.java +++ b/core/src/main/java/org/polypheny/db/functions/CrossModelFunctions.java @@ -231,7 +231,7 @@ private static void nodePropertiesTableInsert( DataContext context, List( node.properties.keySet() ) ); - context.addParameterValues( 2, valueType, new ArrayList<>( node.properties.values().stream().map( e -> PolyString.of( e.toJson() ) ).collect( Collectors.toList() ) ) ); + context.addParameterValues( 2, valueType, new ArrayList<>( node.properties.values().stream().map( e -> PolyString.of( e.toJsonOrNull() ) ).collect( Collectors.toList() ) ) ); drainInserts( enumerables.get( i ), node.properties.size() ); context.resetParameterValues(); } diff --git a/core/src/main/java/org/polypheny/db/functions/Functions.java b/core/src/main/java/org/polypheny/db/functions/Functions.java index 4aeaaa5de3..f287b773dd 100644 --- a/core/src/main/java/org/polypheny/db/functions/Functions.java +++ b/core/src/main/java/org/polypheny/db/functions/Functions.java @@ -3189,12 +3189,13 @@ public static PolyValue itemOptional( Map object, PolyValu } + @SuppressWarnings("unused") public static List reparse( PolyType innerType, Long dimension, String stringValue ) { //Type conversionType = PolyTypeUtil.createNestedListType( dimension, innerType ); if ( stringValue == null ) { return null; } - return PolyValue.GSON.fromJson( stringValue, PolyList.class ); + return PolyValue.readJsonOrNull( stringValue, PolyList.class ).asList(); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java b/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java index 4ba531cb21..93eb815664 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java @@ -16,20 +16,16 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import com.fasterxml.jackson.annotation.JsonProperty; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; import io.activej.serializer.CompatibilityLevel; import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; -import java.lang.reflect.Type; +import io.activej.serializer.annotations.Deserialize; +import io.activej.serializer.annotations.Serialize; +import io.activej.serializer.annotations.SerializeNullable; import java.math.BigDecimal; import java.math.MathContext; import java.util.Objects; @@ -47,10 +43,13 @@ @Slf4j public class PolyBigDecimal extends PolyNumber { + @JsonProperty + @Serialize + @SerializeNullable public BigDecimal value; - public PolyBigDecimal( BigDecimal value ) { + public PolyBigDecimal( @JsonProperty @Deserialize("value") BigDecimal value ) { super( PolyType.DECIMAL ); this.value = value; } @@ -246,20 +245,4 @@ public PolyBigDecimal decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyBigDecimalSerializer implements JsonDeserializer, JsonSerializer { - - - @Override - public PolyBigDecimal deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyBigDecimal.of( json.getAsBigDecimal() ); - } - - - @Override - public JsonElement serialize( PolyBigDecimal src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java b/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java index 522691eedd..e0e4e40646 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import lombok.EqualsAndHashCode; import lombok.Value; import org.apache.calcite.avatica.util.ByteString; @@ -123,19 +115,4 @@ public int getBitCount() { } - public static class PolyBinarySerializer implements JsonSerializer, JsonDeserializer { - - @Override - public JsonElement serialize( PolyBinary src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value.toBase64String() ); - } - - - @Override - public PolyBinary deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyBinary.of( ByteString.ofBase64( json.getAsString() ) ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java b/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java index 8dd56250f9..81d51119af 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java @@ -16,13 +16,7 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import com.fasterxml.jackson.annotation.JsonProperty; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -32,7 +26,6 @@ import io.activej.serializer.annotations.Deserialize; import io.activej.serializer.annotations.Serialize; import io.activej.serializer.annotations.SerializeNullable; -import java.lang.reflect.Type; import lombok.EqualsAndHashCode; import lombok.Value; import org.apache.calcite.linq4j.tree.Expression; @@ -51,11 +44,12 @@ public class PolyBoolean extends PolyValue { public static final PolyBoolean FALSE = PolyBoolean.of( false ); @Serialize + @JsonProperty @SerializeNullable public Boolean value; - public PolyBoolean( @Deserialize("value") Boolean value ) { + public PolyBoolean( @JsonProperty @Deserialize("value") Boolean value ) { super( PolyType.BOOLEAN ); this.value = value; } @@ -131,22 +125,6 @@ public PolyBoolean decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyBooleanSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public PolyBoolean deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyBoolean.of( json.getAsBoolean() ); - } - - - @Override - public JsonElement serialize( PolyBoolean src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value ); - } - - } - - @Override public PolySerializable copy() { return null; diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyDate.java b/core/src/main/java/org/polypheny/db/type/entity/PolyDate.java index 8550db6ab2..73180f067f 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyDate.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyDate.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import java.util.Date; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -103,21 +95,6 @@ public Expression asExpression() { } - public static class PolyDateSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public JsonElement serialize( PolyDate src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.milliSinceEpoch ); - } - - - @Override - public PolyDate deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyDate.of( json.getAsLong() ); - } - - } - @Override public PolySerializable copy() { diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyDouble.java b/core/src/main/java/org/polypheny/db/type/entity/PolyDouble.java index 61accadab5..f5800baa33 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyDouble.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyDouble.java @@ -16,13 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -31,7 +24,6 @@ import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Deserialize; import io.activej.serializer.annotations.Serialize; -import java.lang.reflect.Type; import java.math.BigDecimal; import lombok.EqualsAndHashCode; import org.apache.calcite.linq4j.tree.Expression; @@ -188,22 +180,6 @@ public PolyDouble decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyDoubleSerializer implements JsonDeserializer, JsonSerializer { - - @Override - public PolyDouble deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyDouble.of( json.getAsDouble() ); - } - - - @Override - public JsonElement serialize( PolyDouble src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value ); - } - - } - - @Override public String toString() { return value.toString(); diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyFloat.java b/core/src/main/java/org/polypheny/db/type/entity/PolyFloat.java index 6a509b3e13..efafd164c8 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyFloat.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyFloat.java @@ -16,13 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -31,7 +24,6 @@ import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Deserialize; import io.activej.serializer.annotations.Serialize; -import java.lang.reflect.Type; import java.math.BigDecimal; import lombok.EqualsAndHashCode; import org.apache.calcite.linq4j.tree.Expression; @@ -185,21 +177,6 @@ public PolyFloat decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyFloatSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public JsonElement serialize( PolyFloat src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value ); - } - - - @Override - public PolyFloat deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyFloat.of( json.getAsFloat() ); - } - - } - @Override public String toString() { diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java b/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java index 8368a953f3..f741795e47 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java @@ -16,13 +16,7 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import com.fasterxml.jackson.annotation.JsonProperty; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -31,7 +25,6 @@ import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Deserialize; import io.activej.serializer.annotations.Serialize; -import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.MathContext; import java.util.Objects; @@ -49,10 +42,11 @@ public class PolyInteger extends PolyNumber { public static final PolyInteger ZERO = PolyInteger.of( 0 ); @Serialize + @JsonProperty public Integer value; - public PolyInteger( @Deserialize("value") Integer value ) { + public PolyInteger( @JsonProperty @Deserialize("value") Integer value ) { super( PolyType.INTEGER ); this.value = value; } @@ -242,22 +236,6 @@ public PolyInteger decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyIntegerSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public PolyInteger deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyInteger.of( json.getAsInt() ); - } - - - @Override - public JsonElement serialize( PolyInteger src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value ); - } - - } - - @Override public String toString() { return value.toString(); diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyInterval.java b/core/src/main/java/org/polypheny/db/type/entity/PolyInterval.java index 5b56ddacb3..4a3380c899 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyInterval.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyInterval.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import java.math.BigDecimal; import lombok.EqualsAndHashCode; import lombok.Value; @@ -97,28 +89,4 @@ public Long getMonths() { } - public static class PolyIntervalSerializer implements JsonSerializer, JsonDeserializer { - - - public static final String DATA = "data"; - public static final String QUALIFIER = "qualifier"; - - - @Override - public PolyInterval deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject object = json.getAsJsonObject(); - return PolyInterval.of( object.get( DATA ).getAsBigDecimal(), context.deserialize( object.get( QUALIFIER ), IntervalQualifier.class ) ); - } - - - @Override - public JsonElement serialize( PolyInterval src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject object = new JsonObject(); - object.add( QUALIFIER, context.serialize( src.qualifier ) ); - object.addProperty( DATA, src.value ); - return object; - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyList.java b/core/src/main/java/org/polypheny/db/type/entity/PolyList.java index f513b682ae..0c3b46b0a3 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyList.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyList.java @@ -16,15 +16,8 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -32,8 +25,6 @@ import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Deserialize; -import io.activej.serializer.annotations.Serialize; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -56,11 +47,12 @@ public class PolyList extends PolyValue implements List @Delegate - @Serialize + @JsonProperty + @JsonSerialize public List value; - public PolyList( @Deserialize("value") List value ) { + public PolyList( @JsonProperty @Deserialize("value") List value ) { super( PolyType.ARRAY ); this.value = new ArrayList<>( value ); } @@ -137,12 +129,6 @@ public PolySerializable copy() { } - @Override - public String toJson() { - return value == null ? "null" : value.stream().map( e -> e == null ? "null" : e.isString() ? String.format( "\"%s\"", e.asString().value ) : e.toJson() ).collect( Collectors.joining( ",", "[", "]" ) ); - } - - public static class PolyListSerializerDef extends SimpleSerializerDef> { @Override @@ -172,55 +158,4 @@ public PolyList decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyListSerializer implements JsonSerializer>, JsonDeserializer> { - - private static final String CLASSNAME = "className"; - private static final String INSTANCE = "instance"; - private static final String SIZE = "size"; - - - @Override - public JsonElement serialize( PolyList src, Type typeOfSrc, JsonSerializationContext context ) { - if ( src == null ) { - return JsonNull.INSTANCE; - } - - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty( SIZE, src.size() ); - jsonObject.addProperty( CLASSNAME, src.isEmpty() || src.value.get( 0 ) == null ? PolyValue.class.getName() : src.value.get( 0 ).getClass().getName() ); - JsonArray jsonArray = new JsonArray(); - for ( PolyValue entry : src.value ) { - if ( entry == null ) { - jsonArray.add( JsonNull.INSTANCE ); - continue; - } - jsonArray.add( context.serialize( entry, entry.getClass() ) ); - } - jsonObject.add( INSTANCE, jsonArray ); - return jsonObject; - } - - - @Override - public PolyList deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - String className = jsonObject.get( CLASSNAME ).getAsString(); - int size = jsonObject.get( SIZE ).getAsInt(); - List list = new ArrayList<>(); - - try { - Type type = Class.forName( className ); - JsonArray jsonArray = jsonObject.get( INSTANCE ).getAsJsonArray(); - for ( JsonElement element : jsonArray ) { - list.add( context.deserialize( element, type ) ); - } - } catch ( ClassNotFoundException e ) { - throw new JsonParseException( "Invalid class name: " + className, e ); - } - - return PolyList.of( list ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyLong.java b/core/src/main/java/org/polypheny/db/type/entity/PolyLong.java index 63de91d55a..c9f79d97e5 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyLong.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyLong.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.MathContext; import java.util.Objects; @@ -204,21 +196,6 @@ public static PolyLong convert( PolyValue value ) { } - public static class PolyLongSerializer implements JsonDeserializer, JsonSerializer { - - @Override - public PolyLong deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyLong.of( json.getAsLong() ); - } - - - @Override - public JsonElement serialize( PolyLong src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.value ); - } - - } - @Override public int hashCode() { diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java b/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java index 4f2b5bf7ae..b59f4f062e 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java @@ -16,20 +16,12 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; import io.activej.serializer.CompatibilityLevel; import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; -import java.lang.reflect.Type; import java.math.BigDecimal; import java.util.Map; import lombok.NonNull; @@ -66,12 +58,6 @@ public int compareTo( @NotNull PolyValue o ) { } - @Override - public String toJson() { - return "null"; - } - - @Override public @Nullable Long deriveByteSize() { return 1L; @@ -388,19 +374,4 @@ public PolyNull decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyNullSerializer implements JsonDeserializer, JsonSerializer { - - @Override - public PolyNull deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyNull.NULL; - } - - - @Override - public JsonElement serialize( PolyNull src, Type typeOfSrc, JsonSerializationContext context ) { - return JsonNull.INSTANCE; - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyString.java b/core/src/main/java/org/polypheny/db/type/entity/PolyString.java index 837b11b428..332d141a61 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyString.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyString.java @@ -16,15 +16,8 @@ package org.polypheny.db.type.entity; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Charsets; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -33,7 +26,6 @@ import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Deserialize; import io.activej.serializer.annotations.Serialize; -import java.lang.reflect.Type; import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -52,12 +44,13 @@ public class PolyString extends PolyValue { @Serialize + @JsonProperty public String value; public Charset charset; - public PolyString( @Deserialize("value") String value ) { + public PolyString( @JsonProperty @Deserialize("value") String value ) { this( value, Charsets.UTF_16 ); } @@ -139,12 +132,6 @@ public int hashCode() { } - @Override - public String toJson() { - return value; - } - - @Override public @NotNull Long deriveByteSize() { return (long) (value == null ? 1 : value.getBytes( charset ).length); @@ -197,21 +184,6 @@ public PolyString decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyStringSerializer implements JsonDeserializer, JsonSerializer { - - @Override - public PolyString deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyString.of( json.getAsString() ); - } - - - @Override - public JsonElement serialize( PolyString src, Type typeOfSrc, JsonSerializationContext context ) { - return src.value == null ? JsonNull.INSTANCE : new JsonPrimitive( src.value ); - } - - } - @Override public String toString() { diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolySymbol.java b/core/src/main/java/org/polypheny/db/type/entity/PolySymbol.java index 2c2712b9df..c60ee2e095 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolySymbol.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolySymbol.java @@ -16,15 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; -import java.util.Arrays; import lombok.EqualsAndHashCode; import lombok.Value; import org.apache.calcite.linq4j.tree.Expression; @@ -87,31 +78,4 @@ public PolySerializable copy() { } - public static class PolySymbolSerializer implements JsonSerializer, JsonDeserializer { - - - @Override - public JsonElement serialize( PolySymbol src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject object = new JsonObject(); - object.addProperty( "type", src.value.getClass().getName() ); - object.addProperty( "data", src.value.name() ); - return object; - } - - - @Override - public PolySymbol deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject object = json.getAsJsonObject(); - String className = object.get( "type" ).getAsString(); - try { - Class> clazz = (Class>) Class.forName( className ); - String name = object.get( "data" ).getAsString(); - return PolySymbol.of( Arrays.stream( clazz.getEnumConstants() ).filter( s -> s.name().equals( name ) ).findFirst().orElse( null ) ); - } catch ( ClassNotFoundException e ) { - throw new JsonParseException( "Invalid class name: " + className, e ); - } - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyTime.java b/core/src/main/java/org/polypheny/db/type/entity/PolyTime.java index 2169b484c9..d7e5ca4934 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyTime.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyTime.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import java.sql.Time; import lombok.EqualsAndHashCode; import lombok.Value; @@ -116,20 +108,4 @@ public Long getMilliSinceEpoch() { } - public static class PolyTimeSerializer implements JsonSerializer, JsonDeserializer { - - - @Override - public JsonElement serialize( PolyTime src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.ofDay ); - } - - - @Override - public PolyTime deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyTime.of( json.getAsInt() ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyTimeStamp.java b/core/src/main/java/org/polypheny/db/type/entity/PolyTimeStamp.java index 22362d030e..b1ddb8c7fa 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyTimeStamp.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyTimeStamp.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import java.sql.Time; import java.sql.Timestamp; import java.util.Date; @@ -130,20 +122,4 @@ public static PolyTimeStamp convert( PolyValue value ) { return 16L; } - - public static class PolyTimeStampSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public PolyTimeStamp deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - return PolyTimeStamp.of( json.getAsLong() ); - } - - - @Override - public JsonElement serialize( PolyTimeStamp src, Type typeOfSrc, JsonSerializationContext context ) { - return new JsonPrimitive( src.milliSinceEpoch ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java index 26e3e28b64..64ae242db3 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java @@ -16,13 +16,17 @@ package org.polypheny.db.type.entity; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -30,7 +34,6 @@ import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SerializerBuilder; import io.activej.serializer.SimpleSerializerDef; -import io.activej.serializer.annotations.Deserialize; import io.activej.serializer.annotations.Serialize; import io.activej.serializer.annotations.SerializeClass; import java.io.IOException; @@ -55,45 +58,25 @@ import org.polypheny.db.type.ArrayType; import org.polypheny.db.type.PolySerializable; import org.polypheny.db.type.PolyType; -import org.polypheny.db.type.entity.PolyBigDecimal.PolyBigDecimalSerializer; import org.polypheny.db.type.entity.PolyBigDecimal.PolyBigDecimalSerializerDef; -import org.polypheny.db.type.entity.PolyBinary.PolyBinarySerializer; -import org.polypheny.db.type.entity.PolyBoolean.PolyBooleanSerializer; import org.polypheny.db.type.entity.PolyBoolean.PolyBooleanSerializerDef; -import org.polypheny.db.type.entity.PolyDate.PolyDateSerializer; -import org.polypheny.db.type.entity.PolyDouble.PolyDoubleSerializer; import org.polypheny.db.type.entity.PolyDouble.PolyDoubleSerializerDef; -import org.polypheny.db.type.entity.PolyFloat.PolyFloatSerializer; import org.polypheny.db.type.entity.PolyFloat.PolyFloatSerializerDef; -import org.polypheny.db.type.entity.PolyInteger.PolyIntegerSerializer; import org.polypheny.db.type.entity.PolyInteger.PolyIntegerSerializerDef; -import org.polypheny.db.type.entity.PolyInterval.PolyIntervalSerializer; -import org.polypheny.db.type.entity.PolyList.PolyListSerializer; import org.polypheny.db.type.entity.PolyList.PolyListSerializerDef; -import org.polypheny.db.type.entity.PolyLong.PolyLongSerializer; -import org.polypheny.db.type.entity.PolyNull.PolyNullSerializer; import org.polypheny.db.type.entity.PolyNull.PolyNullSerializerDef; -import org.polypheny.db.type.entity.PolyString.PolyStringSerializer; import org.polypheny.db.type.entity.PolyString.PolyStringSerializerDef; -import org.polypheny.db.type.entity.PolySymbol.PolySymbolSerializer; -import org.polypheny.db.type.entity.PolyTime.PolyTimeSerializer; -import org.polypheny.db.type.entity.PolyTimeStamp.PolyTimeStampSerializer; import org.polypheny.db.type.entity.category.PolyBlob; import org.polypheny.db.type.entity.category.PolyNumber; import org.polypheny.db.type.entity.category.PolyTemporal; import org.polypheny.db.type.entity.document.PolyDocument; -import org.polypheny.db.type.entity.document.PolyDocument.PolyDocumentSerializer; import org.polypheny.db.type.entity.document.PolyDocument.PolyDocumentSerializerDef; import org.polypheny.db.type.entity.graph.PolyDictionary; -import org.polypheny.db.type.entity.graph.PolyDictionary.PolyDictionarySerializer; import org.polypheny.db.type.entity.graph.PolyDictionary.PolyDictionarySerializerDef; import org.polypheny.db.type.entity.graph.PolyEdge; -import org.polypheny.db.type.entity.graph.PolyEdge.PolyEdgeSerializer; import org.polypheny.db.type.entity.graph.PolyGraph; -import org.polypheny.db.type.entity.graph.PolyGraph.PolyGraphSerializer; import org.polypheny.db.type.entity.graph.PolyGraph.PolyGraphSerializerDef; import org.polypheny.db.type.entity.graph.PolyNode; -import org.polypheny.db.type.entity.graph.PolyNode.PolyNodeSerializer; import org.polypheny.db.type.entity.graph.PolyNode.PolyNodeSerializerDef; import org.polypheny.db.type.entity.graph.PolyPath; import org.polypheny.db.type.entity.relational.PolyMap; @@ -124,6 +107,7 @@ PolyPath.class }) // add on Constructor already exists exception public abstract class PolyValue implements Expressible, Comparable, PolySerializable { + @JsonIgnore // used internally to serialize into binary format public static BinarySerializer serializer = SerializerBuilder.create( CLASS_LOADER ) .with( PolyInteger.class, ctx -> new PolyIntegerSerializerDef() ) @@ -142,33 +126,12 @@ public abstract class PolyValue implements Expressible, Comparable, P .with( PolyGraph.class, ctx -> new PolyGraphSerializerDef() ) .build( PolyValue.class ); - // used to serialize to Json - public static final GsonBuilder GSON_BUILDER = new GsonBuilder() - .enableComplexMapKeySerialization() - .registerTypeAdapter( PolyNode.class, new PolyNodeSerializer() ) - .registerTypeAdapter( PolyEdge.class, new PolyEdgeSerializer() ) - .registerTypeAdapter( PolyDictionary.class, new PolyDictionarySerializer() ) - .registerTypeAdapter( PolyDocument.class, new PolyDocumentSerializer() ) - .registerTypeAdapter( PolyBigDecimal.class, new PolyBigDecimalSerializer() ) - .registerTypeAdapter( PolyList.class, new PolyListSerializer<>() ) - .registerTypeAdapter( PolyString.class, new PolyStringSerializer() ) - .registerTypeAdapter( PolyLong.class, new PolyLongSerializer() ) - .registerTypeAdapter( PolyInteger.class, new PolyIntegerSerializer() ) - .registerTypeAdapter( PolyBoolean.class, new PolyBooleanSerializer() ) - .registerTypeAdapter( PolyDouble.class, new PolyDoubleSerializer() ) - .registerTypeAdapter( PolyBinary.class, new PolyBinarySerializer() ) - .registerTypeAdapter( PolyFloat.class, new PolyFloatSerializer() ) - .registerTypeAdapter( PolySymbol.class, new PolySymbolSerializer() ) - .registerTypeAdapter( PolyTime.class, new PolyTimeSerializer() ) - .registerTypeAdapter( PolyDate.class, new PolyDateSerializer() ) - .registerTypeAdapter( PolyTimeStamp.class, new PolyTimeStampSerializer() ) - .registerTypeAdapter( PolyInterval.class, new PolyIntervalSerializer() ) - .registerTypeAdapter( PolyNull.class, new PolyNullSerializer() ) - .registerTypeAdapter( PolyGraph.class, new PolyGraphSerializer() ) - .registerTypeAdapter( PolyValue.class, new PolyValueTypeAdapter() ); - - - public static final Gson GSON = GSON_BUILDER.create(); + + public static final ObjectMapper JSON_WRAPPER = new ObjectMapper();/*.registerModule( new SimpleModule() + .addDeserializer( PolyValue.class, new PolyDeserializer( PolyValue.class ) ) + .addSerializer( PolyValue.class, new PolySerializer( PolyValue.class ) ) );*/ + + public static final ObjectMapper JSON_RAW = new ObjectMapper(); @Serialize @@ -176,10 +139,11 @@ public abstract class PolyValue implements Expressible, Comparable, P @NonFinal + @JsonIgnore Long byteSize; - public PolyValue( @Deserialize("type") PolyType type ) { + public PolyValue( PolyType type ) { this.type = type; } @@ -251,6 +215,26 @@ public static Function1 wrapNullableIfNecessary( Function1 E readJsonOrNull( String value, Class clazz ) { + try { + return JSON_WRAPPER.readValue( value, clazz ); + } catch ( JsonProcessingException e ) { + log.warn( "error on deserialize json" ); + return null; + } + } + + @NotNull public Optional getByteSize() { if ( byteSize == null ) { @@ -421,6 +405,7 @@ public String serialize() { @Override + @JsonIgnore public BinarySerializer getSerializer() { return (BinarySerializer) serializer; } @@ -807,11 +792,6 @@ public static PolyValue convert( PolyValue value, PolyType type ) { } - public String toJson() { - return toString(); - } - - public static class PolyValueSerializerDef extends SimpleSerializerDef { @Override @@ -835,59 +815,77 @@ public PolyValue decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyValueTypeAdapter extends TypeAdapter { + public static class PolySerializer extends StdSerializer { private static final String CLASSNAME = "className"; private static final String INSTANCE = "instance"; + protected PolySerializer( Class t ) { + super( t ); + } + + @Override - public void write( JsonWriter out, PolyValue value ) throws IOException { + public void serialize( PolyValue value, JsonGenerator gen, SerializerProvider serializers ) throws IOException { if ( value == null ) { - out.nullValue(); + gen.writeNull(); return; } - out.beginObject(); - out.name( CLASSNAME ); - out.value( value.getClass().getName() ); - out.name( INSTANCE ); - GSON.toJson( value, value.getClass(), out ); - out.endObject(); + gen.writeStartObject(); + gen.writeFieldName( CLASSNAME ); + gen.writeString( value.getClass().getName() ); + gen.writeFieldName( INSTANCE ); + gen.writeRawValue( JSON_RAW.writeValueAsString( value ) ); + gen.writeEndObject(); + } + + } + + + public static class PolyDeserializer extends StdDeserializer { + + private static final String CLASSNAME = "className"; + private static final String INSTANCE = "instance"; + + + protected PolyDeserializer( Class vc ) { + super( vc ); } @Override - public PolyValue read( JsonReader in ) throws IOException { - JsonToken token = in.peek(); - if ( token == JsonToken.NULL ) { - in.nextNull(); + public PolyValue deserialize( JsonParser p, DeserializationContext ctxt ) throws IOException, JsonProcessingException { + JsonToken token = p.currentToken(); + if ( token == JsonToken.VALUE_NULL ) { + p.nextValue(); return null; } - in.beginObject(); String className = null; PolyValue instance = null; + String name = p.nextFieldName(); - while ( in.hasNext() ) { - String name = in.nextName(); + while ( name != null ) { if ( name.equals( CLASSNAME ) ) { - className = in.nextString(); + className = p.nextTextValue(); } else if ( name.equals( INSTANCE ) ) { - Type type; + Class type; try { - type = Class.forName( className ); + type = (Class) Class.forName( className ); } catch ( ClassNotFoundException e ) { - throw new JsonParseException( "Invalid class name: " + className, e ); + throw new JsonParseException( p, "Invalid class name: " + className, e ); } - instance = GSON.fromJson( in, type ); + instance = JSON_WRAPPER.readValue( p, type ); } else { - in.skipValue(); + p.skipChildren(); } + name = p.nextFieldName(); } - in.endObject(); return instance; + } } diff --git a/core/src/main/java/org/polypheny/db/type/entity/category/PolyBlob.java b/core/src/main/java/org/polypheny/db/type/entity/category/PolyBlob.java index 0605409d1e..1a7ecd5075 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/category/PolyBlob.java +++ b/core/src/main/java/org/polypheny/db/type/entity/category/PolyBlob.java @@ -22,7 +22,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.NonFinal; @@ -92,15 +91,6 @@ public static PolyBlob of( InputStream stream ) { } - @Override - public String toJson() { - if ( value == null && stream == null ) { - return null; - } - return Arrays.toString( value ); - } - - @Override public @Nullable Long deriveByteSize() { return null; diff --git a/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java b/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java index ca247e392b..d56e1e3049 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java +++ b/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java @@ -179,9 +179,4 @@ public PolyNumber ceil( PolyNumber b1 ) { public abstract PolyNumber negate(); - @Override - public String toJson() { - return BigDecimalValue() == null ? null : BigDecimalValue().toEngineeringString(); - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java b/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java index a13691dfef..59ff11cd68 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java +++ b/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java @@ -16,15 +16,6 @@ package org.polypheny.db.type.entity.document; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -32,7 +23,6 @@ import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Deserialize; -import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -131,34 +121,4 @@ public String toString() { } - @Override - public String toJson() { - return "{" + map.entrySet().stream().map( e -> String.format( (e.getValue() != null && !e.getValue().isNull() && e.getValue().isString() ? "\"%s\":\"%s\"" : "\"%s\":%s"), e.getKey().toJson(), e.getValue() == null ? JsonNull.INSTANCE.toString() : e.getValue().toJson() ) ).collect( Collectors.joining( "," ) ) + "}"; - } - - - public static class PolyDocumentSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public PolyDocument deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject object = json.getAsJsonObject(); - Map map = new HashMap<>(); - for ( Entry entry : object.entrySet() ) { - map.put( PolyString.of( entry.getKey() ), context.deserialize( entry.getValue(), PolyValue.class ) ); - } - return new PolyDocument( map ); - } - - - @Override - public JsonElement serialize( PolyDocument src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject object = new JsonObject(); - for ( Entry entry : src.map.entrySet() ) { - object.add( entry.getKey().toString(), entry.getValue().isString() ? new JsonPrimitive( entry.getValue().asString().value ) : context.serialize( entry.getValue(), PolyValue.class ) ); - } - return object; - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/GraphObject.java b/core/src/main/java/org/polypheny/db/type/entity/graph/GraphObject.java index 5705d1897e..02dc2173c1 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/GraphObject.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/GraphObject.java @@ -44,10 +44,6 @@ protected GraphObject( PolyString id, PolyType type, PolyString variableName ) { } - public String toJson() { - return PolyValue.GSON.toJson( this ); - } - public enum GraphObjectType { GRAPH, diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/GraphPropertyHolder.java b/core/src/main/java/org/polypheny/db/type/entity/graph/GraphPropertyHolder.java index f407ca3d5c..9511e9c126 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/GraphPropertyHolder.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/GraphPropertyHolder.java @@ -16,7 +16,7 @@ package org.polypheny.db.type.entity.graph; -import com.google.gson.annotations.Expose; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.util.List; import java.util.Map.Entry; import lombok.Getter; @@ -30,9 +30,10 @@ public abstract class GraphPropertyHolder extends GraphObject { // every parameter in a PolyValue, which is used during querying needs to be wrapped - @Expose + @JsonSerialize public final PolyDictionary properties; - @Expose + + @JsonSerialize public final PolyList labels; diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java index c2a2906ea4..45058c7d3a 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java @@ -16,22 +16,12 @@ package org.polypheny.db.type.entity.graph; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; import io.activej.serializer.CompatibilityLevel; import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; -import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -46,8 +36,6 @@ public class PolyDictionary extends PolyMap { - private static Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create(); - public PolyDictionary( Map map ) { super( map ); @@ -74,7 +62,7 @@ public Expression asExpression() { public static PolyDictionary fromString( String json ) { - return gson.fromJson( json, PolyDictionary.class ); + return PolyValue.readJsonOrNull( json, PolyDictionary.class ); } @@ -110,28 +98,4 @@ public PolyDictionary decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyDictionarySerializer implements JsonSerializer, JsonDeserializer { - - @Override - public PolyDictionary deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject object = json.getAsJsonObject(); - Map map = new HashMap<>(); - for ( Entry entry : object.entrySet() ) { - map.put( PolyString.of( entry.getKey() ), context.deserialize( entry.getValue(), PolyValue.class ) ); - } - return new PolyDictionary( map ); - } - - - @Override - public JsonElement serialize( PolyDictionary src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject object = new JsonObject(); - for ( Entry entry : src.map.entrySet() ) { - object.add( entry.getKey().toString(), context.serialize( entry.getValue(), entry.getValue().getClass() ) ); - } - return object; - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyEdge.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyEdge.java index fbfdf34161..3d81ddb9bc 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyEdge.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyEdge.java @@ -16,14 +16,6 @@ package org.polypheny.db.type.entity.graph; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; import java.util.List; import java.util.UUID; import lombok.EqualsAndHashCode; @@ -205,36 +197,5 @@ public String toString() { } - public static class PolyEdgeSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public PolyEdge deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - PolyString id = PolyString.of( jsonObject.get( "id" ).getAsString() ); - PolyDictionary props = context.deserialize( jsonObject.get( "properties" ), PolyDictionary.class ); - List labels = context.deserialize( jsonObject.get( "labels" ), PolyList.class ); - PolyString source = PolyString.of( jsonObject.get( "source" ).getAsString() ); - PolyString target = PolyString.of( jsonObject.get( "target" ).getAsString() ); - EdgeDirection dir = EdgeDirection.valueOf( jsonObject.get( "direction" ).getAsString() ); - PolyString var = context.deserialize( jsonObject.get( "var" ), PolyString.class ); - return new PolyEdge( id, props, labels, source, target, dir, var ); - } - - - @Override - public JsonElement serialize( PolyEdge src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty( "id", src.id.value ); - jsonObject.add( "properties", context.serialize( src.properties ) ); - jsonObject.add( "labels", context.serialize( src.labels ) ); - jsonObject.addProperty( "source", src.source.value ); - jsonObject.addProperty( "target", src.target.value ); - jsonObject.addProperty( "direction", src.direction.name() ); - jsonObject.add( "var", context.serialize( src.variableName ) ); - return jsonObject; - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyGraph.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyGraph.java index f2ef781ce4..ab615a6204 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyGraph.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyGraph.java @@ -17,13 +17,6 @@ package org.polypheny.db.type.entity.graph; import com.google.common.collect.Lists; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import com.google.gson.annotations.Expose; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; @@ -31,7 +24,6 @@ import io.activej.serializer.CompatibilityLevel; import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -360,28 +352,4 @@ public PolyGraph decode( BinaryInput in ) throws CorruptedDataException { } - - public static class PolyGraphSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public JsonElement serialize( PolyGraph src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty( "id", src.id.value ); - jsonObject.add( "nodes", context.serialize( src.nodes ) ); - jsonObject.add( "edges", context.serialize( src.edges ) ); - return jsonObject; - } - - - @Override - public PolyGraph deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - PolyString id = PolyString.of( jsonObject.get( "id" ).getAsString() ); - PolyMap nodes = context.deserialize( jsonObject.get( "nodes" ), PolyMap.class ); - PolyMap edges = context.deserialize( jsonObject.get( "edges" ), PolyMap.class ); - return new PolyGraph( id, nodes, edges ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyNode.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyNode.java index 19c2282c94..9401d7dfb4 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyNode.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyNode.java @@ -16,20 +16,12 @@ package org.polypheny.db.type.entity.graph; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; import io.activej.serializer.CompatibilityLevel; import io.activej.serializer.CorruptedDataException; import io.activej.serializer.SimpleSerializerDef; -import java.lang.reflect.Type; import java.util.List; import java.util.UUID; import lombok.Getter; @@ -155,29 +147,4 @@ public PolyNode decode( BinaryInput in ) throws CorruptedDataException { } - public static class PolyNodeSerializer implements JsonSerializer, JsonDeserializer { - - @Override - public JsonElement serialize( PolyNode src, Type typeOfSrc, JsonSerializationContext context ) { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty( "id", src.id.value ); - jsonObject.add( "properties", context.serialize( src.properties ) ); - jsonObject.add( "labels", context.serialize( src.labels ) ); - jsonObject.add( "var", context.serialize( src.variableName ) ); - return jsonObject; - } - - - @Override - public PolyNode deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - PolyString id = PolyString.of( jsonObject.get( "id" ).getAsString() ); - PolyDictionary props = context.deserialize( jsonObject.get( "properties" ), PolyDictionary.class ); - List labels = context.deserialize( jsonObject.get( "labels" ), PolyList.class ); - PolyString var = context.deserialize( jsonObject.get( "var" ), PolyString.class ); - return new PolyNode( id, props, labels, var ); - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/util/BsonUtil.java b/core/src/main/java/org/polypheny/db/util/BsonUtil.java index 4a04032466..255ac9adf9 100644 --- a/core/src/main/java/org/polypheny/db/util/BsonUtil.java +++ b/core/src/main/java/org/polypheny/db/util/BsonUtil.java @@ -310,7 +310,7 @@ private static Function getBsonTransformerPrimitive( Queue Function transformer = getBsonTransformer( types, bucket ); return ( o ) -> new BsonArray( o.asList().stream().map( transformer ).collect( Collectors.toList() ) ); case DOCUMENT: - return o -> BsonDocument.parse( o.asDocument().toJson() ); + return o -> BsonDocument.parse( o.asDocument().toJsonOrNull() ); case CHAR: case VARCHAR: default: @@ -343,7 +343,7 @@ private static Object getObjFromRex( Object obj, Function tr private static BsonValue handleDocument( PolyValue obj ) { - return BsonDocument.parse( obj.asDocument().toJson() ); + return BsonDocument.parse( obj.asDocument().toJsonOrNull() ); } diff --git a/core/src/main/java/org/polypheny/db/util/LimitIterator.java b/core/src/main/java/org/polypheny/db/util/LimitIterator.java index 41719f12b9..4f44010ac3 100644 --- a/core/src/main/java/org/polypheny/db/util/LimitIterator.java +++ b/core/src/main/java/org/polypheny/db/util/LimitIterator.java @@ -24,20 +24,20 @@ * Iterator that returns at most {@code limit} rows from an underlying {@link Iterator}. * */ -public class LimitIterator implements Iterator { +public class LimitIterator implements Iterator { - private final Iterator iterator; + private final Iterator iterator; private final long limit; int i = 0; - private LimitIterator( Iterator iterator, long limit ) { + private LimitIterator( Iterator iterator, long limit ) { this.iterator = iterator; this.limit = limit; } - public static Iterator of( Iterator iterator, long limit ) { + public static Iterator of( Iterator iterator, long limit ) { if ( limit <= 0 ) { return iterator; } @@ -52,7 +52,7 @@ public boolean hasNext() { @Override - public E[] next() { + public E next() { ++i; return iterator.next(); } diff --git a/dbms/src/test/java/org/polypheny/db/TestHelper.java b/dbms/src/test/java/org/polypheny/db/TestHelper.java index a2927e2ba6..a13fd90753 100644 --- a/dbms/src/test/java/org/polypheny/db/TestHelper.java +++ b/dbms/src/test/java/org/polypheny/db/TestHelper.java @@ -534,7 +534,7 @@ public static class JdbcConnection implements AutoCloseable { public JdbcConnection( boolean autoCommit ) throws SQLException { try { - Class driver = Class.forName( "org.polypheny.jdbc.Driver" ); + Class.forName( "org.polypheny.jdbc.Driver" ); } catch ( ClassNotFoundException e ) { log.error( "Polypheny JDBC Driver not found", e ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index ab821cdee0..f9871d6fec 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -19,18 +19,12 @@ import static java.lang.String.format; import static org.junit.Assert.fail; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; -import java.rmi.RemoteException; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Map; import javax.annotation.Nullable; import lombok.Getter; +import lombok.SneakyThrows; import org.junit.AfterClass; import org.junit.BeforeClass; import org.polypheny.db.TestHelper; @@ -41,14 +35,9 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.cypher.helper.TestObject; import org.polypheny.db.cypher.helper.TestPath; -import org.polypheny.db.type.entity.PolyList; -import org.polypheny.db.type.entity.PolyString; import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.type.entity.graph.GraphObject.GraphObjectType; import org.polypheny.db.type.entity.graph.GraphPropertyHolder; -import org.polypheny.db.type.entity.graph.PolyDictionary; import org.polypheny.db.type.entity.graph.PolyEdge; -import org.polypheny.db.type.entity.graph.PolyEdge.EdgeDirection; import org.polypheny.db.type.entity.graph.PolyNode; import org.polypheny.db.type.entity.graph.PolyPath; import org.polypheny.db.util.Pair; @@ -240,11 +229,12 @@ private static boolean matchesExactRows( List> parsed, Row[] rows ) } + @SneakyThrows private boolean contains( String[][] actual, boolean exclusive, int index, Class clazz, TestObject[] expected ) { List parsed = new ArrayList<>(); for ( String[] entry : actual ) { - parsed.add( PolyValue.GSON.fromJson( entry[index], clazz ) ); + parsed.add( PolyValue.JSON_WRAPPER.readValue( entry[index], clazz ) ); } assert !exclusive || parsed.size() == expected.length; @@ -363,68 +353,5 @@ public boolean matches( List objects ) { } - public static class GraphObjectAdapter extends TypeAdapter { - - - @Override - public void write( JsonWriter out, GraphPropertyHolder value ) throws IOException { - throw new RemoteException( "Test adapter does not need to write." ); - } - - - @Override - public GraphPropertyHolder read( JsonReader in ) throws IOException { - PolyString id = null; - Map properties = null; - GraphObjectType type = null; - PolyString source = null; - PolyString target = null; - PolyList labels = null; - EdgeDirection direction = null; - - in.beginObject(); - - while ( in.peek() != JsonToken.END_OBJECT ) { - String name = in.nextName(); - switch ( name ) { - case "id": - id = PolyString.of( in.nextString() ); - break; - case "properties": - properties = PolyValue.GSON.fromJson( in, Map.class ); - break; - case "type": - type = GraphObjectType.valueOf( in.nextString() ); - break; - case "source": - source = PolyString.of( in.nextString() ); - break; - case "target": - target = PolyString.of( in.nextString() ); - break; - case "labels": - labels = PolyValue.GSON.fromJson( in, List.class ); - break; - case "direction": - direction = EdgeDirection.valueOf( in.nextString() ); - break; - default: - throw new RuntimeException( format( "Was not able to parse : %s GraphObject.", name ) ); - - } - } - in.endObject(); - - if ( type == GraphObjectType.EDGE ) { - return new PolyEdge( id, new PolyDictionary( properties ), labels, source, target, direction, null ); - } else if ( type == GraphObjectType.NODE ) { - return new PolyNode( id, new PolyDictionary( properties ), labels, null ); - } else { - throw new RuntimeException( "Was not able to parse GraphObject." ); - } - } - - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java index a20efb5e54..47027a5fc7 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java @@ -24,6 +24,7 @@ import java.util.Map.Entry; import java.util.stream.Collectors; import javax.annotation.Nullable; +import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; import org.polypheny.db.TestHelper; import org.polypheny.db.cypher.CypherTestTemplate; @@ -77,9 +78,10 @@ public boolean matches( Object other, boolean exclusive ) { } + @SneakyThrows @Override public Object toPoly( String val ) { - return PolyValue.GSON.fromJson( val, CypherTestTemplate.Type.from( this ).getPolyClass() ); + return PolyValue.JSON_WRAPPER.readValue( val, CypherTestTemplate.Type.from( this ).getPolyClass() ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java index 733822bc25..52c3a24202 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java @@ -17,6 +17,7 @@ package org.polypheny.db.cypher.helper; import java.util.List; +import lombok.SneakyThrows; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.graph.GraphObject; @@ -59,9 +60,10 @@ public boolean matches( Object other, boolean exclusive ) { } + @SneakyThrows @Override public Object toPoly( String val ) { - return PolyValue.GSON.fromJson( val, CypherTestTemplate.Type.from( this ).getPolyClass() ); + return PolyValue.JSON_WRAPPER.readValue( val, CypherTestTemplate.Type.from( this ).getPolyClass() ); } } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index 7fb00a1f4b..791399d42e 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -963,10 +963,10 @@ public Iterable createIterable( final StatementHandle h, final QueryStat final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { - log.trace( "createIterable( StatementHandle {}, QueryState {}, Signature {}, List {}, Frame {} )", h, state, signature, parameters, firstFrame ); + log.trace( "createExternalIterable( StatementHandle {}, QueryState {}, Signature {}, List {}, Frame {} )", h, state, signature, parameters, firstFrame ); } - log.error( "[NOT IMPLEMENTED YET] createIterable( StatementHandle {}, QueryState {}, Signature {}, List {}, Frame {} )", h, state, signature, parameters, firstFrame ); + log.error( "[NOT IMPLEMENTED YET] createExternalIterable( StatementHandle {}, QueryState {}, Signature {}, List {}, Frame {} )", h, state, signature, parameters, firstFrame ); return null; } } @@ -1136,12 +1136,12 @@ public Frame fetch( final StatementHandle h, final long offset, final int fetchM log.trace( "fetch( StatementHandle {}, long {}, int {} )", h, offset, fetchMaxRowCount ); } - final PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + final PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); final PolyphenyDbSignature signature = statementHandle.getSignature(); - final Iterator iterator; + final Iterator iterator; if ( statementHandle.getOpenResultSet() == null ) { - final Iterable iterable = createIterable( statementHandle.getStatement().getDataContext(), signature ); + final Iterable iterable = createExternalIterable( statementHandle.getStatement().getDataContext(), signature ); iterator = iterable.iterator(); statementHandle.setOpenResultSet( iterator ); statementHandle.getExecutionStopWatch().start(); @@ -1149,11 +1149,11 @@ public Frame fetch( final StatementHandle h, final long offset, final int fetchM iterator = statementHandle.getOpenResultSet(); statementHandle.getExecutionStopWatch().resume(); } - final List rows = MetaImpl.collect( signature.cursorFactory, (Iterable) LimitIterator.of( iterator, fetchMaxRowCount ), new ArrayList<>() ); + + final List rows = MetaImpl.collect( signature.cursorFactory, LimitIterator.of( iterator, fetchMaxRowCount ), new ArrayList<>() ); statementHandle.getExecutionStopWatch().suspend(); boolean done = fetchMaxRowCount == 0 || rows.size() < fetchMaxRowCount; - @SuppressWarnings("unchecked") - List rows1 = (List) rows; + if ( done ) { statementHandle.getExecutionStopWatch().stop(); signature.getExecutionTimeMonitor().setExecutionTime( statementHandle.getExecutionStopWatch().getNanoTime() ); @@ -1165,12 +1165,12 @@ public Frame fetch( final StatementHandle h, final long offset, final int fetchM log.error( "Exception while closing result iterator", e ); } } - return new Meta.Frame( offset, done, rows1 ); + return new Meta.Frame( offset, done, rows ); } } - private Iterable createIterable( DataContext dataContext, PolyphenyDbSignature signature ) { + private Iterable createExternalIterable( DataContext dataContext, PolyphenyDbSignature signature ) { return externalize( signature.enumerable( dataContext ), signature.rowType ); } @@ -1372,21 +1372,26 @@ private void prepare( StatementHandle h, String sql ) throws NoSuchStatementExce } - private Enumerable externalize( Enumerable enumerable, AlgDataType rowType ) { + private Enumerable externalize( Enumerable enumerable, AlgDataType rowType ) { return new AbstractEnumerable<>() { @Override - public Enumerator enumerator() { + public Enumerator enumerator() { List> transform = new ArrayList<>(); for ( AlgDataTypeField field : rowType.getFieldList() ) { transform.add( PolyValue.wrapNullableIfNecessary( PolyValue.getPolyToJava( field.getType(), true ), field.getType().isNullable() ) ); } + boolean isSingle = rowType.getFieldCount() == 1; return Linq4j.transform( enumerable.enumerator(), row -> { + if ( isSingle ) { + return transform.get( 0 ).apply( row[0] ); + } + Object[] objects = new Object[row.length]; for ( int i = 0, rowLength = objects.length; i < rowLength; i++ ) { - if ( ((PolyValue[]) row)[i] != null ) { - objects[i] = transform.get( i ).apply( row[i] ); - } + //if ( ((PolyValue[]) row)[i] != null ) { + objects[i] = transform.get( i ).apply( row[i] ); + //} } return objects; } ); @@ -1608,8 +1613,8 @@ private PolyphenyDbConnectionHandle getPolyphenyDbConnectionHandle( String conne } - private PolyphenyDbStatementHandle getPolyphenyDbStatementHandle( StatementHandle h ) throws NoSuchStatementException { - final PolyphenyDbStatementHandle statement; + private PolyphenyDbStatementHandle getPolyphenyDbStatementHandle( StatementHandle h ) throws NoSuchStatementException { + final PolyphenyDbStatementHandle statement; if ( openStatements.containsKey( h.connectionId + "::" + h.id ) ) { statement = openStatements.get( h.connectionId + "::" + h.id ); } else { diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java index ffe0579acc..33a986d5d9 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java @@ -27,11 +27,11 @@ * */ @Getter -public class PolyphenyDbStatementHandle { +public class PolyphenyDbStatementHandle { private final PolyphenyDbConnectionHandle connection; private final int statementId; - private volatile transient Iterator openResultSet; + private volatile transient Iterator openResultSet; private volatile transient PolyphenyDbSignature signature; @Setter private volatile transient String preparedQuery; @@ -51,7 +51,7 @@ public PolyphenyDbStatementHandle( final PolyphenyDbConnectionHandle connection, } - public synchronized void setOpenResultSet( Iterator result ) { + public synchronized void setOpenResultSet( Iterator result ) { if ( this.openResultSet != null ) { // this.openResultSet.close(); } diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/ResultSetEnumerable.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/ResultSetEnumerable.java index 4fe0297408..3b200efebd 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/ResultSetEnumerable.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/ResultSetEnumerable.java @@ -297,7 +297,7 @@ private static void setDynamicParam( PreparedStatement preparedStatement, int i, preparedStatement.setArray( i, array ); array.free(); // according to documentation this is advised to not hog the memory } else { - preparedStatement.setString( i, PolyValue.GSON.toJson( value.asList() ) ); + preparedStatement.setString( i, value.asList().toJsonOrNull() ); } break; case IMAGE: diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java index 6078164c32..74190db35b 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java @@ -577,7 +577,7 @@ public SqlNode toSql( RexProgram program, RexNode rex ) { return SqlLiteral.createArray( array, literal.getType(), POS ); } else { // atm arrays in adapter which do not support arrays are compared in their serialized form, this should be changed todo dl - return SqlLiteral.createCharString( PolyValue.GSON.toJson( literal.value.asList() ), POS ); + return SqlLiteral.createCharString( literal.value.toJsonOrNull(), POS ); } case GRAPH: // node or edge diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java index d102a2a68e..12dd67b45d 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java @@ -87,7 +87,7 @@ private void handleInsert( Implementor implementor, MongoDocuments documents ) { implementor.operations = documents.documents .stream() .filter( PolyValue::isDocument ) - .map( d -> BsonDocument.parse( d.toJson() ) ) + .map( d -> BsonDocument.parse( d.toJsonOrNull() ) ) .collect( Collectors.toList() ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java index db99917018..97a092c2a6 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java @@ -339,7 +339,7 @@ private void handleDocumentInsert( Implementor implementor, MongoDocuments docum implementor.operations = documents.documents .stream() .filter( PolyValue::isDocument ) - .map( d -> BsonDocument.parse( d.toJson() ) ) + .map( d -> BsonDocument.parse( d.toJsonOrNull() ) ) .collect( Collectors.toList() ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java index f170588ce5..8483d7d6db 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java @@ -589,7 +589,7 @@ static Object fixParameterValue( PolyValue value, Pair type return ((TimestampString) value).getMillisSinceEpoch();*/ return value.asTemporal().getMilliSinceEpoch(); case DOCUMENT: - return value.asDocument().toJson();//.toString(); + return value.asDocument().toJsonOrNull();//.toString(); case INTEGER: return value.asNumber().intValue(); case BIGINT: diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index e2ed1311e7..7da51b09f0 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -3108,7 +3108,7 @@ public static List computeResultData( final List> rows temp[counter] = f.getName(); TemporalFileManager.addFile( transaction.getXid().toString(), f ); } else { - temp[counter] = o.toJson(); + temp[counter] = o.toJsonOrNull(); } /*switch ( header.get( counter ).dataType ) { case "TIMESTAMP": diff --git a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java index 23af5f6b3d..4978e7b53f 100644 --- a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java +++ b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java @@ -109,7 +109,7 @@ public void onMessage( final WsMessageContext ctx ) { GraphRequest graphRequest = ctx.messageAsClass( GraphRequest.class ); PolyGraph graph = LanguageCrud.getGraph( graphRequest.namespaceId, crud.getTransactionManager() ); - ctx.send( graph.toJson() ); + ctx.send( graph.toJsonOrNull() ); break; case "QueryRequest": diff --git a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java index 2844375b17..fca3b9f440 100644 --- a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java @@ -306,7 +306,7 @@ private static DocResult getDocResult( Statement statement, QueryLanguage langua private static String toJson( @Nullable PolyValue src ) { return src == null ? null - : src.toJson(); + : src.toJsonOrNull(); } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java b/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java index 2d8fefc1a4..983a4909c7 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java @@ -89,7 +89,6 @@ public RelationalResult( return new RelationalResultBuilderImpl(); } - public String toJson() { Gson gson = new Gson(); return gson.toJson( this );