Java Code Examples for org.apache.derby.jdbc.ClientDataSource#setCreateDatabase()
The following examples show how to use
org.apache.derby.jdbc.ClientDataSource#setCreateDatabase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcDatasetRuntimeTest.java From components with Apache License 2.0 | 6 votes |
@BeforeClass public static void startDatabase() throws Exception { ServerSocket socket = new ServerSocket(0); port = socket.getLocalPort(); socket.close(); JDBC_URL = "jdbc:derby://localhost:" + port + "/target/tcomp"; System.setProperty("derby.stream.error.file", "target/derby.log"); derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port); derbyServer.start(null); dataSource = new ClientDataSource(); dataSource.setCreateDatabase("create"); dataSource.setDatabaseName("target/tcomp"); dataSource.setServerName("localhost"); dataSource.setPortNumber(port); try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { statement.executeUpdate("create table " + TABLE_IN + "(id INT, name VARCHAR(500))"); statement.executeUpdate("create table " + TABLE_OUT + "(id INT, name VARCHAR(500))"); } } }
Example 2
Source File: JDBCBeamRuntimeTest.java From components with Apache License 2.0 | 5 votes |
@BeforeClass public static void startDatabase() throws Exception { ServerSocket socket = new ServerSocket(0); port = socket.getLocalPort(); socket.close(); LOGGER.info("Starting Derby database on {}", port); JDBC_URL = "jdbc:derby://localhost:" + port + "/target/tcomp"; System.setProperty("derby.stream.error.file", "target/derby.log"); derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port); derbyServer.start(null); dataSource = new ClientDataSource(); dataSource.setCreateDatabase("create"); dataSource.setDatabaseName("target/tcomp"); dataSource.setServerName("localhost"); dataSource.setPortNumber(port); try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { statement.executeUpdate("create table " + TABLE_IN + "(id INT, name VARCHAR(500))"); statement.executeUpdate("create table " + TABLE_OUT + "(id INT, name VARCHAR(500))"); } } }
Example 3
Source File: DynamicJdbcIOTest.java From DataflowTemplates with Apache License 2.0 | 4 votes |
@BeforeClass public static void startDatabase() throws Exception { ServerSocket socket = new ServerSocket(0); port = socket.getLocalPort(); socket.close(); LOG.info("Starting Derby database on {}", port); // by default, derby uses a lock timeout of 60 seconds. In order to speed up the test // and detect the lock faster, we decrease this timeout System.setProperty("derby.locks.waitTimeout", "2"); System.setProperty("derby.stream.error.file", "target/derby.log"); derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port); StringWriter out = new StringWriter(); derbyServer.start(new PrintWriter(out)); boolean started = false; int count = 0; // Use two different methods to detect when server is started: // 1) Check the server stdout for the "started" string // 2) wait up to 15 seconds for the derby server to start based on a ping // on faster machines and networks, this may return very quick, but on slower // networks where the DNS lookups are slow, this may take a little time while (!started && count < 30) { if (out.toString().contains("started")) { started = true; } else { count++; TimeUnit.MILLISECONDS.sleep(500); try { derbyServer.ping(); started = true; } catch (Throwable t) { // ignore, still trying to start } } } if (!started) { // Server has not started in the expected time frame throw new IllegalStateException("Derby server failed to start."); } dataSource = new ClientDataSource(); dataSource.setCreateDatabase("create"); dataSource.setDatabaseName("target/beam"); dataSource.setServerName("localhost"); dataSource.setPortNumber(port); readTableName = getTestTableName("UT_READ"); createTable(dataSource, readTableName); addInitialData(dataSource, readTableName); }
Example 4
Source File: JdbcIOTest.java From beam with Apache License 2.0 | 4 votes |
@BeforeClass public static void beforeClass() throws Exception { port = NetworkTestHelper.getAvailableLocalPort(); LOG.info("Starting Derby database on {}", port); // by default, derby uses a lock timeout of 60 seconds. In order to speed up the test // and detect the lock faster, we decrease this timeout System.setProperty("derby.locks.waitTimeout", "2"); System.setProperty("derby.stream.error.file", "target/derby.log"); derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port); StringWriter out = new StringWriter(); derbyServer.start(new PrintWriter(out)); boolean started = false; int count = 0; // Use two different methods to detect when server is started: // 1) Check the server stdout for the "started" string // 2) wait up to 15 seconds for the derby server to start based on a ping // on faster machines and networks, this may return very quick, but on slower // networks where the DNS lookups are slow, this may take a little time while (!started && count < 30) { if (out.toString().contains("started")) { started = true; } else { count++; Thread.sleep(500); try { derbyServer.ping(); started = true; } catch (Throwable t) { // ignore, still trying to start } } } dataSource = new ClientDataSource(); dataSource.setCreateDatabase("create"); dataSource.setDatabaseName("target/beam"); dataSource.setServerName("localhost"); dataSource.setPortNumber(port); readTableName = DatabaseTestHelper.getTestTableName("UT_READ"); DatabaseTestHelper.createTable(dataSource, readTableName); addInitialData(dataSource, readTableName); }