Interface Pool
- All Superinterfaces:
SqlClient
- All Known Subinterfaces:
JDBCPool
A connection pool which reuses a number of SQL connections.
- Author:
- Julien Viet
-
Method Summary
Modifier and TypeMethodDescriptionGet a connection from the pool.static Poolpool(Vertx vertx, SqlConnectOptions database, PoolOptions options) Create a connection pool to thedatabasewith the givenoptions.static Poolpool(SqlConnectOptions connectOptions) Likepool(SqlConnectOptions, PoolOptions)with default options.static Poolpool(SqlConnectOptions database, PoolOptions options) Likepool(Vertx, SqlConnectOptions, PoolOptions)with a Vert.x instance created automatically.preparedQuery(String sql) Create a prepared query, one of thePreparedQuery.execute(Tuple)orPreparedQuery.executeBatch(List)methods must be called to execute the query.Create a query, theQuery.execute()method must be called to execute the query.intsize()default <T> Future<T> withConnection(Function<SqlConnection, Future<T>> function) Get a connection from the pool and execute the givenfunction.default <T> Future<T> withTransaction(TransactionPropagation txPropagation, Function<SqlConnection, Future<T>> function) LikewithTransaction(Function)but allows for setting the mode, defining how the acquired connection is managed during the execution of the function.default <T> Future<T> withTransaction(Function<SqlConnection, Future<T>> function) Execute the givenfunctionwithin a transaction.Methods inherited from interface SqlClient
close, preparedQuery
-
Method Details
-
pool
Likepool(SqlConnectOptions, PoolOptions)with default options. -
pool
Likepool(Vertx, SqlConnectOptions, PoolOptions)with a Vert.x instance created automatically. -
pool
Create a connection pool to thedatabasewith the givenoptions.A
Driverwill be selected among the drivers found on the classpath returningtruewhenDriver.acceptsOptions(SqlConnectOptions)applied to the first options of the list.- Parameters:
vertx- the Vertx instance to be used with the connection pooldatabase- the options used to create the connection pool, such as database hostnameoptions- the options for creating the pool- Returns:
- the connection pool
- Throws:
ServiceConfigurationError- if no compatible drivers are found, or if multiple compatible drivers are found
-
getConnection
Future<SqlConnection> getConnection()Get a connection from the pool.- Returns:
- a future notified with the
SqlConnection
-
query
Create a query, theQuery.execute()method must be called to execute the query. A connection is borrowed from the connection pool when the query is executed and then immediately returned to the pool after it completes. -
preparedQuery
Create a prepared query, one of thePreparedQuery.execute(Tuple)orPreparedQuery.executeBatch(List)methods must be called to execute the query. A connection is borrowed from the connection pool when the query is executed and then immediately returned to the pool after it completes.- Specified by:
preparedQueryin interfaceSqlClient- Returns:
- the prepared query
-
withTransaction
Execute the givenfunctionwithin a transaction.The
functionis passed a client executing all operations within a transaction. When the future returned by the function- succeeds the transaction commits
- fails the transaction rollbacks
The
handleris given a success result when the function returns a succeeded futures and the transaction commits. Otherwise it is given a failure result.- Parameters:
function- the code to execute- Returns:
- a future notified with the result
-
withTransaction
default <T> Future<T> withTransaction(TransactionPropagation txPropagation, Function<SqlConnection, Future<T>> function) LikewithTransaction(Function)but allows for setting the mode, defining how the acquired connection is managed during the execution of the function. -
withConnection
Get a connection from the pool and execute the givenfunction.When the future returned by the
functioncompletes, the connection is returned to the pool.The
handleris given a success result when the function returns a succeeded futures. Otherwise it is given a failure result.- Parameters:
function- the code to execute- Returns:
- a future notified with the result
-
size
int size()- Returns:
- the current pool size approximation
-