Search in sources :

Example 11 with StaticClientSideMetadataProvider

use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.

the class MaxRowsTest method test.

@Test
public void test() throws Exception {
    try (Server server = new Server(TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
        server.start();
        server.waitForStandaloneBoot();
        try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            try (BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client);
                Connection con = dataSource.getConnection();
                Statement statement = con.createStatement()) {
                statement.execute("CREATE TABLE mytable (key string primary key, name string)");
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k1','name1')"));
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k2','name2')"));
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k3','name3')"));
                try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(3, count);
                }
                statement.setMaxRows(2);
                try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(2, count);
                }
                statement.setMaxRows(0);
                try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(3, count);
                }
                statement.setMaxRows(Integer.MAX_VALUE);
                try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(3, count);
                }
                try (PreparedStatement ps = con.prepareStatement("SELECT * FROM mytable")) {
                    try (ResultSet rs = ps.executeQuery()) {
                        int count = 0;
                        while (rs.next()) {
                            count++;
                        }
                        assertEquals(3, count);
                    }
                    ps.setMaxRows(2);
                    try (ResultSet rs = ps.executeQuery()) {
                        int count = 0;
                        while (rs.next()) {
                            count++;
                        }
                        assertEquals(2, count);
                    }
                    ps.setMaxRows(0);
                    try (ResultSet rs = ps.executeQuery()) {
                        int count = 0;
                        while (rs.next()) {
                            count++;
                        }
                        assertEquals(3, count);
                    }
                    ps.setMaxRows(Integer.MAX_VALUE);
                    try (ResultSet rs = ps.executeQuery()) {
                        int count = 0;
                        while (rs.next()) {
                            count++;
                        }
                        assertEquals(3, count);
                    }
                }
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 12 with StaticClientSideMetadataProvider

use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.

the class HerdDBResultSetTest method getStatement.

@Test
public void getStatement() throws Exception {
    try (final Server server = new Server(TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
        server.start();
        server.waitForStandaloneBoot();
        try (final HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            try (final BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client)) {
                try (Connection con = dataSource.getConnection();
                    Statement statement = con.createStatement()) {
                    statement.execute("CREATE TABLE mytable (c1 int primary key)");
                }
                try (final Connection con = dataSource.getConnection();
                    final PreparedStatement statement = con.prepareStatement("select * from mytable");
                    final ResultSet rows = statement.executeQuery()) {
                    Assert.assertEquals(statement, rows.getStatement());
                }
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 13 with StaticClientSideMetadataProvider

use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.

the class SimpleJoinTest method test.

@Test
public void test() throws Exception {
    try (Server server = new Server(TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
        server.start();
        server.waitForStandaloneBoot();
        try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            try (BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client);
                Connection con = dataSource.getConnection();
                Statement statement = con.createStatement()) {
                statement.execute("CREATE TABLE mytable (key string primary key, name string)");
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k1','name1')"));
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k2','name2')"));
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k3','name3')"));
                try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable a" + " INNER JOIN mytable b ON 1=1")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(9, count);
                }
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 14 with StaticClientSideMetadataProvider

use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.

the class CreateTableSpaceWithStaticMetadataProviderTest method test.

@Test
public void test() throws Exception {
    try (HerdDBEmbeddedDataSource dataSource = new HerdDBEmbeddedDataSource()) {
        dataSource.getProperties().setProperty(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
        dataSource.getProperties().setProperty(ClientConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
        dataSource.setMaxActive(20);
        try (Connection con = dataSource.getConnection()) {
        }
        assertTrue(dataSource.getClient().getClientSideMetadataProvider() instanceof StaticClientSideMetadataProvider);
        try (Connection con = dataSource.getConnection();
            Statement statement = con.createStatement()) {
            String leader = dataSource.getClient().getClientSideMetadataProvider().getTableSpaceLeader(TableSpace.DEFAULT);
            statement.execute("CREATE TABLESPACE 'mytablespace','wait:5000','leader:" + leader + "'");
            statement.execute("CREATE TABLE mytablespace.mytable(pk int primary key)");
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 15 with StaticClientSideMetadataProvider

use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.

the class CreateTableSpaceWithStaticMetadataProviderTest method testStandAloneServer.

@Test
public void testStandAloneServer() throws Exception {
    try (HerdDBEmbeddedDataSource dataSource = new HerdDBEmbeddedDataSource()) {
        dataSource.getProperties().setProperty(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
        dataSource.getProperties().setProperty(ClientConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
        dataSource.getProperties().setProperty(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_STANDALONE);
        dataSource.getProperties().setProperty(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_STANDALONE);
        dataSource.setStartServer(true);
        dataSource.setMaxActive(20);
        try (Connection con = dataSource.getConnection()) {
        }
        assertTrue(dataSource.getClient().getClientSideMetadataProvider() instanceof StaticClientSideMetadataProvider);
        try (Connection con = dataSource.getConnection();
            Statement statement = con.createStatement()) {
            String leader = dataSource.getClient().getClientSideMetadataProvider().getTableSpaceLeader(TableSpace.DEFAULT);
            System.out.println("leader:" + leader);
            statement.execute("CREATE TABLESPACE 'mytablespace','wait:5000','leader:" + leader + "'");
            statement.execute("CREATE TABLE mytablespace.mytable(pk int primary key)");
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Aggregations

StaticClientSideMetadataProvider (herddb.server.StaticClientSideMetadataProvider)59 Server (herddb.server.Server)56 Test (org.junit.Test)54 ClientConfiguration (herddb.client.ClientConfiguration)41 HDBClient (herddb.client.HDBClient)41 Connection (java.sql.Connection)39 Statement (java.sql.Statement)36 PreparedStatement (java.sql.PreparedStatement)30 ResultSet (java.sql.ResultSet)29 Path (java.nio.file.Path)15 RawString (herddb.utils.RawString)8 ServerConfiguration (herddb.server.ServerConfiguration)7 Map (java.util.Map)7 SQLException (java.sql.SQLException)6 HashSet (java.util.HashSet)4 HDBConnection (herddb.client.HDBConnection)3 MissingJDBCParameterException (herddb.model.MissingJDBCParameterException)3 List (java.util.List)3 HDBOperationTimeoutException (herddb.client.impl.HDBOperationTimeoutException)2 Transaction (herddb.model.Transaction)2