Loading...
Searching...
No Matches
Transactor.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/gdal/Transactor.h
22
23 */
24
25#ifndef __TERRALIB_GDAL_INTERNAL_TRANSACTOR_H
26#define __TERRALIB_GDAL_INTERNAL_TRANSACTOR_H
27
28// TerraLib
29#include "../dataaccess/datasource/DataSourceTransactor.h"
30#include "Config.h"
31
32//STL
33#include <memory>
34
35// Boost
36#include <boost/filesystem.hpp>
37#include <boost/ptr_container/ptr_vector.hpp>
38#include <boost/shared_ptr.hpp>
39
40namespace te
41{
42 namespace dt
43 {
44 class Property;
45 }
46
47 namespace gm
48 {
49 class Envelope;
50 class Geometry;
51 }
52 namespace da
53 {
54 class DataSet;
55 class DataSource;
56 class ObjectIdSet;
57 typedef boost::shared_ptr<DataSetType> DataSetTypePtr;
58 }
59
60 namespace gdal
61 {
62 class DataSource;
63
64 /*!
65 \class Transactor
66 */
68 {
69 public:
70
71 Transactor(const std::string& accessInfo);
72
74
76
77 std::vector<std::string> getDataSetNames();
78
79 std::size_t getNumberOfDataSets();
80
81 std::unique_ptr<te::da::DataSetType> getDataSetType(const std::string& name);
82
83 boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName);
84
85 std::unique_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
86
87 std::unique_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos);
88
89 std::vector<std::string> getPropertyNames(const std::string& datasetName);
90
91 std::size_t getNumberOfProperties(const std::string& datasetName);
92
93 bool propertyExists(const std::string& datasetName, const std::string& name);
94
95 bool propertyExists(const std::string& datasetName, size_t propertyPos);
96
97 void addProperty(const std::string& , te::dt::Property* ) {}
98
99 void dropProperty(const std::string& , const std::string& ) {}
100
101 void renameProperty(const std::string& , const std::string& , const std::string& ) {}
102
103 std::unique_ptr<te::da::DataSet> getDataSet(const std::string& name,
105 bool connected = false,
106 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
107
108 std::unique_ptr<te::da::DataSet> getDataSet(const std::string& name,
109 const std::string& propertyName,
110 const te::gm::Envelope* e,
113 bool connected = false,
114 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
115
116 std::unique_ptr<te::da::DataSet> getDataSet(const std::string& name,
117 const std::string& propertyName,
118 const te::gm::Geometry* g,
121 bool connected = false,
122 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
123
124 std::unique_ptr<te::da::DataSet> getDataSet(const std::string& name,
125 const te::da::ObjectIdSet* oids,
127 bool connected = false,
128 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
129
130 std::unique_ptr<te::da::DataSet> query(const te::da::Select& q,
132 bool connected = false,
133 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
134
135 std::unique_ptr<te::da::DataSet> query(const std::string& query,
137 bool connected = false,
138 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
139
140 std::size_t getNumberOfItems(const std::string& datasetName) { return 1; }
141
143
144 bool dataSetExists(const std::string& name);
145
147 const std::map<std::string, std::string>& options);
148
149 void cloneDataSet(const std::string& name,
150 const std::string& cloneName,
151 const std::map<std::string, std::string>& options) ;
152
153 void dropDataSet(const std::string& name);
154
155 void renameDataSet(const std::string& name,
156 const std::string& newName);
157
158 void add(const std::string& ,
160 const std::map<std::string, std::string>& ,
161 std::size_t,
162 bool) {}
163
164 void remove(const std::string& ,
165 const te::da::ObjectIdSet* ){}
166
167 void update(const std::string& ,
169 const std::vector<std::size_t>& ,
170 const te::da::ObjectIdSet* ,
171 const std::map<std::string, std::string>& ,
172 std::size_t ) {}
173
174 std::unique_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
175 const std::string& propertyName);
176
177 std::unique_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
178 std::size_t propertyPos);
179
180 void begin() {}
181
182 void commit() {}
183
184 void rollBack() {}
185
186 bool isInTransaction() const { return false; }
187
188 void execute(const te::da::Query& /*command*/) {}
189
190 void execute(const std::string& /*command*/) {}
191
192 std::unique_ptr<te::da::PreparedQuery> getPrepared(const std::string& /*qName = std::string("")*/) { return std::unique_ptr<te::da::PreparedQuery>(); }
193
194 std::unique_ptr<te::da::BatchExecutor> getBatchExecutor() { return std::unique_ptr<te::da::BatchExecutor>(); }
195
196 void cancel() {}
197
198 boost::int64_t getLastGeneratedId() { return 0; }
199
200 std::string escape(const std::string& /*value*/) { return std::string(""); }
201
202 std::unique_ptr<te::da::PrimaryKey> getPrimaryKey(const std::string& )
203 { return std::unique_ptr<te::da::PrimaryKey>(); }
204
205 bool primaryKeyExists(const std::string&, const std::string& ) { return false; }
206
207 void addPrimaryKey(const std::string&, te::da::PrimaryKey*) {}
208
209 void dropPrimaryKey(const std::string&) {}
210
211 std::unique_ptr<te::da::ForeignKey> getForeignKey(const std::string& , const std::string& ) { return std::unique_ptr<te::da::ForeignKey>(); }
212
213 std::vector<std::string> getForeignKeyNames(const std::string& ) { return std::vector<std::string>(); }
214
215 bool foreignKeyExists(const std::string& , const std::string& ) { return false; }
216
217 void addForeignKey(const std::string& , te::da::ForeignKey*) {}
218
219 void dropForeignKey(const std::string& , const std::string& ) {}
220
221 std::unique_ptr<te::da::UniqueKey> getUniqueKey(const std::string& , const std::string& )
222 { return std::unique_ptr<te::da::UniqueKey>(); }
223
224 std::vector<std::string> getUniqueKeyNames(const std::string& )
225 { return std::vector<std::string>(); }
226
227 bool uniqueKeyExists(const std::string& , const std::string& ) { return false; }
228
229 void addUniqueKey(const std::string& , te::da::UniqueKey* ) {}
230
231 void dropUniqueKey(const std::string& , const std::string& ) {}
232
233 std::unique_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& , const std::string& )
234 { return std::unique_ptr<te::da::CheckConstraint>(); }
235
236 std::vector<std::string> getCheckConstraintNames(const std::string& )
237 { return std::vector<std::string>(); }
238
239 bool checkConstraintExists(const std::string& , const std::string& ) {return false; }
240
241 void addCheckConstraint(const std::string& , te::da::CheckConstraint* ) {}
242
243 void dropCheckConstraint(const std::string& , const std::string& ) {}
244
245 std::unique_ptr<te::da::Index> getIndex(const std::string& , const std::string& )
246 { return std::unique_ptr<te::da::Index>(); }
247
248 std::vector<std::string> getIndexNames(const std::string& )
249 { return std::vector<std::string>(); }
250
251 bool indexExists(const std::string& , const std::string& )
252 { return false; }
253
254 void addIndex(const std::string& , te::da::Index* , const std::map<std::string, std::string>& ) {}
255
256 void dropIndex(const std::string& , const std::string& ) {}
257
258 bool sequenceExists(const std::string& )
259 { return false; }
260
261 std::unique_ptr<te::da::Sequence> getSequence(const std::string& )
262 { return std::unique_ptr<te::da::Sequence>(); }
263
264 std::vector<std::string> getSequenceNames()
265 { return std::vector<std::string>(); }
266
268
269 void dropSequence(const std::string&) {}
270
271 void optimize(const std::map<std::string, std::string>& ){}
272
273 private:
274
275 std::string m_source;
276 std::unique_ptr<te::da::DataSetType> getType(const std::string& dsfullname);
277 void getDataSetNames(const std::string& source, std::vector<std::string>& dsnames);
278 bool hasDataSets(const std::string& source);
279 size_t getNumberOfDataSets(const std::string& source);
280 std::unique_ptr<te::da::DataSetType> getDataSetType(const std::string& source, const std::string& name, std::string& uri);
281
282 };
283 } // end namespace gdal
284} // end namespace te
285
286#endif // __TERRALIB_GDAL_INTERNAL_TRANSACTOR_H
287
A class that describes a check constraint.
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 DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
An abstract class for data providers like a DBMS, Web Services or a regular file.
Definition: DataSource.h:120
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:49
It describes an index associated to a DataSetType.
Definition: Index.h:53
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 describes a primary key (pk) constraint.
Definition: PrimaryKey.h:49
A Query is independent from the data source language/dialect.
Definition: Query.h:47
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:67
It describes a sequence (a number generator).
Definition: Sequence.h:57
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:50
It models a property definition.
Definition: Property.h:60
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: Transactor.h:140
void remove(const std::string &, const te::da::ObjectIdSet *)
It removes all the informed items from the dataset.
Definition: Transactor.h:164
std::unique_ptr< te::da::Index > getIndex(const std::string &, const std::string &)
It gets the index with the given name from the dataset.
Definition: Transactor.h:245
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.h:264
bool primaryKeyExists(const std::string &, const std::string &)
It checks if a primary key exists in the dataset.
Definition: Transactor.h:205
void dropCheckConstraint(const std::string &, const std::string &)
It removes the check constraint from the dataset.
Definition: Transactor.h:243
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 addProperty(const std::string &, te::dt::Property *)
It adds a new property to the dataset schema.
Definition: Transactor.h:97
std::vector< std::string > getForeignKeyNames(const std::string &)
It gets the foreign key names of the given dataset.
Definition: Transactor.h:213
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.h:198
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
void dropIndex(const std::string &, const std::string &)
It removes the index from the dataset schema.
Definition: Transactor.h:256
bool propertyExists(const std::string &datasetName, size_t propertyPos)
void addPrimaryKey(const std::string &, te::da::PrimaryKey *)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.h:207
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &source, const std::string &name, std::string &uri)
std::unique_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.h:194
bool sequenceExists(const std::string &)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.h:258
void dropPrimaryKey(const std::string &)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.h:209
bool hasDataSets(const std::string &source)
bool hasDataSets()
It checks if the data source has any dataset.
std::unique_ptr< te::da::UniqueKey > getUniqueKey(const std::string &, const std::string &)
It gets the unique key in the dataset with the given name.
Definition: Transactor.h:221
void addIndex(const std::string &, te::da::Index *, const std::map< std::string, std::string > &)
It adds an index to the dataset.
Definition: Transactor.h:254
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. A dataset can be connected or disconnected....
std::unique_ptr< te::da::Sequence > getSequence(const std::string &)
It gets the sequence with the given name in the data source.
Definition: Transactor.h:261
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
std::unique_ptr< te::da::DataSetType > getType(const std::string &dsfullname)
std::unique_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. A dataset can be connected or di...
void addCheckConstraint(const std::string &, te::da::CheckConstraint *)
It adds a check constraint to the dataset.
Definition: Transactor.h:241
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
void execute(const std::string &)
It executes the specifed command in the data source native language.
Definition: Transactor.h:190
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
std::string escape(const std::string &)
It escapes a string for using in commands and queries.
Definition: Transactor.h:200
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
std::unique_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &, const std::string &)
It gets the check constraint of the dataset with the given name.
Definition: Transactor.h:233
void dropForeignKey(const std::string &, const std::string &)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.h:219
void begin()
It starts a new transaction.
Definition: Transactor.h:180
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.h:196
void addForeignKey(const std::string &, te::da::ForeignKey *)
It adds a foreign key constraint to a dataset.
Definition: Transactor.h:217
void getDataSetNames(const std::string &source, std::vector< std::string > &dsnames)
void addUniqueKey(const std::string &, te::da::UniqueKey *)
It adds a unique key constraint to the dataset.
Definition: Transactor.h:229
void renameProperty(const std::string &, const std::string &, const std::string &)
It renames a property of the given dataset.
Definition: Transactor.h:101
bool checkConstraintExists(const std::string &, const std::string &)
It checks if a check-constraint with the given name exists in the data source.
Definition: Transactor.h:239
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.h:186
void dropProperty(const std::string &, const std::string &)
It removes a property from the given dataset.
Definition: Transactor.h:99
bool indexExists(const std::string &, const std::string &)
It checks if an index with the given name exists in the dataset.
Definition: Transactor.h:251
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, const te::da::ObjectIdSet *oids, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
std::unique_ptr< te::da::ForeignKey > getForeignKey(const std::string &, const std::string &)
It retrieves the foreign key from the given dataset.
Definition: Transactor.h:211
void add(const std::string &, te::da::DataSet *, const std::map< std::string, std::string > &, std::size_t, bool)
It adds data items to the dataset in the data source.
Definition: Transactor.h:158
std::unique_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, std::size_t propertyPos)
It retrieves the bounding rectangle for the spatial property lying in the given position in the datas...
std::unique_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset.
std::vector< std::string > getUniqueKeyNames(const std::string &)
It gets the unique key names of the given dataset.
Definition: Transactor.h:224
void execute(const te::da::Query &)
It executes the specified command using a generic query representation.
Definition: Transactor.h:188
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given 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 optimize(const std::map< std::string, std::string > &)
For some data access drivers, this method will perform some operations to optimize the data storage.
Definition: Transactor.h:271
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, const std::string &propertyName, const te::gm::Envelope *e, te::gm::SpatialRelation r, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name using a spatial filter over the specified property....
void commit()
It commits the transaction.
Definition: Transactor.h:182
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.
void update(const std::string &, te::da::DataSet *, const std::vector< std::size_t > &, const te::da::ObjectIdSet *, const std::map< std::string, std::string > &, std::size_t)
It updates the contents of a dataset for the set of data items.
Definition: Transactor.h:167
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.h:184
std::unique_ptr< te::da::PreparedQuery > getPrepared(const std::string &)
It creates a prepared query object that may be used for query commands (select, insert,...
Definition: Transactor.h:192
Transactor(const std::string &accessInfo)
std::string m_source
Definition: Transactor.h:275
std::unique_ptr< te::da::DataSet > query(const std::string &query, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using the data source native language....
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
void addSequence(te::da::Sequence *)
It creates a new sequence in the data source.
Definition: Transactor.h:267
std::unique_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &)
It retrieves the primary key of the dataset.
Definition: Transactor.h:202
bool uniqueKeyExists(const std::string &, const std::string &)
It checks if a unique key with the given name exists in the dataset.
Definition: Transactor.h:227
void dropSequence(const std::string &)
It removes the sequence from the data source.
Definition: Transactor.h:269
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
void dropUniqueKey(const std::string &, const std::string &)
It removes the unique key constraint from the dataset.
Definition: Transactor.h:231
bool foreignKeyExists(const std::string &, const std::string &)
It checks if a foreign key with the given name exists in the data source.
Definition: Transactor.h:215
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, const std::string &propertyName, const te::gm::Geometry *g, te::gm::SpatialRelation r, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name using a spatial filter over the given geometric prop...
std::vector< std::string > getIndexNames(const std::string &)
It gets the index names of the given dataset.
Definition: Transactor.h:248
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::vector< std::string > getCheckConstraintNames(const std::string &)
It gets the check constraint names of the given dataset.
Definition: Transactor.h:236
size_t getNumberOfDataSets(const std::string &source)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
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
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:128
TerraLib.
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
Proxy configuration file for TerraView (see terraview_config.h).