Loading...
Searching...
No Matches
DataSource.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/dataaccess/datasource/DataSource.h
22
23 \brief An abstract class for data providers like a DBMS, Web Services or a regular file.
24*/
25
26#ifndef __TERRALIB_DATAACCESS_DATASOURCE_INTERNAL_DATASOURCE_H
27#define __TERRALIB_DATAACCESS_DATASOURCE_INTERNAL_DATASOURCE_H
28
29// TerraLib
30#include "../../common/Enums.h"
31#include "../../core/uri/URI.h"
32#include "../../geometry/Enums.h"
33#include "../dataset/CheckConstraint.h"
34#include "../dataset/DataSet.h"
35#include "../dataset/DataSetType.h"
36#include "../dataset/ForeignKey.h"
37#include "../dataset/Index.h"
38#include "../dataset/PrimaryKey.h"
39#include "../dataset/Sequence.h"
40#include "../dataset/UniqueKey.h"
41#include "../Config.h"
42
43// STL
44#include <map>
45#include <memory>
46#include <string>
47#include <vector>
48#include <set>
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
56namespace te
57{
58 namespace dt
59 {
60 class Property;
61 }
62
63 namespace gm
64 {
65 class Envelope;
66 class Geometry;
67 }
68
69 namespace da
70 {
71 class DataSetTypeCapabilities;
72 class DataSourceCapabilities;
73 class DataSourceTransactor;
74 class ObjectIdSet;
75 class Query;
76 class Select;
77 class SQLDialect;
78 class CheckConstraint;
79 class ForeignKey;
80 class Index;
81 class PrimaryKey;
82 class Sequence;
83 class UniqueKey;
84
85 /*!
86 \class DataSource
87
88 \brief An abstract class for data providers like a DBMS, Web Services or a regular file.
89
90 A data source is the fundamental class of the data access module and
91 it may represent a data repository. Among other things, a repository can be:
92 <ul>
93 <li>a PostgreSQL database</li>
94 <li>an Oracle database</li>
95 <li>an OGC Web Feature Service</li>
96 <li>a directory of ESRI shape-files</li>
97 <li>a data stream</li>
98 <li>
99
100 A data source can be used to access data in a repository
101 and it requires a driver implementation that must register a
102 concrete factory for building data source objects
103 of the type of the driver (DataSourceFactory).
104
105 Each data source is characterized by a set of parameters that can be used
106 to set up an access channel to its underlying repository. This information
107 is referred as the data source connection information.
108
109 A data source exposes the data contained in it as a collection of datasets.
110 The information about the data stored in a data source may be retrieved.
111
112 Besides the descriptive information about the underlying data repository,
113 each data source also provides information about their capabilities.
114
115 \ingroup dataaccess
116
117 \sa DataSourceManager, DataSourceFactory, DataSet, DataSetType
118 */
119 class TEDATAACCESSEXPORT DataSource : public boost::noncopyable
120 {
121 public:
122
123 DataSource(const std::string& connInfo);
124
125 /*! \brief Default constructor that can be called by subclasses. */
127
128 //DataSource(te::core::URI uri);
129
130 /*! \brief Virtual destructor. */
131 virtual ~DataSource();
132
133 /*!
134 \brief An identification value for the data source.
135
136 \return The data source identification.
137 */
138 const std::string& getId() const;
139
140 /*!
141 \brief It sets the data source identification.
142
143 \param id An identification value.
144 */
145 void setId(const std::string& id);
146
147 /*!
148 \brief An Uniform Resource Identifier used to describe the datasource connection.
149
150 \return A reference to the URI of the datasource.
151 */
153
154 /** @name Data Source Basic Methods
155 * Basic Methods for operating a data source.
156 */
157 //@{
158
159 /*!
160 \brief It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
161
162 \return The data source type name. Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
163
164 \note Each data source driver must have a unique name.
165
166 \note Thread-safe!
167 */
168 virtual std::string getType() const = 0;
169
170 /*!
171 \brief It returns the set of parameters used to set up the access channel to the underlying repository.
172
173 This is the connection information used by a data source in order to enter in an operational mode,
174 when the open method is called.
175
176 The key-value-pairs (kvp) may contain information about: maximum number of accepted connections,
177 user name and password required for establishing a connection, the url of a service, or any other
178 information needed by the data source to operate. This information is dependent on the data source
179 driver, so check the driver documentation for any additional information about the kvp.
180
181 \return An associative container (key-value-pair) with information about the data source.
182
183 \note Thread-safe!
184 */
185 //virtual const te::core::URI& getConnectionInfo() const = 0;
186
187 /*!
188 \brief It sets the connection information to be used when connecting to the data source.
189
190 \param connInfo The connection information.
191 */
192 //virtual void setConnectionInfo(const std::string& connInfo) = 0;
193
194 /*!
195 \brief It returns an object that can execute transactions in the context of a data source.
196
197 Use this method to get an object that allows to retrieve a dataset, to insert or update data,
198 or to modify dataset types(schemas). You don't need to cache this kind of object because each
199 driver in TerraLib already keeps a connection pooling. So, as soon as you finish using
200 the transactor, destroy it.
201
202 \return A pointer to an object that can execute transactions in the context of a data source.
203
204 \exception Exception An exception can be thrown, if it is not possible to get a transactor;
205 for example, if there is no available connection.
206
207 \note Thread-safe!
208 */
209 virtual std::unique_ptr<DataSourceTransactor> getTransactor() = 0;
210
211 /*!
212 \brief It opens the data source and makes it ready for using.
213
214 If the subclass needs to open a connection to a database server,
215 to open a file, or to get information from a Web Service, this
216 method can do this kind of job to prepare the data source to be
217 in an operational mode. It will use the connection information
218 provided by the setConnectionInfo methods.
219
220 \exception Exception An exception can be thrown, if the data source cannot be opened.
221
222 \note Not thread-safe!
223 */
224 virtual void open() = 0;
225
226 /*!
227 \brief It closes the data source and clears all the resources used by its internal communication channel.
228
229 This method closes any connection, any opened file, and releases any other resources.
230
231 \exception Exception An exception can be thrown, if the data source cannot be closed.
232
233 \note Not thread-safe!
234 */
235 virtual void close() = 0;
236
237 /*!
238 \brief It returns true if the data source is opened, otherwise it returns false.
239
240 This method will not check if the data source is available for using;
241 it will just answer if the data source has already been opened.
242 If you want to know if the data source is available for using,
243 check the isValid() method.
244
245 \return It returns true if the data source is opened; otherwise, it returns false.
246
247 \note Not thread-safe!
248 */
249 virtual bool isOpened() const = 0;
250
251 /*!
252 \brief It checks if the data source is valid (available for using).
253
254 For a DBMS, it will check the opened connections.
255 For a WFS client, it will check if the server is reachable.
256 For a file, it will check if it can be read.
257
258 \return It returns true if the data source is available; otherwise, it returns false.
259
260 \note Not thread-safe!
261 */
262 virtual bool isValid() const = 0;
263
264 /*!
265 \brief It returns the known capabilities of the data source.
266
267 The returned object has all the information about the operations the data source can perform.
268 Here you will find if the data source implementation supports primary keys,
269 foreign keys, if it can be used in a thread environment and much more information.
270
271 \param capabilities The known capabilities of the data source.
272
273 \note Thread-safe!
274 */
275 virtual const DataSourceCapabilities& getCapabilities() const = 0;
276
277 /*!
278 \brief It returns the data source SQL dialect, if there is one.
279
280 \return The data source SQL dialect.
281
282 \note Thread-safe!
283 */
284 virtual const SQLDialect* getDialect() const = 0;
285 //@}
286
287 /** @name Data Retrieval
288 * Methods for retrieving data from the data source.
289 */
290 //@{
291
292 /*!
293 \brief It gets the dataset identified by the given name.
294 This method always returns a disconnected dataset, that is, a dataset that no more depends
295 of the data source that provided the connection for its creation. Therefore, the disconnected
296 dataset continues to live after the connection given by the data source has been released.
297
298 \param name The dataset name.
299 \param accessPolicy Access policy.
300 \param travType The traverse type associated to the returned dataset.
301
302 \exception Exception It can throw an exception if:
303 <ul>
304 <li>something goes wrong during the data retrieval</li>
305 <li>if the data source driver doesn't support the traversal type</li>
306 </ul>
307
308 \note Thread-safe!
309 */
310 virtual std::unique_ptr<DataSet> getDataSet(const std::string& name,
312 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
313
314 /*!
315 \brief It gets the dataset identified by the given name using a spatial filter over the specified property.
316 This method always returns a disconnected dataset, that is, a dataset that no more depends
317 of the data source that provided the connection for its creation. Therefore, the disconnected
318 dataset continues to live after the connection given by the data source has been released.
319
320 \param name The dataset name.
321 \param propertyName The name of the spatial property used to apply the spatial filter.
322 \param e A rectangle used as a spatial filter when retrieving the dataset.
323 \param r The spatial relation used during the filtering.
324 \param accessPolicy Access policy.
325 \param travType The traversal type associated to the returned dataset.
326
327 \exception Exception It can throw an exception if:
328 <ul>
329 <li>something goes wrong during the data retrieval</li>
330 <li>if the data source driver doesn't support the traversal type</li>
331 </ul>
332
333 \note The envelope coordinates should be in the same coordinate system as the dataset.
334
335 \note Thread-safe!
336 */
337 virtual std::unique_ptr<DataSet> getDataSet(const std::string& name,
338 const std::string& propertyName,
339 const te::gm::Envelope* e,
342 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
343
344 /*!
345 \brief It gets the dataset identified by the given name using a spatial filter over the given geometric property.
346 This method always returns a disconnected dataset, that is, a dataset that no more depends
347 of the data source that provided the connection for its creation. Therefore, the disconnected
348 dataset continues to live after the connection given by the data source has been released.
349
350 \param name The dataset name.
351 \param propertyName The name of the spatial property used to apply the spatial filter.
352 \param g The geometry used as a spatial filter when retrieving the dataset.
353 \param r The spatial relation used during the filtering.
354 \param accessPolicy Access policy.
355 \param travType The traverse type associated to the returned dataset.
356
357 \note The geometry coordinates should be in the same coordinate system as the dataset.
358
359 \note Thread-safe!
360 */
361 virtual std::unique_ptr<DataSet> getDataSet(const std::string& name,
362 const std::string& propertyName,
363 const te::gm::Geometry* g,
366 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
367
368 /*!
369 \brief It gets the dataset identified by the given name using the identification of the objects.
370 This method always returns a disconnected dataset, that is, a dataset that no more depends
371 of the data source that provided the connection for its creation. Therefore, the disconnected
372 dataset continues to live after the connection given by the data source has been released.
373
374 \param name The dataset name.
375 \param oids A pointer to the set of objects. Do not pass a null pointer nor an empty set.
376 \param accessPolicy Access policy.
377 \param travType The traverse type associated to the returned dataset.
378
379 \exception Exception It can throw an exception if:
380 <ul>
381 <li>something goes wrong during data retrieval</li>
382 <li>if the data source driver doesn't support the traversal type</li>
383 </ul>
384
385 \note Thread-safe!
386 */
387 std::unique_ptr<te::da::DataSet> getDataSet(const std::string& name,
388 const te::da::ObjectIdSet* oids,
390 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
391
392 /*!
393 \brief It executes a query that may return some data using a generic query.
394 This method always returns a disconnected dataset, that is, a dataset that no more depends
395 of the data source that provided the connection for its creation. Therefore, the disconnected
396 dataset continues to live after the connection given by the data source has been released.
397
398 This method is different of the method that accepts a dataset name and
399 a spatial filter; this method allows the retrieving of only a
400 subset of the attributes, since a query can include a property list.
401
402 \param q A valid query object.
403 \param travType The traverse type associated to the returned dataset.
404 \param accessPolicy Access policy.
405
406 \exception Exception It can throw an exception if:
407 <ul>
408 <li>something goes wrong during data retrieval</li>
409 <li>if the data source driver doesn't support the traversal type</li>
410 </ul>
411
412 \note Thread-safe!
413 */
414 virtual std::unique_ptr<DataSet> query(const Select& q,
416 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
417
418 /*!
419 \brief It executes a query that may return some data using the data source native language.
420 This method always returns a disconnected dataset, that is, a dataset that is no more dependent
421 of the data source that provided the connection for its creation. Therefore, the disconnected
422 dataset continues to live after the connection given by the data source has been released.
423
424 \param query A query string in the data source native language.
425 \param travType The traverse type associated to the returned dataset.
426 \param accessPolicy Access policy.
427
428 \exception Exception It can throw an exception if:
429 <ul>
430 <li>something goes wrong during data retrieval</li>
431 <li>if the data source driver doesn't support the traversal type</li>
432 </ul>
433
434 \note Don't use this method, if you want portability for your application.
435 \note Thread-safe!
436 */
437 virtual std::unique_ptr<DataSet> query(const std::string& query,
439 const te::common::AccessPolicy accessPolicy = te::common::RAccess);
440 //@}
441
442 /** @name Command Execution Methods
443 * Methods for executing commands against the data source.
444 */
445 //@{
446 /*!
447 \brief It executes the specified command using a generic query representation.
448
449 \param command A query like: CREATE, DROP, ALTER, INSERT, UPDATE, DELETE.
450
451 \exception Exception An exception can be thrown if the query cannot be performed.
452
453 \note Thread-safe!
454 */
455 virtual void execute(const Query& command);
456
457 /*!
458 \brief It executes the specified command in the data source native language.
459
460 \param command A query string in the data source native language (like: CREATE, DROP, ALTER, INSERT, UPDATE, DELETE).
461
462 \exception Exception An exception can be thrown if the query can not be performed.
463
464 \note Thread-safe!
465 */
466 virtual void execute(const std::string& command);
467 //@}
468
469 /** @name Auxiliary Methods for Commands and Queries
470 * Auxiliary methods for commands and queries.
471 */
472 //@{
473 /*!
474 \brief It escapes a string for using in commands and queries.
475
476 \param value Any string.
477
478 \return A valid escaped string.
479
480 \note Thread-safe!
481 */
482 virtual std::string escape(const std::string& value);
483
484 /*!
485 \brief It checks if the given dataset name is valid.
486
487 \param datasetName A dataset name whose validity will be checked.
488
489 \return True, if the name is valid according to the data source rules.
490
491 \note Thread-safe!
492 */
493 virtual bool isDataSetNameValid(const std::string& datasetName);
494
495 /*!
496 \brief It checks if the given property name is valid.
497
498 \param propertyName A property name whose validity will be checked.
499
500 \return True, if the name is valid according to the data source rules.
501
502 \note Thread-safe!
503 */
504 virtual bool isPropertyNameValid(const std::string& propertyName);
505 //@}
506
507 /** @name Dataset Metadata Retrieval
508 * Methods for retrieving metadata about the datasets of the data source.
509 */
510 //@{
511 /*!
512 \brief It gets the dataset names available in the data source.
513
514 \return The dataset names available in the data source.
515
516 \exception Exception An exception can be thrown, if the dataset names could not be retrieved.
517
518 \note Each dataset in the data source must have a unique name. For example, in a DBMS the name
519 may contain the schema name before the table name separated by a dot notation (".").
520
521 \note Thread-safe!
522 */
523 virtual std::vector<std::string> getDataSetNames();
524
525 /*!
526 \brief It retrieves the number of data sets available in the data source.
527
528 \exception Exception An exception can be thrown, if the number of datasets could not be retrieved.
529
530 \return The number of data sets available in the data source.
531
532 \note Thread-safe!
533 */
534 virtual std::size_t getNumberOfDataSets();
535
536 /*!
537 \brief It gets information about the given dataset.
538
539 This method can provide the following information about a dataset:
540 <ul>
541 <li>the list of properties, including: name, data type, size, if the value is required or not, if it is an autoincrement</li>
542 <li>primary key</li>
543 <li>foreign keys</li>
544 <li>unique keys</li>
545 <li>check constraints</li>
546 <li>indexes</li>
547 </ul>
548
549 \param name The name of the dataset we are looking information for.
550
551 \exception Exception An exception can be thrown, if the information about the dataset could not be retrieved.
552
553 \return The dataset schema.
554
555 \note Thread-safe!
556 */
557 virtual std::unique_ptr<te::da::DataSetType> getDataSetType(const std::string& name);
558
559 /*!
560 \brief It gets capabilities about a data set.
561
562 \param name Name of the dataset.
563
564 \return The capabilities of the data set.
565 */
566 std::unique_ptr<te::da::DataSetTypeCapabilities> getCapabilities(const std::string& name);
567
568 /*!
569 \brief It retrieves the properties of the dataset.
570
571 \param datasetName The dataset name.
572
573 \exception Exception An exception can be thrown, if the dataset properties could not be retrieved.
574
575 \return The dataset properties.
576
577 \note Thread-safe!
578 */
579 virtual boost::ptr_vector<te::dt::Property> getProperties(const std::string& datasetName);
580
581 /*!
582 \brief It retrieves the property with the given name from the dataset.
583
584 \param datasetName The dataset name.
585 \param propertyName The property name.
586
587 \exception Exception An exception can be thrown, if the dataset property could not be retrieved.
588
589 \return The property with the given name from the dataset.
590
591 \note Thread-safe!
592 */
593 virtual std::unique_ptr<te::dt::Property> getProperty(const std::string& datasetName, const std::string& name);
594
595 /*!
596 \brief It retrieves the property lying in the given position from the dataset.
597
598 \param datasetName The dataset name.
599 \param propertyPos The property position.
600
601 \exception Exception An exception can be thrown, if the property lying in the given position could not be retrieved.
602
603 \return The property in the given position.
604
605 \note Thread-safe!
606 */
607 virtual std::unique_ptr<te::dt::Property> getProperty(const std::string& datasetName, std::size_t propertyPos);
608
609 /*!
610 \brief It gets the property names of the given dataset.
611
612 \param datasetName The dataset name.
613
614 \exception Exception An exception can be thrown, if the property names of the dataset could not be retrieved.
615
616 \return The property names of the dataset.
617
618 \note Each dataset in the data source must have a unique name. For example, in a DBMS the name
619 may contain the schema name before the table name separated by a dot notation (".").
620
621 \note Thread-safe!
622 */
623 virtual std::vector<std::string> getPropertyNames(const std::string& datasetName);
624
625 /*!
626 \brief It gets the number of properties of the given dataset.
627
628 \param datasetName The dataset name.
629
630 \exception Exception An exception can be thrown, if the number of dataset properties could not be retrieved.
631
632 \return The number of dataset properties.
633
634 \note Thread-safe!
635 */
636 virtual std::size_t getNumberOfProperties(const std::string& datasetName);
637
638 /*!
639 \brief It checks if a property with the given name exists in the dataset.
640
641 \param datasetName The dataset name.
642 \param name The property name.
643
644 \exception Exception An exception can be thrown, if the existence of the dataset property could not be obtained.
645
646 \return True, if the property exists in the dataset; otherwise, it returns false.
647
648 \note Thread-safe!
649 */
650 virtual bool propertyExists(const std::string& datasetName, const std::string& name);
651
652 /*!
653 \brief It adds a new property to the dataset schema.
654
655 \param datasetName The dataset where the property will be added.
656 \param p The new property to be added.
657
658 \exception Exception An exception can be thrown, if the property could not be added to the dataset schema.
659
660 \note Don't delete the given property, because the schema will take the ownership of it.
661 \note Thread-safe!
662 */
663 virtual void addProperty(const std::string& datasetName, te::dt::Property* p);
664
665 /*!
666 \brief It removes a property from the given dataset.
667
668 \param datasetName The dataset from where the given property will be removed.
669 \param name The property to be removed from the dataset.
670
671 \exception Exception An exception can be thrown, if the dataset property could not be removed.
672
673 \note Thread-safe!
674 */
675 virtual void dropProperty(const std::string& datasetName, const std::string& name);
676
677 /*!
678 \brief It renames a property of the given dataset.
679
680 \param datasetName The dataset containing the property to be renamed.
681 \param propertyName The property to be renamed from the dataset.
682 \param newPropertyName The new property name.
683
684 \exception Exception An exception can be thrown, if the dataset property could not be renamed.
685
686 \note Thread-safe!
687 */
688 virtual void renameProperty(const std::string& datasetName,
689 const std::string& propertyName,
690 const std::string& newPropertyName);
691
692 virtual void changePropertyDefinition(const std::string& datasetName, const std::string& propName, te::dt::Property* newProp);
693
694 virtual void changePropertiesDefinitions(const std::string& datasetName, const std::vector<std::string>& propsNames, const std::vector<te::dt::Property*> newProps);
695
696 /*!
697 \brief It retrieves the primary key of the dataset.
698
699 \param datasetName The dataset name.
700
701 \exception Exception An exception can be thrown, if the primary key could not be retrieved.
702
703 \return If a primary key exists in the dataset, it is returned; otherwise, a NULL is returned.
704
705 \note Thread-safe!
706 */
707 virtual std::unique_ptr<te::da::PrimaryKey> getPrimaryKey(const std::string& datasetName);
708
709 /*!
710 \brief It checks if a primary key exists in the dataset.
711
712 \param datasetName The dataset name.
713 \param name The primary key name.
714
715 \exception Exception An exception can be thrown, if the existence of the primary key could not be determined.
716
717 \return True, if a primary key exists in the dataset; otherwise, it returns false.
718
719 \note Thread-safe!
720 */
721 virtual bool primaryKeyExists(const std::string& datasetName, const std::string& name);
722
723 /*!
724 \brief It adds a primary key constraint to the dataset schema.
725
726 \param datasetName The name of the dataset where the primary key will be added.
727 \param pk The primary key constraint.
728
729 \exception Exception An exception can be thrown, if the primary key could not be added to the dataset schema.
730
731 \note Don't delete the given primary key, because the schema will take the ownership of it.
732 \note Thread-safe!
733 */
734 virtual void addPrimaryKey(const std::string& datasetName, PrimaryKey* pk);
735
736 /*!
737 \brief It removes the primary key constraint from the dataset schema.
738
739 \param datasetName The dataset from where the primary key will be removed.
740
741 \exception Exception An exception can be thrown, if the primary key could not be dropped from the dataset schema.
742
743 \note Thread-safe!
744 */
745 virtual void dropPrimaryKey(const std::string& datasetName);
746
747 /*!
748 \brief It retrieves the foreign key from the given dataset.
749
750 \param datasetName The dataset name.
751 \param name The foreign key name.
752
753 \exception Exception An exception can be thrown, if the foreign key could not be retrieved.
754
755 \return If the foreign key exists in the dataset, it is returned; otherwise, a NULL is returned.
756
757 \note Thread-safe!
758 */
759 virtual std::unique_ptr<ForeignKey> getForeignKey(const std::string& datasetName, const std::string& name);
760
761 /*!
762 \brief It gets the foreign key names of the given dataset.
763
764 \param datasetName The dataset name.
765
766 \exception Exception An exception can be thrown, if the foreign key names could not be retrieved.
767
768 \return The foreign key names of the dataset.
769
770 \note Thread-safe!
771 */
772 virtual std::vector<std::string> getForeignKeyNames(const std::string& datasetName);
773
774 /*!
775 \brief It checks if a foreign key with the given name exists in the data source.
776
777 \param datasetName The dataset name.
778 \param name The foreign key name.
779
780 \exception Exception An exception can be thrown, if the existence of the foreign key could not be obtained.
781
782 \return True, if the foreign key exists in the dataset; otherwise, it returns false.
783 */
784 virtual bool foreignKeyExists(const std::string& datasetName, const std::string& name);
785
786 /*!
787 \brief It adds a foreign key constraint to a dataset.
788
789 \param datasetName The dataset where the foreign key constraint will be added.
790 \param fk The foreign key constraint.
791
792 \exception Exception An exception can be thrown, if the foreign key could not be added to the dataset schema.
793
794 \note Don't delete the given foreign key, because the schema will take the ownership of it.
795 \note Thread-safe!
796 */
797 virtual void addForeignKey(const std::string& datasetName, ForeignKey* fk);
798
799 /*!
800 \brief It removes the foreign key constraint from the dataset schema.
801
802 \param datasetName The dataset where the foreign key will be removed.
803 \param fkName The foreign key to be removed.
804
805 \exception Exception An exception can be thrown, if the foreign key could not be removed from the dataset schema.
806
807 \note Thread-safe!
808 */
809 virtual void dropForeignKey(const std::string& datasetName, const std::string& fkName);
810
811 /*!
812 \brief It gets the unique key in the dataset with the given name.
813
814 \param datasetName The dataset name.
815 \param name The unique key name.
816
817 \exception Exception An exception can be thrown, if the unique key could not be retrieved.
818
819 \return The unique key with the given name in the dataset.
820
821 \note Thread-safe!
822 */
823 virtual std::unique_ptr<te::da::UniqueKey> getUniqueKey(const std::string& datasetName, const std::string& name);
824
825 /*!
826 \brief It gets the unique key names of the given dataset.
827
828 \param datasetName The dataset name.
829
830 \exception Exception An exception can be thrown, if the unique key names could not be obtained.
831
832 \return The unique key names of the dataset.
833
834 \note Thread-safe!
835 */
836 virtual std::vector<std::string> getUniqueKeyNames(const std::string& datasetName);
837
838 /*!
839 \brief It checks if a unique key with the given name exists in the dataset.
840
841 \param datasetName The dataset name.
842 \param name The unique key name.
843
844 \exception Exception An exception can be thrown, if the existence of the unique key could not be determined.
845
846 \return True, if the unique key exists in the dataset; otherwise, it returns false.
847
848 \note Thread-safe!
849 */
850 virtual bool uniqueKeyExists(const std::string& datasetName, const std::string& name);
851
852 /*!
853 \brief It adds a unique key constraint to the dataset.
854
855 \param datasetName The dataset where the unique key will be added.
856 \param uk The unique key constraint.
857
858 \exception Exception An exception can be thrown, if the unique key could not be added to the dataset schema.
859
860 \note Don't delete the given unique key, because the schema will take the ownership of it.
861 \note Thread-safe!
862 */
863 virtual void addUniqueKey(const std::string& datasetName, UniqueKey* uk);
864
865 /*!
866 \brief It removes the unique key constraint from the dataset.
867
868 \param datasetName The dataset from where the unique key will be removed.
869 \param name The unique key constraint name.
870
871 \exception Exception An exception can be thrown, if the unique key could not be removed from the dataset schema.
872
873 \note Thread-safe!
874 */
875 virtual void dropUniqueKey(const std::string& datasetName, const std::string& name);
876
877 /*!
878 \brief It gets the check constraint of the dataset with the given name.
879
880 \param datasetName The dataset name.
881 \param name The check constraint name.
882
883 \exception Exception An exception can be thrown, if the check constraint could not be retrieved.
884
885 \return The check constraint with the given name.
886
887 \note Thread-safe!
888 */
889 virtual std::unique_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& datasetName, const std::string& name);
890
891 /*!
892 \brief It gets the check constraint names of the given dataset.
893
894 \param datasetName The dataset name.
895
896 \exception Exception An exception can be thrown, if the check constraint names could not be retrieved.
897
898 \return The check constraint names of the dataset.
899
900 \note Thread-safe!
901 */
902 virtual std::vector<std::string> getCheckConstraintNames(const std::string& datasetName);
903
904 /*!
905 \brief It checks if a check-constraint with the given name exists in the data source.
906
907 \param datasetName The dataset name.
908 \param name The check-constraint name.
909
910 \exception Exception An exception can be thrown, if the existence of the check constraint could not be determined.
911
912 \return True, if the check-constraint exists in the dataset; otherwise, it returns false.
913
914 \note Thread-safe!
915 */
916 virtual bool checkConstraintExists(const std::string& datasetName, const std::string& name);
917
918 /*!
919 \brief It adds a check constraint to the dataset.
920
921 \param datasetName The dataset where the constraint will be added.
922 \param cc The check constraint to be added.
923
924 \exception Exception An exception can be thrown, if the check constraint could not be added to the dataset schema.
925
926 \note Don't delete the given check constraint, because the schema will take the ownership of it.
927 \note Thread-safe!
928 */
929 virtual void addCheckConstraint(const std::string& datasetName, CheckConstraint* cc);
930
931 /*!
932 \brief It removes the check constraint from the dataset.
933
934 \param datasetName The dataset from where the check constraint will be removed.
935 \param name The check constraint to be removed.
936
937 \exception Exception An exception can be thrown, if the check constraint could not be removed from the dataset schema.
938
939 \note Thread-safe!
940 */
941 virtual void dropCheckConstraint(const std::string& datasetName, const std::string& name);
942
943 /*!
944 \brief It gets the index with the given name from the dataset.
945
946 \param datasetName The dataset name.
947 \param name The index name.
948
949 \exception Exception An exception can be thrown, if the index could not be retrieved.
950
951 \return The index from the given dataset.
952
953 \note Thread-safe!
954 */
955 virtual std::unique_ptr<te::da::Index> getIndex(const std::string& datasetName, const std::string& name);
956
957 /*!
958 \brief It gets the index names of the given dataset.
959
960 \param datasetName The dataset name.
961
962 \exception Exception An exception can be thrown, if the index names could not be retrieved.
963
964 \return The index names of the given dataset.
965
966 \note Thread-safe!
967 */
968 virtual std::vector<std::string> getIndexNames(const std::string& datasetName);
969
970 /*!
971 \brief It checks if an index with the given name exists in the dataset.
972
973 \param datasetName The dataset name.
974 \param name The index name.
975
976 \exception Exception An exception can be thrown, if the index existence could not be determined.
977
978 \return True, if the index exists in the dataset; otherwise, it returns false.
979
980 \note Thread-safe!
981 */
982 virtual bool indexExists(const std::string& datasetName, const std::string& name);
983
984 /*!
985 \brief It adds an index to the dataset.
986
987 \param datasetName The dataset where the index will be added.
988 \param idx The index to be added.
989 \param options A list of optional modifiers (driver specific).
990
991 \exception Exception An exception can be thrown, if the index could not be added to the dataset schema.
992
993 \note Don't delete the given index, because the schema will take the ownership of it.
994 \note Thread-safe!
995 */
996 virtual void addIndex(const std::string& datasetName, Index* idx,
997 const std::map<std::string, std::string>& options);
998
999 /*!
1000 \brief It removes the index from the given dataset.
1001
1002 \param datasetName The dataset where the index will be removed.
1003 \param idxName The index to be removed.
1004
1005 \exception Exception An exception can be thrown, if the index could not be removed from the dataset schema.
1006
1007 \note Thread-safe!
1008 */
1009 virtual void dropIndex(const std::string& datasetName, const std::string& idxName);
1010
1011 /*!
1012 \brief It gets the sequence with the given name in the data source.
1013
1014 \param name The sequence name.
1015
1016 \exception Exception An exception can be thrown, if the sequence could not be retrieved from the data source.
1017
1018 \return The sequence with the given name.
1019
1020 \note Thread-safe!
1021 */
1022 virtual std::unique_ptr<Sequence> getSequence(const std::string& name);
1023
1024 /*!
1025 \brief It gets the sequence names available in the data source.
1026
1027 \note Each sequence in the data source must have a unique name. For example, in a DBMS the name
1028 may contain the schema name before the sequence name separated by a dot notation (".").
1029
1030 \exception Exception An exception can be thrown, if the sequence names could not be retrieved.
1031
1032 \return The sequence names of the data source.
1033
1034 \note Thread-safe!
1035 */
1036 virtual std::vector<std::string> getSequenceNames();
1037
1038 /*!
1039 \brief It checks if a sequence with the given name exists in the data source.
1040
1041 \param name The sequence name.
1042
1043 \exception Exception An exception can be thrown, if the index existence could not be determined.
1044
1045 \return True, if the sequence exists in the data source; otherwise, it returns false.
1046
1047 \note Thread-safe!
1048 */
1049 virtual bool sequenceExists(const std::string& name);
1050
1051 /*!
1052 \brief It adds a new sequence in the data source.
1053
1054 \exception Exception An exception can be thrown, if the sequence could not be added to the data source.
1055
1056 \note Don't delete the given sequence, because the data source will take the ownership of it.
1057 \note Thread-safe!
1058 */
1059 virtual void addSequence(Sequence* sequence);
1060
1061 /*!
1062 \brief It removes the sequence from the data source.
1063
1064 \param name The sequence that will be removed.
1065
1066 \exception Exception An exception can be thrown, if the sequence could not be removed from the data source.
1067
1068 \note Thread-safe!
1069 */
1070 virtual void dropSequence(const std::string& name);
1071
1072 /*!
1073 \brief It retrieves the bounding rectangle of the spatial property for the given dataset.
1074
1075 \param datasetName The dataset name.
1076 \param propertyName The spatial property name.
1077
1078 \exception Exception An exception can be thrown, if the extent of the geometry property could not be retrieved.
1079
1080 \return The spatial property bounding rectangle, or NULL, if none can be retrieved.
1081
1082 \note Thread-safe!
1083 */
1084 virtual std::unique_ptr<te::gm::Envelope> getExtent(const std::string& datasetName,
1085 const std::string& propertyName);
1086
1087 /*!
1088 \brief It retrieves the bounding rectangle for the spatial property lying in the given position in the dataset.
1089
1090 \param datasetName The dataset name.
1091 \param propertyPos The spatial property position.
1092
1093 \exception Exception An exception can be thrown, if the extent of the geometry property lying in the given position could not be retrieved.
1094
1095 \return The spatial property bounding rectangle, or NULL, if none can be retrieved.
1096
1097 \note Thread-safe!
1098 */
1099 virtual std::unique_ptr<te::gm::Envelope> getExtent(const std::string& datasetName, std::size_t propertyPos);
1100
1101 /*!
1102 \brief It retrieves the number of items of the given dataset.
1103
1104 \param datasetName The dataset name.
1105
1106 \exception Exception An exception can be thrown, if the number of items of the dataset could not be retrieved.
1107
1108 \return The number of items of the given dataset.
1109
1110 \note Thread-safe!
1111 */
1112 virtual std::size_t getNumberOfItems(const std::string& datasetName);
1113
1114 /*!
1115 \brief It checks if the data source has any dataset.
1116
1117 \exception Exception An exception can be thrown, if it is not possible to check if the data source has datasets .
1118
1119 \return True, if the data source has datasets; otherwise, it returns false.
1120
1121 \note Thread-safe!
1122 */
1123 virtual bool hasDataSets();
1124
1125 /*!
1126 \brief It checks if a dataset with the given name exists in the data source.
1127
1128 \param name The dataset name.
1129
1130 \exception Exception An exception can be thrown, if the existence of a dataset in the data source could not be determined.
1131
1132 \return True, if the dataset exists in the data source; otherwise, it returns false.
1133
1134 \note Thread-safe!
1135 */
1136 virtual bool dataSetExists(const std::string& name);
1137
1138 /*!
1139 \brief It gets the datasource geometry type name equivalent to terralib.
1140
1141 \param type The terralib geometry type.
1142
1143 \return The geometry type name equivalent to terralib.
1144 */
1145 virtual std::string getGeometryTypeName(te::gm::GeomType type);
1146 //@}
1147
1148 /** @name Dataset Schema Persistence Methods
1149 * Methods for dealing with datasource and dataset schema changes.
1150 */
1151 //@{
1152
1153 /*!
1154 \brief It creates the dataset schema definition in the target data source.
1155
1156 If a dataset schema with the same name already exists in the target data source,
1157 this may throw an exception.
1158
1159 After calling this method, the dataset schema may be updated.
1160
1161 \param dt The dataset schema to be created. It may be changed during the operation.
1162 \param options A list of optional modifiers (driver specific).
1163
1164 \pre The schema of a related dataset in a foreign key must be already in the data source.
1165
1166 \post In some data sources, this method may output implicit indexes, sequences or constraints.
1167 The method, if necessary, will create and adjust the dataset schema.
1168
1169 \post The caller of this method will take the ownership of the given schema.
1170
1171 \note If you want to create a new schema based on an already existing one,
1172 you must create a fresh copy of the DataSetType with the clone() method.
1173
1174 \note Thread-safe!
1175 */
1176 virtual void createDataSet(DataSetType* dt, const std::map<std::string, std::string>& options);
1177
1178 /*!
1179 \brief It clones the dataset in the data source.
1180
1181 \param name The dataset to be cloned.
1182 \param cloneName The name of the cloned dataset.
1183 \param options A list of optional modifiers. It is driver specific.
1184
1185 \exception Exception An exception can be thrown, if the dataset schema could not be cloned.
1186
1187 \note Thread-safe!
1188 */
1189 virtual void cloneDataSet(const std::string& name,
1190 const std::string& cloneName,
1191 const std::map<std::string, std::string>& options);
1192
1193 /*!
1194 \brief It removes the dataset schema from the data source.
1195
1196 \param name The dataset name whose schema will be removed from the data source.
1197
1198 \exception Exception An exception can be thrown, if the dataset could not be removed from the data source.
1199
1200 \note Thread-safe!
1201 */
1202 virtual void dropDataSet(const std::string& name);
1203
1204 /*!
1205 \brief It renames a dataset.
1206
1207 \param name The name of the dataset to be renamed.
1208 \param newName The new dataset name.
1209
1210 \exception Exception An exception can be thrown, if the dataset could not be renamed.
1211
1212 \note Thread-safe!
1213 */
1214 virtual void renameDataSet(const std::string& name, const std::string& newName);
1215 //@}
1216
1217 /** @name Dataset Persistence Methods
1218 * Methods for dealing with the persistence of data in a data source.
1219 */
1220 //@{
1221
1222 /*!
1223 \brief It adds data items to the dataset in the data source.
1224
1225 \param datasetName The target dataset name.
1226 \param d The data items to be added to the dataset.
1227 \param options A list of optional modifiers (driver specific).
1228 \param limit The number of items to be used from the input dataset. If set to 0 (default), all items are used.
1229
1230 \exception Exception An exception can be thrown, if the input dataset items could not be added to the given dataset.
1231
1232 \note The dataset reading will start in the current position.
1233 So, keep in mind that it is the caller responsability
1234 to inform the right position(and a valid one) in the dataset 'd', to start the inserting process.
1235
1236 \note Thread-safe!
1237 */
1238 virtual void add(const std::string& datasetName,
1239 DataSet* d,
1240 const std::map<std::string, std::string>& options,
1241 std::size_t limit = 0);
1242
1243 /*!
1244 \brief It removes all the informed items from the dataset.
1245
1246 It removes all the data items from a dataset which are identified by
1247 a set of object identifiers. If this set is not informed, all items will be removed.
1248
1249 \param datasetName The dataset name.
1250 \param oids A set of object identifiers used used to remove data from the dataset, or NULL, for removing all.
1251
1252 \exception Exception An exception can be thrown, if the data items could not be removed.
1253
1254 \note Thread-safe!
1255 */
1256 virtual void remove(const std::string& datasetName, const te::da::ObjectIdSet* oids = 0);
1257
1258 /*!
1259 \brief It updates the contents of a dataset for the set of data items.
1260
1261 \param datasetName The target dataset name.
1262 \param dataset The list of data items to be updated.
1263 \param properties The list of properties of the dataset to be updated.
1264 \param oids The list of objects to be updated.
1265 \param options A list of optional modifiers. It is driver specific.
1266 \param limit The number of items to be used from the input dataset. If set to 0 (default) all items are used.
1267
1268 \exception Exception An exception can be thrown, if the dataset could not be updated.
1269
1270 \note The dataset reading will start in the
1271 current position. So, keep in mind that it is the caller responsability
1272 to inform the right position(and a valid one) for the dataset 'd', to start the updating process.
1273
1274 \note Thread-safe!
1275 */
1276 virtual void update(const std::string& datasetName,
1277 DataSet* dataset,
1278 const std::vector<std::size_t>& properties,
1279 const te::da::ObjectIdSet* oids,
1280 const std::map<std::string, std::string>& options,
1281 std::size_t limit = 0);
1282
1283 /*!
1284 \brief It updates the contents of a dataset.
1285
1286 All rows are edited. The third parameter tells wich columns are edited for each row.
1287
1288 \param datasetName Name pf the dataset.
1289 \param dataset Dataset with editions.
1290 \param properties Columns edited for each row. Note that the size of \a properties must be the same of the \a dataset.
1291 \param ids List of positions of the columns that identifies rows.
1292
1293 \exception te::da::Exception An exception can be thrown, if the dataset could not be updated.
1294 */
1295 virtual void update(const std::string& datasetName,
1296 DataSet* dataset,
1297 const std::vector< std::set<int> >& properties,
1298 const std::vector<size_t>& ids);
1299
1300 /*!
1301 \brief It return the DataSource current encoding.
1302
1303 \return The DataSource current encoding.
1304 */
1306
1307 /*!
1308 \brief It sets the encodings for the data source.
1309
1310 \param et The char encoding type.
1311
1312 \note This function only takes effect if datasource support this option.
1313
1314 */
1315 virtual void setEncoding(const te::core::EncodingType& et);
1316
1317 //@}
1318
1319 /** @name Data Source static methods
1320 * Data Source static methods
1321 */
1322 //@{
1323
1324 /*!
1325 \brief It creates a new repository for a data source.
1326
1327 \param dsType The type of data source to be created (example: POSTGIS, ORACLE, SQLITE).
1328 \param connInfo The information for creating a new data source.
1329
1330 \exception Exception An exception can be thrown, if the data source could not be created.
1331
1332 \return A data source for the new data repository.
1333
1334 \note Thread-safe!
1335 */
1336 static std::unique_ptr<DataSource> create(const std::string& dsType, const std::string& connInfo);
1337
1338 /* static std::unique_ptr<DataSource> create(const std::string& dsType, const std::string& uri);*/
1339
1340 /*!
1341 \brief It removes a data source identified by its connection information and the driver type.
1342
1343 \param dsType The data source type name (example: POSTGIS, ORACLE, SQLITE).
1344 \param dsInfo The connection information for removing the data source.
1345
1346 \exception Exception An exception can be thrown, if the data source could not be removed.
1347
1348 \note No other instance of the data source to be removed can be opened, when calling this method.
1349
1350 \note Thread-safe!
1351 */
1352 static void drop(const std::string& dsType, const std::string& connInfo);
1353
1354 /*!
1355 \brief It checks if the data source exists with the connection information and the driver type.
1356
1357 \param dsType The data source type name (example: POSTGIS, ORACLE, SQLITE).
1358 \param dsInfo The data source information.
1359
1360 \exception Exception An exception can be thrown, if the data source exists in the driver.
1361
1362 \return True, if the data source exists; otherwise, it returns false.
1363
1364 \note Thread-safe!
1365 */
1366 static bool exists(const std::string& dsType, const std::string& connInfo);
1367
1368 /*!
1369 \brief It returns the data source names available in the driver.
1370
1371 \param dsType The type name of the data source(example: PostGIS, Oracle, WFS).
1372 \param dsInfo The information about the data sources.
1373
1374 \exception Exception An exception can be thrown, if the data source names could not be retrieved.
1375
1376 \return The data source names available.
1377
1378 \exception Exception An exception can be thrown, if the list of data source names could not be retrieved.
1379 */
1380 static std::vector<std::string> getDataSourceNames(const std::string& dsType, const std::string& connInfo);
1381
1382 //@}
1383
1384 protected:
1385
1386 /** @name Protected Data Source Methods????
1387 * The protected methods of the data source
1388 */
1389 //@{
1390
1391 /*!
1392 \brief It creates a new data source.
1393
1394 \param connInfo The information for creating a new data source.
1395
1396 \exception Exception An exception can be thrown, if the data source could not be created.
1397
1398 \note Not thread-safe!
1399 */
1400 virtual void create(const std::string& connInfo) = 0;
1401
1402 /*!
1403 \brief It removes the data source with the connection information from a driver.
1404
1405 \param connInfo The information for removing a data source from a driver.
1406
1407 \exception Exception An exception can be thrown, if the data source could not be removed.
1408
1409 \note Not thread-safe!
1410 */
1411 virtual void drop(const std::string& connInfo) = 0;
1412
1413 /*!
1414 \brief Check the existence of a data source in a driver.
1415
1416 \param connInfo The data source information.
1417
1418 \exception Exception An exception can be thrown, if the existence of a data source in a driver could not be determined.
1419
1420 \return True, if the data source exists, or false, otherwise.
1421
1422 \note Thread-safe!
1423 */
1424 virtual bool exists(const std::string& connInfo) = 0;
1425
1426 /*!
1427 \brief It gets the data source names available in a driver.
1428
1429 \param dsInfo The data source information.
1430
1431 \exception Exception An exception can be thrown, if the data source names could not be retrieved.
1432
1433 \return The data source names available in the driver.
1434
1435 \note Not thread-safe!
1436 */
1437 virtual std::vector<std::string> getDataSourceNames(const std::string& connInfo) = 0;
1438
1440
1441 //@}
1442
1443 protected:
1444
1445 std::string m_id; //!< The data source identification.
1446 te::core::URI m_uri; //!< The URI used to describe the datasource connection;
1447 };
1448
1449 typedef boost::shared_ptr<DataSource> DataSourcePtr;
1450
1451 } // end namespace da
1452} // end namespace te
1453
1454#endif // __TERRALIB_DATAACCESS_DATASOURCE_INTERNAL_DATASOURCE_H
A class to store the proxy information that must be used to access data located in URIs.
Definition: URI.h:50
A class that describes a check constraint.
A class that models the description of a dataset.
Definition: DataSetType.h:73
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
An abstract class for data providers like a DBMS, Web Services or a regular file.
Definition: DataSource.h:120
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, const te::da::ObjectIdSet *oids, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name using the identification of the objects....
virtual void setEncoding(const te::core::EncodingType &et)
It sets the encodings for the data source.
virtual void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
virtual void create(const std::string &connInfo)=0
It creates a new data source.
virtual void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
DataSource(const std::string &connInfo)
virtual void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
virtual boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
virtual void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
virtual std::string getGeometryTypeName(te::gm::GeomType type)
It gets the datasource geometry type name equivalent to terralib.
virtual void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
virtual bool hasDataSets()
It checks if the data source has any dataset.
virtual void addIndex(const std::string &datasetName, Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository.
virtual void execute(const Query &command)
It executes the specified command using a generic query representation.
virtual void update(const std::string &datasetName, DataSet *dataset, const std::vector< std::set< int > > &properties, const std::vector< size_t > &ids)
It updates the contents of a dataset.
virtual std::unique_ptr< Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
virtual bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
virtual bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
virtual std::unique_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
virtual bool isDataSetNameValid(const std::string &datasetName)
It checks if the given dataset name is valid.
virtual bool isValid() const =0
It checks if the data source is valid (available for using).
virtual std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
virtual void addUniqueKey(const std::string &datasetName, UniqueKey *uk)
It adds a unique key constraint to the dataset.
virtual ~DataSource()
Virtual destructor.
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
virtual std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
DataSource(const te::core::URI &uri)
Default constructor that can be called by subclasses.
virtual 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.
static bool exists(const std::string &dsType, const std::string &connInfo)
It checks if the data source exists with the connection information and the driver type.
virtual void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
virtual te::core::EncodingType getEncoding()
It return the DataSource current encoding.
virtual 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.
static std::vector< std::string > getDataSourceNames(const std::string &dsType, const std::string &connInfo)
It returns the data source names available in the driver.
virtual bool isOpened() const =0
It returns true if the data source is opened, otherwise it returns false.
virtual std::unique_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset.
virtual bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
virtual bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
virtual std::unique_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, std::size_t propertyPos)
It retrieves the bounding rectangle for the spatial property lying in the given position in the datas...
virtual void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
virtual std::unique_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.
virtual void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
const te::core::URI & getConnectionInfo() const
An Uniform Resource Identifier used to describe the datasource connection.
virtual void drop(const std::string &connInfo)=0
It removes the data source with the connection information from a driver.
virtual bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
virtual void addSequence(Sequence *sequence)
It adds a new sequence in the data source.
virtual void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
virtual std::string getType() const =0
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS,...
te::core::URI m_uri
The URI used to describe the datasource connection;.
Definition: DataSource.h:1446
virtual std::unique_ptr< ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
virtual std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, std::size_t propertyPos)
It retrieves the property lying in the given position from the dataset.
std::string m_id
The data source identification.
Definition: DataSource.h:1445
virtual std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
virtual void dropSequence(const std::string &name)
It removes the sequence from the data source.
virtual void changePropertiesDefinitions(const std::string &datasetName, const std::vector< std::string > &propsNames, const std::vector< te::dt::Property * > newProps)
virtual void close()=0
It closes the data source and clears all the resources used by its internal communication channel.
virtual bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
const std::string & getId() const
An identification value for the data source.
virtual std::unique_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
virtual std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
virtual void addCheckConstraint(const std::string &datasetName, CheckConstraint *cc)
It adds a check constraint to the dataset.
virtual bool exists(const std::string &connInfo)=0
Check the existence of a data source in a driver.
virtual std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
virtual void execute(const std::string &command)
It executes the specified command in the data source native language.
virtual void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
std::unique_ptr< te::da::DataSetTypeCapabilities > getCapabilities(const std::string &name)
It gets capabilities about a data set.
virtual std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
static void drop(const std::string &dsType, const std::string &connInfo)
It removes a data source identified by its connection information and the driver type.
virtual std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
virtual 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.
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset,...
virtual std::unique_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.
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, const std::string &propertyName, const te::gm::Geometry *g, te::gm::SpatialRelation r, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name using a spatial filter over the given geometric prop...
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
virtual std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
virtual void update(const std::string &datasetName, 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.
static std::unique_ptr< DataSource > create(const std::string &dsType, const std::string &connInfo)
It creates a new repository for a data source.
virtual void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the given dataset.
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, const std::string &propertyName, const te::gm::Envelope *e, te::gm::SpatialRelation r, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name using a spatial filter over the specified property....
virtual std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
virtual void addPrimaryKey(const std::string &datasetName, PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
virtual std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
virtual std::unique_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
virtual std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
virtual void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
virtual void add(const std::string &datasetName, 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.
virtual void addForeignKey(const std::string &datasetName, ForeignKey *fk)
It adds a foreign key constraint to a dataset.
virtual bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
virtual std::vector< std::string > getDataSourceNames(const std::string &connInfo)=0
It gets the data source names available in a driver.
virtual void open()=0
It opens the data source and makes it ready for using.
virtual std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
virtual std::unique_ptr< DataSet > query(const std::string &query, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using the data source native language....
void setId(const std::string &id)
It sets the data source identification.
virtual const SQLDialect * getDialect() const =0
It returns the data source SQL dialect, if there is one.
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:49
It describes an index associated to a DataSetType.
Definition: Index.h:53
This class represents a set of unique ids created in the same context. i.e. from the same data set.
Definition: ObjectIdSet.h:56
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:49
A Query is independent from the data source language/dialect.
Definition: Query.h:47
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:56
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:67
It describes a sequence (a number generator).
Definition: Sequence.h:57
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:50
It models a property definition.
Definition: Property.h:60
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
@ FORWARDONLY
Definition: Enums.h:55
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
@ RAccess
Definition: Enums.h:43
EncodingType
Supported character encodings.
Definition: CharEncoding.h:51
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1449
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:42
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:128
TerraLib.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97