Akonadi

transactionhandler.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
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
11using namespace Akonadi;
12using namespace Akonadi::Server;
13
14TransactionHandler::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:95
virtual bool beginTransaction(const QString &name)
Begins a transaction.
virtual bool rollbackTransaction()
Reverts all changes within the current transaction.
bool inTransaction() const
Returns true if there is a transaction in progress.
virtual bool commitTransaction()
Commits all changes within the current transaction and emits all collected notification signals.
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition handler.h:32
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:54:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.