diff --git a/core/src/main/java/org/polypheny/db/PolyImplementation.java b/core/src/main/java/org/polypheny/db/PolyImplementation.java index 1bc56d9cac..31a94aba21 100644 --- a/core/src/main/java/org/polypheny/db/PolyImplementation.java +++ b/core/src/main/java/org/polypheny/db/PolyImplementation.java @@ -398,7 +398,7 @@ public List> getRows() { List> res = new ArrayList<>(); int i = 0; while ( i++ < batch && iterator.hasNext() ) { - res.add( List.of( (T[]) iterator.next() ) ); + res.add( rowType.getFieldCount() == 1 ? List.of( iterator.next() ) : List.of( (T[]) iterator.next() ) ); } //List> res = MetaImpl.collect( cursorFactory, (Iterator) iterator., new ArrayList<>() ).stream().map( e -> (List) e ).collect( Collectors.toList() ); diff --git a/core/src/main/java/org/polypheny/db/type/PolyType.java b/core/src/main/java/org/polypheny/db/type/PolyType.java index 8209636e7d..4357ab713e 100644 --- a/core/src/main/java/org/polypheny/db/type/PolyType.java +++ b/core/src/main/java/org/polypheny/db/type/PolyType.java @@ -38,8 +38,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializer; import java.math.BigDecimal; import java.sql.Types; import java.util.Arrays; @@ -47,6 +45,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import lombok.Getter; import org.apache.calcite.avatica.util.TimeUnit; import org.polypheny.db.util.Util; @@ -527,6 +526,7 @@ public enum PolyType { /** * Bitwise-or of flags indicating allowable precision/scale combinations. */ + @Getter private final int signatures; /** @@ -1228,15 +1228,5 @@ private interface PrecScale { int YES_YES = 4; } - - - public static JsonSerializer getSerializer() { - return ( src, typeOfSrc, context ) -> { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty( "name", src.name() ); - jsonObject.addProperty( "signatures", src.signatures ); - return jsonObject; - }; - } } diff --git a/information/src/main/java/org/polypheny/db/webui/InformationServer.java b/information/src/main/java/org/polypheny/db/webui/InformationServer.java index e128161df9..90fec49d0f 100644 --- a/information/src/main/java/org/polypheny/db/webui/InformationServer.java +++ b/information/src/main/java/org/polypheny/db/webui/InformationServer.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; @@ -31,7 +30,6 @@ import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.eclipse.jetty.websocket.api.Session; -import org.jetbrains.annotations.NotNull; import org.polypheny.db.StatusService; import org.polypheny.db.information.InformationAction; import org.polypheny.db.information.InformationManager; @@ -46,7 +44,6 @@ @Slf4j public class InformationServer implements InformationObserver { - private static final Gson gson; public static final TypeAdapterFactory throwableTypeAdapterFactory; public static final TypeAdapter throwableTypeAdapter; @@ -82,7 +79,6 @@ public Throwable read( JsonReader in ) throws IOException { return new Throwable( in.nextString() ); } }; - gson = new GsonBuilder().registerTypeAdapterFactory( throwableTypeAdapterFactory ).create(); } 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 0b0c3c1d60..5219bae0e5 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; import com.google.gson.JsonDeserializer; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; @@ -44,9 +43,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.sql.Array; import java.sql.ResultSetMetaData; -import java.sql.SQLException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -174,6 +171,8 @@ import org.polypheny.db.webui.crud.StatisticCrud; import org.polypheny.db.webui.models.DbTable; import org.polypheny.db.webui.models.ForeignKey; +import org.polypheny.db.webui.models.IndexAdapterModel; +import org.polypheny.db.webui.models.IndexAdapterModel.IndexMethodModel; import org.polypheny.db.webui.models.IndexModel; import org.polypheny.db.webui.models.MaterializedInfos; import org.polypheny.db.webui.models.Namespace; @@ -191,6 +190,7 @@ import org.polypheny.db.webui.models.UnderlyingTables; import org.polypheny.db.webui.models.catalog.AdapterModel; import org.polypheny.db.webui.models.catalog.AdapterModel.AdapterSettingValueModel; +import org.polypheny.db.webui.models.catalog.PolyTypeModel; import org.polypheny.db.webui.models.catalog.UiColumnDefinition; import org.polypheny.db.webui.models.requests.BatchUpdateRequest; import org.polypheny.db.webui.models.requests.BatchUpdateRequest.Update; @@ -2136,20 +2136,21 @@ void getAvailableStoresForIndexes( final Context ctx ) { IndexModel index = ctx.bodyAsClass( IndexModel.class ); PlacementModel dataPlacements = getPlacements( index ); Map> stores = AdapterManager.getInstance().getStores(); - //see https://stackoverflow.com/questions/18857884/how-to-convert-arraylist-of-custom-class-to-jsonarray-in-java - JsonArray jsonArray = HttpServer.gson.toJsonTree( stores.values().stream().filter( ( s ) -> { + List filtered = stores.values().stream().filter( ( s ) -> { if ( s.getAvailableIndexMethods() == null || s.getAvailableIndexMethods().isEmpty() ) { return false; } return dataPlacements.stores.stream().anyMatch( ( dp ) -> dp.uniqueName.equals( s.getUniqueName() ) ); - } ).toArray( DataStore[]::new ) ).getAsJsonArray(); + } ).map( IndexAdapterModel::from ).collect( Collectors.toCollection( ArrayList::new ) ); + if ( RuntimeConfig.POLYSTORE_INDEXES_ENABLED.getBoolean() ) { - JsonObject pdbFakeStore = new JsonObject(); - pdbFakeStore.addProperty( "uniqueName", "Polypheny-DB" ); - pdbFakeStore.add( "availableIndexMethods", HttpServer.gson.toJsonTree( IndexManager.getAvailableIndexMethods() ) ); - jsonArray.add( pdbFakeStore ); + IndexAdapterModel poly = new IndexAdapterModel( + -1L, + "Polypheny-DB", + IndexManager.getAvailableIndexMethods().stream().map( IndexMethodModel::from ).collect( Collectors.toList() ) ); + filtered.add( poly ); } - ctx.json( jsonArray ); + ctx.json( filtered ); } @@ -2233,7 +2234,7 @@ void getSources( final Context ctx ) { /** * Deploy a new adapter */ - void addAdapter( final Context ctx ) throws ServletException, IOException { + void addAdapter( final Context ctx ) { AdapterModel a = ctx.bodyAsClass( AdapterModel.class ); Map settings = new HashMap<>(); @@ -2815,7 +2816,7 @@ else if ( !namespace.isCreate() && namespace.isDrop() ) { * Get all supported data types of the DBMS. */ public void getTypeInfo( final Context ctx ) { - ctx.json( PolyType.availableTypes().toArray( new PolyType[0] ) ); + ctx.json( PolyType.availableTypes().stream().map( t -> PolyTypeModel.from( t ) ).collect( Collectors.toList() ) ); } @@ -3211,8 +3212,8 @@ public static List computeResultData( final List> rows default: temp[counter] = o.toString(); }*/ - temp[counter] = o.toString(); - if ( header.get( counter ).dataType.endsWith( "ARRAY" ) ) { + temp[counter] = o.toJson(); + /*if ( header.get( counter ).dataType.endsWith( "ARRAY" ) ) { if ( o instanceof Array ) { try { temp[counter] = gson.toJson( ((Array) o).getArray(), Object[].class ); @@ -3228,7 +3229,7 @@ public static List computeResultData( final List> rows } if ( header.get( counter ).dataType.contains( "Path" ) ) { temp[counter] = o.toJson(); - } + }*/ } counter++; } diff --git a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java index 1891ce509f..b23ea0c311 100644 --- a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java +++ b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; @@ -39,22 +40,10 @@ import java.util.function.Consumer; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.StatusService; -import org.polypheny.db.adapter.AbstractAdapterSetting; -import org.polypheny.db.adapter.AdapterManager.AdapterInformation; -import org.polypheny.db.adapter.AdapterSettingDeserializer; -import org.polypheny.db.adapter.DataSource; -import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.iface.Authenticator; -import org.polypheny.db.information.InformationDuration; -import org.polypheny.db.information.InformationDuration.Duration; -import org.polypheny.db.information.InformationGroup; -import org.polypheny.db.information.InformationPage; -import org.polypheny.db.information.InformationStacktrace; -import org.polypheny.db.plugins.PolyPluginManager.PluginStatus; import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.type.PolyType; import org.polypheny.db.webui.crud.LanguageCrud; import org.polypheny.db.webui.models.results.RelationalResult; @@ -68,7 +57,6 @@ public class HttpServer implements Runnable { private final TransactionManager transactionManager; private final Authenticator authenticator; - public static final Gson gson; private final Gson gsonExpose = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .enableComplexMapKeySerialization() @@ -98,12 +86,11 @@ public Throwable read( JsonReader in ) throws IOException { return new Throwable( in.nextString() ); } }; - gson = new GsonBuilder() + /*gson = new GsonBuilder() .enableComplexMapKeySerialization() .registerTypeHierarchyAdapter( DataSource.class, DataSource.getSerializer() ) .registerTypeHierarchyAdapter( DataStore.class, DataStore.getSerializer() ) .registerTypeHierarchyAdapter( Throwable.class, throwableTypeAdapter ) - .registerTypeAdapter( PolyType.class, PolyType.getSerializer() ) .registerTypeAdapter( AdapterInformation.class, AdapterInformation.getSerializer() ) .registerTypeAdapter( AbstractAdapterSetting.class, new AdapterSettingDeserializer() ) .registerTypeAdapter( InformationDuration.class, InformationDuration.getSerializer() ) @@ -113,7 +100,7 @@ public Throwable read( JsonReader in ) throws IOException { .registerTypeAdapter( InformationGroup.class, InformationGroup.getSerializer() ) .registerTypeAdapter( InformationStacktrace.class, InformationStacktrace.getSerializer() ) .registerTypeAdapter( PluginStatus.class, PluginStatus.getSerializer() ) - .create(); + .create();*/ } @@ -149,6 +136,8 @@ public void run() { config.http.maxRequestSize = maxRequestSize; config.jsonMapper( new JavalinJackson().updateMapper( mapper -> { mapper.setSerializationInclusion( JsonInclude.Include.NON_NULL ); + mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); + mapper.writerWithDefaultPrettyPrinter(); } ) ); } ).start( RuntimeConfig.WEBUI_SERVER_PORT.getInteger() ); @@ -157,7 +146,7 @@ public void run() { Catalog.defaultUserId, Catalog.defaultNamespaceId ); - WebSocket webSocketHandler = new WebSocket( crud, gson ); + WebSocket webSocketHandler = new WebSocket( crud ); webSockets( server, webSocketHandler ); // Get modified index.html 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 5224f9a5c9..3da456ec10 100644 --- a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java +++ b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java @@ -17,7 +17,6 @@ package org.polypheny.db.webui; -import com.google.gson.Gson; import io.javalin.websocket.WsCloseContext; import io.javalin.websocket.WsConfig; import io.javalin.websocket.WsConnectContext; @@ -53,12 +52,10 @@ public class WebSocket implements Consumer { private static final Queue sessions = new ConcurrentLinkedQueue<>(); private final Crud crud; private final ConcurrentHashMap> queryAnalyzers = new ConcurrentHashMap<>(); - private final Gson gson; - WebSocket( Crud crud, Gson gson ) { + WebSocket( Crud crud ) { this.crud = crud; - this.gson = gson; } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/IndexAdapterModel.java b/webui/src/main/java/org/polypheny/db/webui/models/IndexAdapterModel.java new file mode 100644 index 0000000000..2b9551720f --- /dev/null +++ b/webui/src/main/java/org/polypheny/db/webui/models/IndexAdapterModel.java @@ -0,0 +1,60 @@ +/* + * Copyright 2019-2023 The Polypheny Project + * + * 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. + */ + +package org.polypheny.db.webui.models; + +import java.util.List; +import java.util.stream.Collectors; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Value; +import org.jetbrains.annotations.Nullable; +import org.polypheny.db.adapter.DataStore; +import org.polypheny.db.adapter.DataStore.AvailableIndexMethod; +import org.polypheny.db.webui.models.catalog.IdEntity; + +@EqualsAndHashCode(callSuper = true) +@Value +public class IndexAdapterModel extends IdEntity { + + public List availableIndexMethods; + + + public IndexAdapterModel( @Nullable Long id, @Nullable String name, List availableIndexMethods ) { + super( id, name ); + this.availableIndexMethods = availableIndexMethods; + } + + + public static IndexAdapterModel from( DataStore store ) { + return new IndexAdapterModel( store.adapterId, store.getUniqueName(), store.getAvailableIndexMethods().stream().map( IndexMethodModel::from ).collect( Collectors.toList() ) ); + } + + + @AllArgsConstructor + public static class IndexMethodModel { + + public String name; + public String displayName; + + + public static IndexMethodModel from( AvailableIndexMethod index ) { + return new IndexMethodModel( index.name, index.displayName ); + } + + } + +} diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/PolyTypeModel.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/PolyTypeModel.java new file mode 100644 index 0000000000..f9d0154d4e --- /dev/null +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/PolyTypeModel.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019-2023 The Polypheny Project + * + * 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. + */ + +package org.polypheny.db.webui.models.catalog; + +import lombok.Value; +import org.polypheny.db.type.PolyType; + +@Value +public class PolyTypeModel { + + public String name; + + public int signatures; + + + public PolyTypeModel( String name, int signatures ) { + this.name = name; + this.signatures = signatures; + } + + + public static PolyTypeModel from( PolyType type ) { + return new PolyTypeModel( type.name(), type.getSignatures() ); + } + +} diff --git a/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java index e4a3162e9e..1244bf0d14 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java @@ -17,10 +17,19 @@ package org.polypheny.db.webui.models.requests; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + public class QueryRequest extends UIRequest { - public QueryRequest( String query, boolean analyze, boolean cache, String language, Long namespaceId ) { + @JsonCreator + public QueryRequest( + @JsonProperty("query") String query, + @JsonProperty("analyze") boolean analyze, + @JsonProperty("cache") boolean cache, + @JsonProperty("language") String language, + @JsonProperty("namespaceId") Long namespaceId ) { this.query = query; this.analyze = analyze; this.cache = cache; diff --git a/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java index 58b0d3aa54..d48ac29a62 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java @@ -153,7 +153,7 @@ private UIRequest( JsonReader in ) throws IOException { public static TypeAdapter getSerializer() { - return new TypeAdapter() { + return new TypeAdapter<>() { @Override public void write( JsonWriter out, UIRequest value ) throws IOException { if ( value == null ) { @@ -197,7 +197,7 @@ public UIRequest read( JsonReader in ) throws IOException { private static TypeAdapter> getMapTypeAdapter( BiConsumer valSerializer, Function valDeserializer ) { - return new TypeAdapter>() { + return new TypeAdapter<>() { @Override public void write( JsonWriter out, Map value ) throws IOException { if ( value == null ) { 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 96a89bcec1..3fa0b33c53 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 @@ -17,24 +17,20 @@ package org.polypheny.db.webui.models.results; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.google.gson.Gson; -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.util.ArrayList; -import java.util.List; -import java.util.function.Function; import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; -import org.jetbrains.annotations.NotNull; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.webui.HttpServer; -import org.polypheny.db.webui.models.catalog.FieldDefinition; import org.polypheny.db.webui.models.catalog.UiColumnDefinition; import org.polypheny.db.webui.models.requests.UIRequest; @@ -56,8 +52,6 @@ public class RelationalResult extends Result { * Information for the pagination: how many pages there can be in total */ public int highestPage; - - /** * Table from which the data has been fetched */ @@ -70,7 +64,6 @@ public class RelationalResult extends Result { * The request from the UI is being sent back and contains information about which columns are being filtered and which are being sorted */ public UIRequest request; - /** * Number of affected rows */ @@ -84,6 +77,7 @@ public class RelationalResult extends Result { /** * language type of result MQL/SQL/CQL */ + @JsonSerialize(using = LanguageSerializer.class) public QueryLanguage language = QueryLanguage.from( "sql" ); /** @@ -92,141 +86,33 @@ public class RelationalResult extends Result { public boolean hasMoreRows; - /** - * Deserializer Constructor, which is able to create a Result from its - * serialized form - * - * @param in the reader, which contains the Result - */ - public static RelationalResult create( JsonReader in ) throws IOException { - RelationalResultBuilder builder = RelationalResult.builder(); - while ( in.peek() != JsonToken.END_OBJECT ) { - switch ( in.nextName() ) { - case "header": - in.beginArray(); - TypeAdapter serializer = UiColumnDefinition.serializer; - List cols = new ArrayList<>(); - while ( in.peek() != JsonToken.END_ARRAY ) { - cols.add( serializer.read( in ) ); - } - in.endArray(); - builder.header( cols.toArray( new UiColumnDefinition[0] ) ); - break; - case "data": - builder.data( extractNestedArray( in ) ); - break; - case "currentPage": - builder.currentPage( in.nextInt() ); - break; - case "highestPage": - builder.highestPage( in.nextInt() ); - break; - case "table": - builder.table( in.nextString() ); - break; - case "tables": - builder.tables( extractArray( in ).toArray( new String[0] ) ); - break; - case "request": - builder.request( UIRequest.getSerializer().read( in ) ); - break; - case "error": - builder.error( in.nextString() ); - break; - case "exception": - builder.exception( HttpServer.throwableTypeAdapter.read( in ) ); - break; - case "affectedRows": - builder.affectedRows( in.nextInt() ); - break; - case "generatedQuery": - builder.generatedQuery( in.nextString() ); - break; - case "type": - builder.type( extractEnum( in, ResultType::valueOf ) ); - break; - case "namespaceType": - builder.namespaceType( extractEnum( in, NamespaceType::valueOf ) ); - break; - case "namespaceName": - builder.namespaceName( in.nextString() ); - break; - case "language": - builder.language( QueryLanguage.getSerializer().read( in ) ); - break; - case "hasMoreRows": - builder.hasMoreRows( in.nextBoolean() ); - break; - case "xid": - builder.xid( in.nextString() ); - break; - default: - throw new RuntimeException( "There was an unrecognized column while deserializing Result." ); - } - } - return builder.build(); - - } - - - private static String[][] extractNestedArray( JsonReader in ) throws IOException { - if ( in.peek() == JsonToken.NULL ) { - in.nextNull(); - return null; - } - in.beginArray(); - List> rawData = new ArrayList<>(); - while ( in.peek() != JsonToken.END_ARRAY ) { - List list = extractArray( in ); - rawData.add( list ); - } - in.endArray(); - return toNestedArray( rawData ); - } - - - private static String[][] toNestedArray( List> nestedList ) { - String[][] array = new String[nestedList.size()][]; - int i = 0; - for ( List list : nestedList ) { - array[i] = list.toArray( new String[0] ); - i++; - } - - return array; - } - - - @NotNull - private static List extractArray( JsonReader in ) throws IOException { - if ( in.peek() == JsonToken.NULL ) { - in.nextNull(); - return new ArrayList<>(); - } - List list = new ArrayList<>(); - in.beginArray(); - while ( in.peek() != JsonToken.END_ARRAY ) { - if ( in.peek() == JsonToken.NULL ) { - in.nextNull(); - list.add( null ); - } else if ( in.peek() == JsonToken.STRING ) { - list.add( in.nextString() ); - } else { - throw new RuntimeException( "Error while un-parsing Result." ); - } - } - in.endArray(); - return list; - } - - - private static > T extractEnum( JsonReader in, Function enumFunction ) throws IOException { - if ( in.peek() == JsonToken.NULL ) { - in.nextNull(); - return null; - } else { - return enumFunction.apply( in.nextString() ); - } + @JsonCreator + public RelationalResult( + @JsonProperty("namespaceType") NamespaceType namespaceType, + @JsonProperty("namespaceName") String namespaceName, + @JsonProperty("data") String[][] data, + @JsonProperty("UiColumnDefinition") UiColumnDefinition[] header, + @JsonProperty("exception") Throwable exception, + @JsonProperty("query") String query, + @JsonProperty("xid") String xid, + @JsonProperty("error") String error, + @JsonProperty("currentPage") int currentPage, + @JsonProperty("highestPage") int highestPage, + @JsonProperty("table") String table, + @JsonProperty("tables") String[] tables, + @JsonProperty("UIRequest") UIRequest request, + @JsonProperty("int") int affectedRows, + @JsonProperty("ResultType") ResultType type, + @JsonProperty("hasMoreRows") boolean hasMoreRows ) { + super( namespaceType, namespaceName, data, header, exception, query, xid, error ); + this.currentPage = currentPage; + this.highestPage = highestPage; + this.table = table; + this.tables = tables; + this.request = request; + this.affectedRows = affectedRows; + this.type = type; + this.hasMoreRows = hasMoreRows; } @@ -241,124 +127,6 @@ public String toJson() { } - public static TypeAdapter getSerializer() { - return new TypeAdapter<>() { - - @Override - public void write( JsonWriter out, RelationalResult result ) throws IOException { - if ( result == null ) { - out.nullValue(); - return; - } - - out.beginObject(); - out.name( "header" ); - handleDbColumns( out, result ); - out.name( "data" ); - handleNestedArray( out, result.data ); - out.name( "currentPage" ); - out.value( result.currentPage ); - out.name( "highestPage" ); - out.value( result.highestPage ); - out.name( "table" ); - out.value( result.table ); - out.name( "tables" ); - handleArray( out, result.tables ); - out.name( "request" ); - UIRequest.getSerializer().write( out, result.request ); - out.name( "error" ); - out.value( result.error ); - out.name( "exception" ); - HttpServer.throwableTypeAdapter.write( out, result.exception ); - out.name( "affectedRows" ); - out.value( result.affectedRows ); - out.name( "generatedQuery" ); - out.value( result.query ); - out.name( "type" ); - handleEnum( out, result.type ); - out.name( "namespaceType" ); - handleEnum( out, result.namespaceType ); - out.name( "namespaceName" ); - out.value( result.namespaceName ); - out.name( "language" ); - QueryLanguage.getSerializer().write( out, result.language ); - out.name( "hasMoreRows" ); - out.value( result.hasMoreRows ); - out.name( "xid" ); - out.value( result.xid ); - out.endObject(); - } - - - private void handleDbColumns( JsonWriter out, RelationalResult result ) throws IOException { - if ( result.header == null ) { - out.nullValue(); - return; - } - out.beginArray(); - - for ( FieldDefinition column : result.header ) { - if ( column instanceof UiColumnDefinition ) { - UiColumnDefinition.serializer.write( out, (UiColumnDefinition) column ); - } else { - FieldDefinition.serializer.write( out, column ); - } - } - out.endArray(); - } - - - private void handleArray( JsonWriter out, String[] result ) throws IOException { - if ( result == null ) { - out.nullValue(); - return; - } - out.beginArray(); - for ( String table : result ) { - out.value( table ); - } - out.endArray(); - } - - - private void handleNestedArray( JsonWriter out, String[][] result ) throws IOException { - if ( result == null ) { - out.nullValue(); - return; - } - out.beginArray(); - for ( String[] data : result ) { - handleArray( out, data ); - } - out.endArray(); - } - - - private void handleEnum( JsonWriter out, Enum enums ) throws IOException { - if ( enums == null ) { - out.nullValue(); - } else { - out.value( enums.name() ); - } - } - - - @Override - public RelationalResult read( JsonReader in ) throws IOException { - if ( in.peek() == null ) { - in.nextNull(); - return null; - } - in.beginObject(); - RelationalResult res = RelationalResult.create( in ); - in.endObject(); - return res; - } - - }; - } - - /** * Remove when bugs in SuperBuilder regarding generics are fixed */ @@ -449,4 +217,14 @@ public B hasMoreRows( boolean hasMoreRows ) { } + private static class LanguageSerializer extends JsonSerializer { + + @Override + public void serialize( QueryLanguage value, JsonGenerator gen, SerializerProvider serializers ) throws IOException { + gen.writeString( value.getSerializedName() ); + } + + } + + } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java b/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java index 45c311e84f..91cee5187c 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java @@ -16,6 +16,7 @@ package org.polypheny.db.webui.models.results; +import lombok.AllArgsConstructor; import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; @@ -25,6 +26,7 @@ @Value @NonFinal @SuperBuilder +@AllArgsConstructor public abstract class Result { /**