ConnectedDataSet.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/ConnectedDataSet.h
22 
23  \brief Implementation of a connected dataset for the PostGIS driver.
24 */
25 
26 #ifndef __TERRALIB_POSTGIS_INTERNAL_CONNECTED_DATASET_H
27 #define __TERRALIB_POSTGIS_INTERNAL_CONNECTED_DATASET_H
28 
29 // TerraLib
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "Connection.h"
32 #include "Config.h"
33 
34 // Forward declaration for libpq
35 //extern "C"
36 //{
37 // struct pg_conn;
38 // typedef struct pg_conn PGconn;
39 // struct pg_result;
40 // typedef struct pg_result PGresult;
41 //}
42 
43 namespace te
44 {
45 // Forward declaration
46  namespace da
47  {
48  class GeometryProperty;
49  }
50 
51  namespace pgis
52  {
53  // Forward declaration
54  class DataSource;
55 
56  /*!
57  \class ConnectedDataSet
58 
59  \brief Implementation of a connected dataset for the PostGIS driver.
60 
61  \sa te::da::ConnectedDataSet
62  */
64  {
65  public:
66  /*!
67  \brief Constructor.
68 
69  \param result The internal PGresult.
70  \param dataSource The DataSource to get the connection.
71  \param connectionId The connection id used by this dataset.
72  \param id_cursor The id for the current cursor.
73  \param size The number of rows the layer has.
74  \param ptypes The types of each property.
75  \param timeIsInteger A flag that indicates if the postgis stores,
76  internally, the time and timestamp as an integer.
77  */
79  DataSource* dataSource,
80  const int& connectionId,
81  const std::string& id_cursor,
82  const int& size,
83  const std::vector<int>& ptypes,
84  bool timeIsInteger = true,
85  int newFetchSize = 5000);
86 
87  /*! \brief The destructor will clear the internal PGresult. */
89 
91 
93 
94  std::size_t getNumProperties() const;
95 
96  int getPropertyDataType(std::size_t i) const;
97 
98  std::string getPropertyName(std::size_t i) const;
99 
100  std::string getDatasetNameOfProperty(std::size_t i) const;
101 
102  bool isEmpty() const;
103 
104  bool isConnected() const;
105 
106  std::size_t size() const;
107 
108  std::unique_ptr<te::gm::Envelope> getExtent(std::size_t i);
109 
110  bool moveNext();
111 
112  bool movePrevious();
113 
115 
116  bool moveFirst();
117 
118  bool moveLast();
119 
120  bool move(std::size_t i);
121 
122  bool isAtBegin() const;
123 
124  bool isBeforeBegin() const;
125 
126  bool isAtEnd() const;
127 
128  bool isAfterEnd() const;
129 
130  bool isPositionValid() const;
131 
132  char getChar(std::size_t i) const;
133 
134  unsigned char getUChar(std::size_t i) const;
135 
136  boost::int16_t getInt16(std::size_t i) const;
137 
138  boost::int32_t getInt32(std::size_t i) const;
139 
140  boost::int64_t getInt64(std::size_t i) const;
141 
142  bool getBool(std::size_t i) const;
143 
144  float getFloat(std::size_t i) const;
145 
146  double getDouble(std::size_t i) const;
147 
148  std::string getNumeric(std::size_t i) const;
149 
150  std::string getString(std::size_t i) const;
151 
152  std::unique_ptr<te::dt::ByteArray> getByteArray(std::size_t i) const;
153 
154  std::unique_ptr<te::gm::Geometry> getGeometry(std::size_t i) const;
155 
156  std::unique_ptr<te::rst::Raster> getRaster(std::size_t i) const;
157 
158  std::unique_ptr<te::dt::DateTime> getDateTime(std::size_t i) const;
159 
160  std::unique_ptr<te::dt::Array> getArray(std::size_t i) const;
161 
162  bool isNull(std::size_t i) const;
163 
164  /** @name PostGIS Extended Methods
165  * Methods that exists only in the PostGIS DataSet implementation.
166  */
167  //@{
168 
169  /*!
170  \brief It returns the internal pg result.
171 
172  \return The internal pg result.
173  */
174  PGresult* getPGResult() const { return m_result; }
175 
176  //Connection* getConnection() const { return m_conn; }
177 
178  //@}
179 
180  protected:
181 
182  int m_iFetch; //!< The index of the current row of current fetch.
183  int m_iLayer; //!< The index of total layer of the current row.
184  int m_size; //!< The number of datasets in the collection.
185  PGresult* m_result; //!< The internal buffer with the result query.
186  DataSource* m_ds; //!< The DataSource to get the connection.
187  int m_connectionId; //!< The connection id used by this dataset.
188  int m_fetchSize; //!< The size of cursor fetch.
189  std::string m_idcursor; //!< The id of current cursor.
190  std::vector<int> m_ptypes; //!< The list of property types.
191  te::gm::Envelope* m_mbr; //!< The dataset extent.
192  bool m_timeIsInteger; //!< It indicates if the postgis stores, internally, the time and timestamp as an integer.
193  int m_newFetchSize; //!< The size to be used every time we need to fetch more date
194  };
195 
196  } // end namespace pgis
197 } // end namespace te
198 
199 
200 #endif // __TERRALIB_POSTGIS_INTERNAL_CONNECTED_DATASET_H
te::pgis::ConnectedDataSet::m_size
int m_size
The number of datasets in the collection.
Definition: ConnectedDataSet.h:184
te::gm::Envelope
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
te::pgis::ConnectedDataSet::getAccessPolicy
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
te::pgis::ConnectedDataSet::getTraverseType
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::pgis::ConnectedDataSet::getUChar
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
te::pgis::ConnectedDataSet::m_idcursor
std::string m_idcursor
The id of current cursor.
Definition: ConnectedDataSet.h:189
te::pgis::ConnectedDataSet::isEmpty
bool isEmpty() const
It returns true if the collection is empty.
te::pgis::ConnectedDataSet::isBeforeBegin
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
te::pgis::ConnectedDataSet::getGeometry
std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
te::pgis::ConnectedDataSet::m_iFetch
int m_iFetch
The index of the current row of current fetch.
Definition: ConnectedDataSet.h:182
PGresult
struct pg_result PGresult
Definition: Connection.h:48
te::pgis::ConnectedDataSet::getExtent
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
te::pgis::ConnectedDataSet::getInt64
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
te::pgis::ConnectedDataSet::getFloat
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
te::pgis::ConnectedDataSet::getChar
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
te::common::TraverseType
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
te::pgis::ConnectedDataSet::getByteArray
std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
te::pgis::ConnectedDataSet::moveBeforeFirst
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
te::pgis::ConnectedDataSet::isAfterEnd
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
te::pgis::ConnectedDataSet::getInt16
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
te::pgis::ConnectedDataSet::getPropertyDataType
int getPropertyDataType(std::size_t i) const
It returns the underlying data type of the property at position pos.
te::pgis::ConnectedDataSet
Implementation of a connected dataset for the PostGIS driver.
Definition: ConnectedDataSet.h:64
te::pgis::DataSource
The PostGIS driver.
Definition: DataSource.h:55
te::pgis::ConnectedDataSet::m_mbr
te::gm::Envelope * m_mbr
The dataset extent.
Definition: ConnectedDataSet.h:191
te::pgis::ConnectedDataSet::isAtEnd
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
te::pgis::ConnectedDataSet::size
std::size_t size() const
It returns the collection size, if it is known.
te::pgis::ConnectedDataSet::getInt32
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
te::pgis::ConnectedDataSet::getString
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
Connection.h
A class that implements a connection to a PostgreSQL database.
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::ConnectedDataSet::m_newFetchSize
int m_newFetchSize
The size to be used every time we need to fetch more date.
Definition: ConnectedDataSet.h:193
te::pgis::ConnectedDataSet::getRaster
std::unique_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
te::pgis::ConnectedDataSet::isConnected
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
te::pgis::ConnectedDataSet::getDatasetNameOfProperty
std::string getDatasetNameOfProperty(std::size_t i) const
It returns the underlying dataset name of the property at position pos.
te::pgis::ConnectedDataSet::getArray
std::unique_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
te::pgis::ConnectedDataSet::moveLast
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
te::pgis::ConnectedDataSet::getPropertyName
std::string getPropertyName(std::size_t i) const
It returns the property name at position pos.
te::pgis::ConnectedDataSet::isAtBegin
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not.
te::pgis::ConnectedDataSet::m_ptypes
std::vector< int > m_ptypes
The list of property types.
Definition: ConnectedDataSet.h:190
te::pgis::ConnectedDataSet::getDouble
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
te::pgis::ConnectedDataSet::m_connectionId
int m_connectionId
The connection id used by this dataset.
Definition: ConnectedDataSet.h:187
te::pgis::ConnectedDataSet::moveNext
bool moveNext()
It moves the internal pointer to the next item of the collection.
te::pgis::ConnectedDataSet::m_iLayer
int m_iLayer
The index of total layer of the current row.
Definition: ConnectedDataSet.h:183
te::pgis::ConnectedDataSet::m_fetchSize
int m_fetchSize
The size of cursor fetch.
Definition: ConnectedDataSet.h:188
te::pgis::ConnectedDataSet::m_result
PGresult * m_result
The internal buffer with the result query.
Definition: ConnectedDataSet.h:185
te::pgis::ConnectedDataSet::getNumeric
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
te::pgis::ConnectedDataSet::getDateTime
std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
te::pgis::ConnectedDataSet::movePrevious
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
te::da::DataSet
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::pgis::ConnectedDataSet::move
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
te::pgis::ConnectedDataSet::m_ds
DataSource * m_ds
The DataSource to get the connection.
Definition: ConnectedDataSet.h:186
te::pgis::ConnectedDataSet::~ConnectedDataSet
~ConnectedDataSet()
The destructor will clear the internal PGresult.
te::pgis::ConnectedDataSet::m_timeIsInteger
bool m_timeIsInteger
It indicates if the postgis stores, internally, the time and timestamp as an integer.
Definition: ConnectedDataSet.h:192
te::pgis::ConnectedDataSet::getPGResult
PGresult * getPGResult() const
It returns the internal pg result.
Definition: ConnectedDataSet.h:174
te::pgis::ConnectedDataSet::getBool
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
te::pgis::ConnectedDataSet::isPositionValid
bool isPositionValid() const
It tells if the dataset internal pointer is on a valid position.
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::pgis::ConnectedDataSet::moveFirst
bool moveFirst()
It moves the internal pointer to the first item in the collection.
te::pgis::ConnectedDataSet::getNumProperties
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
te::pgis::ConnectedDataSet::ConnectedDataSet
ConnectedDataSet(PGresult *result, DataSource *dataSource, const int &connectionId, const std::string &id_cursor, const int &size, const std::vector< int > &ptypes, bool timeIsInteger=true, int newFetchSize=5000)
Constructor.
te::pgis::ConnectedDataSet::isNull
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.