All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSourceTransactor.cpp
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.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/ObjectIdSet.h"
31 #include "../query/DataSetName.h"
32 #include "../query/Field.h"
33 #include "../query/Fields.h"
34 #include "../query/Select.h"
35 #include "../query/Where.h"
36 #include "../utils/Utils.h"
37 #include "../Exception.h"
38 #include "DataSource.h"
39 #include "DataSourceTransactor.h"
40 
42 {
43 }
44 
46 {
47 }
48 
49 std::auto_ptr<te::da::DataSet> te::da::DataSourceTransactor::getDataSet(const std::string& name,
50  const te::da::ObjectIdSet* oids,
51  te::common::TraverseType travType,
52  bool connected,
53  const te::common::AccessPolicy accessPolicy)
54 {
55  assert(!name.empty());
56  assert(oids);
57  assert(oids->size() > 0);
58 
59  // ObjectIds restriction
60  Expression* exp = oids->getExpression();
61  assert(exp);
62 
63  // Where clause
64  Where* filter = new Where(exp);
65 
66  // All fields (?)
67  te::da::Fields* all = new te::da::Fields;
68  all->push_back(new te::da::Field("*"));
69 
70  // From the data set
71  FromItem* fromItem = new DataSetName(name);
72  From* from = new From;
73  from->push_back(fromItem);
74 
75  // The final Select
76  std::auto_ptr<Select> select(new Select(all, from, filter));
77 
78  std::auto_ptr<te::da::DataSet> result = query(select.get(), travType, connected);
79 
80  return result;
81 }
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 class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
The Field class can be used to model an expression that takes part of the output items of a SELECT...
Definition: Field.h:50
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
Expression * getExpression() const
It returns the expression that can be used to retrieve the data set that contains the all indentified...
Definition: ObjectIdSet.cpp:77
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.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
DataSourceTransactor()
Default constructor that can be called by subclasses.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
std::size_t size() const
It returns the object id set size.
virtual ~DataSourceTransactor()
Virtual destructor.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
This is an abstract class that models a query expression.
Definition: Expression.h:47
A class that can be used to model a filter expression that can be applied to a query.
Definition: Where.h:47
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...