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/memory/DataSource.h
22 
23  \brief
24 */
25 
26 #ifndef __TERRALIB_MEMORY_INTERNAL_DATASOURCE_H
27 #define __TERRALIB_MEMORY_INTERNAL_DATASOURCE_H
28 
29 // TerraLib
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/datasource/DataSource.h"
32 #include "Config.h"
33 
34 // Boost
35 #include <boost/thread.hpp>
36 
37 namespace te
38 {
39  namespace da
40  {
41  class ObjectIdSet;
42  }
43  namespace mem
44  {
45  /*!
46  \class DataSource
47 
48  \brief Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
49 
50  \sa te::da::DataSource
51  */
53  {
54  public:
55 
56  DataSource(const std::string& connInfo);
57 
59 
61 
62  /*!
63  \brief It returns a map relating the dataset names and their contents.
64 
65  \return The map relating the dataset names and their contents..
66  */
67  const std::map<std::string, te::da::DataSetPtr>& getDataSets() const;
68 
69  /*!
70  \brief It returns a map relating the dataset names and their schemas.
71 
72  \return The map relating the dataset names and their schemas.
73  */
74  const std::map<std::string, te::da::DataSetTypePtr> getSchemas() const;
75 
76  std::string getType() const;
77 
78  std::unique_ptr<te::da::DataSourceTransactor> getTransactor();
79 
80  void open();
81 
82  void close();
83 
84  bool isOpened() const;
85 
86  bool isValid() const;
87 
89 
91 
92  std::unique_ptr<te::da::DataSet> getDataSet(const std::string& name,
94  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
95 
96  std::vector<std::string> getDataSetNames();
97 
98  std::size_t getNumberOfDataSets();
99 
100  std::unique_ptr<te::da::DataSetType> getDataSetType(const std::string& datasetName);
101 
102  boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName);
103 
104  std::unique_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
105 
106  std::unique_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos);
107 
108  std::vector<std::string> getPropertyNames(const std::string& datasetName);
109 
110  std::size_t getNumberOfProperties(const std::string& datasetName);
111 
112  bool propertyExists(const std::string& datasetName, const std::string& name);
113 
114  void addProperty(const std::string& datasetName, te::dt::Property* p);
115 
116  void dropProperty(const std::string& datasetName, const std::string& propertyName);
117 
118  void renameProperty(const std::string& datasetName, const std::string& name, const std::string& newName);
119 
120  std::size_t getNumberOfItems(const std::string& datasetName);
121 
122  bool hasDataSets();
123 
124  bool dataSetExists(const std::string& name);
125 
126  void createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& options);
127 
128  void cloneDataSet(const std::string& name, const std::string& cloneName,
129  const std::map<std::string, std::string>& options);
130 
131  void dropDataSet(const std::string& name);
132 
133  void renameDataSet(const std::string& name, const std::string& newName);
134 
135  void add(const std::string& datasetName, te::da::DataSet* d,
136  const std::map<std::string, std::string>& options, std::size_t limit);
137 
138  void remove(const std::string& datasetName, const te::da::ObjectIdSet* oids);
139 
140  void update(const std::string& datasetName,
141  te::da::DataSet* dataset,
142  const std::vector<std::size_t>& properties,
143  const te::da::ObjectIdSet* oids,
144  const std::map<std::string, std::string>& options,
145  std::size_t limit = 0);
146 
147  /*!
148  \brief It sets the capabilities document.
149 
150  \param capabilities The memory data source capabilities.
151 
152  \note The memory data source will take the ownership of the given capabilities object.
153 
154  \note Memory driver extended method.
155  */
157 
158  protected:
159 
160  void create(const std::string& connInfo);
161 
162  void drop(const std::string& connInfo);
163 
164  bool exists(const std::string& connInfo);
165 
166  std::vector<std::string> getDataSourceNames(const std::string& connInfo);
167 
168  private:
169 
170  std::map<std::string, te::da::DataSetPtr> m_datasets; //!< The set of datasets stored in memory.
171  std::map<std::string, te::da::DataSetTypePtr> m_schemas; //!< The set of dataset schemas.
172  mutable boost::recursive_mutex m_mtx; //!< The internal mutex.
173  std::size_t m_numDatasets; //!< The number of datasets kept in the data source.
174  std::size_t m_maxNumDatasets; //!< The maximum number of datasets to be handled by the data source.
175  bool m_isOpened; //!< A flag to control the state of the data source.
176  bool m_deepCopy; //!< If true, each dataset is cloned in the getDataSet method.
177 
178  static te::da::DataSourceCapabilities sm_capabilities; //!< The Memory data source capabilities.
179  static const te::da::SQLDialect sm_dialect; //!< A dummy dialect.
180  };
181 
182  } // end namespace mem
183 } // end namespace te
184 
185 #endif // __TERRALIB_MEMORY_INTERNAL_DATASOURCE_H
te::mem::DataSource::DataSource
DataSource(const te::core::URI &uri)
te::mem::DataSource::m_datasets
std::map< std::string, te::da::DataSetPtr > m_datasets
The set of datasets stored in memory.
Definition: DataSource.h:170
te::mem::DataSource::getNumberOfDataSets
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
te::mem::DataSource::dropDataSet
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::da::SQLDialect
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:56
te::mem::DataSource::m_mtx
boost::recursive_mutex m_mtx
The internal mutex.
Definition: DataSource.h:172
te::mem::DataSource::getNumberOfProperties
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
te::mem::DataSource::renameProperty
void renameProperty(const std::string &datasetName, const std::string &name, const std::string &newName)
It renames a property of the given dataset.
te::mem::DataSource::drop
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
te::mem::DataSource::getPropertyNames
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
te::mem::DataSource::remove
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids)
It removes all the informed items from the dataset.
te::common::RAccess
@ RAccess
Definition: Enums.h:43
te::mem::DataSource::m_maxNumDatasets
std::size_t m_maxNumDatasets
The maximum number of datasets to be handled by the data source.
Definition: DataSource.h:174
te::mem::DataSource::DataSource
DataSource(const std::string &connInfo)
te::mem::DataSource::getDataSet
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset,...
te::mem::DataSource::isValid
bool isValid() const
It checks if the data source is valid (available for using).
te::mem::DataSource::getCapabilities
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
te::mem::DataSource::hasDataSets
bool hasDataSets()
It checks if the data source has any dataset.
te::mem::DataSource::getDataSetType
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &datasetName)
It gets information about the given dataset.
te::mem::DataSource::isOpened
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
te::common::TraverseType
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
te::mem::DataSource::getNumberOfItems
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
te::mem::DataSource::getDialect
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
te::mem::DataSource::update
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
te::mem::DataSource::propertyExists
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
te::mem::DataSource::close
void close()
It closes the data source and clears all the resources used by its internal communication channel.
te::mem::DataSource::sm_dialect
static const te::da::SQLDialect sm_dialect
A dummy dialect.
Definition: DataSource.h:179
te::mem::DataSource::createDataSet
void createDataSet(te::da::DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
te::mem::DataSource::~DataSource
~DataSource()
Virtual destructor.
te::mem::DataSource::m_numDatasets
std::size_t m_numDatasets
The number of datasets kept in the data source.
Definition: DataSource.h:173
te::mem::DataSource::create
void create(const std::string &connInfo)
It creates a new data source.
capabilities
te::da::DataSourceCapabilities capabilities
Definition: PostGISCapabilities.h:129
te::mem::DataSource::getType
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS,...
te::mem::DataSource::setCapabilities
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
It sets the capabilities document.
te::mem::DataSource::m_schemas
std::map< std::string, te::da::DataSetTypePtr > m_schemas
The set of dataset schemas.
Definition: DataSource.h:171
te::mem::DataSource::getDataSetNames
std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
te::core::URI
A class to store the proxy information that must be used to access data located in URIs.
Definition: URI.h:50
te::mem::DataSource::getSchemas
const std::map< std::string, te::da::DataSetTypePtr > getSchemas() const
It returns a map relating the dataset names and their schemas.
te::mem::DataSource::getDataSourceNames
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
te::mem::DataSource::getDataSets
const std::map< std::string, te::da::DataSetPtr > & getDataSets() const
It returns a map relating the dataset names and their contents.
te::mem::DataSource::getProperty
std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
TEMEMORYEXPORT
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
te::da::DataSourceCapabilities
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
Definition: DataSourceCapabilities.h:56
te::mem::DataSource::getTransactor
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository.
te::mem::DataSource::cloneDataSet
void cloneDataSet(const std::string &name, const std::string &cloneName, const std::map< std::string, std::string > &options)
It clones the dataset in the data source.
te::mem::DataSource::sm_capabilities
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
Definition: DataSource.h:178
te::da::DataSource
An abstract class for data providers like a DBMS, Web Services or a regular file.
Definition: DataSource.h:120
te::mem::DataSource::dropProperty
void dropProperty(const std::string &datasetName, const std::string &propertyName)
It removes a property from the given dataset.
te::dt::Property
It models a property definition.
Definition: Property.h:60
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::mem::DataSource::add
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit)
It adds data items to the dataset in the data source.
te::mem::DataSource::open
void open()
It opens the data source and makes it ready for using.
te::mem::DataSource::m_isOpened
bool m_isOpened
A flag to control the state of the data source.
Definition: DataSource.h:175
te::mem::DataSource::getProperties
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
te::mem::DataSource::renameDataSet
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
te::da::DataSetType
A class that models the description of a dataset.
Definition: DataSetType.h:73
te::mem::DataSource::addProperty
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
te::mem::DataSource::dataSetExists
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
te::mem::DataSource::getProperty
std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, std::size_t propertyPos)
It retrieves the property lying in the given position from the dataset.
te::mem::DataSource::exists
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::mem::DataSource::m_deepCopy
bool m_deepCopy
If true, each dataset is cloned in the getDataSet method.
Definition: DataSource.h:176
te::mem::DataSource
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
Definition: DataSource.h:53
te::da::ObjectIdSet
This class represents a set of unique ids created in the same context. i.e. from the same data set.
Definition: ObjectIdSet.h:56
te::common::FORWARDONLY
@ FORWARDONLY
Definition: Enums.h:55