kexi

transaction.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KEXIDB_TRANSACTION_H
21#define KEXIDB_TRANSACTION_H
22
23#include <tqguardedptr.h>
24
25#include <kexidb/kexidb_export.h>
26
27namespace KexiDB {
28
29class Connection;
30
35class KEXI_DB_EXPORT TransactionData
36{
37 public:
38 TransactionData(Connection *conn);
39 ~TransactionData();
40
41 //helper for debugging
42 static int globalcount;
43 //helper for debugging
44 static int globalCount();
45
46 Connection *m_conn;
47 bool m_active : 1;
48 uint refcount;
49};
50
52
59class KEXI_DB_EXPORT Transaction : public TQObject
60{
61 public:
65
67 Transaction( const Transaction& trans );
68
69 virtual ~Transaction();
70
71 Transaction& operator=(const Transaction& trans);
72
73 bool operator==(const Transaction& trans ) const;
74
75 Connection* connection() const;
76
79 bool active() const;
80
82 bool isNull() const;
83
85 static const Transaction null;
86
87 //helper for debugging
88 static int globalCount();
89 static int globalcount;
90 protected:
91
92 TransactionData *m_data;
93
94 friend class Connection;
95};
96
98
119class KEXI_DB_EXPORT TransactionGuard
120{
121 public:
125
127 TransactionGuard( const Transaction& trans );
128
132
135
138 void setTransaction( const Transaction& trans ) { m_trans = trans; }
139
142 bool commit();
143
145 void doNothing();
146
148 const Transaction transaction() const { return m_trans; }
149
150 protected:
151 Transaction m_trans;
152 bool m_doNothing : 1;
153};
154
155} //namespace KexiDB
156
157#endif
158
159
Provides database connection, allowing queries and data modification.
Definition connection.h:62
const Transaction transaction() const
void setTransaction(const Transaction &trans)
TransactionGuard(Connection &conn)
This class encapsulates transaction handle.
Definition transaction.h:60
static const Transaction null
Definition transaction.h:85
High-level database connectivity library with database backend drivers.