Creating a pool
rdbc-pool project and this documentation is still a work in progress. It's not ready yet for production use.
A connection pool is a specialized
ConnectionFactory implementation that
maintains a set of ready to use connections and performs connection validation
before returning them to clients. The pool delegates connection requests to
underlying factory provided by client during pool creation.
Creating a pool¶
The pool is implemented in
ConnectionPool class. To create instance of
the pool use
ConnectionPool companion object's
apply method as follows:
1 2 3 4 5 6
import io.rdbc.pool.sapi.ConnectionPool import io.rdbc.pool.sapi.ConnectionPoolConfig val cf: ConnectionFactory = ??? val pool = ConnectionPool(cf, ConnectionPoolConfig())
To create the pool you first need to create and configure a connection factory
provided by rdbc driver you use (see the line 4 in the above snippet) and then
pass it as the
ConnectionPool#apply argument (line 6). The second argument
apply method is
ConnectionPoolConfig instance holding the pool
configuration. See configuration chapter for available configuration options.
Closing a pool¶
As any other
ConnectionFactory, a pool needs to be shut down to clean up
ConnectionPool#shutdown method to do it.