Nemiver  0.3
nmv-transaction.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset: 4; -*- */
2 
3 /*
4  *This file is part of the Nemiver Project.
5  *
6  *Nemiver is free software; you can redistribute
7  *it and/or modify it under the terms of
8  *the GNU General Public License as published by the
9  *Free Software Foundation; either version 2,
10  *or (at your option) any later version.
11  *
12  *Nemiver is distributed in the hope that it will
13  *be useful, but WITHOUT ANY WARRANTY;
14  *without even the implied warranty of
15  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *See the GNU General Public License for more details.
17  *
18  *You should have received a copy of the
19  *GNU General Public License along with Nemiver;
20  *see the file COPYING.
21  *If not, write to the Free Software Foundation,
22  *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  *
24  *See COPYRIGHT file copyright information.
25  */
26 #ifndef __NMV_TRANSACTION_H__
27 #define __NMV_TRANSACTION_H__
28 
31 
32 #include "nmv-ustring.h"
33 #include "nmv-object.h"
34 #include "nmv-connection.h"
35 #include "nmv-exception.h"
36 
37 namespace nemiver {
38 namespace common {
39 
40 struct TransactionPriv;
41 
50 {
51  friend struct TransactionPriv;
52  TransactionPriv *m_priv;
53  Transaction ();
54 
55 public:
56 
57  Transaction (Connection &a_con);
58  Transaction (const Transaction &);
59  Transaction& operator= (const Transaction &);
60  virtual ~Transaction ();
61  Connection& get_connection ();
62  bool begin (const common::UString &a_subtransaction_name="");
63  bool commit (const common::UString &a_subtransaction_name="");
64  bool is_commited ();
65  bool rollback ();
66  long long get_id ();
67  Glib::Mutex& get_mutex () const;
68 };//end class Transaction
69 
73 
74 //this class starts a transaction
75 //upon instanciation, and reverts
76 //the transaction if the transaction
77 //hasn't been commited by hand before
78 //the desctructor is called.
79 //This is a simple pattern to have exception safe
80 //based transaction code.
82 {
85  bool m_ignore;
86 
88  const common::UString &a_name ="generic-transaction",
89  bool a_ignore=false) :
90  m_trans (a_trans),
91  m_ignore (a_ignore)
92  {
93  if (m_ignore) {
94  return;
95  }
96  THROW_IF_FAIL (m_trans.begin (a_name));
97  m_is_started = true;
98  }
99 
100  void end (const common::UString& a_name="generic-transaction")
101  {
102  if (m_ignore) {
103  return;
104  }
105  THROW_IF_FAIL (m_trans.commit (a_name));
106  m_is_started = false;
107  }
108 
109  operator common::Transaction& ()
110  {
111  return m_trans;
112  }
113 
115  {
116  return m_trans;
117  }
118 
120  {
121  if (m_ignore) {
122  return;
123  }
124  if (m_is_started) {
126  "Failed to rollback transation");
127  m_is_started = false;
128  }
129  }
130 };//end TransactionAutoHelper
131 }//end namespace common
132 }//end namespace nemiver
133 
134 #endif //__NMV_TRANSACTION_H__
135 
nemiver::common::TransactionAutoHelper::end
void end(const common::UString &a_name="generic-transaction")
Definition: nmv-transaction.h:100
nemiver::common::TransactionAutoHelper::m_is_started
bool m_is_started
Definition: nmv-transaction.h:84
nemiver::common::Object
Definition: nmv-object.h:43
nemiver
Definition: nmv-address.h:31
nemiver::common::ObjectRef
Definition: nmv-safe-ptr-utils.h:45
nemiver::common::TransactionAutoHelper
Definition: nmv-transaction.h:81
nmv-ustring.h
NEMIVER_API
#define NEMIVER_API
Definition: nmv-api-macros.h:53
nemiver::common::Transaction::rollback
bool rollback()
nemiver::common::TransactionAutoHelper::get
common::Transaction & get()
Definition: nmv-transaction.h:114
nemiver::common::TransactionAutoHelper::m_ignore
bool m_ignore
Definition: nmv-transaction.h:85
nemiver::common::Connection
Definition: nmv-connection.h:49
nemiver::common::UString
Definition: nmv-ustring.h:45
ABORT_IF_FAIL2
#define ABORT_IF_FAIL2(a_cond, a_reason)
Definition: nmv-exception.h:89
nmv-connection.h
nemiver::common::TransactionSafePtr
common::SafePtr< Transaction, common::ObjectRef, common::ObjectUnref > TransactionSafePtr
Definition: nmv-transaction.h:72
nemiver::common::TransactionAutoHelper::m_trans
Transaction & m_trans
Definition: nmv-transaction.h:83
nemiver::common::Transaction::commit
bool commit(const common::UString &a_subtransaction_name="")
nemiver::common::TransactionAutoHelper::~TransactionAutoHelper
~TransactionAutoHelper()
Definition: nmv-transaction.h:119
nemiver::common::ObjectUnref
Definition: nmv-safe-ptr-utils.h:55
nemiver::common::TransactionAutoHelper::TransactionAutoHelper
TransactionAutoHelper(common::Transaction &a_trans, const common::UString &a_name="generic-transaction", bool a_ignore=false)
Definition: nmv-transaction.h:87
nemiver::common::Transaction::begin
bool begin(const common::UString &a_subtransaction_name="")
nemiver::common::Transaction
the application level persistence transaction class. abstracts a transaction several persistent objec...
Definition: nmv-transaction.h:49
nmv-object.h
nemiver::common::SafePtr
Definition: nmv-safe-ptr.h:71
THROW_IF_FAIL
#define THROW_IF_FAIL(a_cond)
Definition: nmv-exception.h:65
nmv-exception.h
common
Definition: nmv-proc-list-dialog.h:32