Akonadi

transactionhandler.cpp
1 /*
2  Copyright (c) 2006 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "transactionhandler.h"
21 #include "connection.h"
22 #include "storage/datastore.h"
23 
24 using namespace Akonadi;
25 using namespace Akonadi::Server;
26 
27 TransactionHandler::TransactionHandler(AkonadiServer &akonadi)
28  : Handler(akonadi)
29 {}
30 
32 {
33  const auto &cmd = Protocol::cmdCast<Protocol::TransactionCommand>(m_command);
34 
35  DataStore *store = connection()->storageBackend();
36 
37  switch (cmd.mode()) {
38  case Protocol::TransactionCommand::Invalid:
39  return failureResponse("Invalid operation");
40  case Protocol::TransactionCommand::Begin:
41  if (!store->beginTransaction(QStringLiteral("CLIENT TRANSACTION"))) {
42  return failureResponse("Unable to begin transaction.");
43  }
44  break;
45  case Protocol::TransactionCommand::Rollback:
46  if (!store->inTransaction()) {
47  return failureResponse("There is no transaction in progress.");
48  }
49  if (!store->rollbackTransaction()) {
50  return failureResponse("Unable to roll back transaction.");
51  }
52  break;
53  case Protocol::TransactionCommand::Commit:
54  if (!store->inTransaction()) {
55  return failureResponse("There is no transaction in progress.");
56  }
57  if (!store->commitTransaction()) {
58  return failureResponse("Unable to commit transaction.");
59  }
60  break;
61  }
62 
63  return successResponse<Protocol::TransactionResponse>();
64 }
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:48
Helper integration between Akonadi and Qt.
This class handles all the database access.
Definition: datastore.h:108
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jun 6 2020 23:09:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.