kexi

transaction.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXIDB_TRANSACTION_H
00021 #define KEXIDB_TRANSACTION_H
00022 
00023 #include <qguardedptr.h>
00024 
00025 #include <kexidb/kexidb_export.h>
00026 
00027 namespace KexiDB {
00028 
00029 class Connection;
00030 
00035 class KEXI_DB_EXPORT TransactionData
00036 {
00037     public:
00038         TransactionData(Connection *conn);
00039         ~TransactionData();
00040 
00041         //helper for debugging
00042         static int globalcount;
00043         //helper for debugging
00044         static int globalCount();
00045         
00046         Connection *m_conn;
00047         bool m_active : 1;
00048         uint refcount;
00049 };
00050 
00052 
00059 class KEXI_DB_EXPORT Transaction : public QObject
00060 {
00061     public:
00064         Transaction();
00065         
00067         Transaction( const Transaction& trans );
00068         
00069         virtual ~Transaction();
00070 
00071         Transaction& operator=(const Transaction& trans);
00072 
00073         bool operator==(const Transaction& trans ) const;
00074         
00075         Connection* connection() const;
00076         
00079         bool active() const;
00080         
00082         bool isNull() const;
00083         
00085         static const Transaction null;
00086 
00087         //helper for debugging
00088         static int globalCount();
00089         static int globalcount;
00090     protected:
00091         
00092         TransactionData *m_data;
00093         
00094     friend class Connection;
00095 };
00096 
00098 
00119 class KEXI_DB_EXPORT TransactionGuard
00120 {
00121     public:
00124         TransactionGuard( Connection& conn );
00125         
00127         TransactionGuard( const Transaction& trans );
00128 
00131         TransactionGuard();
00132 
00134         ~TransactionGuard();
00135 
00138         void setTransaction( const Transaction& trans ) { m_trans = trans; }
00139 
00142         bool commit();
00143 
00145         void doNothing();
00146 
00148         const Transaction transaction() const { return m_trans; }
00149 
00150     protected:
00151         Transaction m_trans;
00152         bool m_doNothing : 1;
00153 };
00154 
00155 } //namespace KexiDB
00156 
00157 #endif
00158 
00159 
KDE Home | KDE Accessibility Home | Description of Access Keys