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;
}
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());
}
});
}
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
});
}
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();
});
}
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());
}
});
}
Aggregations