Search in sources :

Example 1 with DB2Pool

use of io.vertx.db2client.DB2Pool 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 2 with DB2Pool

use of io.vertx.db2client.DB2Pool 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 3 with DB2Pool

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

the class DB2ClientExamples method configureFromUri.

public void configureFromUri(Vertx vertx) {
    // Connection URI
    String connectionUri = "db2://dbuser:secretpassword@database.server.com:50000/mydb";
    // Create the pool from the connection URI
    DB2Pool pool = DB2Pool.pool(connectionUri);
    // Create the connection from the connection URI
    DB2Connection.connect(vertx, connectionUri, res -> {
    // Handling your connection
    });
}
Also used : DB2Pool(io.vertx.db2client.DB2Pool)

Example 4 with DB2Pool

use of io.vertx.db2client.DB2Pool 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 DB2Pool

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

the class DB2ClientExamples method poolVersusPooledClient.

public void poolVersusPooledClient(Vertx vertx, String sql, DB2ConnectOptions connectOptions, PoolOptions poolOptions) {
    // Pooled client
    SqlClient pooledClient = DB2Pool.client(vertx, connectOptions, poolOptions);
    // Pipelined
    Future<RowSet<Row>> res1 = pooledClient.query(sql).execute();
    // Connection pool
    DB2Pool pool = DB2Pool.pool(vertx, connectOptions, poolOptions);
    // Not pipelined
    Future<RowSet<Row>> res2 = pool.query(sql).execute();
}
Also used : SqlClient(io.vertx.sqlclient.SqlClient) RowSet(io.vertx.sqlclient.RowSet) DB2Pool(io.vertx.db2client.DB2Pool)

Aggregations

DB2Pool (io.vertx.db2client.DB2Pool)8 PoolOptions (io.vertx.sqlclient.PoolOptions)5 DB2ConnectOptions (io.vertx.db2client.DB2ConnectOptions)4 Vertx (io.vertx.core.Vertx)2 Row (io.vertx.sqlclient.Row)2 RowSet (io.vertx.sqlclient.RowSet)2 SqlClient (io.vertx.sqlclient.SqlClient)2 Collectors (java.util.stream.Collectors)2 RuntimeValue (io.quarkus.runtime.RuntimeValue)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Future (io.vertx.core.Future)1 CloseFuture (io.vertx.core.impl.CloseFuture)1 ContextInternal (io.vertx.core.impl.ContextInternal)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 JsonObject (io.vertx.core.json.JsonObject)1 JksOptions (io.vertx.core.net.JksOptions)1 ClientMetrics (io.vertx.core.spi.metrics.ClientMetrics)1 VertxMetrics (io.vertx.core.spi.metrics.VertxMetrics)1 DB2Connection (io.vertx.db2client.DB2Connection)1