Search in sources :

Example 51 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class SimpleJoinTest method testSubQuery.

@Test
public void testSubQuery() 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)");
                statement.execute("CREATE TABLE table1 (k1 string primary key,n1 int,s1 string)");
                statement.execute("CREATE TABLE table2 (k2 string primary key,n2 int,s2 string)");
                statement.execute("INSERT INTO table1 (k1,n1,s1) values('a',1,'A')");
                statement.execute("INSERT INTO table1 (k1,n1,s1) values('b',2,'B')");
                statement.execute("INSERT INTO table2 (k2,n2,s2) values('c',3,'A')");
                statement.execute("INSERT INTO table2 (k2,n2,s2) values('d',4,'A')");
                try (ResultSet rs = statement.executeQuery("SELECT t1.k1, max(n1) as maxn1, max(select n2 from table2 t2 WHERE t1.s1=t2.s2) as maxn2 FROM " + " table1 t1 " + " group by k1")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(2, 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 52 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class SimpleTableScanWithNullsTest 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();
                Connection con2 = dataSource.getConnection();
                Statement statement = con.createStatement()) {
                statement.execute("CREATE TABLE `sm_machine` (\n" + "  `ip` varchar(20) NOT NULL DEFAULT '',\n" + "  `firefox_version` int(50) DEFAULT NULL,\n" + "  `chrome_version` int(50) DEFAULT NULL,\n" + "  `ie_version` int(50) DEFAULT NULL,\n" + "  `log` varchar(2000) DEFAULT NULL,\n" + "  `offset` int(50) DEFAULT NULL,\n" + "  PRIMARY KEY (`ip`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
                statement.executeUpdate("INSERT INTO `sm_machine` " + // + "`ie_version`,`log`,`offset`) "
                "VALUES" + "('10.168.10.106',26,36,9,NULL,1)," + "('10.168.10.107',26,31,10,NULL,1)," + "('10.168.10.108',26,36,11,NULL,2)," + "('10.168.10.109',33,38,10,NULL,3)," + "('10.168.10.110',33,38,10,NULL,4)");
                statement.executeQuery("SELECT * FROM sm_machine").close();
                try (ResultSet rs = statement.executeQuery("SELECT bad_field FROM sm_machine")) {
                    fail();
                } catch (SQLException ok) {
                }
                try (PreparedStatement statement2 = con.prepareStatement("SELECT bad_field FROM sm_machine");
                    ResultSet rs = statement2.executeQuery()) {
                    fail();
                } catch (SQLException ok) {
                }
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 53 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class SwitchTableSpaceTest 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 TABLESPACE 'ts1'");
                statement.execute("CREATE TABLESPACE 'ts2'");
                server.waitForTableSpaceBoot("ts1", true);
                server.waitForTableSpaceBoot("ts2", true);
                statement.execute("CREATE TABLE ts1.mytable (key string primary key, name string)");
                statement.execute("CREATE TABLE ts2.mytable2 (key string primary key, name string)");
                con.setAutoCommit(true);
                assertEquals(1, statement.executeUpdate("INSERT INTO ts1.mytable (key,name) values('k1','name1')"));
                assertEquals("ts1", con.getSchema());
                assertEquals(1, statement.executeUpdate("INSERT INTO ts2.mytable2 (key,name) values('k1','name1')"));
                assertEquals("ts2", con.getSchema());
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) Statement(java.sql.Statement) Connection(java.sql.Connection) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 54 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class TransactionsTest method emptyTransaction.

/**
 * Commit on a connection without any work
 */
@Test
public void emptyTransaction() 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()) {
                con.setAutoCommit(false);
                con.commit();
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) Connection(java.sql.Connection) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 55 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class TransactionsTest 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();
                Connection con2 = dataSource.getConnection();
                Statement statement = con.createStatement();
                Statement statement2 = con2.createStatement()) {
                statement.execute("CREATE TABLE mytable (key string primary key, name string)");
                con.setAutoCommit(false);
                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 = statement2.executeQuery("SELECT COUNT(*) FROM mytable")) {
                    assertTrue(rs.next());
                    assertEquals(0, rs.getLong(1));
                }
                con.commit();
                try (ResultSet rs = statement2.executeQuery("SELECT COUNT(*) FROM mytable")) {
                    assertTrue(rs.next());
                    assertEquals(3, rs.getLong(1));
                }
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k4','name4')"));
                con.commit();
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k5','name5')"));
                try (ResultSet rs = statement2.executeQuery("SELECT COUNT(*) FROM mytable")) {
                    assertTrue(rs.next());
                    assertEquals(4, rs.getLong(1));
                }
                try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable")) {
                    assertTrue(rs.next());
                    assertEquals(5, rs.getLong(1));
                }
                con.rollback();
                try (ResultSet rs = statement2.executeQuery("SELECT COUNT(*) FROM mytable")) {
                    assertTrue(rs.next());
                    assertEquals(4, rs.getLong(1));
                }
                try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable")) {
                    assertTrue(rs.next());
                    assertEquals(4, rs.getLong(1));
                }
                con.commit();
                try (PreparedStatement ps1 = con.prepareStatement("SELECT COUNT(*) FROM mytable");
                    ResultSet rs = ps1.executeQuery()) {
                    assertTrue(rs.next());
                    assertEquals(4, rs.getLong(1));
                }
                con.commit();
                // complex multi record update
                try (PreparedStatement ps1 = con.prepareStatement("UPDATE mytable set name='aa' WHERE 1=-1")) {
                    assertEquals(0, ps1.executeUpdate());
                }
                con.commit();
                // complex multi record update
                try (PreparedStatement ps1 = con.prepareStatement("UPDATE mytable set name='aa' WHERE 1=1")) {
                    assertEquals(4, ps1.executeUpdate());
                }
                con.commit();
                // direct record update
                try (PreparedStatement ps1 = con.prepareStatement("UPDATE mytable set name='aa' WHERE key='k5'")) {
                    assertEquals(0, ps1.executeUpdate());
                }
                con.commit();
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (herddb.client.ClientConfiguration)89 HDBClient (herddb.client.HDBClient)83 Test (org.junit.Test)79 Server (herddb.server.Server)56 HDBConnection (herddb.client.HDBConnection)45 StaticClientSideMetadataProvider (herddb.server.StaticClientSideMetadataProvider)41 Connection (java.sql.Connection)39 Statement (java.sql.Statement)34 PreparedStatement (java.sql.PreparedStatement)30 ResultSet (java.sql.ResultSet)29 Table (herddb.model.Table)23 CreateTableStatement (herddb.model.commands.CreateTableStatement)23 InsertStatement (herddb.model.commands.InsertStatement)22 ServerConfiguration (herddb.server.ServerConfiguration)17 ScanResultSet (herddb.client.ScanResultSet)13 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ProgressListener (herddb.backup.ProgressListener)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 HashSet (java.util.HashSet)12 Index (herddb.model.Index)9