27 #include "../common/StringUtils.h"
28 #include "../common/Translator.h"
29 #include "../dataaccess/dataset/CheckConstraint.h"
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/ForeignKey.h"
32 #include "../dataaccess/dataset/Index.h"
33 #include "../dataaccess/dataset/PrimaryKey.h"
34 #include "../dataaccess/dataset/Sequence.h"
35 #include "../dataaccess/dataset/UniqueKey.h"
36 #include "../dataaccess/datasource/ScopedTransaction.h"
37 #include "../dataaccess/query/Select.h"
38 #include "../dataaccess/query/SQLDialect.h"
39 #include "../dataaccess/utils/Utils.h"
40 #include "../datatype/Array.h"
41 #include "../datatype/Property.h"
42 #include "../datatype/SimpleData.h"
43 #include "../geometry/GeometryProperty.h"
44 #include "../geometry/Utils.h"
45 #include "../raster/Grid.h"
46 #include "../raster/BandProperty.h"
47 #include "../raster/RasterProperty.h"
48 #include "../geometry/Geometry.h"
67 #include <boost/format.hpp>
100 m_connInfo = connInfo;
112 return m_pool->getConnection();
117 m_pool->release(conn);
122 return m_timeIsInteger;
127 m_timeIsInteger = timeIsInteger;
136 std::map<std::string, std::string>::const_iterator it = m_connInfo.find(
"PG_CLIENT_ENCODING");
137 if(it != m_connInfo.end())
142 m_pool->initialize();
144 std::auto_ptr<te::da::DataSourceTransactor> t = getTransactor();
162 return m_pool->isInitialized();
167 return m_pool->isValid();
182 return m_geomTypeOid;
187 return m_rasterTypeOid;
192 return m_currentSchema;
208 std::auto_ptr<DataSource> ds(
new DataSource());
210 ds->setConnectionInfo(dsInfo);
215 std::string sql =
"CREATE DATABASE ";
217 std::map<std::string, std::string>::const_iterator it = dsInfo.find(
"PG_NEWDB_NAME");
218 std::map<std::string, std::string>::const_iterator it_end = dsInfo.end();
221 sql +=
"\"" + it->second +
"\"";
223 throw Exception(
TE_TR(
"The database could not be created due the missing parameter: PG_NEWDB_NAME!"));
225 it = dsInfo.find(
"PG_NEWDB_TEMPLATE");
228 sql +=
" TEMPLATE = " + it->second;
230 it = dsInfo.find(
"PG_NEWDB_OWNER");
233 sql +=
" OWNER = " + it->second;
235 it = dsInfo.find(
"PG_NEWDB_ENCODING");
238 sql +=
" ENCODING = " + it->second;
240 it = dsInfo.find(
"PG_NEWDB_TABLESPACE");
243 sql +=
" TABLESPACE = " + it->second;
245 it = dsInfo.find(
"PG_NEWDB_CONN_LIMIT");
248 sql +=
" CONNECTION LIMIT = " + it->second;
255 it = dsInfo.find(
"PG_NEWDB_HOST");
258 it = dsInfo.find(
"PG_HOST");
261 m_connInfo[
"PG_HOST"] = it->second;
263 it = dsInfo.find(
"PG_NEWDB_HOSTADDR");
266 it = dsInfo.find(
"PG_HOST_ADDR");
269 m_connInfo[
"PG_HOST_ADDR"] = it->second;
271 it = dsInfo.find(
"PG_NEWDB_PORT");
274 it = dsInfo.find(
"PG_PORT");
277 m_connInfo[
"PG_PORT"] = it->second;
279 it = dsInfo.find(
"PG_NEWDB_NAME");
282 m_connInfo[
"PG_DB_NAME"] = it->second;
284 it = dsInfo.find(
"PG_NEWDB_USER");
287 it = dsInfo.find(
"PG_USER");
290 m_connInfo[
"PG_USER"] = it->second;
292 it = dsInfo.find(
"PG_NEWDB_PASSWORD");
295 it = dsInfo.find(
"PG_PASSWORD");
298 m_connInfo[
"PG_PASSWORD"] = it->second;
300 it = dsInfo.find(
"PG_NEWDB_CONNECT_TIMEOUT");
303 it = dsInfo.find(
"PG_CONNECT_TIMEOUT");
306 m_connInfo[
"PG_CONNECT_TIMEOUT"] = it->second;
308 it = dsInfo.find(
"PG_NEWDB_OPTIONS");
311 it = dsInfo.find(
"PG_OPTIONS");
314 m_connInfo[
"PG_OPTIONS"] = it->second;
316 it = dsInfo.find(
"PG_NEWDB_SSL_MODE");
319 it = dsInfo.find(
"PG_SSL_MODE");
322 m_connInfo[
"PG_SSL_MODE"] = it->second;
324 it = dsInfo.find(
"PG_NEWDB_KRBSRVNAME");
327 it = dsInfo.find(
"PG_KRBSRVNAME");
330 m_connInfo[
"PG_KRBSRVNAME"] = it->second;
332 it = dsInfo.find(
"PG_NEWDB_GSSLIB");
335 it = dsInfo.find(
"PG_GSSLIB");
338 m_connInfo[
"PG_GSSLIB"] = it->second;
340 it = dsInfo.find(
"PG_NEWDB_INITIAL_POOL_SIZE");
343 it = dsInfo.find(
"PG_INITIAL_POOL_SIZE");
346 m_connInfo[
"PG_INITIAL_POOL_SIZE"] = it->second;
348 it = dsInfo.find(
"PG_NEWDB_MIN_POOL_SIZE");
351 it = dsInfo.find(
"PG_MIN_POOL_SIZE");
354 m_connInfo[
"PG_MIN_POOL_SIZE"] = it->second;
356 it = dsInfo.find(
"PG_NEW_DB_MAX_POOL_SIZE");
359 it = dsInfo.find(
"PG_MAX_POOL_SIZE");
362 m_connInfo[
"PG_MAX_POOL_SIZE"] = it->second;
364 it = dsInfo.find(
"PG_NEWDB_MAX_IDLE_TIME");
367 it = dsInfo.find(
"PG_MAX_IDLE_TIME");
370 m_connInfo[
"PG_MAX_IDLE_TIME"] = it->second;
372 it = dsInfo.find(
"PG_NEWDB_CLIENT_ENCODING");
375 it = dsInfo.find(
"PG_CLIENT_ENCODING");
378 m_connInfo[
"PG_CLIENT_ENCODING"] = it->second;
384 std::auto_ptr<DataSource> ds(
new DataSource());
386 ds->setConnectionInfo(dsInfo);
391 std::string sql =
"DROP DATABASE ";
393 std::map<std::string, std::string>::const_iterator it = dsInfo.find(
"PG_DB_TO_DROP");
395 if(it == dsInfo.end())
396 throw Exception(
TE_TR(
"Could not drop the database due the missing parameter: PG_DB_TO_DROP!"));
398 if((it->second ==
"postgres") || (it->second ==
"template_postgis"))
399 throw Exception(
TE_TR(
"The database postgres or template_postgis is not allowed to be dropped!"));
410 if(dsInfo.count(
"PG_CHECK_DB_EXISTENCE") == 0)
411 throw Exception(
TE_TR(
"Could not check the PostgreSQL database existence due the missing parameter: PG_CHECK_DB_EXISTENCE!"));
413 const std::string& dbName = dsInfo.find(
"PG_CHECK_DB_EXISTENCE")->second;
416 std::auto_ptr<DataSource> ds(
new DataSource());
418 ds->setConnectionInfo(dsInfo);
422 std::string sql(
"SELECT * FROM pg_database WHERE datname = '");
426 std::auto_ptr<te::da::DataSet> database(ds->query(sql));
430 return database->moveNext();
436 std::auto_ptr<DataSource> ds(
new DataSource());
438 ds->setConnectionInfo(dsInfo);
442 std::string sql(
"SELECT datname FROM pg_database");
444 std::auto_ptr<te::da::DataSet> dataset(ds->query(sql));
446 std::vector<std::string> dataSourceNames;
448 while(dataset->moveNext())
449 dataSourceNames.push_back(dataset->getString(0));
453 return dataSourceNames;
459 std::vector<te::common::CharEncoding> encodings;
void getDatabaseInfo(std::string ¤tSchema)
It retrieves some information about the database such as the default schema used when no one is provi...
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
ConnectionPool * m_pool
The connection pool.
Utility functions for the data access module.
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
CharEncoding
Supported charsets (character encoding).
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
~DataSource()
Virtual destructor.
void open()
It opens the connection(s) to the PostgreSQL database server.
static te::da::DataSourceCapabilities * sm_capabilities
The query dialect supported by PostGIS driver.
An static class with global definitions.
It represents the SQL query dialect accepted by a given data source.
unsigned int getRasterTypeId() const
It returns the type id associated to the PostGIS Raster type.
const std::string & getCurrentSchema() const
It returns the current schema associated to the database connection, or NULL, if none is set...
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
A class that implements a connection to a PostgreSQL database.
#define TE_TR(message)
It marks a string in order to get translated.
void closeConnection(Connection *conn)
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
void setTimeAsInteger(bool timeIsInteger)
static te::da::SQLDialect * sm_queryDialect
The query dialect supported by PostGIS driver.
The transactor class for the PostGIS driver.
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
static CharEncoding getCharEncodingType(const std::string &name)
It returns the charset type of the given charset name.
te::pgis::Connection * getConnection()
bool isValid() const
It checks if the data source is valid (available for using).
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
A class that implements a connection to a PostgreSQL database.
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
Implementation of the data source for the PostGIS driver.
A Transactor can be viewed as a connection to the data source for reading/writing things into it...
void close()
It closes the data source and clears all the resources used by its internal communication channel...
ConnectionPool * getConnPool() const
It returns a pointer to the internal connection pool.
An exception class for the PostGIS driver.
A visitor for building an SQL statement using PostGIS dialect.
te::common::CharEncoding getCharEncoding() const
It returns the datasource char encoding.
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
This class implements a connection pool for the PostGIS driver.
unsigned int getGeomTypeId()
It will check in the database catalog the number that identifies the PostGIS Geometry type...
unsigned int getRasterTypeId()
It will check in the database catalog the number that identifies the PostGIS Raster type...
A dataset is the unit of information manipulated by the data access module of TerraLib.
A class that implements a connection pool for PostGIS.
#define PGIS_DRIVER_IDENTIFIER
The PostGIS driver identifier string.
std::vector< te::common::CharEncoding > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
unsigned int getGeomTypeId() const
It returns the type id associated to the PostGIS Geometry type.
A class that implements a prepared query for PostgreSQL data access driver.