Package io.vertx.sqlclient
Interface ClientBuilder<C>
-
public interface ClientBuilder<C>
Builder forSqlClient
instances.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description C
build()
Build and return the client.ClientBuilder<C>
connectingTo(SqlConnectOptions database)
Configure thedatabase
the client should connect to.ClientBuilder<C>
connectingTo(String database)
Configure thedatabase
the client should connect to.ClientBuilder<C>
connectingTo(java.util.function.Supplier<Future<SqlConnectOptions>> supplier)
Configure thedatabase
the client should connect to.ClientBuilder<C>
connectingTo(List<SqlConnectOptions> databases)
Configure thedatabase
the client should connect to.static ClientBuilder<Pool>
pool(Driver<?> driver)
Provide a builder for a pool of connections for the specifiedDriver
static Pool
pool(Driver<?> driver, Handler<ClientBuilder<Pool>> block)
Build a pool with the specifiedblock
argument andDriver
Theblock
argument is usually a lambda that configures the provided builderClientBuilder<C>
using(Vertx vertx)
Sets the vertx instance to use.ClientBuilder<C>
with(NetClientOptions options)
Configure the client pool with the given transportoptions
.ClientBuilder<C>
with(PoolOptions options)
Configure the client with the given pooloptions
ClientBuilder<C>
withConnectHandler(Handler<SqlConnection> handler)
Set a handler called when the pool has established a connection to the database.
-
-
-
Method Detail
-
pool
static ClientBuilder<Pool> pool(Driver<?> driver)
Provide a builder for a pool of connections for the specifiedDriver
Example usage:
Pool pool = ClientBuilder.pool(driver).connectingTo(connectOptions).build()
-
pool
static Pool pool(Driver<?> driver, Handler<ClientBuilder<Pool>> block)
Build a pool with the specifiedblock
argument andDriver
Theblock
argument is usually a lambda that configures the provided builderExample usage:
Pool pool = ClientBuilder.pool(driver, builder -> builder.connectingTo(connectOptions));
- Returns:
- the pool as configured by the code
block
-
with
ClientBuilder<C> with(PoolOptions options)
Configure the client with the given pooloptions
- Parameters:
options
- the pool options- Returns:
- a reference to this, so the API can be used fluently
-
with
ClientBuilder<C> with(NetClientOptions options)
Configure the client pool with the given transportoptions
. Note: the SSL options part is ignored, sinceSqlConnectOptions
configures the transport SSL.- Parameters:
options
- the transport options- Returns:
- a reference to this, so the API can be used fluently
-
connectingTo
ClientBuilder<C> connectingTo(SqlConnectOptions database)
Configure thedatabase
the client should connect to. The targetdatabase
is specified as aSqlConnectOptions
coordinates.- Parameters:
database
- the database coordinates- Returns:
- a reference to this, so the API can be used fluently
-
connectingTo
ClientBuilder<C> connectingTo(String database)
Configure thedatabase
the client should connect to. The targetdatabase
is specified as aSqlConnectOptions
coordinates.- Parameters:
database
- the database URI- Returns:
- a reference to this, so the API can be used fluently
-
connectingTo
ClientBuilder<C> connectingTo(java.util.function.Supplier<Future<SqlConnectOptions>> supplier)
Configure thedatabase
the client should connect to. When the client needs to connect to the database, it gets fresh database configuration from the databasesupplier
.- Parameters:
supplier
- the supplier of database coordinates- Returns:
- a reference to this, so the API can be used fluently
-
connectingTo
ClientBuilder<C> connectingTo(List<SqlConnectOptions> databases)
Configure thedatabase
the client should connect to. When the client needs to connect to the database, it gets a database configuration from the list ofdatabases
using a round-robin policy.- Parameters:
databases
- the list of database coordinates- Returns:
- a reference to this, so the API can be used fluently
-
using
ClientBuilder<C> using(Vertx vertx)
Sets the vertx instance to use.- Parameters:
vertx
- the vertx instance- Returns:
- a reference to this, so the API can be used fluently
-
withConnectHandler
ClientBuilder<C> withConnectHandler(Handler<SqlConnection> handler)
Set a handler called when the pool has established a connection to the database.This handler allows interactions with the database before the connection is added to the pool.
When the handler has finished, it must call
SqlClient.close()
to release the connection to the pool.- Parameters:
handler
- the handler- Returns:
- a reference to this, so the API can be used fluently
-
build
C build()
Build and return the client.- Returns:
- the client
-
-