All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../common/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 {
45 }
46 
48 {
49 }
50 
51 std::auto_ptr<te::da::DataSet> te::da::DataSourceTransactor::getDataSet(const std::string& name,
52  const te::da::ObjectIdSet* oids,
53  te::common::TraverseType travType,
54  bool connected,
55  const te::common::AccessPolicy accessPolicy)
56 {
57  assert(!name.empty());
58  assert(oids);
59  assert(oids->size() > 0);
60 
61  // ObjectIds restriction
62  Expression* exp = oids->getExpression();
63  assert(exp);
64 
65  // Where clause
66  Where* filter = new Where(exp);
67 
68  // All fields (?)
69  te::da::Fields* all = new te::da::Fields;
70  all->push_back(new te::da::Field("*"));
71 
72  // From the data set
73  FromItem* fromItem = new DataSetName(name);
74  From* from = new From;
75  from->push_back(fromItem);
76 
77  // The final Select
78  std::auto_ptr<Select> select(new Select(all, from, filter));
79 
80  std::auto_ptr<te::da::DataSet> result = query(select.get(), travType, connected);
81 
82  return result;
83 }
84 
85 std::auto_ptr<te::da::DataSetTypeCapabilities> te::da::DataSourceTransactor::getCapabilities(const std::string &name)
86 {
87  std::auto_ptr<te::da::DataSetTypeCapabilities> cap(new te::da::DataSetTypeCapabilities);
88 
89  cap->setSupportAll();
90 
91  return cap;
92 }
93 
94 void te::da::DataSourceTransactor::changePropertyDefinition(const std::string& datasetName, const std::string& propName, te::dt::Property* newProp)
95 {
96 }
97 
98 void te::da::DataSourceTransactor::update(const std::string &/*datasetName*/, te::da::DataSet* /*dataset*/, const std::vector< std::set<int> >& /*properties*/,
99  const std::vector<size_t>& /*ids*/)
100 {
101  throw te::da::Exception("Operation not implemented for this data source");
102 }
103 
104 bool te::da::DataSourceTransactor::isDataSetNameValid(const std::string& datasetName)
105 {
106  std::string invalidChar;
107  return te::da::IsValidName(datasetName, invalidChar);
108 }
109 
110 bool te::da::DataSourceTransactor::isPropertyNameValid(const std::string& propertyName)
111 {
112  std::string invalidChar;
113  return te::da::IsValidName(propertyName, invalidChar);
114 }
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...
Definition: Field.h:50
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 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.
Definition: Expression.h:47
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).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
virtual ~DataSourceTransactor()
Virtual destructor.
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 DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
A class that can be used to model a filter expression that can be applied to a query.
Definition: Where.h:47
virtual std::auto_ptr< te::da::DataSetTypeCapabilities > getCapabilities(const std::string &name)
It gets capabilities about a data set.
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
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
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...
Definition: Utils.cpp:934
virtual std::auto_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.