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/stmemory/DataSource.h
22 
23  \brief Implements a DataSource that contains st memory DataSets indexed by space and time.
24 */
25 
26 #ifndef __TERRALIB_STMEMORY_INTERNAL_DATASOURCE_H
27 #define __TERRALIB_STMEMORY_INTERNAL_DATASOURCE_H
28 
29 // TerraLib
30 #include "../dataaccess/datasource/DataSource.h"
31 #include "../dataaccess/datasource/DataSourceCapabilities.h"
32 #include "../dataaccess/query/SQLDialect.h"
33 #include "Config.h"
34 
35 // STL
36 #include <map>
37 #include <vector>
38 
39 namespace te { namespace da { class DataSetType; } }
40 namespace te { namespace dt { class DateTimePeriod; } }
41 
42 namespace te
43 {
44  namespace stmem
45  {
46 // Forward declaration
47  class DataSet;
48  class Transactor;
49 
50  /*!
51  \class DataSource
52 
53  \brief Implements a DataSource that contains In-Memory DataSets indexed by space and time.
54 
55  \sa te::da::DataSource
56  */
58  {
59  friend class Transactor;
60 
61  public:
62 
63  /*! \brief Constructor */
64  DataSource();
65 
66  /*! \brief Destructor */
67  ~DataSource();
68 
69  /*! \name DataSource inherited methods */
70  //@{
71  std::string getType() const;
72 
73  const std::map<std::string, std::string>& getConnectionInfo() const;
74 
75  void setConnectionInfo(const std::map<std::string, std::string>& connInfo);
76 
77  std::auto_ptr<te::da::DataSourceTransactor> getTransactor();
78 
79  void open();
80 
81  void close();
82 
83  bool isOpened() const;
84 
85  bool isValid() const;
86 
87  const te::da::DataSourceCapabilities& getCapabilities() const;
88 
89  const te::da::SQLDialect* getDialect() const;
90  //@}
91 
92  /*!
93  \brief It adds a new DataSet and DataSetType into the DataSource.
94 
95  \param name The DataSet name.
96  \param t The DataSet Type.
97  \param d The DataSet.
98 
99  \note It will take the ownership of the given pointers.
100  \note It can throw an Exception if there is already a DataSet with the given name
101  */
102  void add(const std::string& name, te::da::DataSetType* t, DataSet* d);
103 
104  /*!
105  \brief It returns a data set with observations whose phenomenon times satisfy a
106  given temporal relation.
107 
108  The possible temporal relations are: 1. AFTER;
109  2. AFTER | EQUALS; 3. BEFORE; 4. BEFORE | EQUALS; 5. DURING; 6. EQUALS
110 
111  \param name The DataSet name.
112  \param dt A given datetime.
113  \param r A given temporal relation.
114  \param travType The traverse type associated to the returned dataset.
115  \param connected If the returned DataSet is connecet or not.
116 
117  \return A pointer to a new DataSet that shares the intenal content.
118 
119  \note The caller will take the ownership of the returned pointer.
120  \note When the temporal relation is DURING, dt must be a time period.
121  \note It can throw an Exception when internal errors occur.
122  */
123  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
126  bool connected = false,
127  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
128 
129  /*!
130  \brief It returns a data set with observations whose observed geometries satisfy a
131  given spatial relation and phenomenon times satisfy a given temporal relation.
132 
133  The possible spatial relations are: INTERSECTS
134  The possible temporal relations are: 1. AFTER;
135  2. AFTER | EQUALS; 3. BEFORE; 4. BEFORE | EQUALS; 5. DURING; 6. EQUALS
136 
137  \param name The DataSet name.
138  \param geom A given geometry.
139  \param sr A given spatial relation.
140  \param dt A given datetime.
141  \param tr A given temporal relation.
142  \param travType The traverse type associated to the returned dataset.
143  \param connected If the returned DataSet is connecet or not.
144 
145  \return A pointer to a new DataSet that shares the intenal content.
146 
147  \note The caller will take the ownership of the returned pointer.
148  \note It will NOT take the ownership of the given pointers.
149  \note When the temporal relation is DURING, dt must be a time period.
150  \note It can throw an Exception when internal errors occur.
151  */
152  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
156  bool connected = false,
157  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
158 
159  /*!
160  \brief It returns a data set with observations whose observed geometries satisfy a
161  given spatial relation and phenomenon times satisfy a given temporal relation.
162 
163  The possible spatial relations are: INTERSECTS
164  The possible temporal relations are: 1. AFTER;
165  2. AFTER | EQUALS; 3. BEFORE; 4. BEFORE | EQUALS; 5. DURING; 6. EQUALS
166 
167  \param name The DataSet name.
168  \param e A given envelope.
169  \param sr A given spatial relation.
170  \param dt A given datetime.
171  \param tr A given temporal relation.
172  \param travType The traverse type associated to the returned dataset.
173  \param connected If the returned DataSet is connecet or not.
174 
175  \return A pointer to a new DataSet that shares the intenal content.
176 
177  \note The caller will take the ownership of the returned pointer.
178  \note It will NOT take the ownership of the given pointers.
179  \note When the temporal relation is DURING, dt must be a time period.
180  \note It can throw an Exception when internal errors occur.
181  */
182  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
186  bool connected = false,
187  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
188 
189  /*!
190  \brief It returns the temporal extent associated to a DataSet.
191 
192  \param name The DataSet name.
193 
194  \return A pointer to its temporal extent.
195 
196  \note The caller will take the ownership of the returned pointer.
197  \note It can throw an Exception when internal errors occur.
198  */
199  std::auto_ptr<te::dt::DateTimePeriod> getTemporalExtent(const std::string& name);
200 
201  protected:
202 
203  void create(const std::map<std::string, std::string>& dsInfo);
204 
205  void drop(const std::map<std::string, std::string>& dsInfo);
206 
207  bool exists(const std::map<std::string, std::string>& dsInfo);
208 
209  std::vector<std::string> getDataSourceNames(const std::map<std::string, std::string>& info);
210 
211  std::vector<te::common::CharEncoding> getEncodings(const std::map<std::string, std::string>& dsInfo);
212 
213  private:
214 
215  std::map<std::string, std::string> m_connInfo; //!< DataSource information.
216  std::map<std::string, DataSet* > m_datasets; //!< The set of datasets stored in memory.
217  std::map<std::string, te::da::DataSetType* > m_schemas; //!< The set of dataset schemas.
218  std::size_t m_maxdatasets; //!< The maximum number of datasets to be handled by the data source.
219  bool m_isOpened; //!< A flag to control the state of the data source.
220  bool m_deepCopy; //!< If true each dataset is cloned in the getDataSet method.
221  std::auto_ptr<Transactor> m_transactor; //!< A transactor
222 
223  static te::da::DataSourceCapabilities sm_capabilities; //!< The Memory data source capabilities.
224  static const te::da::SQLDialect sm_dialect; //!< A dummy dialect.
225  };
226 
227  } // end namespace stmem
228 } // end namespace te
229 
230 #endif // __TERRALIB_STMEMORY_INTERNAL_DATASOURCE_H
231 
bool m_deepCopy
If true each dataset is cloned in the getDataSet method.
Definition: DataSource.h:220
A class that models the description of a dataset.
Definition: DataSetType.h:72
Implements a DataSource that contains In-Memory DataSets indexed by space and time.
Definition: DataSource.h:57
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
Definition: Enums.h:140
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:127
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
std::map< std::string, te::da::DataSetType * > m_schemas
The set of dataset schemas.
Definition: DataSource.h:217
bool m_isOpened
A flag to control the state of the data source.
Definition: DataSource.h:219
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
Definition: DataSource.h:223
#define TESTMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
std::map< std::string, std::string > m_connInfo
DataSource information.
Definition: DataSource.h:215
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
URI C++ Library.
std::map< std::string, DataSet * > m_datasets
The set of datasets stored in memory.
Definition: DataSource.h:216
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
An implementation of DataSourceTransactor class for the ST in-memory driver.
Definition: Transactor.h:49
Implementation of a in-memory data set that contains spatiotemporal observations indexed by time and ...
Definition: DataSet.h:61
std::auto_ptr< Transactor > m_transactor
A transactor.
Definition: DataSource.h:221
static const te::da::SQLDialect sm_dialect
A dummy dialect.
Definition: DataSource.h:224
std::size_t m_maxdatasets
The maximum number of datasets to be handled by the data source.
Definition: DataSource.h:218