use of org.apache.derby.jdbc.ClientDataSource in project torodb by torodb.
the class OfficialDerbyDriver method getConfiguredDataSource.
@Override
public DataSource getConfiguredDataSource(DerbyDbBackendConfiguration configuration, String poolName) {
DataSource dataSource;
if (configuration.embedded()) {
EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
embeddedDataSource.setCreateDatabase("create");
if (configuration.inMemory()) {
embeddedDataSource.setDatabaseName("memory:" + configuration.getDbName());
} else {
embeddedDataSource.setDatabaseName(configuration.getDbName());
}
try (Connection connection = embeddedDataSource.getConnection()) {
LOGGER.debug("Derby test connection has been successfully created.");
} catch (SQLException ex) {
throw new SystemException(ex);
}
embeddedDataSource.setCreateDatabase(null);
dataSource = embeddedDataSource;
} else {
ClientDataSource clientDataSource = new ClientDataSource();
clientDataSource.setServerName(configuration.getDbHost());
clientDataSource.setPortNumber(configuration.getDbPort());
clientDataSource.setUser(configuration.getUsername());
clientDataSource.setPassword(configuration.getPassword());
if (configuration.inMemory()) {
clientDataSource.setDatabaseName("memory:" + configuration.getDbName());
} else {
clientDataSource.setDatabaseName(configuration.getDbName());
}
dataSource = clientDataSource;
}
if (LOGGER.isTraceEnabled()) {
try {
dataSource.setLogWriter(LOGGER_WRITER);
} catch (SQLException sqlException) {
throw new SystemException(sqlException);
}
}
//TODO
try (Connection conn = dataSource.getConnection();
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1")) {
rs.next();
} catch (SQLException ex) {
throw new SystemException(ex);
}
return dataSource;
}
use of org.apache.derby.jdbc.ClientDataSource in project beam by apache.
the class JdbcIOTest method startDatabase.
@BeforeClass
public static void startDatabase() throws Exception {
ServerSocket socket = new ServerSocket(0);
port = socket.getLocalPort();
socket.close();
LOG.info("Starting Derby database on {}", port);
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;
// 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);
JdbcTestDataSet.createReadDataTable(dataSource);
}
Aggregations