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 namespace te
35 {
36  namespace core { class URI; }
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(const std::string& connInfo);
64 
65  DataSource(const te::core::URI& uri);
66 
67  ~DataSource();
68 
69  std::string getType() const;
70 
71  std::auto_ptr<te::da::DataSourceTransactor> getTransactor();
72 
73  te::pgis::Connection* getConnection();
74 
75  void closeConnection(Connection* conn);
76 
77  bool isTimeAnInteger();
78 
79  void setTimeAsInteger(bool timeIsInteger);
80 
81  /*!
82  \brief It opens the connection(s) to the PostgreSQL database server.
83 
84  This method will:
85  <ul>
86  <li>start the connection pool;</li>
87  <li>register the data type maps and get PostGIS geometry type OID;</li>
88  <li>get PostgreSQL version information;</li>
89  <li>get PostGIS version information;</li>
90  <li>get default schema name;</li>
91  <li>register user defined types (udts);</li>
92  </ul>
93 
94  \exception Exception It throws an exception if the data source can not be opened.
95 
96  \note Not thread safe!
97  */
98  void open();
99 
100  void close();
101 
102  bool isOpened() const;
103 
104  bool isValid() const;
105 
106  const te::da::DataSourceCapabilities& getCapabilities() const;
107 
108  const te::da::SQLDialect* getDialect() const;
109 
110  /*!
111  \brief It returns the type id associated to the PostGIS Geometry type.
112 
113  \return The type id associated to the PostGIS Geometry type.
114 
115  \note PostGIS driver extended method.
116  */
117  unsigned int getGeomTypeId() const;
118 
119  /*!
120  \brief It returns the type id associated to the PostGIS Raster type.
121 
122  \return The type id associated to the PostGIS Raster type.
123 
124  \note PostGIS driver extended method.
125  */
126  unsigned int getRasterTypeId() const;
127 
128  /*!
129  \brief It returns the current schema associated to the database connection, or NULL, if none is set.
130 
131  \return The current schema associated to the database connection, or NULL, if none is set.
132 
133  \note PostGIS driver extended method.
134  */
135  const std::string& getCurrentSchema() const;
136 
137  /*!
138  \brief It returns a pointer to the internal connection pool.
139 
140  \return A pointer to the internal connection pool.
141 
142  \note The caller must not delete the connectio pool. It is used by transactor class.
143 
144  \note PostGIS driver extended method.
145  */
146  ConnectionPool* getConnPool() const;
147 
148  protected:
149 
150  void create(const std::string& connInfo);
151 
152  void drop(const std::string& connInfo);
153 
154  bool exists(const std::string& connInfo);
155 
156  std::vector<std::string> getDataSourceNames(const std::string& connInfo);
157 
158  private:
159 
160  ConnectionPool* m_pool; //!< The connection pool.
161  unsigned int m_geomTypeOid; //!< PostGIS Geometry type OID.
162  unsigned int m_rasterTypeOid; //!< PostGIS Raster type OID.
163  std::string m_currentSchema; //!< The default schema used when no one is provided.
164  bool m_timeIsInteger; //!< It indicates if the postgis stores, internally, time and timestamp as an integer.
165 
166  static te::da::DataSourceCapabilities sm_capabilities; //!< PostGIS capabilities.
167  static te::da::SQLDialect* sm_dialect; //!< PostGIS SQL dialect.
168  };
169 
170  } // end namespace pgis
171 } // end namespace te
172 
173 #endif // __TERRALIB_POSTGIS_INTERNAL_DATASOURCE_H
ConnectionPool * m_pool
The connection pool.
Definition: DataSource.h:160
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
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:119
#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:162
Configuration flags for the PostGIS Driver Implementation of TerraLib.
URI C++ Library.
static te::da::SQLDialect * sm_dialect
PostGIS SQL dialect.
Definition: DataSource.h:167
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
bool m_timeIsInteger
It indicates if the postgis stores, internally, time and timestamp as an integer. ...
Definition: DataSource.h:164
std::string m_currentSchema
The default schema used when no one is provided.
Definition: DataSource.h:163
This class implements a connection pool for the PostGIS driver.
static te::da::DataSourceCapabilities sm_capabilities
PostGIS capabilities.
Definition: DataSource.h:166
unsigned int m_geomTypeOid
PostGIS Geometry type OID.
Definition: DataSource.h:161