27 #include "../common/Translator.h"
28 #include "../dataaccess/dataset/DataSetType.h"
29 #include "../dataaccess/datasource/DataSourceCatalog.h"
30 #include "../dataaccess/datasource/DataSourceCapabilities.h"
31 #include "../dataaccess/datasource/DataSourceTransactor.h"
32 #include "../dataaccess/query/SQLDialect.h"
33 #include "../dataaccess/utils/Utils.h"
34 #include "../geometry/Envelope.h"
40 #include <boost/algorithm/string/case_conv.hpp>
41 #include <boost/format.hpp>
42 #include <boost/lexical_cast.hpp>
87 m_connInfo = connInfo;
93 return std::auto_ptr<te::da::DataSourceTransactor>(0);
102 std::map<std::string, std::string>::const_iterator it = m_connInfo.find(
"MAX_DATASETS");
104 if(it != m_connInfo.end())
105 m_maxNumDatasets = boost::lexical_cast<std::size_t>(it->second);
108 it = m_connInfo.find(
"OPERATION_MODE");
110 if((it != m_connInfo.end()) && (boost::to_upper_copy(it->second) ==
"NON-SHARED"))
143 return sm_capabilities;
155 if(!dataSetExists(name))
156 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
158 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
160 std::map<std::string, te::da::DataSetPtr>::const_iterator it = m_datasets.find(name);
162 return std::auto_ptr<te::da::DataSet>(
new DataSet(*(it->second), m_deepCopy));
167 std::vector<std::string> datasetNames;
169 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
171 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it;
172 for(it = m_schemas.begin(); it != m_schemas.end(); ++it)
173 datasetNames.push_back(it->first);
180 return m_numDatasets;
185 if(!dataSetExists(datasetName))
186 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
188 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
190 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it = m_schemas.find(datasetName);
194 return std::auto_ptr<te::da::DataSetType>(dt);
199 boost::ptr_vector<te::dt::Property> properties;
201 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
203 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it = m_schemas.find(datasetName);
205 if(it == m_schemas.end())
210 const std::size_t np = dt->size();
212 for(std::size_t i = 0; i < np; ++i)
213 properties.push_back(dt->getProperty(i)->clone());
220 if(!propertyExists(datasetName,name))
221 throw Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name: \"%2%\"!")) % datasetName % name).str());
223 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
225 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
229 return std::auto_ptr<te::dt::Property>(p->
clone());
234 if(!dataSetExists(datasetName))
235 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
237 assert(propertyPos < getNumberOfProperties(datasetName));
239 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
241 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
245 return std::auto_ptr<te::dt::Property>(p->
clone());
250 if(!dataSetExists(datasetName))
251 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
253 std::vector<std::string> pNames;
255 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
257 std::map<std::string, te::da::DataSetTypePtr>::const_iterator it = m_schemas.find(datasetName);
261 std::vector<te::dt::Property*>& properties = dt->getProperties();
262 for(std::size_t i = 0; i < properties.size(); ++i)
263 pNames.push_back(properties[i]->getName());
270 return getPropertyNames(datasetName).size();
275 std::vector<std::string> pNames = getPropertyNames(datasetName);
277 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
279 if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
287 std::string pName = p->
getName();
289 if(propertyExists(datasetName, p->
getName()))
290 throw Exception((boost::format(
TE_TR(
"The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % pName).str());
292 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
294 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
299 std::auto_ptr<te::da::DataSet> dataset = getDataSet(datasetName);
307 if(!propertyExists(datasetName, propertyName))
308 throw Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % propertyName).str());
310 std::auto_ptr<te::da::DataSet> dataset = getDataSet(datasetName);
312 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
314 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
327 const std::string& name,
328 const std::string& newName)
330 if(!propertyExists(datasetName, name))
331 throw Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
333 if(!isPropertyNameValid(newName))
334 throw Exception((boost::format(
TE_TR(
"The new property name \"%1%\" is not valid!")) % newName).str());
336 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
339 std::auto_ptr<te::da::DataSet> dataset = getDataSet(datasetName);
341 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
349 dt->getProperty(pos)->setName(newName);
354 if(!dataSetExists(datasetName))
355 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
357 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
361 return dataset.get()->size();
366 return (m_numDatasets == 0) ?
false :
true;
371 std::vector<std::string> datasetNames = getDataSetNames();
373 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
375 if(std::find(datasetNames.begin(), datasetNames.end(), name) != datasetNames.end())
382 const std::map<std::string, std::string>& )
384 std::string datasetName = dt->
getName();
386 if(m_schemas.find(datasetName) != m_schemas.end())
387 throw Exception((boost::format(
TE_TR(
"A dataset with the same name (%1%) already exists!")) % datasetName).str());
389 if((m_numDatasets + 1) > m_maxNumDatasets)
390 throw Exception((boost::format(
TE_TR(
"The maximum number of datasets was exceeded!"))).str());
392 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
395 m_schemas[datasetName] = dtp;
399 m_datasets[datasetName] = dataset;
405 const std::string& cloneName,
406 const std::map<std::string, std::string>& )
408 if(!dataSetExists(name))
409 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
411 if(!isDataSetNameValid(cloneName))
412 throw Exception((boost::format(
TE_TR(
"The dataset clone name \"%1%\" is not valid!")) % cloneName).str());
414 if(!dataSetExists(cloneName))
415 throw Exception((boost::format(
TE_TR(
"There is already a dataset with this name: \"%1%\"!")) % cloneName).str());
420 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
424 m_schemas[cloneName] = clonedtp;
429 m_datasets[cloneName] = datasetClone;
436 if(!dataSetExists(name))
437 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
439 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
441 m_schemas.erase(m_schemas.find(name));
442 m_datasets.erase(m_datasets.find(name));
449 if(!dataSetExists(name))
450 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % name).str());
452 if(!isDataSetNameValid(newName))
453 throw Exception((boost::format(
TE_TR(
"The new name \"%1%\" is not valid!")) % newName).str());
455 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
457 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
459 dt->setName(newName);
460 dt->setCompositeName(newName);
462 m_schemas.erase(m_schemas.find(name));
463 m_schemas[newName] = dt;
466 m_datasets.erase(m_datasets.find(name));
467 m_datasets[newName] = dataset;
472 const std::map<std::string, std::string>& ,
475 if(!dataSetExists(datasetName))
476 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
478 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
481 datasetp->
copy(*d, limit);
486 if(!dataSetExists(datasetName))
487 throw Exception((boost::format(
TE_TR(
"There is no dataset with this name: \"%1%\"!")) % datasetName).str());
489 boost::lock_guard<boost::recursive_mutex> lock(m_mtx);
501 const std::vector<std::size_t>& ,
503 const std::map<std::string, std::string>& ,
529 return std::vector<std::string>();
534 return std::vector<te::common::CharEncoding>();
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
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.
~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.
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
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.
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.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
virtual Property * clone() const =0
It returns a clone of the object.
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.
std::auto_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 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...
#define TE_TR(message)
It marks a string in order to get translated.
An exception class for the TerraLib In-Memory Data Access driver.
It models a property definition.
void drop(std::size_t pos)
It drops a property from the dataset.
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.
std::vector< te::common::CharEncoding > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
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.
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.
virtual std::auto_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...
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.
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of 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.
std::auto_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::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &datasetName)
It gets information about the given dataset.
bool moveNext()
It moves the internal pointer to the next item of the collection.
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.
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
boost::shared_ptr< DataSet > DataSetPtr
const std::map< std::string, te::da::DataSetPtr > & getDataSets() const
It returns a map relating the dataset names and their contents.
#define TE_MEMORY_MAX_DATASETS
The maximum number of datasets to be handled by a data source.
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
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.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids)
It removes all the informed items from the dataset.
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.
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
#define TE_MEMORY_DRIVER_IDENTIFIER
The In-Memory driver identifier string.
void open()
It opens the data source and makes it ready for using.
const std::string & getName() const
It returns the property name.