27 #include "../core/translator/Translator.h" 28 #include "../core/uri/URI.h" 29 #include "../core/uri/Utils.h" 30 #include "../dataaccess/dataset/DataSetType.h" 31 #include "../dataaccess/datasource/DataSourceCatalog.h" 32 #include "../dataaccess/datasource/DataSourceCapabilities.h" 33 #include "../dataaccess/datasource/DataSourceTransactor.h" 34 #include "../dataaccess/query/SQLDialect.h" 35 #include "../dataaccess/utils/Utils.h" 36 #include "../geometry/Envelope.h" 42 #include <boost/algorithm/string/case_conv.hpp> 43 #include <boost/format.hpp> 44 #include <boost/lexical_cast.hpp> 95 return std::unique_ptr<te::da::DataSourceTransactor>();
104 throw Exception(
TE_TR(
"There is no valid information about the data source"));
107 std::map<std::string, std::string>::const_iterator it;
110 it = kvp.find(
"MAX_DATASETS");
116 it = kvp.find(
"OPERATION_MODE");
118 if((it != kvp.end()) && (boost::to_upper_copy(it->second) ==
"NON-SHARED"))
164 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
166 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
168 std::map<std::string, te::da::DataSetPtr>::const_iterator it =
m_datasets.find(name);
175 std::vector<std::string> datasetNames;
177 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
179 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it;
181 datasetNames.push_back(it->first);
194 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
196 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
198 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it =
m_schemas.find(datasetName);
202 return std::unique_ptr<te::da::DataSetType>(
dt);
207 boost::ptr_vector<te::dt::Property> properties;
209 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
211 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it =
m_schemas.find(datasetName);
218 const std::size_t np = dt->size();
220 for(std::size_t i = 0; i < np; ++i)
221 properties.push_back(dt->getProperty(i)->clone());
229 throw Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name: \"%2%\"!")) % datasetName % name).str());
231 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
237 return std::unique_ptr<te::dt::Property>(p->
clone());
243 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
249 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
253 return std::unique_ptr<te::dt::Property>(p->
clone());
259 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
261 std::vector<std::string> pNames;
263 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
265 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it =
m_schemas.find(datasetName);
269 std::vector<te::dt::Property*>& properties = dt->getProperties();
270 for(std::size_t i = 0; i < properties.size(); ++i)
271 pNames.push_back(properties[i]->getName());
285 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
287 if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
295 std::string pName = p->
getName();
298 throw Exception((boost::format(
TE_TR(
"The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % pName).str());
302 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
307 std::unique_ptr<te::da::DataSet> dataset =
getDataSet(datasetName);
316 throw Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % propertyName).str());
318 std::unique_ptr<te::da::DataSet> dataset =
getDataSet(datasetName);
322 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
335 const std::string& name,
336 const std::string& newName)
339 throw Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
342 throw Exception((boost::format(
TE_TR(
"The new property name \"%1%\" is not valid!")) % newName).str());
347 std::unique_ptr<te::da::DataSet> dataset =
getDataSet(datasetName);
349 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
357 dt->getProperty(pos)->setName(newName);
363 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
365 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
369 return dataset.get()->size();
381 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
383 if(std::find(datasetNames.begin(), datasetNames.end(), name) != datasetNames.end())
390 const std::map<std::string, std::string>& )
392 std::string datasetName = dt->
getName();
395 throw Exception((boost::format(
TE_TR(
"A dataset with the same name (%1%) already exists!")) % datasetName).str());
398 throw Exception((boost::format(
TE_TR(
"The maximum number of datasets was exceeded!"))).str());
400 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
413 const std::string& cloneName,
414 const std::map<std::string, std::string>& )
417 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
420 throw Exception((boost::format(
TE_TR(
"The dataset clone name \"%1%\" is not valid!")) % cloneName).str());
423 throw Exception((boost::format(
TE_TR(
"There is already a dataset with this name: \"%1%\"!")) % cloneName).str());
428 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
445 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
447 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
458 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
461 throw Exception((boost::format(
TE_TR(
"The new name \"%1%\" is not valid!")) % newName).str());
465 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
467 dt->setName(newName);
468 dt->setCompositeName(newName);
480 const std::map<std::string, std::string>& ,
484 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
486 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
489 datasetp->
copy(*d, limit);
495 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
497 boost::lock_guard<boost::recursive_mutex> lock(
m_mtx);
509 const std::vector<std::size_t>& ,
511 const std::map<std::string, std::string>& ,
537 return std::vector<std::string>();
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository...
const std::map< std::string, te::da::DataSetTypePtr > getSchemas() const
It returns a map relating the dataset names and their schemas.
static te::da::DataSourceCapabilities sm_capabilities
The Memory data source capabilities.
virtual bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
~DataSource()
Virtual destructor.
boost::shared_ptr< DataSet > DataSetPtr
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
boost::shared_ptr< DataSetType > DataSetTypePtr
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
It sets the capabilities document.
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.
std::size_t m_maxNumDatasets
The maximum number of datasets to be handled by the data source.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
Base exception class for plugin module.
A class that models the description of a dataset.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
An exception class for the TerraLib In-Memory Data Access driver.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
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...
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
It represents the SQL query dialect accepted by a given data source.
static const te::da::SQLDialect sm_dialect
A dummy dialect.
bool hasDataSets()
It checks if the data source has any dataset.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool isValid() const
Return if the given URI is valid or not.
#define TE_TR(message)
It marks a string in order to get translated.
virtual Property * clone() const =0
It returns a clone of the object.
It models a property definition.
void drop(std::size_t pos)
It drops a property from the dataset.
std::string query() const
Retrieving the query.
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.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
void close()
It closes the data source and clears all the resources used by its internal communication channel...
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
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.
std::size_t m_numDatasets
The number of datasets kept in the data source.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
te::da::DataSourceCapabilities capabilities
bool isValid() const
It checks if the data source is valid (available for using).
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
static te::dt::TimeDuration dt(20, 30, 50, 11)
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.
bool m_isOpened
A flag to control the state of the data source.
#define TE_MEMORY_MAX_DATASETS
The maximum number of datasets to be handled by a data source.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void remove()
It removes the current dataset item.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
virtual bool isDataSetNameValid(const std::string &datasetName)
It checks if the given dataset name is valid.
bool moveNext()
It moves the internal pointer to the next item of the collection.
A class for representing an Uniform Resource Identifier (URI).
int getType() const
It returns the property data type.
A dataset is the unit of information manipulated by the data access module of TerraLib.
void copy(te::da::DataSet &src, std::size_t limit=0)
It copies up to limit items from the source dataset.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
virtual std::unique_ptr< 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...
boost::recursive_mutex m_mtx
The internal mutex.
te::core::URI m_uri
The URI used to describe the datasource connection;.
boost::shared_ptr< DataSet > DataSetPtr
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
std::map< std::string, te::da::DataSetTypePtr > m_schemas
The set of dataset schemas.
#define TE_MEMORY_DRIVER_IDENTIFIER
The In-Memory driver identifier string.
void create(const std::string &connInfo)
It creates a new data source.
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &datasetName)
It gets information about the given 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)
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
std::map< std::string, te::da::DataSetPtr > m_datasets
The set of datasets stored in memory.
std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
void renameProperty(const std::string &datasetName, const std::string &name, const std::string &newName)
It renames a property of the given dataset.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids)
It removes all the informed items from the dataset.
bool m_deepCopy
If true, each dataset is cloned in the getDataSet method.
void setPropertyName(const std::string &name, std::size_t pos)
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.
void dropProperty(const std::string &datasetName, const std::string &propertyName)
It removes a property from the given dataset.
void open()
It opens the data source and makes it ready for using.
const std::string & getName() const
It returns the property name.