Loading...
Searching...
No Matches
ConnectionPool.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file terralib/postgis/ConnectionPool.h
22
23 \brief A class that implements a connection pool for PostGIS.
24*/
25
26#ifndef __TERRALIB_POSTGIS_INTERNAL_CONNECTIONPOOL_H
27#define __TERRALIB_POSTGIS_INTERNAL_CONNECTIONPOOL_H
28
29// TerraLib
30#include "../dataaccess/datasource/AbstractConnectionPool.h"
31#include "Config.h"
32
33namespace te
34{
35 namespace pgis
36 {
37// Forward declarations
38 class Connection;
39 class DataSource;
40 class ScopedConnection;
41
42 /*!
43 \class ConnectionPool
44
45 \brief This class implements a connection pool for the PostGIS driver.
46
47 \sa AbstractConnectionPool, ConnectionPoolManager, Connection
48 */
50 {
51 public:
52
53 void initialize();
54
55 void finalize();
56
57 void idle();
58
59 bool isValid() const;
60
61 bool isInitialized() const;
62
64
65 std::size_t getPoolSize() const;
66
67 std::size_t getInitialPoolSize() const;
68
69 void setInitialPoolSize(std::size_t size);
70
71 std::size_t getMinPoolSize() const;
72
73 void setMinPoolSize(std::size_t size);
74
75 std::size_t getMaxPoolSize() const;
76
77 void setMaxPoolSize(std::size_t size);
78
79 /*!
80 \brief It returns a connection from the pool.
81
82 \return A connection if one is available or an exception will be raised.
83
84 \exception Exception It throws an exception if it is not possible to get a connection.
85
86 \warning You must call the release() method after using the connection to assure
87 that the connection was returned to the pool. This approach
88 will increase concurrency in the connection.
89
90 \note PostGIS extended method.
91 */
93
94
95 /*!
96 \brief It brings the informed connection back to the pool.
97
98 \param conn The connection to be put back the pool.
99
100 \note PostGIS extended method.
101 */
102 void release(Connection* conn);
103
104 /*!
105 \brief It returns the maximum idle time in seconds that a connection can be maintained in the pool without being used.
106
107 \return The maximum idle time that a connection can be maintained in the pool without being used.
108
109 \note Thread-safe.
110
111 \note PostGIS extended method.
112 */
113 unsigned int getMaxIdleTime() const;
114
115 /*!
116 \brief It sets the maximum idle time that a connection can be maintained in the pool without being used.
117
118 \param t It specifies the maximum idle time in seconds that a connection
119 can be maintained in the pool without being used.
120
121 \note A zero value indicates that the connections will not be removed from the
122 pool when it is not being used for a while.
123
124 \note Thread-safe.
125
126 \note PostGIS extended method.
127 */
128 void setMaxIdleTime(unsigned int t);
129
130 private:
131 /*!
132 \brief It creates a new connection pool for the database informed.
133
134 \param ds The data source using this pool.
135 */
137
138 /*!
139 \brief Destructor.
140
141 It will automatically close all connections to a PostgreSQL database.
142 */
144
145 /*!
146 \brief Sets the state of the connection by id.
147
148 \param id The connection id.
149 \param inUse The connection state.
150 */
151 void setConnectionInUse(const int& id, const bool& inUse);
152
153 /*!
154 \brief Gets the first available connection.
155
156 \return The first available connection.
157 */
159
160 /*!
161 \brief Gets a connection by id
162
163 \return A connection by id.
164 */
166
167 private:
168
169 class ConnectionPoolImpl;
170
171 ConnectionPoolImpl* m_pImpl; //!< A pointer to the pool implementation.
172
173 friend class DataSource;
174 };
175
176 } // end namespace pgis
177} // end namespace te
178
179
180#endif // __TERRALIB_POSTGIS_INTERNAL_CONNECTIONPOOL_H
This class defines the basic interface for a connection pool.
This class implements a connection pool for the PostGIS driver.
void idle()
It releases the connections that are not in use for a long time.
Connection * getConnection(int id=-1)
It returns a connection from the pool.
void setConnectionInUse(const int &id, const bool &inUse)
Sets the state of the connection by id.
int getAvailableConnectionId()
Gets the first available connection.
te::pgis::Connection * getConnectionById(const int &id)
Gets a connection by id.
bool isValid() const
It checks if all the connections in the pool are valid (the communication channel is ok).
void setInitialPoolSize(std::size_t size)
It sets the initial number of connections opened by the pool at its startup.
void release(Connection *conn)
It brings the informed connection back to the pool.
std::size_t getInitialPoolSize() const
It returns the initial number of connections opened by the pool at its startup.
unsigned int getMaxIdleTime() const
It returns the maximum idle time in seconds that a connection can be maintained in the pool without b...
ConnectionPoolImpl * m_pImpl
A pointer to the pool implementation.
std::size_t getPoolSize() const
It returns the number of connections in the pool.
void initialize()
It initializes the connections to be managed by the pool.
~ConnectionPool()
Destructor.
bool isInitialized() const
It returns true if the connection pool is initialized, otherwise it returns false.
std::size_t getMaxPoolSize() const
It returns the maximum number of connections managed by the pool.
std::size_t getMinPoolSize() const
It returns the minimum number of connections managed by the pool.
void setMinPoolSize(std::size_t size)
It sets the minimum number of connections managed by the pool.
te::pgis::DataSource * getDataSource() const
void setMaxPoolSize(std::size_t size)
It sets the maximum number of connections managed by the pool.
void finalize()
It closes all connections and clears all resources managed by the pool.
void setMaxIdleTime(unsigned int t)
It sets the maximum idle time that a connection can be maintained in the pool without being used.
ConnectionPool(DataSource *ds)
It creates a new connection pool for the database informed.
A class that implements a connection to a PostgreSQL database.
Definition: Connection.h:69
The PostGIS driver.
Definition: DataSource.h:55
TerraLib.
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:195
Proxy configuration file for TerraView (see terraview_config.h).