- Index
- »
- fan.sql
- »
- SqlConnPool
SqlConnPool
const class SqlConnPool : Obj
SqlConnPool manages a pool of reusable SQL connections
It-block construtor
autoCommit sets the autoCommit field on a connection just after it is opened by the pool
Max time to wait when opening a new connection to the database before failing
Time a connection may be held by an execute callback before checkLinger logs a warning that it may be stuck or leaked
Time to linger an idle connection before closing it
Logger
Max number of simultaneous connections to allow before blocking threads
Max lifetime of a connection before it is retired, regardless of how recently it was used
Connection password
Max time to block waiting for a connection before raising TimeoutErr
Connection URI
Connection username
Close idle connections that have lingered past the linger timeout or lived past the maxLifetime
Close all connections and raise exception on any new executes
Allocate a SQL connection inside the given callback
Return if close has been called
onClose is invoked just before a connection is closed by the pool
onOpen is invoked just after a connection is opened by the pool
Bool : autoCommit
autoCommit sets the autoCommit field on a connection just after it is opened by the pool.
If auto-commit is true then each statement is executed and committed as an individual transaction. Otherwise statements are grouped into transaction which must be closed via SqlConn.commit or SqlConn.rollback.
Void checkLinger()
Close idle connections that have lingered past the linger timeout or lived past the maxLifetime. Also log a warning for connections held in-use longer than leakWarn.
Void close()
Close all connections and raise exception on any new executes
const Duration? : connectTimeout
Max time to wait when opening a new connection to the database before failing. If null then the JDBC driver default is used. Note this is implemented via the global DriverManager.setLoginTimeout which applies JVM wide to all JDBC connections.
Void execute(|SqlConn| f)
Allocate a SQL connection inside the given callback. If a connection cannot be acquired before timeout elapses then a TimeoutErr is raised. Do not close the connection inside the callback.
Bool isClosed()
Return if close has been called.
const Duration : leakWarn
Time a connection may be held by an execute callback before checkLinger logs a warning that it may be stuck or leaked. The warning is logged once per checkout.
const Duration : linger
Time to linger an idle connection before closing it. An external actor must call checkLinger periodically to close idle connetions.
const Log : log
Logger
new make(|This|? f)
It-block construtor
const Int : maxConns
Max number of simultaneous connections to allow before blocking threads
const Duration : maxLifetime
Max lifetime of a connection before it is retired, regardless of how recently it was used. This protects against database and network infrastructure that kills long lived connections. It is enforced by checkLinger; connections in use are never retired until released back to the pool.
virtual Void onClose(SqlConn c)
onClose is invoked just before a connection is closed by the pool.
virtual Void onOpen(SqlConn c)
onOpen is invoked just after a connection is opened by the pool.
const Str? : password
Connection password
const Duration : timeout
Max time to block waiting for a connection before raising TimeoutErr
const Str : uri
Connection URI
const Str? : username
Connection username