From d14f78ec4c13bc70e401bb1c3b33a2af2b7d7a1f Mon Sep 17 00:00:00 2001 From: datomo Date: Thu, 9 Feb 2023 23:47:30 +0100 Subject: [PATCH] updated to plugin architecture, minor reformatting and adjustment of header files --- .../postgres/PGInterfaceIntegrationTests.java | 20 ++- .../postgresql-interface}/build.gradle | 30 +--- .../postgresql-interface/gradle.properties | 27 ++++ .../polypheny/db/postgresql/PGInterface.java | 33 ++-- .../PGInterfaceErrorFieldTypes.java | 2 +- .../postgresql/PGInterfaceErrorHandler.java | 5 +- .../db/postgresql/PGInterfaceHeaders.java | 2 +- ...GInterfaceInboundCommunicationHandler.java | 7 +- .../db/postgresql/PGInterfaceMessage.java | 2 +- .../PGInterfacePreparedMessage.java | 10 +- .../postgresql/PGInterfaceQueryHandler.java | 12 +- .../postgresql/PGInterfaceServerHandler.java | 5 +- .../postgresql/PGInterfaceServerWriter.java | 142 ++++-------------- .../postgresql/PostgresqlInterfacePlugin.java | 48 ++++++ .../src/main/resources/log4j2.xml | 0 postgresql-interface/lombok.config | 4 - .../polypheny/db/restapi/HttpRestServer.java | 0 17 files changed, 165 insertions(+), 184 deletions(-) rename {postgresql-interface => plugins/postgresql-interface}/build.gradle (53%) create mode 100644 plugins/postgresql-interface/gradle.properties rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterface.java (93%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java (96%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java (98%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java (98%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java (99%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java (99%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java (98%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java (99%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java (98%) rename {postgresql-interface => plugins/postgresql-interface}/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java (63%) create mode 100644 plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PostgresqlInterfacePlugin.java rename {postgresql-interface => plugins/postgresql-interface}/src/main/resources/log4j2.xml (100%) delete mode 100644 postgresql-interface/lombok.config delete mode 100644 rest-interface/src/main/java/org/polypheny/db/restapi/HttpRestServer.java diff --git a/dbms/src/test/java/org/polypheny/db/postgres/PGInterfaceIntegrationTests.java b/dbms/src/test/java/org/polypheny/db/postgres/PGInterfaceIntegrationTests.java index 3f133c3853..2aea385095 100644 --- a/dbms/src/test/java/org/polypheny/db/postgres/PGInterfaceIntegrationTests.java +++ b/dbms/src/test/java/org/polypheny/db/postgres/PGInterfaceIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -16,7 +16,16 @@ package org.polypheny.db.postgres; +import static org.junit.Assert.assertEquals; + import com.google.common.collect.ImmutableList; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -28,13 +37,9 @@ import org.polypheny.db.catalog.exceptions.UnknownSchemaException; import org.polypheny.db.catalog.exceptions.UnknownTableException; -import java.sql.*; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; - //import static org.polypheny.db.postgresql.PGInterfaceInboundCommunicationHandler.ctx; + /** * Tests the implementation of the PGInterface --> simulates a client that connects via JDBC */ @@ -68,6 +73,7 @@ public static void start() throws SQLException { } + /** * Cleans up after the tests * @@ -134,6 +140,7 @@ public void testIfDMLandDDLandDQLIsExecuted() throws SQLException { } } + /** * Tests if a prepared statement is correctly executed if the PREPARE and EXECUTE statement are sent seperately * @@ -186,6 +193,7 @@ public void testPreparedAndExecuteInOnePart() throws SQLException { } } + /** * This feature is not yet supported, but it tests if prepared statement are executed correctly using the JDBC framework * diff --git a/postgresql-interface/build.gradle b/plugins/postgresql-interface/build.gradle similarity index 53% rename from postgresql-interface/build.gradle rename to plugins/postgresql-interface/build.gradle index 0413dddda5..6d5adbd8af 100644 --- a/postgresql-interface/build.gradle +++ b/plugins/postgresql-interface/build.gradle @@ -8,8 +8,8 @@ configurations { } dependencies { - implementation project(":core") - implementation project(":monitoring") + compileOnly project(":core") + compileOnly project(":monitoring") ////// NETTY // https://mvnrepository.com/artifact/io.netty/netty-all @@ -23,28 +23,6 @@ dependencies { } -sourceSets { - main { - java { - srcDirs = ["src/main/java"] - outputDir = file(project.buildDir.absolutePath + "/classes") - } - resources { - srcDirs = ["src/main/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/classes") - } - test { - java { - srcDirs = ["src/test/java"] - outputDir = file(project.buildDir.absolutePath + "/test-classes") - } - resources { - srcDirs = ["src/test/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/test-classes") - } -} /** @@ -68,3 +46,7 @@ java { withJavadocJar() withSourcesJar() } + +licensee { + allow('Apache-2.0') +} diff --git a/plugins/postgresql-interface/gradle.properties b/plugins/postgresql-interface/gradle.properties new file mode 100644 index 0000000000..fa142a538a --- /dev/null +++ b/plugins/postgresql-interface/gradle.properties @@ -0,0 +1,27 @@ +# +# 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. +# + +pluginVersion = 0.0.1 + +pluginId = postgres-interface +pluginClass = org.polypheny.db.postgresql.PostgresqlInterfacePlugin +pluginProvider = The Polypheny Project +pluginDependencies = +pluginUrlPath = +pluginCategories = interface +pluginPolyDependencies = +pluginIsSystemComponent = false +pluginIsUiVisible = true \ No newline at end of file diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterface.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterface.java similarity index 93% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterface.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterface.java index 7612455be3..3914c4bcc3 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterface.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterface.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -19,31 +19,34 @@ import com.google.common.collect.ImmutableList; import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.*; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.string.StringDecoder; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.StatusService; -import org.polypheny.db.catalog.Catalog.QueryLanguage; import org.polypheny.db.iface.Authenticator; import org.polypheny.db.iface.QueryInterface; import org.polypheny.db.information.InformationGroup; import org.polypheny.db.information.InformationManager; import org.polypheny.db.information.InformationPage; import org.polypheny.db.information.InformationTable; +import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.util.Util; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - /** * First point of contact for the PGInterface, setting changes from the UI are handled here @@ -161,6 +164,12 @@ protected void reloadSettings( List updatedSettings ) { } + @Override + public void languageChange() { + + } + + private class MonitoringPage { //TODO(FF): vergliiche met anderne interfaces (zeigt infos em ui aah) --> sött glaubs ok sii?? @@ -201,7 +210,7 @@ public void update() { DecimalFormat df = new DecimalFormat( "0.0", symbols ); statementsTable.reset(); for ( Map.Entry entry : statementCounters.entrySet() ) { - statementsTable.addRow( entry.getKey().name(), df.format( total == 0 ? 0 : (entry.getValue().longValue() / total) * 100 ) + " %", entry.getValue().longValue() ); + statementsTable.addRow( entry.getKey().getSerializedName(), df.format( total == 0 ? 0 : (entry.getValue().longValue() / total) * 100 ) + " %", entry.getValue().longValue() ); } } diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java similarity index 96% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java index 19cb52b2d3..0e88a68d7e 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorFieldTypes.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java similarity index 98% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java index d458b5cfca..d799a7fef9 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceErrorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -18,9 +18,8 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import lombok.extern.slf4j.Slf4j; - import java.util.LinkedHashMap; +import lombok.extern.slf4j.Slf4j; /** * Writes and sends error messages to the client diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java similarity index 98% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java index 967a6d1390..a8a91f58a1 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java similarity index 99% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java index ee6f0ea712..dd7dcf7006 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceInboundCommunicationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -18,11 +18,10 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.transaction.TransactionManager; - import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import lombok.extern.slf4j.Slf4j; +import org.polypheny.db.transaction.TransactionManager; /** * Manages all incoming communication, not a handler from netty, but called by one diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java similarity index 99% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java index 28122c7542..1e5c2cb027 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java similarity index 98% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java index cb55173d28..e0d1913d05 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfacePreparedMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -17,13 +17,17 @@ package org.polypheny.db.postgresql; import io.netty.channel.ChannelHandlerContext; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.transaction.Statement; import org.polypheny.db.type.PolyType; -import java.util.*; - /** * Contains information for prepared queries, and also methods to handle the information */ diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java similarity index 99% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java index fbe34c9119..96db8f24f1 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceQueryHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -17,6 +17,9 @@ package org.polypheny.db.postgresql; import io.netty.channel.ChannelHandlerContext; +import java.sql.ResultSetMetaData; +import java.util.ArrayList; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.PolyImplementation; import org.polypheny.db.algebra.AlgRoot; @@ -28,6 +31,7 @@ import org.polypheny.db.catalog.exceptions.UnknownSchemaException; import org.polypheny.db.catalog.exceptions.UnknownUserException; import org.polypheny.db.config.RuntimeConfig; +import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.processing.Processor; @@ -37,10 +41,6 @@ import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.TransactionManager; -import java.sql.ResultSetMetaData; -import java.util.ArrayList; -import java.util.List; - /** * Handles all queries from the extended query cycle - "sends" them to polypheny and processes answer @@ -116,7 +116,7 @@ public void sendQueryToPolypheny() { } //get algRoot - Processor sqlProcessor = statement.getTransaction().getProcessor( Catalog.QueryLanguage.SQL ); + Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); Node sqlNode = sqlProcessor.parse( query ).get( 0 ); QueryParameters parameters = new QueryParameters( query, Catalog.NamespaceType.RELATIONAL ); diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java similarity index 98% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java index 2e179a64c9..b4f46ace58 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -18,11 +18,10 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import java.util.ArrayList; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.transaction.TransactionManager; -import java.util.ArrayList; - /** * Forwards the message from the "netty flow" to the internal structure */ diff --git a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java similarity index 63% rename from postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java rename to plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java index 481c29eabb..1fd5ec082a 100644 --- a/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PGInterfaceServerWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 The Polypheny Project + * 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. @@ -18,11 +18,10 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import lombok.extern.slf4j.Slf4j; - import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.LinkedHashMap; +import lombok.extern.slf4j.Slf4j; /** * Writes the messages that need to be sent to the client byte-wise on the buffer @@ -39,16 +38,16 @@ public class PGInterfaceServerWriter { /** * creates a server writer, writes response to client on byteBuf * - * @param type what type of message should be written (in method writeOnByteBuf) - * possible types are: - * - s: write 1 string - * - c: write a char (or number) - writeByte - * - i: writes an int32 - * - ss: writes a message with two strings (the strings are safed as one in the msgBody of the pgMsg and are seperated by the delimiter) - * - sss: same as above, but with three strings - * - dr: write dataRow - writes the message dataRow to the client - * @param pgMsg The message object that contains all necessary information to send it to the client - * @param ctx channelHandlerContext specific to the connection + * @param type what type of message should be written (in method writeOnByteBuf) + * possible types are: + * - s: write 1 string + * - c: write a char (or number) - writeByte + * - i: writes an int32 + * - ss: writes a message with two strings (the strings are safed as one in the msgBody of the pgMsg and are seperated by the delimiter) + * - sss: same as above, but with three strings + * - dr: write dataRow - writes the message dataRow to the client + * @param pgMsg The message object that contains all necessary information to send it to the client + * @param ctx channelHandlerContext specific to the connection * @param pgInterfaceInboundCommunicationHandler */ public PGInterfaceServerWriter( String type, PGInterfaceMessage pgMsg, ChannelHandlerContext ctx, PGInterfaceInboundCommunicationHandler pgInterfaceInboundCommunicationHandler ) { @@ -209,13 +208,13 @@ public ByteBuf writeIntHeaderOnByteBuf( char header ) { * Special case: write the rowDescription * * @param valuesPerCol The values that are needed to be sent in the rowDescription: - * String fieldName: string - column name (field name) (matters) - * int objectIDTable: int32 - ObjectID of table (if col can be id'd to table) --> otherwise 0 (doesn't matter to client while sending) - * int attributeNoCol: int16 - attr.no of col (if col can be id'd to table) --> otherwise 0 (doesn't matter to client while sending) - * int objectIDCol: int32 - objectID of parameter datatype --> 0 = unspecified (doesn't matter to client while sending, but maybe later) - see comment where this method is called from - * int dataTypeSize: int16 - size of dataType (if formatCode = 1, this needs to be set for colValLength) (doesn't matter to client while sending) - * int typeModifier: int32 - The value will generally be -1 (doesn't matter to client while sending) - * int formatCode: int16 - 0: Text | 1: Binary --> sends everything with writeBytes(formatCode = 0), if sent with writeInt it needs to be 1 (matters) + * String fieldName: string - column name (field name) (matters) + * int objectIDTable: int32 - ObjectID of table (if col can be id'd to table) --> otherwise 0 (doesn't matter to client while sending) + * int attributeNoCol: int16 - attr.no of col (if col can be id'd to table) --> otherwise 0 (doesn't matter to client while sending) + * int objectIDCol: int32 - objectID of parameter datatype --> 0 = unspecified (doesn't matter to client while sending, but maybe later) - see comment where this method is called from + * int dataTypeSize: int16 - size of dataType (if formatCode = 1, this needs to be set for colValLength) (doesn't matter to client while sending) + * int typeModifier: int32 - The value will generally be -1 (doesn't matter to client while sending) + * int formatCode: int16 - 0: Text | 1: Binary --> sends everything with writeBytes(formatCode = 0), if sent with writeInt it needs to be 1 (matters) * @return The buffer with the message written on it */ public ByteBuf writeRowDescription( ArrayList valuesPerCol ) { @@ -243,12 +242,12 @@ public ByteBuf writeRowDescription( ArrayList valuesPerCol ) { for ( Object[] oneCol : valuesPerCol ) { ByteBuf bufferTemp = ctx.alloc().buffer(); fieldName = oneCol[0].toString(); - objectIDTable = ( Integer ) oneCol[1]; - attributeNoCol = ( Integer ) oneCol[2]; - objectIDCol = ( Integer ) oneCol[3]; - dataTypeSize = ( Integer ) oneCol[4]; - typeModifier = ( Integer ) oneCol[5]; - formatCode = ( Integer ) oneCol[6]; + objectIDTable = (Integer) oneCol[1]; + attributeNoCol = (Integer) oneCol[2]; + objectIDCol = (Integer) oneCol[3]; + dataTypeSize = (Integer) oneCol[4]; + typeModifier = (Integer) oneCol[5]; + formatCode = (Integer) oneCol[6]; bufferTemp.writeBytes( fieldName.getBytes( StandardCharsets.UTF_8 ) ); bufferTemp.writeByte( 0 ); @@ -265,6 +264,7 @@ public ByteBuf writeRowDescription( ArrayList valuesPerCol ) { return buffer; } + public ByteBuf writeSimpleErrorMessage( LinkedHashMap fields ) { ByteBuf buffer = ctx.alloc().buffer(); int msgLength = 4 + 1; @@ -291,95 +291,5 @@ public ByteBuf writeSimpleErrorMessage( LinkedHashMap fields return buffer; } - public ByteBuf writeSeveralStrings(int nbrStrings) { - ByteBuf buffer = ctx.alloc().buffer(); - - buffer.writeByte(pgMsg.getHeaderChar()); - if (pgMsg.isDefaultLength()) { - buffer.writeInt(pgMsg.getLength() + pgMsg.getMsgBody().length() - (nbrStrings -1)); - } - else { - buffer.writeInt(pgMsg.getLength()); - } - - int[] idx = new int[nbrStrings]; - String[] msgParts = pgMsg.getMsgPart(idx); - - for (int i = 0; i < nbrStrings; i++) { - buffer.writeBytes(msgParts[i].getBytes(StandardCharsets.UTF_8)); - buffer.writeByte(0); - } - - return buffer; - } - - public ByteBuf writeIntHeaderOnByteBuf(char header) { - //write a int header... ("i" (for char headers) doesn't work TODO(FF): Figure out a way to do this with case "i" - //since headers with numbers are always indicators, don't I don't check for not standard lengths - ByteBuf buffer = ctx.alloc().buffer(); - - buffer.writeByte(header); - buffer.writeInt(4); // size excluding char - - return buffer; - } - - public ByteBuf writeRowDescription(ArrayList valuesPerCol) { - //I don't check for length, bcs rowDescription is always the same - ByteBuf buffer = ctx.alloc().buffer(); - //ByteBuf bufferTemp = ctx.alloc().buffer(); - String fieldName; - int objectIDTable; - int attributeNoCol; - int objectIDCol; - int dataTypeSize; - int typeModifier; - int formatCode; - - int messageLength = 0; - buffer.writeByte(pgMsg.getHeaderChar()); - - for (int i = 0; i( oder au ned? werom 8????? - - for(Object[] oneCol : valuesPerCol) { - ByteBuf bufferTemp = ctx.alloc().buffer(); - fieldName = oneCol[0].toString(); - objectIDTable = (Integer) oneCol[1]; - attributeNoCol = (Integer) oneCol[2]; - objectIDCol = (Integer) oneCol[3]; - dataTypeSize = (Integer) oneCol[4]; - typeModifier = (Integer) oneCol[5]; - formatCode = (Integer) oneCol[6]; - - //messageLength += (fieldName.length() + 6); - - bufferTemp.writeBytes(fieldName.getBytes(StandardCharsets.UTF_8)); - bufferTemp.writeByte(0); - bufferTemp.writeInt(objectIDTable); - bufferTemp.writeByte(0); - bufferTemp.writeShort(attributeNoCol); - bufferTemp.writeByte(0); - bufferTemp.writeInt(objectIDCol); //objectId of datatype? - bufferTemp.writeByte(0); - bufferTemp.writeShort(dataTypeSize); - bufferTemp.writeByte(0); - bufferTemp.writeInt(typeModifier); - bufferTemp.writeByte(0); - bufferTemp.writeShort(formatCode); //aber bem 4. esch denn do dezwösche en fähler cho, vorem nöchste flushl... werom au emmer??? --> be comission - - buffer.writeBytes(bufferTemp); //die erste 3x gohts ohni fähler - } - - //return buffer.writeBytes(bufferTemp); - //String bla = new String(buffer.array(), Charset.defaultCharset()); - String bla = buffer.toString(Charset.defaultCharset()); - return buffer; - } } diff --git a/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PostgresqlInterfacePlugin.java b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PostgresqlInterfacePlugin.java new file mode 100644 index 0000000000..bccf3292c0 --- /dev/null +++ b/plugins/postgresql-interface/src/main/java/org/polypheny/db/postgresql/PostgresqlInterfacePlugin.java @@ -0,0 +1,48 @@ +/* + * 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.postgresql; + +import java.util.HashMap; +import java.util.Map; +import org.pf4j.Plugin; +import org.pf4j.PluginWrapper; +import org.polypheny.db.iface.QueryInterfaceManager; + +public class PostgresqlInterfacePlugin extends Plugin { + + /** + * Constructor to be used by plugin manager for plugin instantiation. + * Your plugins have to provide constructor with this exact signature to + * be successfully loaded by manager. + * + * @param wrapper + */ + public PostgresqlInterfacePlugin( PluginWrapper wrapper ) { + super( wrapper ); + } + + + @Override + public void start() { + // Add HTTP interface + Map httpSettings = new HashMap<>(); + httpSettings.put( "port", "5432" ); + httpSettings.put( "maxUploadSizeMb", "10000" ); + QueryInterfaceManager.addInterfaceType( "postgres", PGInterface.class, httpSettings ); + } + +} diff --git a/postgresql-interface/src/main/resources/log4j2.xml b/plugins/postgresql-interface/src/main/resources/log4j2.xml similarity index 100% rename from postgresql-interface/src/main/resources/log4j2.xml rename to plugins/postgresql-interface/src/main/resources/log4j2.xml diff --git a/postgresql-interface/lombok.config b/postgresql-interface/lombok.config deleted file mode 100644 index b034fcb60e..0000000000 --- a/postgresql-interface/lombok.config +++ /dev/null @@ -1,4 +0,0 @@ -# This file is generated by the 'io.freefair.lombok' Gradle plugin -config.stopBubbling = true -lombok.val.flagUsage = error -lombok.var.flagUsage = error diff --git a/rest-interface/src/main/java/org/polypheny/db/restapi/HttpRestServer.java b/rest-interface/src/main/java/org/polypheny/db/restapi/HttpRestServer.java deleted file mode 100644 index e69de29bb2..0000000000