Search in sources :

Example 1 with SqlClient

use of io.vertx.sqlclient.SqlClient in project vertx-sql-client by eclipse-vertx.

the class DB2ClientExamples method connecting02.

public void connecting02(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
    SqlClient client = DB2Pool.client(vertx, connectOptions, poolOptions);
}
Also used : SqlClient(io.vertx.sqlclient.SqlClient) PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions)

Example 2 with SqlClient

use of io.vertx.sqlclient.SqlClient in project vertx-sql-client by eclipse-vertx.

the class DB2ClientExamples method connecting01.

public void connecting01() {
    // 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
    SqlClient client = DB2Pool.client(connectOptions, poolOptions);
}
Also used : SqlClient(io.vertx.sqlclient.SqlClient) PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions)

Example 3 with SqlClient

use of io.vertx.sqlclient.SqlClient 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)

Example 4 with SqlClient

use of io.vertx.sqlclient.SqlClient in project vertx-sql-client by eclipse-vertx.

the class InetCodecTest method testDecodeINET.

private void testDecodeINET(TestContext ctx, BiFunction<SqlClient, String, Query<RowSet<Row>>> a) throws Exception {
    InetAddress addr1 = Inet4Address.getByName("0.1.2.3");
    InetAddress addr2 = Inet6Address.getByName("2001:0db8:0a0b:12f0:0000:0000:0000:0001");
    PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
        a.apply(conn, "SELECT " + "'0.1.2.3'::INET," + "'0.1.2.3/4'::INET," + "'2001:0db8:0a0b:12f0:0000:0000:0000:0001'::INET," + "'2001:0db8:0a0b:12f0:0000:0000:0000:0001/4'::INET").execute(ctx.asyncAssertSuccess(rows -> {
            ctx.assertEquals(1, rows.size());
            Row row = rows.iterator().next();
            Inet v1 = (Inet) row.getValue(0);
            Inet v2 = (Inet) row.getValue(1);
            Inet v3 = (Inet) row.getValue(2);
            Inet v4 = (Inet) row.getValue(3);
            ctx.assertEquals(addr1, v1.getAddress());
            ctx.assertNull(v1.getNetmask());
            ctx.assertEquals(addr1, v2.getAddress());
            ctx.assertEquals(4, v2.getNetmask());
            ctx.assertEquals(addr2, v3.getAddress());
            ctx.assertNull(v3.getNetmask());
            ctx.assertEquals(addr2, v4.getAddress());
            ctx.assertEquals(4, v4.getNetmask());
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) InetAddress(java.net.InetAddress) Inet6Address(java.net.Inet6Address) PgConnection(io.vertx.pgclient.PgConnection) SqlClient(io.vertx.sqlclient.SqlClient) Query(io.vertx.sqlclient.Query) BiFunction(java.util.function.BiFunction) Row(io.vertx.sqlclient.Row) RowSet(io.vertx.sqlclient.RowSet) Test(org.junit.Test) Inet4Address(java.net.Inet4Address) Tuple(io.vertx.sqlclient.Tuple) Row(io.vertx.sqlclient.Row) InetAddress(java.net.InetAddress)

Aggregations

SqlClient (io.vertx.sqlclient.SqlClient)4 DB2ConnectOptions (io.vertx.db2client.DB2ConnectOptions)2 PoolOptions (io.vertx.sqlclient.PoolOptions)2 RowSet (io.vertx.sqlclient.RowSet)2 DB2Pool (io.vertx.db2client.DB2Pool)1 TestContext (io.vertx.ext.unit.TestContext)1 PgConnection (io.vertx.pgclient.PgConnection)1 Query (io.vertx.sqlclient.Query)1 Row (io.vertx.sqlclient.Row)1 Tuple (io.vertx.sqlclient.Tuple)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 BiFunction (java.util.function.BiFunction)1 Test (org.junit.Test)1