All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSource.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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/DataSource.h
22 
23  \brief Implementation of the data source for the PostGIS driver.
24 */
25 
26 #ifndef __TERRALIB_POSTGIS_INTERNAL_DATASOURCE_H
27 #define __TERRALIB_POSTGIS_INTERNAL_DATASOURCE_H
28 
29 // TerraLib
30 #include "../dataaccess/datasource/DataSource.h"
31 #include "../dataaccess/datasource/DataSourceCapabilities.h"
32 #include "Config.h"
33 
34 
35 namespace te
36 {
37  namespace gm { class GeometryProperty; }
38  namespace rst { class RasterProperty; }
39 
40  namespace pgis
41  {
42  // Forward declaration
43  class Connection;
44  class ConnectionPool;
45  struct VersionInfo;
46 
47  /*!
48  \class DataSource
49 
50  \brief The PostGIS driver.
51 
52  \sa te::da::DataSource, te::da::DataSourceFactory, te::da::DataSourceManager, DataSourceFactory
53  */
55  {
56  public:
57 
58  /** @name Initializer Methods
59  * Methods related to the instantiation and destruction.
60  */
61  //@{
62 
63  DataSource();
64 
65  ~DataSource();
66 
67  std::string getType() const;
68 
69  const std::map<std::string, std::string>& getConnectionInfo() const;
70 
71  void setConnectionInfo(const std::map<std::string, std::string>& connInfo);
72 
73  std::auto_ptr<te::da::DataSourceTransactor> getTransactor();
74 
75  te::pgis::Connection* getConnection();
76 
77  void closeConnection(Connection* conn);
78 
79  bool isTimeAnInteger();
80 
81  void setTimeAsInteger(bool timeIsInteger);
82 
83  /*!
84  \brief It opens the connection(s) to the PostgreSQL database server.
85 
86  This method will:
87  <ul>
88  <li>start the connection pool;</li>
89  <li>register the data type maps and get PostGIS geometry type OID;</li>
90  <li>get PostgreSQL version information;</li>
91  <li>get PostGIS version information;</li>
92  <li>get default schema name;</li>
93  <li>register user defined types (udts);</li>
94  </ul>
95 
96  \exception Exception It throws an exception if the data source can not be opened.
97 
98  \note Not thread safe!
99  */
100  void open();
101 
102  void close();
103 
104  bool isOpened() const;
105 
106  bool isValid() const;
107 
108  const te::da::DataSourceCapabilities& getCapabilities() const;
109 
110  const te::da::SQLDialect* getDialect() const;
111 
112  /*!
113  \brief It returns the type id associated to the PostGIS Geometry type.
114 
115  \return The type id associated to the PostGIS Geometry type.
116 
117  \note PostGIS driver extended method.
118  */
119  unsigned int getGeomTypeId() const;
120 
121  /*!
122  \brief It returns the type id associated to the PostGIS Raster type.
123 
124  \return The type id associated to the PostGIS Raster type.
125 
126  \note PostGIS driver extended method.
127  */
128  unsigned int getRasterTypeId() const;
129 
130  /*!
131  \brief It returns the current schema associated to the database connection, or NULL, if none is set.
132 
133  \return The current schema associated to the database connection, or NULL, if none is set.
134 
135  \note PostGIS driver extended method.
136  */
137  const std::string& getCurrentSchema() const;
138 
139  /*!
140  \brief It returns a pointer to the internal connection pool.
141 
142  \return A pointer to the internal connection pool.
143 
144  \note The caller must not delete the connectio pool. It is used by transactor class.
145 
146  \note PostGIS driver extended method.
147  */
148  ConnectionPool* getConnPool() const;
149 
150  protected:
151 
152  void create(const std::map<std::string, std::string>& dsInfo);
153 
154  void drop(const std::map<std::string, std::string>& dsInfo);
155 
156  bool exists(const std::map<std::string, std::string>& dsInfo);
157 
158  std::vector<std::string> getDataSourceNames(const std::map<std::string, std::string>& dsInfo);
159 
160  std::vector<std::string> getEncodings(const std::map<std::string, std::string>& dsInfo);
161 
162  private:
163 
164  std::map<std::string, std::string> m_connInfo; //!< Connection information.
165  ConnectionPool* m_pool; //!< The connection pool.
166  unsigned int m_geomTypeOid; //!< PostGIS Geometry type OID.
167  unsigned int m_rasterTypeOid; //!< PostGIS Raster type OID.
168  std::string m_currentSchema; //!< The default schema used when no one is provided.
169  bool m_timeIsInteger; //!< It indicates if the postgis stores, internally, time and timestamp as an integer.
170 
171  static te::da::DataSourceCapabilities sm_capabilities; //!< PostGIS capabilities.
172  static te::da::SQLDialect* sm_dialect; //!< PostGIS SQL dialect.
173  };
174 
175  } // end namespace pgis
176 } // end namespace te
177 
178 #endif // __TERRALIB_POSTGIS_INTERNAL_DATASOURCE_H
Configuration flags for the PostGIS Driver Implementation of TerraLib.
unsigned int m_rasterTypeOid
PostGIS Raster type OID.
Definition: DataSource.h:167
static te::da::DataSourceCapabilities sm_capabilities
PostGIS capabilities.
Definition: DataSource.h:171
This class implements a connection pool for the PostGIS driver.
std::map< std::string, std::string > m_connInfo
Connection information.
Definition: DataSource.h:164
std::string m_currentSchema
The default schema used when no one is provided.
Definition: DataSource.h:168
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::da::SQLDialect * sm_dialect
PostGIS SQL dialect.
Definition: DataSource.h:172
unsigned int m_geomTypeOid
PostGIS Geometry type OID.
Definition: DataSource.h:166
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
The PostGIS driver.
Definition: DataSource.h:54
A class that implements a connection to a PostgreSQL database.
Definition: Connection.h:68
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:221
bool m_timeIsInteger
It indicates if the postgis stores, internally, time and timestamp as an integer. ...
Definition: DataSource.h:169
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
ConnectionPool * m_pool
The connection pool.
Definition: DataSource.h:165