Interface Pool

  • All Superinterfaces:
    SqlClient
    All Known Subinterfaces:
    JDBCPool

    public interface Pool
    extends SqlClient
    A connection pool which reuses a number of SQL connections.
    Author:
    Julien Viet
    • Method Detail

      • pool

        static Pool pool​(Vertx vertx,
                         SqlConnectOptions database,
                         PoolOptions options)
        Create a connection pool to the database with the given options.

        A Driver will be selected among the drivers found on the classpath returning true when Driver.acceptsOptions(SqlConnectOptions) applied to the first options of the list.

        Parameters:
        vertx - the Vertx instance to be used with the connection pool
        database - the options used to create the connection pool, such as database hostname
        options - 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
      • query

        Query<RowSet<Row>> query​(String sql)
        Create a query, the Query.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.
        Specified by:
        query in interface SqlClient
        Returns:
        the query
      • withTransaction

        default <T> Future<T> withTransaction​(java.util.function.Function<SqlConnection,​Future<T>> function)
        Execute the given function within a transaction.

        The function is 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 handler is 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
      • withConnection

        default <T> Future<T> withConnection​(java.util.function.Function<SqlConnection,​Future<T>> function)
        Get a connection from the pool and execute the given function.

        When the future returned by the function completes, the connection is returned to the pool.

        The handler is 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