All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BatchExecutor.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/sqlite/BatchExecutor.cpp
22 
23  \brief Implementation of the BatchExecutor class for the TerraLib SQLite Data Access driver.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../dataaccess/datasource/ScopedTransaction.h"
29 #include "../dataaccess/query/Query.h"
30 #include "BatchExecutor.h"
31 #include "DataSource.h"
32 #include "DataSourceTransactor.h"
33 #include "SQLVisitor.h"
34 #include "Utils.h"
35 
37  : m_t(t)
38 {
39 }
40 
42 {
43  te::common::FreeContents(m_commands);
44 }
45 
47 {
48  std::auto_ptr<te::da::Query> qq(q);
49 
50  std::auto_ptr<std::string> sql(new std::string);
51 
52  SQLVisitor visitor(*(m_t->getDataSource()->getDialect()), *sql);
53  q->accept(visitor);
54 
55  m_commands.push_back(sql.release());
56 }
57 
59 {
61 
62  const std::size_t ncommands = m_commands.size();
63 
64  for(std::size_t i = 0; i < ncommands; ++i)
65  m_t->execute(*m_commands[i]);
66 
67  te::common::FreeContents(m_commands);
68  m_commands.clear();
69 
70  t.commit();
71 }
72 
73 void te::sqlite::BatchExecutor::execute(const std::string& uri, const std::map<std::string, std::string>& /*options*/)
74 {
76 
77  ExecuteScript(m_t->getDB(), uri.c_str());
78 
79  t.commit();
80 }
81 
82 void te::sqlite::BatchExecutor::execute(std::istream& istr, const std::map<std::string, std::string>& /*options*/)
83 {
85 
86  PerformCommands(m_t->getDB(), istr);
87 
88  t.commit();
89 }
90 
92 {
93  return m_t;
94 }
95 
96 void te::sqlite::BatchExecutor::add(std::string* sql)
97 {
98  m_commands.push_back(sql);
99 }
100 
A visitor for building an SQL statement using SQLite dialect.
An utility class to coordinate transactions.
~BatchExecutor()
Virtual destructor.
te::da::DataSourceTransactor * getTransactor() const
It returns a pointer to the underlying data source transactor.
BatchExecutor()
Constructor.
Definition: BatchExecutor.h:60
void commit()
It commits the transaction.
void PerformCommands(sqlite3 *db, std::istream &istr)
Definition: Utils.cpp:161
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
Utility functions for the TerraLib SQLite Data Access driver.
void add(te::da::Query *q)
It adds the given statement to the list of commands to be executed.
A visitor for building an SQL statement using SQLite dialect.
Definition: SQLVisitor.h:44
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
Implements the DataSource class for the SQLite Data Access Driver.
void ExecuteScript(sqlite3 *db, const char *fileName)
Definition: Utils.cpp:139
An implementation of DataSourceTransactor class for the TerraLib SQLite Data Access Driver...
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
Implementation of the BatchExecutor class for the TerraLib SQLite Data Access driver.
A Query is independent from the data source language/dialect.
Definition: Query.h:46