use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.
the class DB2ConnectionFactory method initializeConfiguration.
@Override
protected void initializeConfiguration(SqlConnectOptions connectOptions) {
DB2ConnectOptions options = (DB2ConnectOptions) connectOptions;
this.pipeliningLimit = options.getPipeliningLimit();
}
use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.
the class DB2Resource method before.
@Override
protected void before() throws Throwable {
if (started)
return;
if (!CUSTOM_DB2) {
instance.start();
options = new DB2ConnectOptions().setHost(instance.getContainerIpAddress()).setPort(instance.getMappedPort(50000)).setDatabase(instance.getDatabaseName()).setUser(instance.getUsername()).setPassword(instance.getPassword());
} else {
System.out.println("Using custom DB2 instance as requested via DB2_HOST=" + get("DB2_HOST"));
Objects.requireNonNull(get("DB2_PORT"), "Must set DB2_PORT to a non-null value if DB2_HOST is set");
Objects.requireNonNull(get("DB2_NAME"), "Must set DB2_NAME to a non-null value if DB2_HOST is set");
Objects.requireNonNull(get("DB2_USER"), "Must set DB2_USER to a non-null value if DB2_HOST is set");
Objects.requireNonNull(get("DB2_PASS"), "Must set DB2_PASS to a non-null value if DB2_HOST is set");
options = new DB2ConnectOptions().setHost(get("DB2_HOST")).setPort(Integer.valueOf(get("DB2_PORT"))).setDatabase(get("DB2_NAME")).setUser(get("DB2_USER")).setPassword(get("DB2_PASS"));
}
String jdbcUrl = "jdbc:db2://" + options.getHost() + ":" + options.getPort() + "/" + options.getDatabase();
System.out.println("Initializing DB2 database at: " + jdbcUrl);
try (Connection con = DriverManager.getConnection(jdbcUrl, options.getUser(), options.getPassword())) {
runInitSql(con);
}
started = true;
}
use of io.vertx.db2client.DB2ConnectOptions in project smallrye-mutiny-vertx-bindings by smallrye.
the class DB2ClientTest method testTransaction.
@Test
public void testTransaction() {
DB2ConnectOptions options = new DB2ConnectOptions().setPort(container.getMappedPort(50000)).setHost(container.getContainerIpAddress()).setDatabase(container.getDatabaseName()).setUser(container.getUsername()).setPassword(container.getPassword());
Pool client = DB2Pool.pool(vertx, options, new PoolOptions().setMaxSize(5));
Uni<Void> uni = client.getConnection().onItem().transformToUni(c -> {
return c.begin().onItem().transformToUni(tx -> c.query("SELECT 1 FROM SYSIBM.SYSDUMMY1").execute().call(() -> c.query("SELECT 1 FROM SYSIBM.SYSDUMMY1").execute()).onItem().transformToUni(results -> tx.commit()).onFailure().recoverWithUni(t -> tx.rollback()));
});
Void v = uni.await().indefinitely();
assertThat(v).isNull();
}
use of io.vertx.db2client.DB2ConnectOptions in project quarkus by quarkusio.
the class DB2PoolRecorder method toConnectOptions.
private DB2ConnectOptions toConnectOptions(DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactiveDB2Config dataSourceReactiveDB2Config) {
DB2ConnectOptions connectOptions;
if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
String url = dataSourceReactiveRuntimeConfig.url.get();
// clean up the URL to make migrations easier
if (url.matches("^vertx-reactive:db2://.*$")) {
url = url.substring("vertx-reactive:".length());
}
connectOptions = DB2ConnectOptions.fromUri(url);
} else {
connectOptions = new DB2ConnectOptions();
}
if (dataSourceRuntimeConfig.username.isPresent()) {
connectOptions.setUser(dataSourceRuntimeConfig.username.get());
}
if (dataSourceRuntimeConfig.password.isPresent()) {
connectOptions.setPassword(dataSourceRuntimeConfig.password.get());
}
// credentials provider
if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
String name = dataSourceRuntimeConfig.credentialsProvider.get();
Map<String, String> credentials = credentialsProvider.getCredentials(name);
String user = credentials.get(USER_PROPERTY_NAME);
String password = credentials.get(PASSWORD_PROPERTY_NAME);
if (user != null) {
connectOptions.setUser(user);
}
if (password != null) {
connectOptions.setPassword(user);
}
}
if (dataSourceReactiveDB2Config.cachePreparedStatements.isPresent()) {
log.warn("datasource.reactive.db2.cache-prepared-statements is deprecated, use datasource.reactive.cache-prepared-statements instead");
connectOptions.setCachePreparedStatements(dataSourceReactiveDB2Config.cachePreparedStatements.get());
} else {
connectOptions.setCachePreparedStatements(dataSourceReactiveRuntimeConfig.cachePreparedStatements);
}
connectOptions.setSsl(dataSourceReactiveDB2Config.ssl);
connectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll);
configurePemTrustOptions(connectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePem);
configureJksTrustOptions(connectOptions, dataSourceReactiveRuntimeConfig.trustCertificateJks);
configurePfxTrustOptions(connectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePfx);
configurePemKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePem);
configureJksKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
configurePfxKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);
connectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);
connectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());
if (dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.isPresent()) {
connectOptions.setHostnameVerificationAlgorithm(dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.get());
}
return connectOptions;
}
use of io.vertx.db2client.DB2ConnectOptions in project smallrye-mutiny-vertx-bindings by smallrye.
the class DB2ClientTest method testSequence.
@Test
public void testSequence() {
DB2ConnectOptions options = new DB2ConnectOptions().setPort(container.getMappedPort(50000)).setHost(container.getContainerIpAddress()).setDatabase(container.getDatabaseName()).setUser(container.getUsername()).setPassword(container.getPassword());
Pool client = DB2Pool.pool(vertx, options, new PoolOptions().setMaxSize(5));
Uni<Tuple2<RowSet<Row>, RowSet<Row>>> uni = client.getConnection().flatMap(c -> Uni.combine().all().unis(c.preparedQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1").execute(), c.preparedQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1").execute()).asTuple());
Tuple2<RowSet<Row>, RowSet<Row>> results = uni.await().indefinitely();
assertThat(results).isNotNull();
assertThat(results.size()).isEqualTo(2);
assertThat(results.getItem1()).isNotNull();
assertThat(results.getItem2()).isNotNull();
}
Aggregations