KDb

KDbTransaction.h
1/* This file is part of the KDE project
2 Copyright (C) 2003-2017 Jarosław Staniek <staniek@kde.org>
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 KDB_TRANSACTION_H
21#define KDB_TRANSACTION_H
22
23#include "config-kdb.h"
24#include "kdb_export.h"
25
26#include <QtGlobal>
27
28class KDbConnection;
30
31/**
32 * @brief This class encapsulates a single database transaction
33 *
34 * The KDbTransaction handle abstracts a database transaction for given database connection.
35 * Transaction objects are value-based, implicitly shared.
36 *
37 * Lifetime of the transaction object is closely related to a KDbConnection object.
38 * Deleting the either instance does not commit or rollback the actual transaction.
39 * Use KDbTransactionGuard for automatic commits or rolls back.
40 *
41 * @see KDbConnection::beginTransaction()
42 */
43class KDB_EXPORT KDbTransaction
44{
45public:
46 /**
47 * @brief Constructs a null transaction.
48 *
49 * @note It can be initialized only by KDbConnection.
50 */
52
53 /**
54 * @brief Copy constructor
55 */
56 KDbTransaction(const KDbTransaction& trans);
57
59
60 //! Options for commiting and rolling back transactions
61 //! @see KDbConnection::beginTransaction() KDbConnection::rollbackTransaction()
62 //! @see KDbTransactionGuard::commit() KDbTransactionGuard::rollback()
63 enum class CommitOption {
64 None = 0,
65 IgnoreInactive = 1 //!< Do not return error for inactive or null transactions when
66 //!< requesting commit or rollback
67 };
68 Q_DECLARE_FLAGS(CommitOptions, CommitOption)
69
70 KDbTransaction& operator=(const KDbTransaction& trans);
71
72 /**
73 * @brief Returns @c true if this transaction is equal to @a other; otherwise returns @c false
74 *
75 * Two transactions are equal if they encapsulate the same physical transaction,
76 * i.e. copy constructor or assignment operator was used.
77 * Two null transaction objects are equal.
78 */
79 bool operator==(const KDbTransaction& other) const;
80
81 //! @return @c true if this transaction is not equal to @a other; otherwise returns @c false.
82 //! @since 3.1
83 inline bool operator!=(const KDbTransaction &other) const { return !operator==(other); }
84
85 /**
86 * @brief Returns database connection for which the transaction belongs.
87 *
88 * @c nullptr is returned for null transactions.
89 */
90 KDbConnection* connection();
91
92 //! @overload
93 //! @since 3.1
94 const KDbConnection* connection() const;
95
96 /**
97 * @brief Returns @c true if transaction is active (i.e. started)
98 *
99 * @return @c false also if transaction is uninitialised (null) or not started.
100 * @see KDbConnection::beginTransaction()
101 * @since 3.1
102 */
103 bool isActive() const;
104
105 /**
106 * @brief Returns @c true if this transaction is null.
107 *
108 * Null implies !isActive().
109 */
110 bool isNull() const;
111
112#ifdef KDB_TRANSACTIONS_DEBUG
113 //! Helper for debugging, returns value of global transaction data reference counter
114 static int globalCount();
115#endif
116
117protected:
118 KDbTransactionData *m_data;
119
120 friend class KDbConnection;
121};
122
123Q_DECLARE_OPERATORS_FOR_FLAGS(KDbTransaction::CommitOptions)
124
125#endif
Provides database connection, allowing queries and data modification.
Internal prototype for storing transaction handle for KDbTransaction object.
This class encapsulates a single database transaction.
bool operator!=(const KDbTransaction &other) const
CommitOption
Options for commiting and rolling back transactions.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.