Skip to content

Commit

Permalink
updated codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
flurfis authored and datomo committed Feb 9, 2023
1 parent fdba699 commit ad1eb1f
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.polypheny.db.catalog.exceptions.UnknownTableException;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
Expand All @@ -51,6 +49,7 @@ public class PGInterfaceIntegrationTests {

/**
* starts an instance of Polypheny and creates a PGInterface, as it does not exist per default
*
* @throws SQLException
*/
@BeforeClass
Expand All @@ -63,23 +62,24 @@ public static void start() throws SQLException {
try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( false ) ) {
Connection connection = polyphenyDbConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate("ALTER INTERFACES ADD \"pgtestinterface\" USING 'org.polypheny.db.postgresql.PGInterface' WITH '{\"port\":\"5433\"}'");
statement.executeUpdate( "ALTER INTERFACES ADD \"pgtestinterface\" USING 'org.polypheny.db.postgresql.PGInterface' WITH '{\"port\":\"5433\"}'" );
}
}

}

/**
* Cleans up after the tests
*
* @throws SQLException
*/
@AfterClass
public static void stop() throws SQLException {

try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection(false) ) {
try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection( false ) ) {
Connection connection = psqlJdbcConnection.getConnection();
try(Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
//statement.executeUpdate( "ALTER INTERFACES DROP pgtestinerface" );
}
}
Expand All @@ -88,22 +88,23 @@ public static void stop() throws SQLException {

/**
* Test that executes the ddl command CREATE and checks within the database if a table was created
*
* @throws SQLException
*/
@Test
public void testIfDDLIsExecuted() throws SQLException {

try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection(false) ) {
try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection( false ) ) {
Connection connection = psqlJdbcConnection.getConnection();
try(Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate("CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))");
CatalogTable catalogTable = Catalog.getInstance().getTable(Catalog.getInstance().getSchema(Catalog.defaultDatabaseId, "public").id , "PGInterfaceTestTable");
assertEquals(catalogTable.name, "pginterfacetesttable");
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
} catch (UnknownTableException e) {
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
statement.executeUpdate( "CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))" );
CatalogTable catalogTable = Catalog.getInstance().getTable( Catalog.getInstance().getSchema( Catalog.defaultDatabaseId, "public" ).id, "PGInterfaceTestTable" );
assertEquals( catalogTable.name, "pginterfacetesttable" );
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
} catch ( UnknownTableException e ) {
e.printStackTrace();
} catch (UnknownSchemaException e) {
} catch ( UnknownSchemaException e ) {
e.printStackTrace();
}
}
Expand All @@ -112,117 +113,103 @@ public void testIfDDLIsExecuted() throws SQLException {

/**
* This test executes several SQL-commands via the client, it creates a table, inserts and selects from it. The returned values from the select are tested
*
* @throws SQLException
*/
@Test
public void testIfDMLandDDLandDQLIsExecuted() throws SQLException {

try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection(false) ) {
try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection( false ) ) {
Connection connection = psqlJdbcConnection.getConnection();
try(Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate("CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))");
statement.executeUpdate("INSERT INTO pginterfacetesttable(PkIdTest, VarcharTest, IntTest) VALUES (1, 'Franz', 1), (2, 'Hello', 2), (3, 'By', 3);");
ResultSet rs = statement.executeQuery("SELECT * FROM pginterfacetesttable;");

TestHelper.checkResultSet(
rs,
ImmutableList.of(
new Object[]{1, "Franz", 1},
new Object[]{2, "Hello", 2},
new Object[]{3, "By", 3})
);

statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
statement.executeUpdate( "CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))" );
statement.executeUpdate( "INSERT INTO pginterfacetesttable(PkIdTest, VarcharTest, IntTest) VALUES (1, 'Franz', 1), (2, 'Hello', 2), (3, 'By', 3);" );
ResultSet rs = statement.executeQuery( "SELECT * FROM pginterfacetesttable;" );

TestHelper.checkResultSet( rs, ImmutableList.of( new Object[]{ 1, "Franz", 1 }, new Object[]{ 2, "Hello", 2 }, new Object[]{ 3, "By", 3 } ) );

statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
}
}
}

/**
* Tests if a prepared statement is correctly executed if the PREPARE and EXECUTE statement are sent seperately
*
* @throws SQLException
*/
@Test
public void testPreparedAndExecuteInTwoParts() throws SQLException {

try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection(false) ) {
try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection( false ) ) {
Connection connection = psqlJdbcConnection.getConnection();
try(Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate("CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))");
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
statement.executeUpdate( "CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))" );

//ResultSet rss = statement.executeQuery("PREPARE lol (int) AS SELECT empid FROM public.emps WHERE empid = $1; EXECUTE lol (100);");
statement.executeUpdate("PREPARE testPrepare (int, text, int) AS INSERT INTO pginterfacetesttable(PkIdTest, VarcharTest, IntTest) VALUES ($1, $2, $3);");
statement.executeUpdate("EXECUTE testPrepare (1, 'Franz', 1);");
ResultSet rs = statement.executeQuery("SELECT * FROM pginterfacetesttable;");
statement.executeUpdate( "PREPARE testPrepare (int, text, int) AS INSERT INTO pginterfacetesttable(PkIdTest, VarcharTest, IntTest) VALUES ($1, $2, $3);" );
statement.executeUpdate( "EXECUTE testPrepare (1, 'Franz', 1);" );
ResultSet rs = statement.executeQuery( "SELECT * FROM pginterfacetesttable;" );

TestHelper.checkResultSet(
rs,
ImmutableList.of(
new Object[]{1, "Franz", 1})
);
TestHelper.checkResultSet( rs, ImmutableList.of( new Object[]{ 1, "Franz", 1 } ) );

statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
}
}
}


/**
* Tests if a prepared statement is correctly executed if the PREPARE and EXECUTE statement are sent together
*
* @throws SQLException
*/
@Test
public void testPreparedAndExecuteInOnePart() throws SQLException {

try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection(false) ) {
try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection( false ) ) {
Connection connection = psqlJdbcConnection.getConnection();
try(Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate("CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))");
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
statement.executeUpdate( "CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, VarcharTest VARCHAR(255), IntTest INTEGER,PRIMARY KEY (PkIdTest))" );

//ResultSet rss = statement.executeQuery("PREPARE lol (int) AS SELECT empid FROM public.emps WHERE empid = $1; EXECUTE lol (100);");
statement.executeUpdate("PREPARE testPrepare (int, text, int) AS INSERT INTO pginterfacetesttable(PkIdTest, VarcharTest, IntTest) VALUES ($1, $2, $3); EXECUTE testPrepare (1, 'Franz', 1);");
ResultSet rs = statement.executeQuery("SELECT * FROM pginterfacetesttable;");
statement.executeUpdate( "PREPARE testPrepare (int, text, int) AS INSERT INTO pginterfacetesttable(PkIdTest, VarcharTest, IntTest) VALUES ($1, $2, $3); EXECUTE testPrepare (1, 'Franz', 1);" );
ResultSet rs = statement.executeQuery( "SELECT * FROM pginterfacetesttable;" );

TestHelper.checkResultSet(
rs,
ImmutableList.of(
new Object[]{1, "Franz", 1})
);
TestHelper.checkResultSet( rs, ImmutableList.of( new Object[]{ 1, "Franz", 1 } ) );

statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
}
}
}

/**
* This feature is not yet supported, but it tests if prepared statement are executed correctly using the JDBC framework
*
* @throws SQLException
*/
@Test
@Ignore
public void testPreparedUsingJdbc() throws SQLException {
//TODO(FF): Prepared Statements using JDBC not yet supported from PGInterface --> read inserted values from bind command (which is not done currently)

try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection(false) ) {
try ( PsqlJdbcConnection psqlJdbcConnection = new PsqlJdbcConnection( false ) ) {
Connection connection = psqlJdbcConnection.getConnection();
try(Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate("CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, IntTest INTEGER,PRIMARY KEY (PkIdTest))");
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
statement.executeUpdate( "CREATE TABLE pginterfacetesttable(PkIdTest INTEGER NOT NULL, IntTest INTEGER,PRIMARY KEY (PkIdTest))" );

PreparedStatement pst = connection.prepareStatement("INSERT INTO pginterfacetesttable(PkIdTest, IntTest) VALUES (?, ?)");
pst.setInt(1, 100);
PreparedStatement pst = connection.prepareStatement( "INSERT INTO pginterfacetesttable(PkIdTest, IntTest) VALUES (?, ?)" );
pst.setInt( 1, 100 );
pst.execute();
ResultSet rs = statement.executeQuery("SELECT * FROM pginterfacetesttable;");
ResultSet rs = statement.executeQuery( "SELECT * FROM pginterfacetesttable;" );

TestHelper.checkResultSet(
rs,
ImmutableList.of(
new Object[]{1, 100})
);
TestHelper.checkResultSet( rs, ImmutableList.of( new Object[]{ 1, 100 } ) );

statement.executeUpdate("DROP TABLE IF EXISTS public.pginterfacetesttable");
statement.executeUpdate( "DROP TABLE IF EXISTS public.pginterfacetesttable" );
}
}
}
Expand All @@ -239,7 +226,7 @@ public static class PsqlJdbcConnection implements AutoCloseable {
private final Connection conn;


public PsqlJdbcConnection(boolean autoCommit ) throws SQLException {
public PsqlJdbcConnection( boolean autoCommit ) throws SQLException {
try {
Class.forName( "org.postgresql.Driver" );
} catch ( ClassNotFoundException e ) {
Expand All @@ -249,8 +236,8 @@ public PsqlJdbcConnection(boolean autoCommit ) throws SQLException {
log.debug( "Connecting to database @ {}", url );

Properties connectionProps = new Properties();
connectionProps.setProperty("sslmode", "disable");
conn = DriverManager.getConnection(url, connectionProps);
connectionProps.setProperty( "sslmode", "disable" );
conn = DriverManager.getConnection( url, connectionProps );

//conn.setAutoCommit( autoCommit );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@

import com.google.common.collect.ImmutableList;
import io.netty.bootstrap.ServerBootstrap;
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.*;
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;
Expand All @@ -47,19 +36,27 @@
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
*/
@Slf4j
public class PGInterface extends QueryInterface {

@SuppressWarnings("WeakerAccess")
@SuppressWarnings( "WeakerAccess" )
public static final String INTERFACE_NAME = "Postgresql Interface";
@SuppressWarnings("WeakerAccess")
@SuppressWarnings( "WeakerAccess" )
// TODO: Update description text
public static final String INTERFACE_DESCRIPTION = "PostgreSQL-based query interface - in development";
@SuppressWarnings("WeakerAccess")
@SuppressWarnings( "WeakerAccess" )
public static final List<QueryInterfaceSetting> AVAILABLE_SETTINGS = ImmutableList.of(
new QueryInterfaceSettingInteger( "port", false, true, false, 5432 )
// new QueryInterfaceSettingInteger( "maxUploadSizeMb", false, true, true, 10000 ),
Expand Down Expand Up @@ -92,7 +89,7 @@ public PGInterface( TransactionManager transactionManager, Authenticator authent
}
// Add information page
monitoringPage = new MonitoringPage();
this.transactionManager = transactionManager;
PGInterface.transactionManager = transactionManager;
}


Expand Down
Loading

0 comments on commit ad1eb1f

Please sign in to comment.