src/terralib/dataaccess/datasource/DataSourceTransactor.cpp
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/DataSourceTransactor.cpp
22 
23  \brief A DataSourceTransactor can be viewed as a gateway for reading/writing things into the data source.
24 */
25 
26 // TerraLib
27 #include "../../core/translator/Translator.h"
28 #include "../../geometry/GeometryProperty.h"
29 #include "../../datatype/Property.h"
30 #include "../dataset/DataSetTypeCapabilities.h"
31 #include "../dataset/ObjectIdSet.h"
32 #include "../query/DataSetName.h"
33 #include "../query/Field.h"
34 #include "../query/Fields.h"
35 #include "../query/Select.h"
36 #include "../query/Where.h"
37 #include "../utils/Utils.h"
38 #include "../Exception.h"
39 #include "../utils/Utils.h"
40 #include "DataSource.h"
41 #include "DataSourceTransactor.h"
42 
44 
46 
47 std::unique_ptr<te::da::DataSet> te::da::DataSourceTransactor::getDataSet(
48  const std::string& name, const te::da::ObjectIdSet* oids,
49  te::common::TraverseType travType, bool connected,
50  const te::common::AccessPolicy /*accessPolicy*/)
51 {
52  assert(!name.empty());
53  assert(oids);
54  assert(oids->size() > 0);
55 
56  // ObjectIds restriction
57  Expression* exp = oids->getExpression();
58  assert(exp);
59 
60  // Where clause
61  Where* filter = new Where(exp);
62 
63  // All fields (?)
64  te::da::Fields* all = new te::da::Fields;
65  all->push_back(new te::da::Field("*"));
66 
67  // From the data set
68  FromItem* fromItem = new DataSetName(name);
69  From* from = new From;
70  from->push_back(fromItem);
71 
72  // The final Select
73  std::unique_ptr<Select> select(new Select(all, from, filter));
74 
75  std::unique_ptr<te::da::DataSet> result = query(select.get(), travType, connected);
76 
77  return result;
78 }
79 
80 std::unique_ptr<te::da::DataSetTypeCapabilities>
82 {
83  std::unique_ptr<te::da::DataSetTypeCapabilities> cap(new te::da::DataSetTypeCapabilities);
84 
85  cap->setSupportAll();
86 
87  return cap;
88 }
89 
91  const std::string& /*datasetName*/, const std::string& /*propName*/,
92  te::dt::Property* /*newProp*/)
93 {
94 }
95 
96 void te::da::DataSourceTransactor::update(const std::string &/*datasetName*/, te::da::DataSet* /*dataset*/, const std::vector< std::set<int> >& /*properties*/,
97  const std::vector<size_t>& /*ids*/)
98 {
99  throw te::da::Exception("Operation not implemented for this data source");
100 }
101 
102 bool te::da::DataSourceTransactor::isDataSetNameValid(const std::string& datasetName)
103 {
104  std::string invalidChar;
105  return te::da::IsValidName(datasetName, invalidChar);
106 }
107 
108 bool te::da::DataSourceTransactor::isPropertyNameValid(const std::string& propertyName)
109 {
110  std::string invalidChar;
111  return te::da::IsValidName(propertyName, invalidChar);
112 }
113 
115 {
116  throw te::da::Exception("Operation not implemented for this data source");
117 }
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
A class that informs what kind of constraint and index is supported by a given data source...
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
The Field class can be used to model an expression that takes part of the output items of a SELECT...
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
DataSourceTransactor()
Default constructor that can be called by subclasses.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
virtual std::unique_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)=0
It executes a query that may return some data using a generic query. A dataset can be connected or di...
virtual void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
It models a property definition.
Definition: Property.h:59
This is an abstract class that models a query expression.
virtual bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
virtual ~DataSourceTransactor()
Virtual destructor.
virtual std::unique_ptr< te::da::DataSetTypeCapabilities > getCapabilities(const std::string &name)
It gets capabilities about a data set.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::size_t size() const
It returns the object id set size.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
A class that can be used to model a filter expression that can be applied to a query.
Definition: Where.h:47
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
virtual std::string getGeometryTypeName(te::gm::GeomType type)
It gets the datasource geometry type name equivalent to terralib.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual void update(const std::string &datasetName, DataSet *dataset, const std::vector< std::size_t > &properties, const ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)=0
It updates the contents of a dataset for the set of data items.
TEDATAACCESSEXPORT bool IsValidName(const std::string &name, std::string &invalidChar)
It checks if the name is not valid as the existence of invalid characters, reserved words...
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)=0
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
Expression * getExpression() const
It returns the expression that can be used to retrieve the data set that contains the all indentified...
virtual bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.