This class implements a connection pool for the PostGIS driver. More...
#include <ConnectionPool.h>
Classes | |
| class | ConnectionPoolImpl |
Public Member Functions | |
| void | finalize () |
| It closes all connections and clears all resources managed by the pool. More... | |
| Connection * | getConnection (int id=-1) |
| It returns a connection from the pool. More... | |
| te::pgis::DataSource * | getDataSource () const |
| std::size_t | getInitialPoolSize () const |
| It returns the initial number of connections opened by the pool at its startup. More... | |
| unsigned int | getMaxIdleTime () const |
| It returns the maximum idle time in seconds that a connection can be maintained in the pool without being used. More... | |
| std::size_t | getMaxPoolSize () const |
| It returns the maximum number of connections managed by the pool. More... | |
| std::size_t | getMinPoolSize () const |
| It returns the minimum number of connections managed by the pool. More... | |
| std::size_t | getPoolSize () const |
| It returns the number of connections in the pool. More... | |
| void | idle () |
| It releases the connections that are not in use for a long time. More... | |
| void | initialize () |
| It initializes the connections to be managed by the pool. More... | |
| bool | isInitialized () const |
| It returns true if the connection pool is initialized, otherwise it returns false. More... | |
| bool | isValid () const |
| It checks if all the connections in the pool are valid (the communication channel is ok). More... | |
| void | release (Connection *conn) |
| It brings the informed connection back to the pool. More... | |
| void | setInitialPoolSize (std::size_t size) |
| It sets the initial number of connections opened by the pool at its startup. More... | |
| void | setMaxIdleTime (unsigned int t) |
| It sets the maximum idle time that a connection can be maintained in the pool without being used. More... | |
| void | setMaxPoolSize (std::size_t size) |
| It sets the maximum number of connections managed by the pool. More... | |
| void | setMinPoolSize (std::size_t size) |
| It sets the minimum number of connections managed by the pool. More... | |
Private Member Functions | |
| ConnectionPool (DataSource *ds) | |
| It creates a new connection pool for the database informed. More... | |
| int | getAvailableConnectionId () |
| Gets the first available connection. More... | |
| te::pgis::Connection * | getConnectionById (const int &id) |
| Gets a connection by id. More... | |
| void | setConnectionInUse (const int &id, const bool &inUse) |
| Sets the state of the connection by id. More... | |
| ~ConnectionPool () | |
| Destructor. More... | |
Private Attributes | |
| ConnectionPoolImpl * | m_pImpl |
| A pointer to the pool implementation. More... | |
Friends | |
| class | DataSource |
This class implements a connection pool for the PostGIS driver.
Definition at line 49 of file ConnectionPool.h.
|
private |
It creates a new connection pool for the database informed.
| ds | The data source using this pool. |
Definition at line 432 of file ConnectionPool.cpp.
References m_pImpl.
|
private |
Destructor.
It will automatically close all connections to a PostgreSQL database.
Definition at line 438 of file ConnectionPool.cpp.
References m_pImpl.
|
virtual |
It closes all connections and clears all resources managed by the pool.
| Exception | It may throws an exception if there is a connection in use or if it is not possible to stop the pool. |
Implements te::da::AbstractConnectionPool.
Definition at line 150 of file ConnectionPool.cpp.
References te::common::FreeContents(), te::pgis::ConnectionPool::ConnectionPoolImpl::m_availableConnectionsIds, te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, te::pgis::ConnectionPool::ConnectionPoolImpl::m_initialized, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, m_pImpl, te::pgis::ConnectionPool::ConnectionPoolImpl::m_poolSize, and TE_TR.
Referenced by te::pgis::DataSource::close().
|
private |
Gets the first available connection.
Definition at line 410 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_availableConnectionsIds, and m_pImpl.
Referenced by getConnection().
| te::pgis::Connection * te::pgis::ConnectionPool::getConnection | ( | int | id = -1 | ) |
It returns a connection from the pool.
| Exception | It throws an exception if it is not possible to get a connection. |
Definition at line 300 of file ConnectionPool.cpp.
References getAvailableConnectionId(), getConnectionById(), te::pgis::ConnectionPool::ConnectionPoolImpl::m_cencoding, te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, te::pgis::ConnectionPool::ConnectionPoolImpl::m_conninfo, te::pgis::Connection::m_id, te::pgis::Connection::m_inuse, te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxIdleTime, te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, m_pImpl, te::pgis::ConnectionPool::ConnectionPoolImpl::m_poolSize, te::common::NO_CONNECTION_AVAILABLE, setConnectionInUse(), and TE_TR.
Referenced by te::pgis::DataSource::getConnection(), te::pgis::Transactor::getConnection(), and te::pgis::ScopedConnection::ScopedConnection().
|
private |
Gets a connection by id.
Definition at line 418 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, and m_pImpl.
Referenced by getConnection().
| te::pgis::DataSource * te::pgis::ConnectionPool::getDataSource | ( | ) | const |
Definition at line 251 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_ds, and m_pImpl.
|
virtual |
It returns the initial number of connections opened by the pool at its startup.
Implements te::da::AbstractConnectionPool.
Definition at line 261 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_initialPoolSize, and m_pImpl.
| unsigned int te::pgis::ConnectionPool::getMaxIdleTime | ( | ) | const |
It returns the maximum idle time in seconds that a connection can be maintained in the pool without being used.
Definition at line 370 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxIdleTime, and m_pImpl.
|
virtual |
It returns the maximum number of connections managed by the pool.
Implements te::da::AbstractConnectionPool.
Definition at line 287 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxPoolSize, and m_pImpl.
|
virtual |
It returns the minimum number of connections managed by the pool.
Implements te::da::AbstractConnectionPool.
Definition at line 274 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_minPoolSize, and m_pImpl.
|
virtual |
It returns the number of connections in the pool.
Implements te::da::AbstractConnectionPool.
Definition at line 256 of file ConnectionPool.cpp.
References m_pImpl, and te::pgis::ConnectionPool::ConnectionPoolImpl::m_poolSize.
|
virtual |
It releases the connections that are not in use for a long time.
This method will try to keep the pool with the minimum number of opened connections. It will be invoked by the connection pool manager when its thread wakeup. It must check the idle connections and must destroy them.
Implements te::da::AbstractConnectionPool.
Definition at line 177 of file ConnectionPool.cpp.
References d, isInitialized(), te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxIdleTime, te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_minPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, m_pImpl, and te::pgis::ConnectionPool::ConnectionPoolImpl::m_poolSize.
|
virtual |
It initializes the connections to be managed by the pool.
| Exception | It throws an exception if it is not possible to initialize the pool. |
Implements te::da::AbstractConnectionPool.
Definition at line 85 of file ConnectionPool.cpp.
References te::core::Expand(), te::da::DataSource::getConnectionInfo(), te::da::DataSource::getEncoding(), te::core::CharEncoding::getEncodingName(), isInitialized(), te::pgis::ConnectionPool::ConnectionPoolImpl::m_cencoding, te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, te::pgis::ConnectionPool::ConnectionPoolImpl::m_conninfo, te::pgis::ConnectionPool::ConnectionPoolImpl::m_ds, te::pgis::Connection::m_id, te::pgis::ConnectionPool::ConnectionPoolImpl::m_initialized, te::pgis::ConnectionPool::ConnectionPoolImpl::m_initialPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxIdleTime, te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_minPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, m_pImpl, te::pgis::ConnectionPool::ConnectionPoolImpl::m_poolSize, te::pgis::MakeConnectionStr(), PGIS_DEFAULT_INITIAL_POOL_SIZE, PGIS_DEFAULT_MAX_IDLE_TIME, PGIS_DEFAULT_MAX_POOL_SIZE, PGIS_DEFAULT_MIN_POOL_SIZE, te::core::URI::query(), setConnectionInUse(), te::pgis::DataSource::setTimeAsInteger(), and TE_TR.
Referenced by te::pgis::DataSource::open().
|
virtual |
It returns true if the connection pool is initialized, otherwise it returns false.
Implements te::da::AbstractConnectionPool.
Definition at line 246 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_initialized, and m_pImpl.
Referenced by idle(), initialize(), and te::pgis::DataSource::isOpened().
|
virtual |
It checks if all the connections in the pool are valid (the communication channel is ok).
Implements te::da::AbstractConnectionPool.
Definition at line 225 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, and m_pImpl.
Referenced by te::pgis::DataSource::isValid().
| void te::pgis::ConnectionPool::release | ( | Connection * | conn | ) |
It brings the informed connection back to the pool.
| conn | The connection to be put back the pool. |
Definition at line 360 of file ConnectionPool.cpp.
References te::pgis::Connection::m_id, te::pgis::Connection::m_lastuse, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, m_pImpl, and setConnectionInUse().
Referenced by te::pgis::DataSource::closeConnection(), and te::pgis::ScopedConnection::release().
Sets the state of the connection by id.
| id | The connection id. |
| inUse | The connection state. |
Definition at line 383 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_availableConnectionsIds, te::pgis::ConnectionPool::ConnectionPoolImpl::m_connections, and m_pImpl.
Referenced by getConnection(), initialize(), and release().
|
virtual |
It sets the initial number of connections opened by the pool at its startup.
| size | It specifies the initial number of connections that must be opened by the pool at its startup. |
Implements te::da::AbstractConnectionPool.
Definition at line 266 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_initialPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, and m_pImpl.
| void te::pgis::ConnectionPool::setMaxIdleTime | ( | unsigned int | t | ) |
It sets the maximum idle time that a connection can be maintained in the pool without being used.
| t | It specifies the maximum idle time in seconds that a connection can be maintained in the pool without being used. |
Definition at line 375 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxIdleTime, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, and m_pImpl.
|
virtual |
It sets the maximum number of connections managed by the pool.
| size | The maximum number of connections that the pool must manage. |
Implements te::da::AbstractConnectionPool.
Definition at line 292 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_maxPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, and m_pImpl.
|
virtual |
It sets the minimum number of connections managed by the pool.
| size | The minimum number of connections that the pool must manage. |
Implements te::da::AbstractConnectionPool.
Definition at line 279 of file ConnectionPool.cpp.
References te::pgis::ConnectionPool::ConnectionPoolImpl::m_minPoolSize, te::pgis::ConnectionPool::ConnectionPoolImpl::m_mtx, and m_pImpl.
|
friend |
Definition at line 173 of file ConnectionPool.h.
|
private |
A pointer to the pool implementation.
Definition at line 169 of file ConnectionPool.h.
Referenced by ConnectionPool(), finalize(), getAvailableConnectionId(), getConnection(), getConnectionById(), getDataSource(), getInitialPoolSize(), getMaxIdleTime(), getMaxPoolSize(), getMinPoolSize(), getPoolSize(), idle(), initialize(), isInitialized(), isValid(), release(), setConnectionInUse(), setInitialPoolSize(), setMaxIdleTime(), setMaxPoolSize(), setMinPoolSize(), and ~ConnectionPool().