All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transactor.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 
40 namespace 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 
73  ~Transactor();
74 
75  te::da::DataSource* getDataSource() const;
76 
77  bool isDataSetNameValid(const std::string& datasetName);
78 
79  bool isPropertyNameValid(const std::string& propertyName);
80 
81  std::vector<std::string> getDataSetNames();
82 
83  std::size_t getNumberOfDataSets();
84 
85  std::auto_ptr<te::da::DataSetType> getDataSetType(const std::string& name);
86 
87  boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName);
88 
89  std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
90 
91  std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos);
92 
93  std::vector<std::string> getPropertyNames(const std::string& datasetName);
94 
95  std::size_t getNumberOfProperties(const std::string& datasetName);
96 
97  bool propertyExists(const std::string& datasetName, const std::string& name);
98 
99  bool propertyExists(const std::string& datasetName, size_t propertyPos);
100 
101  void addProperty(const std::string& , te::dt::Property* ) {}
102 
103  void dropProperty(const std::string& , const std::string& ) {}
104 
105  void renameProperty(const std::string& , const std::string& , const std::string& ) {}
106 
107  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
109  bool connected = false,
110  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
111 
112  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
113  const std::string& propertyName,
114  const te::gm::Envelope* e,
117  bool connected = false,
118  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
119 
120  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
121  const std::string& propertyName,
122  const te::gm::Geometry* g,
125  bool connected = false,
126  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
127 
128  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
129  const te::da::ObjectIdSet* oids,
131  bool connected = false,
132  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
133 
134  std::auto_ptr<te::da::DataSet> query(const te::da::Select& q,
136  bool connected = false,
137  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
138 
139  std::auto_ptr<te::da::DataSet> query(const std::string& query,
141  bool connected = false,
142  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
143 
144  std::size_t getNumberOfItems(const std::string& datasetName) { return 1; }
145 
146  bool hasDataSets();
147 
148  bool dataSetExists(const std::string& name);
149 
150  void createDataSet(te::da::DataSetType* dt,
151  const std::map<std::string, std::string>& options);
152 
153  void cloneDataSet(const std::string& name,
154  const std::string& cloneName,
155  const std::map<std::string, std::string>& options) ;
156 
157  void dropDataSet(const std::string& name);
158 
159  void renameDataSet(const std::string& name,
160  const std::string& newName);
161 
162  void add(const std::string& ,
163  te::da::DataSet* ,
164  const std::map<std::string, std::string>& ,
165  std::size_t ) {}
166 
167  void remove(const std::string& ,
168  const te::da::ObjectIdSet* ){}
169 
170  void update(const std::string& ,
171  te::da::DataSet* ,
172  const std::vector<std::size_t>& ,
173  const te::da::ObjectIdSet* ,
174  const std::map<std::string, std::string>& ,
175  std::size_t ) {}
176 
177  std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
178  const std::string& propertyName);
179 
180  std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
181  std::size_t propertyPos);
182 
183  void begin() {}
184 
185  void commit() {}
186 
187  void rollBack() {}
188 
189  bool isInTransaction() const { return false; }
190 
191  void execute(const te::da::Query& /*command*/) {}
192 
193  void execute(const std::string& /*command*/) {}
194 
195  std::auto_ptr<te::da::PreparedQuery> getPrepared(const std::string& /*qName = std::string("")*/) { return std::auto_ptr<te::da::PreparedQuery>(); }
196 
197  std::auto_ptr<te::da::BatchExecutor> getBatchExecutor() { return std::auto_ptr<te::da::BatchExecutor>(); }
198 
199  void cancel() {}
200 
201  boost::int64_t getLastGeneratedId() { return 0; }
202 
203  std::string escape(const std::string& /*value*/) { return std::string(""); }
204 
205  std::auto_ptr<te::da::PrimaryKey> getPrimaryKey(const std::string& )
206  { return std::auto_ptr<te::da::PrimaryKey>(); }
207 
208  bool primaryKeyExists(const std::string&, const std::string& ) { return false; }
209 
210  void addPrimaryKey(const std::string&, te::da::PrimaryKey*) {}
211 
212  void dropPrimaryKey(const std::string&) {}
213 
214  std::auto_ptr<te::da::ForeignKey> getForeignKey(const std::string& , const std::string& ) { return std::auto_ptr<te::da::ForeignKey>(); }
215 
216  std::vector<std::string> getForeignKeyNames(const std::string& ) { return std::vector<std::string>(); }
217 
218  bool foreignKeyExists(const std::string& , const std::string& ) { return false; }
219 
220  void addForeignKey(const std::string& , te::da::ForeignKey*) {}
221 
222  void dropForeignKey(const std::string& , const std::string& ) {}
223 
224  std::auto_ptr<te::da::UniqueKey> getUniqueKey(const std::string& , const std::string& )
225  { return std::auto_ptr<te::da::UniqueKey>(); }
226 
227  std::vector<std::string> getUniqueKeyNames(const std::string& )
228  { return std::vector<std::string>(); }
229 
230  bool uniqueKeyExists(const std::string& , const std::string& ) { return false; }
231 
232  void addUniqueKey(const std::string& , te::da::UniqueKey* ) {}
233 
234  void dropUniqueKey(const std::string& , const std::string& ) {}
235 
236  std::auto_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& , const std::string& )
237  { return std::auto_ptr<te::da::CheckConstraint>(); }
238 
239  std::vector<std::string> getCheckConstraintNames(const std::string& )
240  { return std::vector<std::string>(); }
241 
242  bool checkConstraintExists(const std::string& , const std::string& ) {return false; }
243 
244  void addCheckConstraint(const std::string& , te::da::CheckConstraint* ) {}
245 
246  void dropCheckConstraint(const std::string& , const std::string& ) {}
247 
248  std::auto_ptr<te::da::Index> getIndex(const std::string& , const std::string& )
249  { return std::auto_ptr<te::da::Index>(); }
250 
251  std::vector<std::string> getIndexNames(const std::string& )
252  { return std::vector<std::string>(); }
253 
254  bool indexExists(const std::string& , const std::string& )
255  { return false; }
256 
257  void addIndex(const std::string& , te::da::Index* , const std::map<std::string, std::string>& ) {}
258 
259  void dropIndex(const std::string& , const std::string& ) {}
260 
261  bool sequenceExists(const std::string& )
262  { return false; }
263 
264  std::auto_ptr<te::da::Sequence> getSequence(const std::string& )
265  { return std::auto_ptr<te::da::Sequence>(); }
266 
267  std::vector<std::string> getSequenceNames()
268  { return std::vector<std::string>(); }
269 
271 
272  void dropSequence(const std::string&) {}
273 
274  void optimize(const std::map<std::string, std::string>& ){}
275 
276  private:
277 
278  boost::filesystem::path m_path;
279  std::auto_ptr<te::da::DataSetType> getType(const std::string& dsfullname);
280  void getDataSetNames(const boost::filesystem::path& path, std::vector<std::string>& dsnames);
281  bool hasDataSets(const boost::filesystem::path& path);
282  size_t getNumberOfDataSets(const boost::filesystem::path& path);
283  std::auto_ptr<te::da::DataSetType> getDataSetType(const boost::filesystem::path& path, const std::string& name, std::string& uri);
284 
285  };
286  } // end namespace gdal
287 } // end namespace te
288 
289 #endif // __TERRALIB_GDAL_INTERNAL_TRANSACTOR_H
290 
Configuration flags for the GDAL Driver of TerraLib.
void begin()
It starts a new transaction.
Definition: Transactor.h:183
It describes an index associated to a DataSetType.
Definition: Index.h:54
void dropSequence(const std::string &)
It removes the sequence from the data source.
Definition: Transactor.h:272
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
bool primaryKeyExists(const std::string &, const std::string &)
It checks if a primary key exists in the dataset.
Definition: Transactor.h:208
void addCheckConstraint(const std::string &, te::da::CheckConstraint *)
It adds a check constraint to the dataset.
Definition: Transactor.h:244
boost::filesystem::path m_path
Definition: Transactor.h:278
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.h:197
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
void addSequence(te::da::Sequence *)
It creates a new sequence in the data source.
Definition: Transactor.h:270
void addProperty(const std::string &, te::dt::Property *)
It adds a new property to the dataset schema.
Definition: Transactor.h:101
bool indexExists(const std::string &, const std::string &)
It checks if an index with the given name exists in the dataset.
Definition: Transactor.h:254
std::auto_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:236
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.h:267
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void execute(const std::string &)
It executes the specifed command in the data source native language.
Definition: Transactor.h:193
void dropPrimaryKey(const std::string &)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.h:212
It describes a sequence (a number generator).
Definition: Sequence.h:56
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.h:201
void addUniqueKey(const std::string &, te::da::UniqueKey *)
It adds a unique key constraint to the dataset.
Definition: Transactor.h:232
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.h:189
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:242
std::vector< std::string > getForeignKeyNames(const std::string &)
It gets the foreign key names of the given dataset.
Definition: Transactor.h:216
std::vector< std::string > getUniqueKeyNames(const std::string &)
It gets the unique key names of the given dataset.
Definition: Transactor.h:227
A Query is independent from the data source language/dialect.
Definition: Query.h:46
std::auto_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:224
std::string escape(const std::string &)
It escapes a string for using in commands and queries.
Definition: Transactor.h:203
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
std::auto_ptr< te::da::Sequence > getSequence(const std::string &)
It gets the sequence with the given name in the data source.
Definition: Transactor.h:264
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:218
void execute(const te::da::Query &)
It executes the specified command using a generic query representation.
Definition: Transactor.h:191
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: Transactor.h:144
void dropIndex(const std::string &, const std::string &)
It removes the index from the dataset schema.
Definition: Transactor.h:259
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
void commit()
It commits the transaction.
Definition: Transactor.h:185
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:257
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.h:187
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &, const std::string &)
It retrieves the foreign key from the given dataset.
Definition: Transactor.h:214
void addPrimaryKey(const std::string &, te::da::PrimaryKey *)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.h:210
bool sequenceExists(const std::string &)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.h:261
void dropCheckConstraint(const std::string &, const std::string &)
It removes the check constraint from the dataset.
Definition: Transactor.h:246
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:113
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
void dropProperty(const std::string &, const std::string &)
It removes a property from the given dataset.
Definition: Transactor.h:103
std::auto_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:248
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
void add(const std::string &, te::da::DataSet *, const std::map< std::string, std::string > &, std::size_t)
It adds data items to the dataset in the data source.
Definition: Transactor.h:162
A class that models the description of a dataset.
Definition: DataSetType.h:72
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.h:199
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:230
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
It models a property definition.
Definition: Property.h:59
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:274
void dropUniqueKey(const std::string &, const std::string &)
It removes the unique key constraint from the dataset.
Definition: Transactor.h:234
std::vector< std::string > getIndexNames(const std::string &)
It gets the index names of the given dataset.
Definition: Transactor.h:251
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &)
It retrieves the primary key of the dataset.
Definition: Transactor.h:205
std::vector< std::string > getCheckConstraintNames(const std::string &)
It gets the check constraint names of the given dataset.
Definition: Transactor.h:239
A class that describes a check constraint.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
std::auto_ptr< te::da::PreparedQuery > getPrepared(const std::string &)
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
Definition: Transactor.h:195
void addForeignKey(const std::string &, te::da::ForeignKey *)
It adds a foreign key constraint to a dataset.
Definition: Transactor.h:220
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
void renameProperty(const std::string &, const std::string &, const std::string &)
It renames a property of the given dataset.
Definition: Transactor.h:105
void dropForeignKey(const std::string &, const std::string &)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.h:222
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:170