File indexing completed on 2024-06-23 05:07:03
0001 /* 0002 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "transactionhandler.h" 0008 #include "connection.h" 0009 #include "storage/datastore.h" 0010 0011 using namespace Akonadi; 0012 using namespace Akonadi::Server; 0013 0014 TransactionHandler::TransactionHandler(AkonadiServer &akonadi) 0015 : Handler(akonadi) 0016 { 0017 } 0018 0019 bool TransactionHandler::parseStream() 0020 { 0021 const auto &cmd = Protocol::cmdCast<Protocol::TransactionCommand>(m_command); 0022 0023 DataStore *store = connection()->storageBackend(); 0024 0025 switch (cmd.mode()) { 0026 case Protocol::TransactionCommand::Invalid: 0027 return failureResponse("Invalid operation"); 0028 case Protocol::TransactionCommand::Begin: 0029 if (!store->beginTransaction(QStringLiteral("CLIENT TRANSACTION"))) { 0030 return failureResponse("Unable to begin transaction."); 0031 } 0032 break; 0033 case Protocol::TransactionCommand::Rollback: 0034 if (!store->inTransaction()) { 0035 return failureResponse("There is no transaction in progress."); 0036 } 0037 if (!store->rollbackTransaction()) { 0038 return failureResponse("Unable to roll back transaction."); 0039 } 0040 break; 0041 case Protocol::TransactionCommand::Commit: 0042 if (!store->inTransaction()) { 0043 return failureResponse("There is no transaction in progress."); 0044 } 0045 if (!store->commitTransaction()) { 0046 return failureResponse("Unable to commit transaction."); 0047 } 0048 break; 0049 } 0050 0051 return successResponse<Protocol::TransactionResponse>(); 0052 }