Search in sources :

Example 1 with DB2ConnectOptions

use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.

the class DB2Driver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    DB2ConnectOptions baseConnectOptions = DB2ConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    boolean pipelinedPool = options instanceof Db2PoolOptions && ((Db2PoolOptions) options).isPipelined();
    int pipeliningLimit = pipelinedPool ? baseConnectOptions.getPipeliningLimit() : 1;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, pipeliningLimit, options, null, null, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) DB2Pool(io.vertx.db2client.DB2Pool) CloseFuture(io.vertx.core.impl.CloseFuture) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) io.vertx.db2client.impl(io.vertx.db2client.impl) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Example 2 with DB2ConnectOptions

use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.

the class DB2ClientExamples method connecting04.

public void connecting04(Vertx vertx) {
    // Connect options
    DB2ConnectOptions connectOptions = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
    // Pool options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
    // Create the pooled client
    DB2Pool client = DB2Pool.pool(vertx, connectOptions, poolOptions);
    // Get a connection from the pool
    client.getConnection().compose(conn -> {
        System.out.println("Got a connection from the pool");
        // All operations execute on the same connection
        return conn.query("SELECT * FROM users WHERE id='julien'").execute().compose(res -> conn.query("SELECT * FROM users WHERE id='emad'").execute()).onComplete(ar -> {
            // Release the connection to the pool
            conn.close();
        });
    }).onComplete(ar -> {
        if (ar.succeeded()) {
            System.out.println("Done");
        } else {
            System.out.println("Something went wrong " + ar.cause().getMessage());
        }
    });
}
Also used : SqlClient(io.vertx.sqlclient.SqlClient) JksOptions(io.vertx.core.net.JksOptions) Vertx(io.vertx.core.Vertx) DB2Connection(io.vertx.db2client.DB2Connection) Pool(io.vertx.sqlclient.Pool) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) PoolOptions(io.vertx.sqlclient.PoolOptions) Tuple(io.vertx.sqlclient.Tuple) Source(io.vertx.docgen.Source) DB2Pool(io.vertx.db2client.DB2Pool) SqlResult(io.vertx.sqlclient.SqlResult) Map(java.util.Map) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Row(io.vertx.sqlclient.Row) RowSet(io.vertx.sqlclient.RowSet) Collector(java.util.stream.Collector) PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) DB2Pool(io.vertx.db2client.DB2Pool)

Example 3 with DB2ConnectOptions

use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.

the class DB2ClientExamples method configureFromDataObject.

public void configureFromDataObject(Vertx vertx) {
    // Data object
    DB2ConnectOptions connectOptions = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
    // Pool Options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
    // Create the pool from the data object
    DB2Pool pool = DB2Pool.pool(vertx, connectOptions, poolOptions);
    pool.getConnection(ar -> {
    // Handling your connection
    });
}
Also used : PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) DB2Pool(io.vertx.db2client.DB2Pool)

Example 4 with DB2ConnectOptions

use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.

the class DB2ClientExamples method gettingStarted.

public void gettingStarted() {
    // Connect options
    DB2ConnectOptions connectOptions = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
    // Pool options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
    // Create the client pool
    DB2Pool client = DB2Pool.pool(connectOptions, poolOptions);
    // A simple query
    client.query("SELECT * FROM users WHERE id='julien'").execute(ar -> {
        if (ar.succeeded()) {
            RowSet<Row> result = ar.result();
            System.out.println("Got " + result.size() + " rows ");
        } else {
            System.out.println("Failure: " + ar.cause().getMessage());
        }
        // Now close the pool
        client.close();
    });
}
Also used : PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Row(io.vertx.sqlclient.Row) DB2Pool(io.vertx.db2client.DB2Pool)

Example 5 with DB2ConnectOptions

use of io.vertx.db2client.DB2ConnectOptions in project vertx-sql-client by eclipse-vertx.

the class DB2ClientExamples method connecting05.

public void connecting05(Vertx vertx) {
    // Pool options
    DB2ConnectOptions options = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
    // Connect to DB2
    DB2Connection.connect(vertx, options).compose(conn -> {
        System.out.println("Connected");
        // All operations execute on the same connection
        return conn.query("SELECT * FROM users WHERE id='julien'").execute().compose(res -> conn.query("SELECT * FROM users WHERE id='emad'").execute()).onComplete(ar -> {
            // Close the connection
            conn.close();
        });
    }).onComplete(res -> {
        if (res.succeeded()) {
            System.out.println("Done");
        } else {
            System.out.println("Could not connect: " + res.cause().getMessage());
        }
    });
}
Also used : SqlClient(io.vertx.sqlclient.SqlClient) JksOptions(io.vertx.core.net.JksOptions) Vertx(io.vertx.core.Vertx) DB2Connection(io.vertx.db2client.DB2Connection) Pool(io.vertx.sqlclient.Pool) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) PoolOptions(io.vertx.sqlclient.PoolOptions) Tuple(io.vertx.sqlclient.Tuple) Source(io.vertx.docgen.Source) DB2Pool(io.vertx.db2client.DB2Pool) SqlResult(io.vertx.sqlclient.SqlResult) Map(java.util.Map) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Row(io.vertx.sqlclient.Row) RowSet(io.vertx.sqlclient.RowSet) Collector(java.util.stream.Collector) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions)

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