Loading...
Searching...
No Matches
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
37namespace 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,
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
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::da::DataSourceCapabilities capabilities
A class to store the proxy information that must be used to access data located in URIs.
Definition: URI.h:50
A class that models the description of a dataset.
Definition: DataSetType.h:73
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
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:120
This class represents a set of unique ids created in the same context. i.e. from the same data set.
Definition: ObjectIdSet.h:56
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:56
It models a property definition.
Definition: Property.h:60
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
Definition: DataSource.h:53
std::map< std::string, te::da::DataSetTypePtr > m_schemas
The set of dataset schemas.
Definition: DataSource.h:171
void open()
It opens the data source and makes it ready for using.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids)
It removes all the informed items from the dataset.
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository.
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
static const te::da::SQLDialect sm_dialect
A dummy dialect.
Definition: DataSource.h:179
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
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.
void close()
It closes the data source and clears all the resources used by its internal communication channel.
void renameProperty(const std::string &datasetName, const std::string &name, const std::string &newName)
It renames a property of the given dataset.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
const std::map< std::string, te::da::DataSetPtr > & getDataSets() const
It returns a map relating the dataset names and their contents.
DataSource(const std::string &connInfo)
bool m_deepCopy
If true, each dataset is cloned in the getDataSet method.
Definition: DataSource.h:176
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &datasetName)
It gets information about the given dataset.
std::size_t m_numDatasets
The number of datasets kept in the data source.
Definition: DataSource.h:173
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.
~DataSource()
Virtual destructor.
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
std::map< std::string, te::da::DataSetPtr > m_datasets
The set of datasets stored in memory.
Definition: DataSource.h:170
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
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.
std::size_t m_maxNumDatasets
The maximum number of datasets to be handled by the data source.
Definition: DataSource.h:174
std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
bool hasDataSets()
It checks if the data source has any dataset.
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
Definition: DataSource.h:178
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,...
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
boost::recursive_mutex m_mtx
The internal mutex.
Definition: DataSource.h:172
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
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.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
bool m_isOpened
A flag to control the state of the data source.
Definition: DataSource.h:175
void create(const std::string &connInfo)
It creates a new data source.
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
bool isValid() const
It checks if the data source is valid (available for using).
void dropProperty(const std::string &datasetName, const std::string &propertyName)
It removes a property from the given dataset.
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
It sets the capabilities document.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS,...
DataSource(const te::core::URI &uri)
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
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.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
const std::map< std::string, te::da::DataSetTypePtr > getSchemas() const
It returns a map relating the dataset names and their schemas.
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.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
@ FORWARDONLY
Definition: Enums.h:55
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
@ RAccess
Definition: Enums.h:43
TerraLib.
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
Proxy configuration file for TerraView (see terraview_config.h).