Akonadi

transaction.h
1 /*
2  SPDX-FileCopyrightText: 2006 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QString>
10 
11 namespace Akonadi
12 {
13 namespace Server
14 {
15 class DataStore;
16 
17 /**
18  Helper class for DataStore transaction handling.
19  Works similar to QMutexLocker.
20  Supports command-local and session-global transactions.
21 */
23 {
24 public:
25  /**
26  Starts a new transaction. The transaction will automatically rolled back
27  on destruction if it hasn't been committed explicitly before.
28  If there is already a global transaction in progress, this one will be used
29  instead of creating a new one.
30  @param db The corresponding DataStore. You must not delete @p db during
31  the lifetime of a Transaction object.
32  @param name A name of the transaction. Used for debugging.
33  @param beginTransaction if false, the transaction won't be started, until begin is explicitly called. The default is to begin the transaction right away.
34  */
35  explicit Transaction(DataStore *db, const QString &name, bool beginTransaction = true);
36 
37  /**
38  Rolls back the transaction if it hasn't been committed explicitly.
39  This also happens if a global transaction is used.
40  */
41  ~Transaction();
42 
43  /**
44  Commits the transaction. Returns true on success.
45  If a global transaction is used, nothing happens, global transactions have
46  to be committed explicitly.
47  */
48  bool commit();
49 
50  void begin();
51 
52 private:
53  Q_DISABLE_COPY(Transaction)
54  DataStore *mDb;
55  QString mName;
56  bool mCommitted;
57 };
58 
59 } // namespace Server
60 } // namespace Akonadi
61 
This class handles all the database access.
Definition: datastore.h:94
Helper class for DataStore transaction handling.
Definition: transaction.h:22
~Transaction()
Rolls back the transaction if it hasn't been committed explicitly.
Definition: transaction.cpp:22
Transaction(DataStore *db, const QString &name, bool beginTransaction=true)
Starts a new transaction.
Definition: transaction.cpp:12
bool commit()
Commits the transaction.
Definition: transaction.cpp:29
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.