ScopedTransaction.h
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.h
22 
23  \brief An utitily class to coordinate transactions.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_SCOPEDTRANSACTION_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_SCOPEDTRANSACTION_H
28 
29 // TerraLib
30 #include "../Config.h"
31 
32 // Boost
33 #include <boost/noncopyable.hpp>
34 
35 namespace te
36 {
37  namespace da
38  {
39 // Forward declarations
40  class DataSourceTransactor;
41 
42  /*!
43  \class ScopedTransaction
44 
45  \brief An utility class to coordinate transactions.
46 
47  This class can be used to create an object that
48  automatically rollback a transaction when it goes out of scope.
49 
50  When the client has finished performing operations
51  it must explicitly call the commit method. This will
52  inform ScopedTransaction to not rollback when it goes out of scope.
53 
54  \sa DataSourceTransactor
55  */
56  class TEDATAACCESSEXPORT ScopedTransaction : public boost::noncopyable
57  {
58  public:
59 
60  /*!
61  \brief Constructor.
62 
63  \param transactor The transactor that will be used to initiate a transaction.
64  */
66 
67  /*! \brief Destructor. */
69 
70  /*!
71  \brief It commits the transaction.
72 
73  \exception It throws an exception if something goes wrong during transaction commitment.
74  */
75  void commit();
76 
77  private:
78 
79  te::da::DataSourceTransactor& m_t; //!< A reference to the underlying transactor.
80  bool m_rollback; //!< A flag that indicates if the transaction may be aborted at the end.
81  };
82 
83  } // end namespace da
84 } // end namespace te
85 
86 #endif // __TERRALIB_DATAACCESS_INTERNAL_SCOPEDTRANSACTION_H
An utility class to coordinate transactions.
URI C++ Library.
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.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97