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 
19 {
20  const auto &cmd = Protocol::cmdCast<Protocol::TransactionCommand>(m_command);
21 
22  DataStore *store = connection()->storageBackend();
23 
24  switch (cmd.mode()) {
25  case Protocol::TransactionCommand::Invalid:
26  return failureResponse("Invalid operation");
27  case Protocol::TransactionCommand::Begin:
28  if (!store->beginTransaction(QStringLiteral("CLIENT TRANSACTION"))) {
29  return failureResponse("Unable to begin transaction.");
30  }
31  break;
32  case Protocol::TransactionCommand::Rollback:
33  if (!store->inTransaction()) {
34  return failureResponse("There is no transaction in progress.");
35  }
36  if (!store->rollbackTransaction()) {
37  return failureResponse("Unable to roll back transaction.");
38  }
39  break;
40  case Protocol::TransactionCommand::Commit:
41  if (!store->inTransaction()) {
42  return failureResponse("There is no transaction in progress.");
43  }
44  if (!store->commitTransaction()) {
45  return failureResponse("Unable to commit transaction.");
46  }
47  break;
48  }
49 
50  return successResponse<Protocol::TransactionResponse>();
51 }
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:35
Helper integration between Akonadi and Qt.
This class handles all the database access.
Definition: datastore.h:95
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 07:17:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.