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 
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  std::vector<std::string> getDataSetNames();
78 
79  std::size_t getNumberOfDataSets();
80 
81  std::auto_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::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
86 
87  std::auto_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::auto_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::auto_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::auto_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::auto_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::auto_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::auto_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 
142  bool hasDataSets();
143 
144  bool dataSetExists(const std::string& name);
145 
146  void createDataSet(te::da::DataSetType* dt,
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& ,
159  te::da::DataSet* ,
160  const std::map<std::string, std::string>& ,
161  std::size_t ) {}
162 
163  void remove(const std::string& ,
164  const te::da::ObjectIdSet* ){}
165 
166  void update(const std::string& ,
167  te::da::DataSet* ,
168  const std::vector<std::size_t>& ,
169  const te::da::ObjectIdSet* ,
170  const std::map<std::string, std::string>& ,
171  std::size_t ) {}
172 
173  std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
174  const std::string& propertyName);
175 
176  std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
177  std::size_t propertyPos);
178 
179  void begin() {}
180 
181  void commit() {}
182 
183  void rollBack() {}
184 
185  bool isInTransaction() const { return false; }
186 
187  void execute(const te::da::Query& /*command*/) {}
188 
189  void execute(const std::string& /*command*/) {}
190 
191  std::auto_ptr<te::da::PreparedQuery> getPrepared(const std::string& /*qName = std::string("")*/) { return std::auto_ptr<te::da::PreparedQuery>(); }
192 
193  std::auto_ptr<te::da::BatchExecutor> getBatchExecutor() { return std::auto_ptr<te::da::BatchExecutor>(); }
194 
195  void cancel() {}
196 
197  boost::int64_t getLastGeneratedId() { return 0; }
198 
199  std::string escape(const std::string& /*value*/) { return std::string(""); }
200 
201  std::auto_ptr<te::da::PrimaryKey> getPrimaryKey(const std::string& )
202  { return std::auto_ptr<te::da::PrimaryKey>(); }
203 
204  bool primaryKeyExists(const std::string&, const std::string& ) { return false; }
205 
206  void addPrimaryKey(const std::string&, te::da::PrimaryKey*) {}
207 
208  void dropPrimaryKey(const std::string&) {}
209 
210  std::auto_ptr<te::da::ForeignKey> getForeignKey(const std::string& , const std::string& ) { return std::auto_ptr<te::da::ForeignKey>(); }
211 
212  std::vector<std::string> getForeignKeyNames(const std::string& ) { return std::vector<std::string>(); }
213 
214  bool foreignKeyExists(const std::string& , const std::string& ) { return false; }
215 
216  void addForeignKey(const std::string& , te::da::ForeignKey*) {}
217 
218  void dropForeignKey(const std::string& , const std::string& ) {}
219 
220  std::auto_ptr<te::da::UniqueKey> getUniqueKey(const std::string& , const std::string& )
221  { return std::auto_ptr<te::da::UniqueKey>(); }
222 
223  std::vector<std::string> getUniqueKeyNames(const std::string& )
224  { return std::vector<std::string>(); }
225 
226  bool uniqueKeyExists(const std::string& , const std::string& ) { return false; }
227 
228  void addUniqueKey(const std::string& , te::da::UniqueKey* ) {}
229 
230  void dropUniqueKey(const std::string& , const std::string& ) {}
231 
232  std::auto_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& , const std::string& )
233  { return std::auto_ptr<te::da::CheckConstraint>(); }
234 
235  std::vector<std::string> getCheckConstraintNames(const std::string& )
236  { return std::vector<std::string>(); }
237 
238  bool checkConstraintExists(const std::string& , const std::string& ) {return false; }
239 
240  void addCheckConstraint(const std::string& , te::da::CheckConstraint* ) {}
241 
242  void dropCheckConstraint(const std::string& , const std::string& ) {}
243 
244  std::auto_ptr<te::da::Index> getIndex(const std::string& , const std::string& )
245  { return std::auto_ptr<te::da::Index>(); }
246 
247  std::vector<std::string> getIndexNames(const std::string& )
248  { return std::vector<std::string>(); }
249 
250  bool indexExists(const std::string& , const std::string& )
251  { return false; }
252 
253  void addIndex(const std::string& , te::da::Index* , const std::map<std::string, std::string>& ) {}
254 
255  void dropIndex(const std::string& , const std::string& ) {}
256 
257  bool sequenceExists(const std::string& )
258  { return false; }
259 
260  std::auto_ptr<te::da::Sequence> getSequence(const std::string& )
261  { return std::auto_ptr<te::da::Sequence>(); }
262 
263  std::vector<std::string> getSequenceNames()
264  { return std::vector<std::string>(); }
265 
267 
268  void dropSequence(const std::string&) {}
269 
270  void optimize(const std::map<std::string, std::string>& ){}
271 
272  te::common::CharEncoding getEncoding();
273 
274  private:
275 
276  boost::filesystem::path m_path;
277  std::auto_ptr<te::da::DataSetType> getType(const std::string& dsfullname);
278  void getDataSetNames(const boost::filesystem::path& path, std::vector<std::string>& dsnames);
279  bool hasDataSets(const boost::filesystem::path& path);
280  size_t getNumberOfDataSets(const boost::filesystem::path& path);
281  std::auto_ptr<te::da::DataSetType> getDataSetType(const boost::filesystem::path& path, const std::string& name, std::string& uri);
282 
283  };
284  } // end namespace gdal
285 } // end namespace te
286 
287 #endif // __TERRALIB_GDAL_INTERNAL_TRANSACTOR_H
288 
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:250
void addUniqueKey(const std::string &, te::da::UniqueKey *)
It adds a unique key constraint to the dataset.
Definition: Transactor.h:228
std::vector< std::string > getUniqueKeyNames(const std::string &)
It gets the unique key names of the given dataset.
Definition: Transactor.h:223
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.h:183
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
void execute(const te::da::Query &)
It executes the specified command using a generic query representation.
Definition: Transactor.h:187
CharEncoding
Supported charsets (character encoding).
bool primaryKeyExists(const std::string &, const std::string &)
It checks if a primary key exists in the dataset.
Definition: Transactor.h:204
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.h:197
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:244
A class that models the description of a dataset.
Definition: DataSetType.h:72
void addSequence(te::da::Sequence *)
It creates a new sequence in the data source.
Definition: Transactor.h:266
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
void dropForeignKey(const std::string &, const std::string &)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.h:218
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:253
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.h:193
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:191
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:127
It describes a sequence (a number generator).
Definition: Sequence.h:56
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:238
A class that describes a check constraint.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.h:185
void addPrimaryKey(const std::string &, te::da::PrimaryKey *)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.h:206
It models a property definition.
Definition: Property.h:59
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:226
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:158
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
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:220
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
std::vector< std::string > getForeignKeyNames(const std::string &)
It gets the foreign key names of the given dataset.
Definition: Transactor.h:212
void begin()
It starts a new transaction.
Definition: Transactor.h:179
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:270
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.h:263
URI C++ Library.
void commit()
It commits the transaction.
Definition: Transactor.h:181
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
void addCheckConstraint(const std::string &, te::da::CheckConstraint *)
It adds a check constraint to the dataset.
Definition: Transactor.h:240
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:210
void dropSequence(const std::string &)
It removes the sequence from the data source.
Definition: Transactor.h:268
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
std::string escape(const std::string &)
It escapes a string for using in commands and queries.
Definition: Transactor.h:199
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
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:260
void dropPrimaryKey(const std::string &)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.h:208
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void renameProperty(const std::string &, const std::string &, const std::string &)
It renames a property of the given dataset.
Definition: Transactor.h:101
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:214
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: Transactor.h:140
void dropUniqueKey(const std::string &, const std::string &)
It removes the unique key constraint from the dataset.
Definition: Transactor.h:230
void addForeignKey(const std::string &, te::da::ForeignKey *)
It adds a foreign key constraint to a dataset.
Definition: Transactor.h:216
bool sequenceExists(const std::string &)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.h:257
void execute(const std::string &)
It executes the specifed command in the data source native language.
Definition: Transactor.h:189
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &)
It retrieves the primary key of the dataset.
Definition: Transactor.h:201
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:232
std::vector< std::string > getIndexNames(const std::string &)
It gets the index names of the given dataset.
Definition: Transactor.h:247
void addProperty(const std::string &, te::dt::Property *)
It adds a new property to the dataset schema.
Definition: Transactor.h:97
void dropIndex(const std::string &, const std::string &)
It removes the index from the dataset schema.
Definition: Transactor.h:255
A Query is independent from the data source language/dialect.
Definition: Query.h:46
It describes an index associated to a DataSetType.
Definition: Index.h:54
boost::filesystem::path m_path
Definition: Transactor.h:276
std::vector< std::string > getCheckConstraintNames(const std::string &)
It gets the check constraint names of the given dataset.
Definition: Transactor.h:235
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.h:195
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:166
Configuration flags for the GDAL Driver of TerraLib.
void dropCheckConstraint(const std::string &, const std::string &)
It removes the check constraint from the dataset.
Definition: Transactor.h:242