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();
57 
58  ~DataSource();
59 
60  /*!
61  \brief It returns a map relating the dataset names and their contents.
62 
63  \return The map relating the dataset names and their contents..
64  */
65  const std::map<std::string, te::da::DataSetPtr>& getDataSets() const;
66 
67  /*!
68  \brief It returns a map relating the dataset names and their schemas.
69 
70  \return The map relating the dataset names and their schemas.
71  */
72  const std::map<std::string, te::da::DataSetTypePtr> getSchemas() const;
73 
74  std::string getType() const;
75 
76  const std::map<std::string, std::string>& getConnectionInfo() const;
77 
78  void setConnectionInfo(const std::map<std::string, std::string>& connInfo);
79 
80  std::auto_ptr<te::da::DataSourceTransactor> getTransactor();
81 
82  void open();
83 
84  void close();
85 
86  bool isOpened() const;
87 
88  bool isValid() const;
89 
90  const te::da::DataSourceCapabilities& getCapabilities() const;
91 
92  const te::da::SQLDialect* getDialect() const;
93 
94  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
96  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
97 
98  std::vector<std::string> getDataSetNames();
99 
100  std::size_t getNumberOfDataSets();
101 
102  std::auto_ptr<te::da::DataSetType> getDataSetType(const std::string& datasetName);
103 
104  boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName);
105 
106  std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
107 
108  std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos);
109 
110  std::vector<std::string> getPropertyNames(const std::string& datasetName);
111 
112  std::size_t getNumberOfProperties(const std::string& datasetName);
113 
114  bool propertyExists(const std::string& datasetName, const std::string& name);
115 
116  void addProperty(const std::string& datasetName, te::dt::Property* p);
117 
118  void dropProperty(const std::string& datasetName, const std::string& propertyName);
119 
120  void renameProperty(const std::string& datasetName, const std::string& name, const std::string& newName);
121 
122  std::size_t getNumberOfItems(const std::string& datasetName);
123 
124  bool hasDataSets();
125 
126  bool dataSetExists(const std::string& name);
127 
128  void createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& options);
129 
130  void cloneDataSet(const std::string& name, const std::string& cloneName,
131  const std::map<std::string, std::string>& options);
132 
133  void dropDataSet(const std::string& name);
134 
135  void renameDataSet(const std::string& name, const std::string& newName);
136 
137  void add(const std::string& datasetName, te::da::DataSet* d,
138  const std::map<std::string, std::string>& options, std::size_t limit);
139 
140  void remove(const std::string& datasetName, const te::da::ObjectIdSet* oids);
141 
142  void update(const std::string& datasetName,
143  te::da::DataSet* dataset,
144  const std::vector<std::size_t>& properties,
145  const te::da::ObjectIdSet* oids,
146  const std::map<std::string, std::string>& options,
147  std::size_t limit = 0);
148 
149  /*!
150  \brief It sets the capabilities document.
151 
152  \param capabilities The memory data source capabilities.
153 
154  \note The memory data source will take the ownership of the given capabilities object.
155 
156  \note Memory driver extended method.
157  */
158  static void setCapabilities(const te::da::DataSourceCapabilities& capabilities);
159 
160  protected:
161 
162  void create(const std::map<std::string, std::string>& dsInfo);
163 
164  void drop(const std::map<std::string, std::string>& dsInfo);
165 
166  bool exists(const std::map<std::string, std::string>& dsInfo);
167 
168  std::vector<std::string> getDataSourceNames(const std::map<std::string, std::string>& dsInfo);
169 
170  std::vector<te::common::CharEncoding> getEncodings(const std::map<std::string, std::string>& dsInfo);
171 
172  private:
173 
174  std::map<std::string, std::string> m_connInfo; //!< DataSource information.
175  std::map<std::string, te::da::DataSetPtr> m_datasets; //!< The set of datasets stored in memory.
176  std::map<std::string, te::da::DataSetTypePtr> m_schemas; //!< The set of dataset schemas.
177  mutable boost::recursive_mutex m_mtx; //!< The internal mutex.
178  std::size_t m_numDatasets; //!< The number of datasets kept in the data source.
179  std::size_t m_maxNumDatasets; //!< The maximum number of datasets to be handled by the data source.
180  bool m_isOpened; //!< A flag to control the state of the data source.
181  bool m_deepCopy; //!< If true, each dataset is cloned in the getDataSet method.
182 
183  static te::da::DataSourceCapabilities sm_capabilities; //!< The Memory data source capabilities.
184  static const te::da::SQLDialect sm_dialect; //!< A dummy dialect.
185  };
186 
187  } // end namespace mem
188 } // end namespace te
189 
190 #endif // __TERRALIB_MEMORY_INTERNAL_DATASOURCE_H
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
Definition: DataSource.h:183
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
std::size_t m_maxNumDatasets
The maximum number of datasets to be handled by the data source.
Definition: DataSource.h:179
A class that models the description of a dataset.
Definition: DataSetType.h:72
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
static const te::da::SQLDialect sm_dialect
A dummy dialect.
Definition: DataSource.h:184
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
Configuration flags for the TerraLib In-memory Data Access driver.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
std::map< std::string, std::string > m_connInfo
DataSource information.
Definition: DataSource.h:174
It models a property definition.
Definition: Property.h:59
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::size_t m_numDatasets
The number of datasets kept in the data source.
Definition: DataSource.h:178
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
te::da::DataSourceCapabilities capabilities
URI C++ Library.
bool m_isOpened
A flag to control the state of the data source.
Definition: DataSource.h:180
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
boost::recursive_mutex m_mtx
The internal mutex.
Definition: DataSource.h:177
std::map< std::string, te::da::DataSetTypePtr > m_schemas
The set of dataset schemas.
Definition: DataSource.h:176
std::map< std::string, te::da::DataSetPtr > m_datasets
The set of datasets stored in memory.
Definition: DataSource.h:175
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSource.h:52
bool m_deepCopy
If true, each dataset is cloned in the getDataSet method.
Definition: DataSource.h:181