DataSourceTransactor.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/sqlite/DataSourceTransactor.h
22 
23  \brief An implementation of DataSourceTransactor class for the TerraLib SQLite Data Access Driver.
24 */
25 
26 #ifndef __TERRALIB_SQLITE_INTERNAL_DATASOURCETRANSACTOR_H
27 #define __TERRALIB_SQLITE_INTERNAL_DATASOURCETRANSACTOR_H
28 
29 // TerraLib
30 #include "../dataaccess/datasource/DataSourceTransactor.h"
31 
32 extern "C"
33 {
34  struct sqlite3;
35  typedef struct sqlite3 sqlite3;
36 }
37 
38 namespace te
39 {
40  namespace sqlite
41  {
42  class DataSource;
43 
45  {
46  public:
47 
49 
51 
53 
54  void begin();
55 
56  void commit();
57 
58  void rollBack();
59 
60  bool isInTransaction() const;
61 
62  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
64  bool connected = false,
65  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
66 
67  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
68  const std::string& propertyName,
69  const te::gm::Envelope* e,
72  bool connected = false,
73  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
74 
75  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
76  const std::string& propertyName,
77  const te::gm::Geometry* g,
80  bool connected = false,
81  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
82 
83  std::auto_ptr<te::da::DataSet> query(const te::da::Select& q,
85  bool connected = false,
86  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
87 
88  std::auto_ptr<te::da::DataSet> query(const std::string& query,
90  bool connected = false,
91  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
92 
93  void execute(const te::da::Query& command);
94 
95  void execute(const std::string& command);
96 
97  std::auto_ptr<te::da::PreparedQuery> getPrepared(const std::string& qName = std::string(""));
98 
99  std::auto_ptr<te::da::BatchExecutor> getBatchExecutor();
100 
101  void cancel();
102 
103  boost::int64_t getLastGeneratedId();
104 
105  std::string escape(const std::string& value);
106 
107  bool isDataSetNameValid(const std::string& datasetName);
108 
109  bool isPropertyNameValid(const std::string& propertyName);
110 
111  std::vector<std::string> getDataSetNames();
112 
113  std::size_t getNumberOfDataSets();
114 
115  std::auto_ptr<te::da::DataSetType> getDataSetType(const std::string& name);
116 
117  boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName);
118 
119  std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
120 
121  std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos);
122 
123  std::vector<std::string> getPropertyNames(const std::string& datasetName);
124 
125  std::size_t getNumberOfProperties(const std::string& datasetName);
126 
127  bool propertyExists(const std::string& datasetName, const std::string& name);
128 
129  void addProperty(const std::string& datasetName, te::dt::Property* p);
130 
131  void dropProperty(const std::string& datasetName, const std::string& name);
132 
133  void renameProperty(const std::string& datasetName,
134  const std::string& propertyName,
135  const std::string& newPropertyName);
136 
137  std::auto_ptr<te::da::PrimaryKey> getPrimaryKey(const std::string& datasetName);
138 
139  bool primaryKeyExists(const std::string& datasetName, const std::string& name);
140 
141  void addPrimaryKey(const std::string& datasetName, te::da::PrimaryKey* pk);
142 
143  void dropPrimaryKey(const std::string& datasetName);
144 
145  std::auto_ptr<te::da::ForeignKey> getForeignKey(const std::string& datasetName, const std::string& name);
146 
147  std::vector<std::string> getForeignKeyNames(const std::string& datasetName);
148 
149  bool foreignKeyExists(const std::string& datasetName, const std::string& name);
150 
151  void addForeignKey(const std::string& datasetName, te::da::ForeignKey* fk);
152 
153  void dropForeignKey(const std::string& datasetName, const std::string& fkName);
154 
155  std::auto_ptr<te::da::UniqueKey> getUniqueKey(const std::string& datasetName, const std::string& name);
156 
157  std::vector<std::string> getUniqueKeyNames(const std::string& datasetName);
158 
159  bool uniqueKeyExists(const std::string& datasetName, const std::string& name);
160 
161  void addUniqueKey(const std::string& datasetName, te::da::UniqueKey* uk);
162 
163  void dropUniqueKey(const std::string& datasetName, const std::string& name);
164 
165  std::auto_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& datasetName, const std::string& name);
166 
167  std::vector<std::string> getCheckConstraintNames(const std::string& datasetName);
168 
169  bool checkConstraintExists(const std::string& datasetName, const std::string& name);
170 
171  void addCheckConstraint(const std::string& datasetName, te::da::CheckConstraint* cc);
172 
173  void dropCheckConstraint(const std::string& datasetName, const std::string& name);
174 
175  std::auto_ptr<te::da::Index> getIndex(const std::string& datasetName, const std::string& name);
176 
177  std::vector<std::string> getIndexNames(const std::string& datasetName);
178 
179  bool indexExists(const std::string& datasetName, const std::string& name);
180 
181  void addIndex(const std::string& datasetName,
182  te::da::Index* idx,
183  const std::map<std::string, std::string>& options);
184 
185  void dropIndex(const std::string& datasetName, const std::string& idxName);
186 
187  std::auto_ptr<te::da::Sequence> getSequence(const std::string& name);
188 
189  std::vector<std::string> getSequenceNames();
190 
191  bool sequenceExists(const std::string& name);
192 
193  void addSequence(te::da::Sequence* sequence);
194 
195  void dropSequence(const std::string& name);
196 
197  std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
198  const std::string& propertyName);
199 
200  std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
201  std::size_t propertyPos);
202 
203  std::size_t getNumberOfItems(const std::string& datasetName);
204 
205  bool hasDataSets();
206 
207  bool dataSetExists(const std::string& name);
208 
209  void createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& options);
210 
211  void cloneDataSet(const std::string& name,
212  const std::string& cloneName,
213  const std::map<std::string, std::string>& options);
214 
215  void dropDataSet(const std::string& name);
216 
217  void renameDataSet(const std::string& name, const std::string& newName);
218 
219  void add(const std::string& datasetName,
220  te::da::DataSet* d,
221  const std::map<std::string, std::string>& options,
222  std::size_t limit = 0);
223 
224  void remove(const std::string& datasetName, const te::da::ObjectIdSet* oids = 0);
225 
226  void update(const std::string& datasetName,
227  te::da::DataSet* dataset,
228  const std::vector<std::size_t>& properties,
229  const te::da::ObjectIdSet* oids,
230  const std::map<std::string, std::string>& options,
231  std::size_t limit = 0);
232 
233  void optimize(const std::map<std::string, std::string>& opInfo);
234 
235  sqlite3* getDB() const;
236 
237  private:
238 
239  class Impl;
240 
241  Impl* m_pImpl;
242  };
243  }
244 }
245 
246 #endif // __TERRALIB_SQLITE_INTERNAL_DATASOURCETRANSACTOR_H
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
struct sqlite3 sqlite3
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
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.
~DataSourceTransactor()
Virtual destructor.
DataSourceTransactor()
Default constructor that can be called by subclasses.
A class that models the description of a dataset.
Definition: DataSetType.h:72
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
std::auto_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. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
std::auto_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &datasetName, const std::string &name)
It gets the check constraint of the dataset with the given name.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:127
void addIndex(const std::string &datasetName, te::da::Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
It describes a sequence (a number generator).
Definition: Sequence.h:56
bool foreignKeyExists(const std::string &datasetName, const std::string &name)
It checks if a foreign key with the given name exists in the data source.
void dropSequence(const std::string &name)
It removes the sequence from the data source.
A class that describes a check constraint.
std::auto_ptr< te::da::UniqueKey > getUniqueKey(const std::string &datasetName, const std::string &name)
It gets the unique key in the dataset with the given name.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
std::auto_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.
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
It models a property definition.
Definition: Property.h:59
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
void begin()
It starts a new transaction.
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
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.
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
bool checkConstraintExists(const std::string &datasetName, const std::string &name)
It checks if a check-constraint with the given name exists in the data source.
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
URI C++ Library.
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
std::auto_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
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.
bool hasDataSets()
It checks if the data source has any dataset.
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
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...
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
std::auto_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...
std::auto_ptr< te::da::PreparedQuery > getPrepared(const std::string &qName=std::string(""))
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
void commit()
It commits the transaction.
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::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
void cancel()
It requests that the data source stop the processing of the current command.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
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::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.