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 
58  DataSource(const te::core::URI& uri);
59 
60  ~DataSource();
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::auto_ptr<te::da::DataSourceTransactor> getTransactor();
79 
80  void open();
81 
82  void close();
83 
84  bool isOpened() const;
85 
86  bool isValid() const;
87 
88  const te::da::DataSourceCapabilities& getCapabilities() const;
89 
90  const te::da::SQLDialect* getDialect() const;
91 
92  std::auto_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::auto_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::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
105 
106  std::auto_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  */
156  static void setCapabilities(const te::da::DataSourceCapabilities& capabilities);
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
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
Definition: DataSource.h:178
#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:174
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:179
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:119
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:173
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:175
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
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:172
std::map< std::string, te::da::DataSetTypePtr > m_schemas
The set of dataset schemas.
Definition: DataSource.h:171
std::map< std::string, te::da::DataSetPtr > m_datasets
The set of datasets stored in memory.
Definition: DataSource.h:170
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:176