use of herddb.client.HDBClient in project herddb by diennea.
the class RollbackOnCloseConnectionTest method test.
@Test
public void test() throws Exception {
try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
server.getNetworkServer().setEnableJVMNetwork(false);
server.start();
try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
long tx;
try (HDBConnection connection = client.openConnection()) {
long resultCreateTable = connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE mytable (id string primary key, n1 long, n2 integer)", 0, false, Collections.emptyList()).updateCount;
Assert.assertEquals(1, resultCreateTable);
tx = connection.beginTransaction(TableSpace.DEFAULT);
long countInsert = connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", tx, false, Arrays.asList("test", 1, 2)).updateCount;
Assert.assertEquals(1, countInsert);
assertTrue(server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getOpenTransactions().contains(tx));
}
for (int i = 0; i < 100; i++) {
if (!server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getOpenTransactions().contains(tx)) {
break;
}
Thread.sleep(100);
}
assertFalse(server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getOpenTransactions().contains(tx));
}
}
}
use of herddb.client.HDBClient in project herddb by diennea.
the class SelectColumnTest 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 " + data.keyType + " primary key, val " + data.valueType + ")");
try (PreparedStatement insert = con.prepareStatement("INSERT INTO mytable (key,val) values(?,?)")) {
for (Object[] odata : data.data) {
insert.setObject(1, odata[0]);
setParameterAccordingToJavaType(insert, 2, odata[1]);
assertEquals(1, insert.executeUpdate());
}
}
if (data.checkKey()) {
try (PreparedStatement selectKey = con.prepareStatement("SELECT key FROM mytable WHERE key = ?")) {
for (Object[] odata : data.data) {
selectKey.setObject(1, odata[0]);
try (ResultSet rs = selectKey.executeQuery()) {
int count = 0;
while (rs.next()) {
data.keyChecker.accept(rs, odata[0]);
count++;
}
assertEquals(1, count);
}
}
}
}
try (PreparedStatement selectKey = con.prepareStatement("SELECT val FROM mytable WHERE key = ?")) {
for (Object[] odata : data.data) {
selectKey.setObject(1, odata[0]);
try (ResultSet rs = selectKey.executeQuery()) {
int count = 0;
while (rs.next()) {
data.valueChecker.accept(rs, odata[1]);
count++;
}
assertEquals(1, count);
}
}
}
}
}
}
}
use of herddb.client.HDBClient 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);
}
}
}
}
}
use of herddb.client.HDBClient 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) {
}
}
}
}
}
use of herddb.client.HDBClient 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());
}
}
}
}
Aggregations