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 () |
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... | |
~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 48 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 348 of file ConnectionPool.cpp.
References te::common::Singleton< ConnectionPoolManager >::getInstance(), and m_pImpl.
|
private |
Destructor.
It will automatically close all connections to a PostgreSQL database.
Definition at line 356 of file ConnectionPool.cpp.
References te::common::Singleton< ConnectionPoolManager >::getInstance().
|
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 144 of file ConnectionPool.cpp.
References te::common::FreeContents(), and TE_TR.
te::pgis::Connection * te::pgis::ConnectionPool::getConnection | ( | ) |
It returns a connection from the pool.
Exception | It throws an exception if it is not possible to get a connection. |
Definition at line 293 of file ConnectionPool.cpp.
References te::common::NO_CONNECTION_AVAILABLE, and TE_TR.
te::pgis::DataSource * te::pgis::ConnectionPool::getDataSource | ( | ) | const |
Definition at line 244 of file ConnectionPool.cpp.
|
virtual |
It returns the initial number of connections opened by the pool at its startup.
Implements te::da::AbstractConnectionPool.
Definition at line 254 of file ConnectionPool.cpp.
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 335 of file ConnectionPool.cpp.
|
virtual |
It returns the maximum number of connections managed by the pool.
Implements te::da::AbstractConnectionPool.
Definition at line 280 of file ConnectionPool.cpp.
|
virtual |
It returns the minimum number of connections managed by the pool.
Implements te::da::AbstractConnectionPool.
Definition at line 267 of file ConnectionPool.cpp.
|
virtual |
It returns the number of connections in the pool.
Implements te::da::AbstractConnectionPool.
Definition at line 249 of file ConnectionPool.cpp.
|
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 170 of file ConnectionPool.cpp.
|
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 80 of file ConnectionPool.cpp.
References te::common::CharEncodingConv::getCharEncodingType(), te::pgis::DataSource::getConnectionInfo(), te::pgis::GetPGEncoding(), 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::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::pgis::DataSource::setTimeAsInteger(), and TE_TR.
|
virtual |
It returns true if the connection pool is initialized, otherwise it returns false.
Implements te::da::AbstractConnectionPool.
Definition at line 239 of file ConnectionPool.cpp.
Referenced by initialize().
|
virtual |
It checks if all the connections in the pool are valid (the communication channel is ok).
Implements te::da::AbstractConnectionPool.
Definition at line 218 of file ConnectionPool.cpp.
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 326 of file ConnectionPool.cpp.
References te::pgis::Connection::m_inuse, and te::pgis::Connection::m_lastuse.
|
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 259 of file ConnectionPool.cpp.
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 340 of file ConnectionPool.cpp.
|
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 285 of file ConnectionPool.cpp.
|
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 272 of file ConnectionPool.cpp.
|
friend |
Definition at line 150 of file ConnectionPool.h.
|
private |
A pointer to the pool implementation.
Definition at line 146 of file ConnectionPool.h.
Referenced by ConnectionPool(), and initialize().