List of usage examples for io.vertx.pgclient PgPool pool
static PgPool pool(Vertx vertx, PgConnectOptions connectOptions, PoolOptions poolOptions)
From source file:examples.PgClientExamples.java
License:Apache License
public void configureFromDataObject(Vertx vertx) { // Data object PgConnectOptions connectOptions = new PgConnectOptions().setPort(5432).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 PgPool pool = PgPool.pool(vertx, connectOptions, poolOptions); pool.getConnection(ar -> {//from www .j a va 2 s. c o m // Handling your connection }); }
From source file:examples.PgClientExamples.java
License:Apache License
public void connecting02(Vertx vertx) { // Connect options PgConnectOptions connectOptions = new PgConnectOptions().setPort(5432).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret"); // Pool options PoolOptions poolOptions = new PoolOptions().setMaxSize(5); // Create the pooled client PgPool client = PgPool.pool(vertx, connectOptions, poolOptions); }
From source file:examples.PgClientExamples.java
License:Apache License
public void connecting04(Vertx vertx) { // Connect options PgConnectOptions connectOptions = new PgConnectOptions().setPort(5432).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret"); // Pool options PoolOptions poolOptions = new PoolOptions().setMaxSize(5); // Create the pooled client PgPool client = PgPool.pool(vertx, connectOptions, poolOptions); // Get a connection from the pool client.getConnection(ar1 -> {/* w w w .ja va 2 s . c o m*/ if (ar1.succeeded()) { System.out.println("Connected"); // Obtain our connection SqlConnection conn = ar1.result(); // All operations execute on the same connection conn.query("SELECT * FROM users WHERE id='julien'", ar2 -> { if (ar2.succeeded()) { conn.query("SELECT * FROM users WHERE id='emad'", ar3 -> { // Release the connection to the pool conn.close(); }); } else { // Release the connection to the pool conn.close(); } }); } else { System.out.println("Could not connect: " + ar1.cause().getMessage()); } }); }