DataSource.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/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  /*!
151  \brief It returns the datasource char encoding.
152 
153  \note PostGIS driver extended method.
154  */
155  te::common::CharEncoding getCharEncoding() const;
156 
157  protected:
158 
159  void create(const std::map<std::string, std::string>& dsInfo);
160 
161  void drop(const std::map<std::string, std::string>& dsInfo);
162 
163  bool exists(const std::map<std::string, std::string>& dsInfo);
164 
165  std::vector<std::string> getDataSourceNames(const std::map<std::string, std::string>& dsInfo);
166 
167  std::vector<te::common::CharEncoding> getEncodings(const std::map<std::string, std::string>& dsInfo);
168 
169  private:
170 
171  std::map<std::string, std::string> m_connInfo; //!< Connection information.
172  ConnectionPool* m_pool; //!< The connection pool.
173  unsigned int m_geomTypeOid; //!< PostGIS Geometry type OID.
174  unsigned int m_rasterTypeOid; //!< PostGIS Raster type OID.
175  std::string m_currentSchema; //!< The default schema used when no one is provided.
176  bool m_timeIsInteger; //!< It indicates if the postgis stores, internally, time and timestamp as an integer.
177  te::common::CharEncoding m_encoding; //!< The datasource char encoding.
178 
179  static te::da::DataSourceCapabilities sm_capabilities; //!< PostGIS capabilities.
180  static te::da::SQLDialect* sm_dialect; //!< PostGIS SQL dialect.
181  };
182 
183  } // end namespace pgis
184 } // end namespace te
185 
186 #endif // __TERRALIB_POSTGIS_INTERNAL_DATASOURCE_H
ConnectionPool * m_pool
The connection pool.
Definition: DataSource.h:172
CharEncoding
Supported charsets (character encoding).
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
std::map< std::string, std::string > m_connInfo
Connection information.
Definition: DataSource.h:171
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.
Definition: Connection.h:68
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:195
The PostGIS driver.
Definition: DataSource.h:54
unsigned int m_rasterTypeOid
PostGIS Raster type OID.
Definition: DataSource.h:174
Configuration flags for the PostGIS Driver Implementation of TerraLib.
URI C++ Library.
static te::da::SQLDialect * sm_dialect
PostGIS SQL dialect.
Definition: DataSource.h:180
te::common::CharEncoding m_encoding
The datasource char encoding.
Definition: DataSource.h:177
bool m_timeIsInteger
It indicates if the postgis stores, internally, time and timestamp as an integer. ...
Definition: DataSource.h:176
std::string m_currentSchema
The default schema used when no one is provided.
Definition: DataSource.h:175
This class implements a connection pool for the PostGIS driver.
static te::da::DataSourceCapabilities sm_capabilities
PostGIS capabilities.
Definition: DataSource.h:179
unsigned int m_geomTypeOid
PostGIS Geometry type OID.
Definition: DataSource.h:173