Akonadi

transactionhandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "transactionhandler.h"
8 #include "connection.h"
9 #include "storage/datastore.h"
10 
11 using namespace Akonadi;
12 using namespace Akonadi::Server;
13 
14 TransactionHandler::TransactionHandler(AkonadiServer &akonadi)
15  : Handler(akonadi)
16 {
17 }
18 
20 {
21  const auto &cmd = Protocol::cmdCast<Protocol::TransactionCommand>(m_command);
22 
23  DataStore *store = connection()->storageBackend();
24 
25  switch (cmd.mode()) {
26  case Protocol::TransactionCommand::Invalid:
27  return failureResponse("Invalid operation");
28  case Protocol::TransactionCommand::Begin:
29  if (!store->beginTransaction(QStringLiteral("CLIENT TRANSACTION"))) {
30  return failureResponse("Unable to begin transaction.");
31  }
32  break;
33  case Protocol::TransactionCommand::Rollback:
34  if (!store->inTransaction()) {
35  return failureResponse("There is no transaction in progress.");
36  }
37  if (!store->rollbackTransaction()) {
38  return failureResponse("Unable to roll back transaction.");
39  }
40  break;
41  case Protocol::TransactionCommand::Commit:
42  if (!store->inTransaction()) {
43  return failureResponse("There is no transaction in progress.");
44  }
45  if (!store->commitTransaction()) {
46  return failureResponse("Unable to commit transaction.");
47  }
48  break;
49  }
50 
51  return successResponse<Protocol::TransactionResponse>();
52 }
This class handles all the database access.
Definition: datastore.h:94
bool inTransaction() const
Returns true if there is a transaction in progress.
Definition: datastore.cpp:1451
virtual bool beginTransaction(const QString &name)
Begins a transaction.
Definition: datastore.cpp:1350
virtual bool rollbackTransaction()
Reverts all changes within the current transaction.
Definition: datastore.cpp:1393
virtual bool commitTransaction()
Commits all changes within the current transaction and emits all collected notification signals.
Definition: datastore.cpp:1415
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:39
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:49 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.