use of org.davidmoten.rx.jdbc.ConnectionProvider in project rxjava2-jdbc by davidmoten.
the class DatabaseCreator method connectionProvider.
private static ConnectionProvider connectionProvider(String url, boolean big) {
return new ConnectionProvider() {
private final AtomicBoolean once = new AtomicBoolean(false);
private final CountDownLatch latch = new CountDownLatch(1);
@Override
public Connection get() {
try {
if (once.compareAndSet(false, true)) {
try {
Connection c = DriverManager.getConnection(url);
createDatabase(c, big);
c.setAutoCommit(false);
return c;
} finally {
latch.countDown();
}
} else {
if (latch.await(30, TimeUnit.SECONDS)) {
return DriverManager.getConnection(url);
} else {
throw new TimeoutException("big database timed out on creation");
}
}
} catch (SQLException | InterruptedException | TimeoutException e) {
throw new SQLRuntimeException(e);
}
}
@Override
public void close() {
//
}
};
}
use of org.davidmoten.rx.jdbc.ConnectionProvider in project rxjava2-jdbc by davidmoten.
the class DatabaseCreator method connectionProviderDerby.
private static ConnectionProvider connectionProviderDerby(String url, boolean withStoredProcs) {
Connection c;
try {
c = DriverManager.getConnection(url);
createDatabaseDerby(c);
if (withStoredProcs) {
addStoredProcs(c);
}
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
return new ConnectionProvider() {
@Override
public Connection get() {
try {
return DriverManager.getConnection(url);
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
}
@Override
public void close() {
//
}
};
}
Aggregations