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
33
namespace
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
*/
49
class
TEPGISEXPORT
ConnectionPool
:
public
te::da::AbstractConnectionPool
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
63
te::pgis::DataSource
* getDataSource()
const
;
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
*/
92
Connection
* getConnection(
int
id
= -1);
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
*/
136
ConnectionPool
(
DataSource
* ds);
137
138
/*!
139
\brief Destructor.
140
141
It will automatically close all connections to a PostgreSQL database.
142
*/
143
~
ConnectionPool
();
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
*/
158
int
getAvailableConnectionId();
159
160
/*!
161
\brief Gets a connection by id
162
163
\return A connection by id.
164
*/
165
te::pgis::Connection
* getConnectionById(
const
int
&
id
);
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
te::pgis::Connection
A class that implements a connection to a PostgreSQL database.
Definition:
Connection.h:68
TEPGISEXPORT
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition:
Config.h:195
te::pgis::DataSource
The PostGIS driver.
Definition:
DataSource.h:54
Config.h
Configuration flags for the PostGIS Driver Implementation of TerraLib.
te
TerraLib.
Definition:
AddressGeocodingOp.h:51
te::pgis::ConnectionPool::m_pImpl
ConnectionPoolImpl * m_pImpl
A pointer to the pool implementation.
Definition:
ConnectionPool.h:169
te::pgis::ConnectionPool
This class implements a connection pool for the PostGIS driver.
Definition:
ConnectionPool.h:49
te::da::AbstractConnectionPool
This class defines the basic interface for a connection pool.
Definition:
AbstractConnectionPool.h:64
git_release
src
terralib
postgis
ConnectionPool.h
Generated on Thu Dec 19 2019 11:46:45 for TerraLib by
1.8.14