All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSource.cpp
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.cpp
22 
23  \brief Implements a DataSource that contains st memory DataSets indexed by space and time.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../common/StringUtils.h"
29 #include "../common/Translator.h"
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/DataSetType.h"
32 #include "../dataaccess/dataset/CheckConstraint.h"
33 #include "../dataaccess/dataset/ForeignKey.h"
34 #include "../dataaccess/dataset/Index.h"
35 #include "../dataaccess/dataset/PrimaryKey.h"
36 #include "../dataaccess/dataset/Sequence.h"
37 #include "../dataaccess/dataset/UniqueKey.h"
38 #include "../datatype/DateTimePeriod.h"
39 
40 #include "DataSet.h"
41 #include "DataSource.h"
42 #include "Transactor.h"
43 #include "Exception.h"
44 #include "Globals.h"
45 
46 // Boost
47 #include <boost/format.hpp>
48 #include <boost/lexical_cast.hpp>
49 
52 
54  : m_connInfo(),
55  m_datasets(),
56  m_schemas(),
57  m_maxdatasets(TE_STMEMORY_DRIVER_MAX_DATASETS),
58  m_isOpened(false),
59  m_deepCopy(false),
60  m_transactor(0)
61 {
62 }
63 
65 {
66  //delete the pointers
67  std::map<std::string, DataSet* >::iterator it = m_datasets.begin();
68  while(it!=m_datasets.end())
69  {
70  delete(it->second);
71  ++it;
72  }
73  m_datasets.clear();
74 
75  //delete the pointers
76  std::map<std::string, te::da::DataSetType* >::iterator it2 = m_schemas.begin();
77  while(it2!=m_schemas.end())
78  {
79  delete(it2->second);
80  ++it2;
81  }
82  m_schemas.clear();
83 }
84 
85 std::string te::stmem::DataSource::getType() const
86 {
88 }
89 
90 const std::map<std::string, std::string>& te::stmem::DataSource::getConnectionInfo() const
91 {
92  return m_connInfo;
93 }
94 
95 void te::stmem::DataSource::setConnectionInfo(const std::map<std::string, std::string>& connInfo)
96 {
97  m_connInfo = connInfo;
98 }
99 
100 std::auto_ptr<te::da::DataSourceTransactor> te::stmem::DataSource::getTransactor()
101 {
102  return std::auto_ptr<te::da::DataSourceTransactor>(new Transactor(this));
103 }
104 
106 {
107 // assure we are in a closed state
108  close();
109 
110  m_transactor.reset(new Transactor(this));
111 
112 // check if it is required a different dataset limit
113  std::map<std::string, std::string>::const_iterator it = m_connInfo.find("MAX_DATASETS");
114 
115  if(it != m_connInfo.end())
116  m_maxdatasets = boost::lexical_cast<std::size_t>(it->second);
117 
118 // check operation mode
119  it = m_connInfo.find("OPERATION_MODE");
120 
121  if((it != m_connInfo.end()) && (te::common::Convert2UCase(it->second) == "NON-SHARED"))
122  m_deepCopy = true;
123 
124  m_isOpened = true;
125 }
126 
128 {
129  if(!m_isOpened)
130  return;
131 
132  //delete the pointers
133  std::map<std::string, DataSet* >::iterator it = m_datasets.begin();
134  while(it!=m_datasets.end())
135  {
136  delete(it->second);
137  ++it;
138  }
139  m_datasets.clear();
140 
141  //delete the pointers
142  std::map<std::string, te::da::DataSetType* >::iterator it2 = m_schemas.begin();
143  while(it2!=m_schemas.end())
144  {
145  delete(it2->second);
146  ++it2;
147  }
148  m_schemas.clear();
149 
150  m_maxdatasets = TE_STMEMORY_DRIVER_MAX_DATASETS;
151 
152  m_isOpened = false;
153 
154  m_deepCopy = false;
155 
156  m_transactor.reset(0);
157 }
158 
160 {
161  return m_isOpened;
162 }
163 
165 {
166  return m_isOpened;
167 }
168 
170 {
171  return sm_capabilities;
172 }
173 
175 {
176  return &sm_dialect;
177 }
178 
179 void te::stmem::DataSource::add(const std::string& name, te::da::DataSetType* t, DataSet* d)
180 {
181  m_transactor->add(name, t, d);
182 }
183 
184 std::auto_ptr<te::da::DataSet> te::stmem::DataSource::getDataSet(const std::string& name, const te::dt::DateTime* dt, te::dt::TemporalRelation r,
185  te::common::TraverseType travType, bool connected,
186  const te::common::AccessPolicy accessPolicy)
187 {
188  return m_transactor->getDataSet(name, dt, r, travType, connected, accessPolicy);
189 }
190 
191 std::auto_ptr<te::da::DataSet> te::stmem::DataSource::getDataSet(const std::string& name,
194  te::common::TraverseType travType, bool connected,
195  const te::common::AccessPolicy accessPolicy)
196 {
197  return m_transactor->getDataSet(name, geom, sr, dt, tr, travType, connected, accessPolicy);
198 }
199 
200 std::auto_ptr<te::da::DataSet> te::stmem::DataSource::getDataSet(const std::string& name,
203  te::common::TraverseType travType, bool connected,
204  const te::common::AccessPolicy accessPolicy)
205 {
206  return m_transactor->getDataSet(name, e, sr, dt, tr, travType, connected, accessPolicy);
207 }
208 
209 std::auto_ptr<te::dt::DateTimePeriod>
211 {
212  return m_transactor->getTemporalExtent(name);
213 }
214 
215 ///protected Methods
216 void te::stmem::DataSource::create(const std::map<std::string, std::string>& /*dsInfo*/)
217 {
218  return;
219 }
220 
221 void te::stmem::DataSource::drop(const std::map<std::string, std::string>& /*dsInfo*/)
222 {
223  return;
224 }
225 
226 bool te::stmem::DataSource::exists(const std::map<std::string, std::string>& /*dsInfo*/)
227 {
228  return false;
229 }
230 
231 std::vector<std::string> te::stmem::DataSource::getDataSourceNames(const std::map<std::string, std::string>& /*dsInfo*/)
232 {
233  return std::vector<std::string>();
234 }
235 
236 std::vector<te::common::CharEncoding> te::stmem::DataSource::getEncodings(const std::map<std::string, std::string>& /*dsInfo*/)
237 {
238  return std::vector<te::common::CharEncoding>();
239 }
An implementation of DataSourceTransactor class for the ST In-memory driver.
Implements a DataSource that contains st memory DataSets indexed by space and time.
static const std::string sm_driverIdentifier
The STMEMORY driver identifier.
Definition: Globals.h:49
#define TE_STMEMORY_DRIVER_MAX_DATASETS
The maximum number of datasets to be handled by a data source.
Definition: Config.h:48
A class that models the description of a dataset.
Definition: DataSetType.h:72
An exception class for the TerraLib ST memory driver.
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
Definition: DataSource.cpp:100
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
Definition: DataSource.cpp:90
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
void add(const std::string &name, te::da::DataSetType *t, DataSet *d)
It adds a new DataSet and DataSetType into the DataSource.
Definition: DataSource.cpp:179
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:163
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
Definition: DataSource.cpp:159
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
Definition: DataSource.cpp:95
bool isValid() const
It checks if the data source is valid (available for using).
Definition: DataSource.cpp:164
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
Definition: DataSource.cpp:85
A static class with global definitions for the TerraLib ST In-memory driver.
void open()
It opens the data source and makes it ready for using.
Definition: DataSource.cpp:105
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &info)
It gets the data source names available in a driver.
Definition: DataSource.cpp:231
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
std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, const te::dt::DateTime *dt, te::dt::TemporalRelation r=te::dt::DURING, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It returns a data set with observations whose phenomenon times satisfy a given temporal relation...
Definition: DataSource.cpp:184
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
Definition: DataSource.h:223
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent(const std::string &name)
It returns the temporal extent associated to a DataSet.
Definition: DataSource.cpp:210
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
~DataSource()
Destructor.
Definition: DataSource.cpp:64
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Definition: DataSource.cpp:174
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
Definition: DataSource.cpp:226
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
DataSource()
Constructor.
Definition: DataSource.cpp:53
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
Definition: DataSource.cpp:169
void create(const std::map< std::string, std::string > &dsInfo)
protected Methods
Definition: DataSource.cpp:216
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
Definition: DataSource.cpp:221
static const te::da::SQLDialect sm_dialect
A dummy dialect.
Definition: DataSource.h:224
A dataset is the unit of information manipulated by the data access module of TerraLib.
std::vector< te::common::CharEncoding > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
Definition: DataSource.cpp:236
void close()
It closes the data source and clears all the resources used by its internal communication channel...
Definition: DataSource.cpp:127