All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSourceTransactor.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/dataaccess/datasource/DataSourceTransactor.h
22 
23  \brief A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things into it.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_DATASOURCETRANSACTOR_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_DATASOURCETRANSACTOR_H
28 
29 // TerraLib
30 #include "../../common/Enums.h"
31 #include "../../geometry/Enums.h"
32 #include "../dataset/CheckConstraint.h"
33 #include "../dataset/DataSetType.h"
34 #include "../dataset/DataSet.h"
35 #include "../dataset/ForeignKey.h"
36 #include "../dataset/Index.h"
37 #include "../dataset/PrimaryKey.h"
38 #include "../dataset/Sequence.h"
39 #include "../dataset/UniqueKey.h"
40 #include "../Config.h"
41 #include "BatchExecutor.h"
42 #include "PreparedQuery.h"
43 
44 // STL
45 #include <map>
46 #include <memory>
47 #include <string>
48 #include <vector>
49 
50 // Boost
51 #include <boost/ptr_container/ptr_vector.hpp>
52 #include <boost/cstdint.hpp>
53 #include <boost/noncopyable.hpp>
54 #include <boost/shared_ptr.hpp>
55 
56 
57 namespace te
58 {
59  // Forward declarations
60  namespace dt { class Property; }
61  namespace gm { class Envelope; class Geometry; }
62 
63  namespace da
64  {
65  // Forward declarations
66  class DataSource;
67  class ObjectIdSet;
68  class Query;
69  class Select;
70 
71  /*!
72  \class DataSourceTransactor
73 
74  \brief A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things into it.
75 
76  A transactor can be used to create a transaction, a prepared query or a batch command executor.
77 
78  If you are planning a multi-thread application, it is better not to share
79  the same transactor between threads because its methods are not thread-safe. Instead,
80  use one transactor per thread.
81 
82  \ingroup dataaccess
83 
84  \sa DataSource, DataSet, Query, PreparedQuery, BatchExecutor
85  */
86  class TEDATAACCESSEXPORT DataSourceTransactor : public boost::noncopyable
87  {
88  public:
89 
90  /*! \brief Default constructor that can be called by subclasses. */
92 
93  /*! \brief Virtual destructor. */
94  virtual ~DataSourceTransactor();
95 
96  /*!
97  \brief It returns the parent data source of the transactor.
98  */
99  virtual DataSource* getDataSource() const = 0;
100 
101  /** @name Transaction
102  * Methods for dealing with transactions.
103  */
104  //@{
105 
106  /*!
107  \brief It starts a new transaction.
108 
109  \note Not thread-safe!
110  */
111  virtual void begin() = 0;
112 
113  /*!
114  \brief It commits the transaction.
115 
116  After commiting or rolling back, you can start another transaction.
117 
118  \note Not thread-safe!
119  */
120  virtual void commit() = 0;
121 
122  /*!
123  \brief It aborts the transaction. Any changes will be rolled-back.
124 
125  After commiting or rolling back, you can start another transaction.
126 
127  \note Not thread-safe!
128  */
129  virtual void rollBack() = 0;
130 
131  /*!
132  \brief It returns true if a transaction is in progress, otherwise, it returns false.
133 
134  \return True, if a transaction is in progress, otherwise, false.
135  */
136  virtual bool isInTransaction() const = 0;
137  //@}
138 
139  /** @name DataSet Retrieval
140  * Methods for retrieving data from the data source.
141  */
142  //@{
143 
144  /*!
145  \brief It gets the dataset identified by the given name.
146  A dataset can be connected or disconnected. A connected dataset, after its creation through
147  the data source transactor, continues to depend on the connection given by its associated
148  data source. Differently, a disconnected dataset, after its creation, no more depends of the
149  connection given by the data source, and it continues to live after the connection has been
150  released to the data source.
151 
152  \param name The dataset name.
153  \param accessPolicy Access policy.
154  \param travType The traverse type associated to the returned dataset.
155  \param connected A flag to indicate if the returned dataset is connected or not.
156 
157  \exception Exception It can throw an exception if:
158  <ul>
159  <li>something goes wrong during the data retrieval</li>
160  <li>if the data source driver doesn't support the traversal type</li>
161  </ul>
162 
163  \note Not thread-safe!
164  */
165  virtual std::auto_ptr<DataSet> getDataSet(const std::string& name,
167  bool connected = false,
168  const te::common::AccessPolicy accessPolicy = te::common::RAccess) = 0;
169 
170  /*!
171  \brief It gets the dataset identified by the given name using a spatial filter over the specified property.
172  A dataset can be connected or disconnected. A connected dataset, after its creation through
173  the data source transactor, continues to depend on the connection given by its associated
174  data source. Differently, a disconnected dataset, after its creation, no more depends of the
175  connection given by the data source, and it continues to live after the connection has been
176  released to the data source.
177 
178  \param name The dataset name.
179  \param propertyName The name of the spatial property that will be used to apply the spatial filter.
180  \param e A rectangle to be used as a spatial filter when retrieving datasets.
181  \param r The spatial relation to be used during the filter.
182  \param accessPolicy Access policy.
183  \param travType The traversal type associated to the returned dataset.
184  \param connected A flag to indicate if the returned dataset is connected or not.
185 
186  \exception Exception It can throw an exception if:
187  <ul>
188  <li>something goes wrong during the data retrieval</li>
189  <li>if the data source driver doesn't support the traversal type</li>
190  </ul>
191 
192  \note The envelope coordinates should be in the same coordinate system as the dataset.
193 
194  \note Not thread-safe!
195  */
196  virtual std::auto_ptr<DataSet> getDataSet(const std::string& name,
197  const std::string& propertyName,
198  const te::gm::Envelope* e,
201  bool connected = false,
202  const te::common::AccessPolicy accessPolicy = te::common::RAccess) = 0;
203 
204  /*!
205  \brief It gets the dataset identified by the given name using a spatial filter over the given geometric property.
206  A dataset can be connected or disconnected. A connected dataset, after its creation through
207  the data source transactor, continues to depend on the connection given by its associated
208  data source. Differently, a disconnected dataset, after its creation, no more depends of the
209  connection given by the data source, and it continues to live after the connection has been
210  released to the data source.
211 
212  \param name The dataset name.
213  \param propertyName The name of the spatial property that will be used to apply the spatial filter.
214  \param g The geometry that will be used as a spatial filter when retrieving the dataset.
215  \param r The spatial relation that will be used during the filtering.
216  \param accessPolicy Access policy.
217  \param travType The traverse type associated to the returned dataset.
218  \param connected A flag to indicate if the returned dataset is connected or not.
219 
220  \exception Exception It can throw an exception if:
221  <ul>
222  <li>something goes wrong during the data retrieval</li>
223  <li>if the data source driver doesn't support the traversal type</li>
224  </ul>
225 
226  \note The geometry coordinates should be in the same coordinate system as the dataset.
227 
228  \note Not thread-safe!
229  */
230  virtual std::auto_ptr<DataSet> getDataSet(const std::string& name,
231  const std::string& propertyName,
232  const te::gm::Geometry* g,
235  bool connected = false,
236  const te::common::AccessPolicy accessPolicy = te::common::RAccess) = 0;
237 
238  /*!
239  \brief It gets the dataset identified by the given name using the set of objects identification.
240  A dataset can be connected or disconnected. A connected dataset, after its creation through
241  the data source transactor, continues to depend on the connection given by its associated
242  data source. Differently, a disconnected dataset, after its creation, no more depends of the
243  connection given by the data source, and it continues to live after the connection has been
244  released to the data source.
245 
246  \param name The dataset name of the dataset.
247  \param oids A pointer for the set of objects. Do not pass null, nor an empty set.
248  \param accessPolicy Access policy.
249  \param travType The traverse type associated to the returned dataset.
250  \param connected A flag to indicate if the returned dataset is connected or not.
251 
252  \exception Exception It can throw an exception if:
253  <ul>
254  <li>something goes wrong during data retrieval</li>
255  <li>if the data source driver doesn't support the traversal type</li>
256  </ul>
257  */
258  std::auto_ptr<te::da::DataSet> getDataSet(const std::string& name,
259  const ObjectIdSet* oids,
261  bool connected = false,
262  const te::common::AccessPolicy accessPolicy = te::common::RAccess);
263 
264  /*!
265  \brief It executes a query that may return some data using a generic query.
266  A dataset can be connected or disconnected. A connected dataset, after its creation through
267  the data source transactor, continues to depend on the connection given by its associated
268  data source. Differently, a disconnected dataset, after its creation, no more depends of the
269  connection given by the data source, and it continues to live after the connection has been
270  released to the data source.
271  This method is different of the method that accepts a dataset name and
272  a spatial filter, because it allows the retrieving of only a
273  subset of the attributes, since a query can include a property list.
274 
275  \exception Exception It can throw an exception if:
276  <ul>
277  <li>something goes wrong during the data retrieval</li>
278  <li>if the data source driver doesn't support the traversal type</li>
279  </ul>
280 
281  \param q A valid query object.
282  \param travType The traverse type associated to the returned dataset.
283  \param connected A flag to indicate if the returned dataset is connected or not.
284  \param accessPolicy Access policy.
285 
286  \note Not thread-safe!
287  */
288  virtual std::auto_ptr<DataSet> query(const Select& q,
290  bool connected = false,
291  const te::common::AccessPolicy accessPolicy = te::common::RAccess) = 0;
292 
293  /*!
294  \brief It executes a query that may return some data using the data source native language.
295  A dataset can be connected or disconnected. A connected dataset, after its creation through
296  the data source transactor, continues to depend on the connection given by its associated
297  data source. Differently, a disconnected dataset, after its creation, no more depends of the
298  connection given by the data source, and it continues to live after the connection has been
299  released to the data source.
300 
301  \param query A query string in the data source native language.
302  \param travType The traverse type associated to the returned dataset.
303  \param connected A flag to indicate if the returned dataset is connected or not.
304  \param accessPolicy Access policy.
305 
306  \exception Exception It can throw an exception if:
307  <ul>
308  <li>something goes wrong during the data retrieval</li>
309  <li>if the data source driver doesn't support the traversal type</li>
310  </ul>
311 
312  \note Don't use this method, if you want portability for your application.
313 
314  \note Not thread-safe!
315  */
316  virtual std::auto_ptr<DataSet> query(const std::string& query,
318  bool connected = false,
319  const te::common::AccessPolicy accessPolicy = te::common::RAccess) = 0;
320  //@}
321 
322  /** @name Command Execution Methods
323 
324  * Methods for executing commands against the data source.
325  */
326  //@{
327 
328  /*!
329  \brief It executes the specified command using a generic query representation.
330 
331  \param command A query like: CREATE, DROP, ALTER, INSERT, UPDATE, DELETE.
332 
333  \exception Exception It can throw an exception, if the query cannot be performed.
334 
335  \note Not thread-safe!
336  */
337  virtual void execute(const Query& command) = 0;
338 
339  /*!
340  \brief It executes the specifed command in the data source native language.
341 
342  \param command A query string in the data source native language (like: CREATE, DROP, ALTER, INSERT, UPDATE, DELETE).
343 
344  \exception Exception It can throw an exception, if the query cannot be performed.
345 
346  \note Not thread-safe!
347  */
348  virtual void execute(const std::string& command) = 0;
349  //@}
350 
351  /** @name Fine Grained Transactor Objects
352  * Methods for retrieving fine-grained transactor objects.
353  */
354  //@{
355  /*!
356  \brief It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
357 
358  \param qName The prepared query name.
359 
360  \exception Exception An exception can be thrown if the prepared query cannot be performed.
361 
362  \return A prepared query object owned by the caller.
363  */
364  virtual std::auto_ptr<PreparedQuery> getPrepared(const std::string& qName = std::string("")) = 0;
365 
366  /*!
367  \brief It creates a batch command executor.
368 
369  \exception Exception An exception can be thrown if the batch command executor cannot be performed.
370 
371  \return A batch command executor owned by the caller.
372  */
373  virtual std::auto_ptr<BatchExecutor> getBatchExecutor() = 0;
374  //@}
375 
376  /** @name Auxiliary Commands for Commands and Queries
377  * Auxiliary methods for commands and queries.
378  */
379  //@{
380 
381  /*!
382  \brief It requests that the data source stop the processing of the current command.
383 
384  \note Not thread-safe!
385  */
386  virtual void cancel() = 0;
387 
388  /*!
389  \brief It returns the last id generated by an insertion command.
390 
391  \return The last id generated by an insertion command.
392 
393  \note This is the way to deal with auto-increment values.
394 
395  \note Not thread-safe!
396  */
397  virtual boost::int64_t getLastGeneratedId() = 0;
398 
399  /*!
400  \brief It escapes a string for using in commands and queries.
401 
402  \param value Any string.
403 
404  \return A valid escaped string.
405 
406  \note Not thread-safe!
407  */
408  virtual std::string escape(const std::string& value) = 0;
409 
410  /*!
411  \brief It returns true if the given string is a valid dataset name.
412 
413  \param datasetName A dataset name whose validity will be checked.
414 
415  \return True, if the name is valid according to the data source rules.
416 
417  \note Not thread-safe!
418  */
419  virtual bool isDataSetNameValid(const std::string& datasetName) = 0;
420 
421  /*!
422  \brief It checks if the given property name is valid.
423 
424  \param propertyName A property name whose validity will be checked.
425 
426  \return True, if the name is valid according to the data source rules.
427 
428  \note Not thread-safe!
429  */
430  virtual bool isPropertyNameValid(const std::string& propertyName) = 0;
431  //@}
432 
433  /** @name Dataset Metadata Retrieval
434  * Methods for retrieving metadata about the datasets of the data source.
435  */
436  //@{
437 
438  /*!
439  \brief It It gets the dataset names available in the data source.
440 
441  \return The dataset names available in the data source.
442 
443  \exception Exception An exception can be thrown, if the dataset names could not be retrieved.
444 
445  \note Each dataset in the data source must have a unique name. For example, in a DBMS the name
446  may contain the schema name before the table name separated by a dot notation (".").
447 
448  \note Not thread-safe!
449  */
450  virtual std::vector<std::string> getDataSetNames() = 0;
451 
452  /*!
453  \brief It retrieves the number of data sets available in the data source.
454 
455  \exception Exception An exception can be thrown, if the number of datasets could not be retrieved.
456 
457  \return The number of data sets available in the data source.
458 
459  \note Not thread-safe!
460  */
461  virtual std::size_t getNumberOfDataSets() = 0;
462 
463  /*!
464  \brief It gets information about the given dataset.
465 
466  This method can provide the following information about a dataset:
467  <ul>
468  <li>the list of properties, including: name, data type, size, if the value is required or not, if it is an autoincrement</li>
469  <li>primary key</li>
470  <li>foreign keys</li>
471  <li>unique keys</li>
472  <li>check constraints</li>
473  <li>indexes</li>
474  </ul>
475 
476  \param name The name of the dataset we are looking information for.
477 
478  \exception Exception An exception can be thrown, if the information about the dataset could not be retrieved.
479 
480  \return The dataset schema.
481 
482  \note Not thread-safe!
483  */
484  virtual std::auto_ptr<te::da::DataSetType> getDataSetType(const std::string& name) = 0;
485 
486  /*!
487  \brief It retrieves the properties of the dataset.
488 
489  \param datasetName The dataset name.
490 
491  \exception Exception An exception can be thrown, if the dataset properties could not be retrieved.
492 
493  \return The properties of the dataset.
494 
495  \note Not thread-safe!
496  */
497  virtual boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName) = 0;
498 
499  /*!
500  \brief It retrieves the property with the given name from the dataset.
501 
502  \param datasetName The dataset name.
503  \param propertyName The property name.
504 
505  \exception Exception An exception can be thrown, if the dataset property could not be retrieved.
506 
507  \return The property with the given name from the dataset.
508 
509  \note Not thread-safe!
510  */
511  virtual std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name) = 0;
512 
513  /*!
514  \brief It retrieves the property lying in the given position from the dataset.
515 
516  \param datasetName The dataset name.
517  \param propertyPos The property position.
518 
519  \exception Exception An exception can be thrown, if the property lying in the given position could not be retrieved.
520 
521  \return The property in the given position.
522 
523  \note Not thread-safe!
524  */
525  virtual std::auto_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos) = 0;
526 
527  /*!
528  \brief It gets the property names of the given dataset.
529 
530  \param datasetName The dataset name.
531 
532  \exception Exception An exception can be thrown, if the property names of the dataset could not be retrieved.
533 
534  \return The property names of the dataset.
535 
536  \note Each dataset in the data source must have a unique name. For example, in a DBMS the name
537  may contain the schema name before the table name separated by a dot notation (".").
538 
539  \note Not thread-safe!
540  */
541  virtual std::vector<std::string> getPropertyNames(const std::string& datasetName) = 0;
542 
543  /*!
544  \brief It gets the number of properties of the given dataset.
545 
546  \param datasetName The dataset name.
547 
548  \exception Exception An exception can be thrown, if the number of dataset properties could not be retrieved.
549 
550  \return The number of properties of the given dataset.
551 
552  \note Not thread-safe!
553  */
554  virtual std::size_t getNumberOfProperties(const std::string& datasetName) = 0;
555 
556  /*!
557  \brief It checks if a property with the given name exists in the dataset.
558 
559  \param datasetName The dataset name.
560  \param name The property name.
561 
562  \exception Exception An exception can be thrown, if the existence of the dataset property could not be obtained.
563 
564  \return True, if the property exists in the dataset; otherwise, it returns false.
565 
566  \note Not thread-safe!
567  */
568  virtual bool propertyExists(const std::string& datasetName, const std::string& name) = 0;
569 
570  /*!
571  \brief It adds a new property to the dataset schema.
572 
573  \param datasetName The dataset where the property will be added.
574  \param p The new property to be added.
575 
576  \exception Exception An exception can be thrown, if the property could not be added to the dataset schema.
577 
578  \note Don't delete the given property, because the schema will take the ownership of it.
579  \note Not thread-safe!
580  */
581  virtual void addProperty(const std::string& datasetName, te::dt::Property* p) = 0;
582 
583  /*!
584  \brief It removes a property from the given dataset.
585 
586  \param datasetName The dataset from where the given property will be removed.
587  \param name The property to be removed from the dataset.
588 
589  \exception Exception An exception can be thrown, if the dataset property could not be removed.
590 
591  \note Not thread-safe!
592  */
593  virtual void dropProperty(const std::string& datasetName, const std::string& name) = 0;
594 
595  /*!
596  \brief It renames a property of the given dataset.
597 
598  \param datasetName The dataset containig the property to be renamed.
599  \param propertyName The property to be renamed from the dataset.
600  \param newPropertyName The new property name.
601 
602  \exception Exception An exception can be thrown, if the dataset property could not be renamed.
603 
604  \note Not thread-safe!
605  */
606  virtual void renameProperty(const std::string& datasetName,
607  const std::string& propertyName,
608  const std::string& newPropertyName) = 0;
609 
610  /*!
611  \brief It retrieves the primary key of the dataset.
612 
613  \param datasetName The dataset name.
614 
615  \exception Exception An exception can be thrown, if the primary key could not be retrieved.
616 
617  \return If a primary key exists in the dataset, it is returned; otherwise, a NULL is returned.
618 
619  \note Not thread-safe!
620  */
621  virtual std::auto_ptr<te::da::PrimaryKey> getPrimaryKey(const std::string& datasetName) = 0;
622 
623  /*!
624  \brief It checks if a primary key exists in the dataset.
625 
626  \param datasetName The dataset name.
627  \param name The primary key name.
628 
629  \exception Exception An exception can be thrown, if the existence of the primary key could not be determined.
630 
631  \return True, if a primary key exists in the dataset; otherwise, it returns false.
632 
633  \note Not thread-safe!
634  */
635  virtual bool primaryKeyExists(const std::string& datasetName, const std::string& name) = 0;
636 
637  /*!
638  \brief It adds a primary key constraint to the dataset schema.
639 
640  \param datasetName The name of the dataset where the primary key will be added.
641  \param pk The primary key constraint.
642 
643  \exception Exception An exception can be thrown, if the primary key could not be added to the dataset schema.
644 
645  \note Don't delete the given primary key, because the schema will take the ownership of it.
646  \note Not thread-safe!
647  */
648  virtual void addPrimaryKey(const std::string& datasetName, PrimaryKey* pk) = 0;
649 
650  /*!
651  \brief It removes the primary key constraint from the dataset schema.
652 
653  \param datasetName The dataset from where the primary key will be removed.
654 
655  \exception Exception An exception can be thrown, if the primary key could not be dropped from the dataset schema.
656 
657  \note Not thread-safe!
658  */
659  virtual void dropPrimaryKey(const std::string& datasetName) = 0;
660 
661  /*!
662  \brief It retrieves the foreign key from the given dataset.
663 
664  \param datasetName The dataset name.
665  \param name The foreign key name.
666 
667  \exception Exception An exception can be thrown, if the foreign key could not be retrieved.
668 
669  \return If the foreign key exists in the dataset, it is returned; otherwise, a NULL is returned.
670 
671  \note Not thread-safe!
672  */
673  virtual std::auto_ptr<ForeignKey> getForeignKey(const std::string& datasetName, const std::string& name) = 0;
674 
675  /*!
676  \brief It gets the foreign key names of the given dataset.
677 
678  \param datasetName The dataset name.
679 
680  \exception Exception An exception can be thrown, if the foreign key names could not be retrieved.
681 
682  \return The foreign key names of the given dataset.
683 
684  \note Not thread-safe!
685  */
686  virtual std::vector<std::string> getForeignKeyNames(const std::string& datasetName) = 0;
687 
688  /*!
689  \brief It checks if a foreign key with the given name exists in the data source.
690 
691  \param datasetName The dataset name.
692  \param name The foreign key name.
693 
694  \exception Exception An exception can be thrown, if the existence of the foreign key could not be obtained.
695 
696  \return True, if the foreign key exists in the dataset; otherwise, it returns false.
697  */
698  virtual bool foreignKeyExists(const std::string& datasetName, const std::string& name) = 0;
699 
700  /*!
701  \brief It adds a foreign key constraint to a dataset.
702 
703  \param datasetName The dataset where the foreign key constraint will be added.
704  \param fk The foreign key constraint.
705 
706  \exception Exception An exception can be thrown, if the foreign key could not be added to the dataset schema.
707 
708  \note Don't delete the given foreign key, because the schema will take the ownership of it.
709  \note Not thread-safe!
710  */
711  virtual void addForeignKey(const std::string& datasetName, ForeignKey* fk) = 0;
712 
713  /*!
714  \brief It removes the foreign key constraint from the dataset schema.
715 
716  \param datasetName The dataset where the foreign key will be removed.
717  \param fkName The foreign key to be removed.
718 
719  \exception Exception An exception can be thrown, if the foreign key could not be removed from the dataset schema.
720 
721  \note Not thread-safe!
722  */
723  virtual void dropForeignKey(const std::string& datasetName, const std::string& fkName) = 0;
724 
725  /*!
726  \brief It gets the unique key in the dataset with the given name.
727 
728  \param datasetName The dataset name.
729  \param name The unique key name.
730 
731  \exception Exception An exception can be thrown, if the unique key could not be retrieved.
732 
733  \return The unique key with the given name in the dataset.
734 
735  \note Not thread-safe!
736  */
737  virtual std::auto_ptr<te::da::UniqueKey> getUniqueKey(const std::string& datasetName, const std::string& name) = 0;
738 
739  /*!
740  \brief It gets the unique key names of the given dataset.
741 
742  \param datasetName The dataset name.
743 
744  \exception Exception An exception can be thrown, if the unique key names could not be obtained.
745 
746  \return The unique key names of the dataset.
747 
748  \note Not thread-safe!
749  */
750  virtual std::vector<std::string> getUniqueKeyNames(const std::string& datasetName) = 0;
751 
752  /*!
753  \brief It checks if a unique key with the given name exists in the dataset.
754 
755  \param datasetName The dataset name.
756  \param name The unique key name.
757 
758  \exception Exception An exception can be thrown, if the existence of the unique key could not be determined.
759 
760  \return True, if the unique key exists in the data source; otherwise, it returns false.
761 
762  \note Not thread-safe!
763  */
764  virtual bool uniqueKeyExists(const std::string& datasetName, const std::string& name) = 0;
765 
766  /*!
767  \brief It adds a unique key constraint to the dataset.
768 
769  \param datasetName The dataset where the unique key will be added.
770  \param uk The unique key constraint.
771 
772  \exception Exception An exception can be thrown, if the unique key could not be added to the dataset schema.
773 
774  \note Don't delete the given unique key, because the schema will take the ownership of it.
775  \note Not thread-safe!
776  */
777  virtual void addUniqueKey(const std::string& datasetName, UniqueKey* uk) = 0;
778 
779  /*!
780  \brief It removes the unique key constraint from the dataset.
781 
782  \param datasetName The dataset from where the unique key will be removed.
783  \param name The unique key constraint name.
784 
785  \exception Exception An exception can be thrown, if the unique key could not be removed from the dataset schema.
786 
787  \note Not thread-safe!
788  */
789  virtual void dropUniqueKey(const std::string& datasetName, const std::string& name) = 0;
790 
791  /*!
792  \brief It gets the check constraint of the dataset with the given name.
793 
794  \param datasetName The dataset name.
795  \param name The check constraint name.
796 
797  \exception Exception An exception can be thrown, if the check constraint could not be retrieved.
798 
799  \return The check constraint with the given name.
800 
801  \note Not thread-safe!
802  */
803  virtual std::auto_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& datasetName, const std::string& name) = 0;
804 
805  /*!
806  \brief It gets the check constraint names of the given dataset.
807 
808  \param datasetName The dataset name.
809 
810  \exception Exception An exception can be thrown, if the check constraint names could not be retrieved.
811 
812  \return The check constraint names of the dataset.
813 
814  \note Not thread-safe!
815  */
816  virtual std::vector<std::string> getCheckConstraintNames(const std::string& datasetName) = 0;
817 
818  /*!
819  \brief It checks if a check-constraint with the given name exists in the data source.
820 
821  \param datasetName The dataset name.
822  \param name The check-constraint name.
823 
824  \exception Exception An exception can be thrown, if the existence of the check constraint could not be determined.
825 
826  \return True, if the check-constraint exists in the dataset; otherwise, it returns false.
827 
828  \note Not thread-safe!
829  */
830  virtual bool checkConstraintExists(const std::string& datasetName, const std::string& name) = 0;
831 
832  /*!
833  \brief It adds a check constraint to the dataset.
834 
835  \param datasetName The dataset where the constraint will be added.
836  \param cc The check constraint.
837 
838  \exception Exception An exception can be thrown, if the check constraint could not be added to the dataset schema.
839 
840  \note Don't delete the given check constraint, because the schema will take the ownership of it.
841  \note Not thread-safe!
842  */
843  virtual void addCheckConstraint(const std::string& datasetName, CheckConstraint* cc) = 0;
844 
845  /*!
846  \brief It removes the check constraint from the dataset.
847 
848  \param datasetName The dataset from where the check constraint will be removed.
849  \param name The check constraint to be removed.
850 
851  \exception Exception An exception can be thrown, if the check constraint could not be removed from the dataset schema.
852 
853  \note Not thread-safe!
854  */
855  virtual void dropCheckConstraint(const std::string& datasetName, const std::string& name) = 0;
856 
857  /*!
858  \brief It gets the index with the given name from the dataset.
859 
860  \param datasetName The dataset name.
861  \param name The index name.
862 
863  \exception Exception An exception can be thrown, if the index could not be retrieved.
864 
865  \return The index with the given name.
866 
867  \note Not thread-safe!
868  */
869  virtual std::auto_ptr<te::da::Index> getIndex(const std::string& datasetName, const std::string& name) = 0;
870 
871  /*!
872  \brief It gets the index names of the given dataset.
873 
874  \param datasetName The dataset name.
875 
876  \exception Exception An exception can be thrown, if the index names could not be retrieved.
877 
878  \return The index names of the given dataset.
879 
880  \note Not thread-safe!
881  */
882  virtual std::vector<std::string> getIndexNames(const std::string& datasetName) = 0;
883 
884  /*!
885  \brief It checks if an index with the given name exists in the dataset.
886 
887  \param datasetName The dataset name.
888  \param name The index name.
889 
890  \exception Exception An exception can be thrown, if the index existence could not be determined.
891 
892  \return True, if the index exists in the dataset; otherwise, it returns false.
893 
894  \note Not thread-safe!
895  */
896  virtual bool indexExists(const std::string& datasetName, const std::string& name) = 0;
897 
898  /*!
899  \brief It adds an index to the dataset.
900 
901  \param datasetName The dataset where the index will be added.
902  \param idx The index to be added.
903  \param options A list of optional modifiers (driver specific).
904 
905  \exception Exception An exception can be thrown, if the index could not be added to the dataset schema.
906 
907  \note Don't delete the given index, because the schema will take the ownership of it.
908  \note Not thread-safe!
909  */
910  virtual void addIndex(const std::string& datasetName, Index* idx,
911  const std::map<std::string, std::string>& options) = 0;
912 
913  /*!
914  \brief It removes the index from the dataset schema.
915 
916  \param datasetName The dataset where the index will be removed.
917  \param idxName The index to be removed.
918 
919  \exception Exception An exception can be thrown, if the index could not be removed from the dataset schema.
920 
921  \note Not thread-safe!
922  */
923  virtual void dropIndex(const std::string& datasetName, const std::string& idxName) = 0;
924 
925  /*!
926  \brief It gets the sequence with the given name in the data source.
927 
928  \param name The sequence name.
929 
930  \exception Exception An exception can be thrown, if the sequence could not be retrieved from the data source.
931 
932  \return The sequence with the given name.
933 
934  \note Not thread-safe!
935  */
936  virtual std::auto_ptr<Sequence> getSequence(const std::string& name) = 0;
937 
938  /*!
939  \brief It gets the sequence names available in the data source.
940 
941  \note Each sequence in the data source must have a unique name. For example, in a DBMS the name
942  may contain the schema name before the sequence name separated by a dot notation (".").
943 
944  \exception Exception An exception can be thrown, if the sequence names could not be retrieved.
945 
946  \return The sequence names of the data source.
947 
948  \note Not thread-safe!
949  */
950  virtual std::vector<std::string> getSequenceNames() = 0;
951 
952  /*!
953  \brief It checks if a sequence with the given name exists in the data source.
954 
955  \param name The sequence name.
956 
957  \exception Exception An exception can be thrown, if the index existence could not be determined.
958 
959  \return True, if the sequence exists in the data source; otherwise, it returns false.
960 
961  \note Not thread-safe!
962  */
963  virtual bool sequenceExists(const std::string& name) = 0;
964 
965  /*!
966  \brief It creates a new sequence in the data source.
967 
968  \exception Exception An exception can be thrown, if the sequence could not be added to the data source.
969 
970  \note Don't delete the given sequence, because the schema will take the ownership of it.
971  \note Not thread-safe!
972  */
973  virtual void addSequence(Sequence* sequence) = 0;
974 
975  /*!
976  \brief It removes the sequence from the data source.
977 
978  \param name The sequence that will be removed.
979 
980  \exception Exception An exception can be thrown, if the sequence could not be removed from the data source.
981 
982  \note Not thread-safe!
983  */
984  virtual void dropSequence(const std::string& name) = 0;
985 
986  /*!
987  \brief It retrieves the bounding rectangle of the spatial property for the given dataset.
988 
989  \param datasetName The dataset name.
990  \param propertyName The spatial property name.
991 
992  \exception Exception An exception can be thrown, if the extent of the geometry property could not be retrieved.
993 
994  \return The spatial property bounding rectangle, or NULL, if none can be retrieved.
995 
996  \note Not thread-safe!
997  */
998  virtual std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
999  const std::string& propertyName) = 0;
1000 
1001  /*!
1002  \brief It retrieves the bounding rectangle for the spatial property lying in the given position in the dataset.
1003 
1004  \param datasetName The dataset name.
1005  \param propertyPos The spatial property position.
1006 
1007  \exception Exception An exception can be thrown, if the extent of the geometry property lying in the given position could not be retrieved.
1008 
1009  \return The spatial property bounding rectangle, or NULL if none can be retrieved.
1010 
1011  \note Not thread-safe!
1012  */
1013  virtual std::auto_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
1014  std::size_t propertyPos) = 0;
1015 
1016  /*!
1017  \brief It retrieves the number of items of the given dataset.
1018 
1019  \param datasetName The dataset name.
1020 
1021  \exception Exception An exception can be thrown, if the number of items of the dataset could not be retrieved.
1022 
1023  \return The number of items of the given dataset.
1024 
1025  \note Not thread-safe!
1026  */
1027  virtual std::size_t getNumberOfItems(const std::string& datasetName) = 0;
1028 
1029  /*!
1030  \brief It checks if the data source has any dataset.
1031 
1032  \exception Exception An exception can be thrown, if it is not possible to check if the data source has datasets .
1033 
1034  \return True, if the data source has datasets; otherwise, it returns false.
1035 
1036  \note Not thread-safe!
1037  */
1038  virtual bool hasDataSets() = 0;
1039 
1040  /*!
1041  \brief It checks if a dataset with the given name exists in the data source.
1042 
1043  \param name The dataset name.
1044 
1045  \exception Exception An exception can be thrown, if the existence of a dataset in the data source could not be determined.
1046 
1047  \return True, if the dataset exists in the data source; otherwise, it returns false.
1048 
1049  \note Not thread-safe!
1050  */
1051  virtual bool dataSetExists(const std::string& name) = 0;
1052  //@}
1053 
1054  /** @name Dataset Schema Persistence Methods
1055  * Methods for dealing with datasource and dataset schema changes.
1056  */
1057  //@{
1058 
1059  /*!
1060  \brief It creates the dataset schema definition in the target data source.
1061 
1062  If a dataset schema with the same name already exists in the target data source,
1063  this may throw an exception.
1064 
1065  After calling this method, the dataset schema may be updated.
1066 
1067  \param dt The dataset schema to be created. It may be changed during the operation.
1068  \param options A list of optional modifiers (driver specific).
1069 
1070  \pre The schema of a related dataset in a foreign key must be already in the data source.
1071 
1072  \post In some data sources, this method may output implicit indexes, sequences or constraints.
1073  The method, if necessary, will create and adjust the dataset schema.
1074 
1075  \post The caller of this method will take the ownership of the given schema.
1076 
1077  \note If you want to create a new schema based on an already existing one,
1078  you must create a fresh copy of the DataSetType with the clone() method.
1079 
1080  \note Not thread-safe!
1081  */
1082  virtual void createDataSet(DataSetType* dt, const std::map<std::string, std::string>& options) = 0;
1083 
1084  /*!
1085  \brief It clones the dataset in the data source.
1086 
1087  \param name The dataset to be cloned.
1088  \param cloneName The name of the cloned dataset.
1089  \param options A list of optional modifiers. It is driver specific.
1090 
1091  \exception Exception An exception can be thrown, if the dataset schema could not be cloned.
1092  \note Not thread-safe!
1093  */
1094  virtual void cloneDataSet(const std::string& name,
1095  const std::string& cloneName,
1096  const std::map<std::string, std::string>& options) = 0;
1097 
1098  /*!
1099  \brief It removes the dataset schema from the data source.
1100 
1101  \param name The dataset name whose schema will be removed from the data source.
1102 
1103  \exception Exception An exception can be thrown, if the dataset could not be removed from the data source.
1104 
1105  \note Not thread-safe!
1106  */
1107  virtual void dropDataSet(const std::string& name) = 0;
1108 
1109  /*!
1110  \brief It renames a dataset.
1111 
1112  \param name The name of the dataset to be renamed.
1113  \param newName The new dataset name.
1114 
1115  \exception Exception An exception can be thrown, if the dataset could not be renamed.
1116 
1117  \note Not thread-safe!
1118  */
1119  virtual void renameDataSet(const std::string& name, const std::string& newName) = 0;
1120  //@}
1121 
1122  /** @name Dataset Persistence Methods
1123  * Methods for dealing with the persistence of data in a data source.
1124  */
1125  //@{
1126 
1127  /*!
1128  \brief It adds data items to the dataset in the data source.
1129 
1130  \param datasetName The target dataset name.
1131  \param d The data items to be added to the dataset.
1132  \param options A list of optional modifiers (driver specific).
1133  \param limit The number of items to be used from the input dataset. If set to 0 (default), all items are used.
1134 
1135  \exception Exception An exception can be thrown, if the input dataset items could not be added to the given dataset.
1136 
1137  \note The dataset reading will start in the current position.
1138  So, keep in mind that it is the caller responsability
1139  to inform the right position(and a valid one) in the dataset 'd', to start the inserting process.
1140 
1141  \note Not thread-safe!
1142  */
1143  virtual void add(const std::string& datasetName,
1144  DataSet* d,
1145  const std::map<std::string, std::string>& options,
1146  std::size_t limit = 0) = 0;
1147 
1148  /*!
1149  \brief It removes all the informed items from the dataset.
1150 
1151  It removes all the data items from a dataset which are identified by
1152  a set of object identifiers. If this set is not informed, all items will be removed.
1153 
1154  \param datasetName The dataset name.
1155  \param oids A list of object identifiers used to remove data from the datasource, or NULL for all.
1156 
1157  \exception Exception An exception can be thrown, if the data items could not be removed.
1158 
1159  \note Not thread-safe!
1160  */
1161  virtual void remove(const std::string& datasetName, const ObjectIdSet* oids = 0) = 0;
1162 
1163  /*!
1164  \brief It updates the contents of a dataset for the set of data items.
1165 
1166  \param datasetName The target dataset name.
1167  \param dataset The list of data items to be updated.
1168  \param properties The list of properties of the dataset to be updated.
1169  \param oids The list of objects to be updated.
1170  \param options A list of optional modifiers. It is driver specific.
1171  \param limit The number of items to be used from the input dataset. If set to 0 (default) all items are used.
1172 
1173  \exception Exception An exception can be thrown, if the dataset could not be updated.
1174 
1175  \note The dataset reading will start in the
1176  current position. So, keep in mind that it is the caller responsability
1177  to inform the right position(and a valid one) for the dataset 'd', to start the updating process.
1178 
1179  \note Not thread-safe!
1180  */
1181  virtual void update(const std::string& datasetName,
1182  DataSet* dataset,
1183  const std::vector<std::size_t>& properties,
1184  const ObjectIdSet* oids,
1185  const std::map<std::string, std::string>& options,
1186  std::size_t limit = 0) = 0;
1187 
1188  /*!
1189  \brief For some data access drivers, this method will perform some operations to optimize the data storage.
1190 
1191  This is can be a typical maintenance command in database systems (like vacuum).
1192 
1193  \param opInfo Any information needed by the underlying driver in order to fine tune the optimization.
1194 
1195  \exception Exception It may throw an exception if something goes wrong.
1196 
1197  \note Not thread-safe!
1198 
1199  \note For some systems you must assure that no other thread are executing commands against the data source.
1200 
1201  \note For some drivers, this method has no effect.
1202  */
1203  virtual void optimize(const std::map<std::string, std::string>& opInfo) = 0;
1204  //@}
1205  };
1206 
1207  typedef boost::shared_ptr<DataSourceTransactor> DataSourceTransactorPtr;
1208 
1209  } // end namespace da
1210 } // end namespace te
1211 
1212 #endif // __TERRALIB_DATAACCESS_INTERNAL_DATASOURCETRANSACTOR_H
boost::shared_ptr< DataSourceTransactor > DataSourceTransactorPtr
It describes an index associated to a DataSetType.
Definition: Index.h:54
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
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
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
A class that models an object that submits commands in batch to the data source.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:135
A class that models a prepared query.
A Query is independent from the data source language/dialect.
Definition: Query.h:46
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
A class that models the description of a dataset.
Definition: DataSetType.h:72
It models a property definition.
Definition: Property.h:59
A class that describes a check constraint.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
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...