use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.
the class BaseBench method startServer.
@Before
public void startServer() throws Exception {
makeServerConfiguration();
threadpool = Executors.newFixedThreadPool(numThreads);
server = new Server(serverConfiguration);
server.start();
server.waitForStandaloneBoot();
client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));
client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
dataSource = new BasicHerdDBDataSource(client);
}
use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.
the class AdvancedInsertSyntaxTest method testInsertFromSelect.
@Test
public void testInsertFromSelect() throws Exception {
try (Server server = new Server(new ServerConfiguration(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 create = con.createStatement();
PreparedStatement statement = con.prepareStatement("INSERT INTO mytable (name) values(?)")) {
create.execute("CREATE TABLE mytable (n1 int primary key auto_increment, name string)");
create.execute("CREATE TABLE mytable2 (n1 int primary key auto_increment, name string)");
{
for (int i = 0; i < 100; i++) {
statement.setString(1, "v" + i);
statement.addBatch();
}
int[] results = statement.executeBatch();
for (int i = 0; i < 100; i++) {
assertEquals(1, results[i]);
}
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable ORDER BY n1")) {
int count = 0;
while (rs.next()) {
assertEquals("v" + count, rs.getString("name"));
assertEquals(count + 1, rs.getInt("n1"));
count++;
}
assertEquals(100, count);
}
}
statement.executeUpdate("INSERT INTO mytable2(n1,name) SELECT n1, name from mytable order by name desc");
try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable2")) {
assertTrue(rs.next());
assertEquals(100, rs.getInt(1));
}
// leverage auto_increment
statement.executeUpdate("INSERT INTO mytable2(name) SELECT name from mytable order by name desc");
try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable2")) {
assertTrue(rs.next());
assertEquals(200, rs.getInt(1));
}
try (ResultSet rs = statement.executeQuery("SELECT n1 FROM mytable2 order by n1")) {
Set<Integer> ids = new HashSet<>();
while (rs.next()) {
int id = rs.getInt(1);
assertTrue(ids.add(id));
}
assertEquals(200, ids.size());
}
}
}
}
}
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)");
}
}
}
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)");
}
}
}
use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.
the class GeneratedKeysTest method testPreparedStatementInt.
@Test
public void testPreparedStatementInt() throws Exception {
try (Server server = new Server(new ServerConfiguration(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 (n1 int primary key auto_increment, name string)");
try (PreparedStatement prepared = con.prepareStatement("INSERT INTO mytable (name) values('name1')", Statement.RETURN_GENERATED_KEYS)) {
assertEquals(1, prepared.executeUpdate());
Object key = null;
try (ResultSet generatedKeys = prepared.getGeneratedKeys()) {
if (generatedKeys.next()) {
key = generatedKeys.getObject(1);
}
}
assertNotNull(key);
assertEquals(Integer.valueOf(1), key);
}
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(1, count);
}
}
}
}
}
Aggregations