Search in sources :

Example 6 with DB2ConnectOptions

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();
}
Also used : DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions)

Example 7 with DB2ConnectOptions

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;
}
Also used : Connection(java.sql.Connection) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions)

Example 8 with DB2ConnectOptions

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();
}
Also used : Pool(io.vertx.mutiny.sqlclient.Pool) Db2Container(org.testcontainers.containers.Db2Container) Tuple2(io.smallrye.mutiny.tuples.Tuple2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DB2Pool(io.vertx.mutiny.db2client.DB2Pool) Test(org.junit.Test) Uni(io.smallrye.mutiny.Uni) PoolOptions(io.vertx.sqlclient.PoolOptions) After(org.junit.After) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Vertx(io.vertx.mutiny.core.Vertx) Row(io.vertx.mutiny.sqlclient.Row) ClassRule(org.junit.ClassRule) Before(org.junit.Before) RowSet(io.vertx.mutiny.sqlclient.RowSet) PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Pool(io.vertx.mutiny.sqlclient.Pool) DB2Pool(io.vertx.mutiny.db2client.DB2Pool) Test(org.junit.Test)

Example 9 with DB2ConnectOptions

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;
}
Also used : DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Example 10 with DB2ConnectOptions

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();
}
Also used : Tuple2(io.smallrye.mutiny.tuples.Tuple2) PoolOptions(io.vertx.sqlclient.PoolOptions) RowSet(io.vertx.mutiny.sqlclient.RowSet) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Pool(io.vertx.mutiny.sqlclient.Pool) DB2Pool(io.vertx.mutiny.db2client.DB2Pool) Row(io.vertx.mutiny.sqlclient.Row) Test(org.junit.Test)

Aggregations

DB2ConnectOptions (io.vertx.db2client.DB2ConnectOptions)16 PoolOptions (io.vertx.sqlclient.PoolOptions)11 DB2Pool (io.vertx.db2client.DB2Pool)5 SqlClient (io.vertx.sqlclient.SqlClient)4 Vertx (io.vertx.core.Vertx)3 JksOptions (io.vertx.core.net.JksOptions)3 DB2Pool (io.vertx.mutiny.db2client.DB2Pool)3 Pool (io.vertx.mutiny.sqlclient.Pool)3 Row (io.vertx.sqlclient.Row)3 Collectors (java.util.stream.Collectors)3 Tuple2 (io.smallrye.mutiny.tuples.Tuple2)2 Future (io.vertx.core.Future)2 DB2Connection (io.vertx.db2client.DB2Connection)2 Source (io.vertx.docgen.Source)2 Row (io.vertx.mutiny.sqlclient.Row)2 RowSet (io.vertx.mutiny.sqlclient.RowSet)2 Pool (io.vertx.sqlclient.Pool)2 RowSet (io.vertx.sqlclient.RowSet)2 SqlConnectOptions (io.vertx.sqlclient.SqlConnectOptions)2 SqlResult (io.vertx.sqlclient.SqlResult)2