All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ScopedTransaction.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/ScopedTransaction.cpp
22 
23  \brief An utility class to coordinate transactions.
24 */
25 
26 // TerraLib
27 #include "DataSourceTransactor.h"
28 #include "ScopedTransaction.h"
29 
31  : m_t(transactor),
32  m_rollback(true)
33 {
34  if(m_t.isInTransaction())
35  m_rollback = false;
36 
37  m_t.begin();
38 }
39 
41 {
42  if(m_rollback)
43  m_t.rollBack();
44 }
45 
47 {
48  if(!m_rollback)
49  return;
50 
51  m_t.commit();
52 
53  m_rollback = false;
54 }
ScopedTransaction(te::da::DataSourceTransactor &transactor)
Constructor.
void commit()
It commits the transaction.
virtual void begin()=0
It starts a new transaction.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
An utitily class to coordinate transactions.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
te::da::DataSourceTransactor & m_t
A reference to the underlying transactor.
bool m_rollback
A flag that indicates if the transaction may be aborted at the end.
virtual bool isInTransaction() const =0
It returns true if a transaction is in progress, otherwise, it returns false.