Akonadi

dbdeadlockcatcher.h
1/*
2 SPDX-FileCopyrightText: 2019 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "dbexception.h"
10
11namespace Akonadi
12{
13namespace Server
14{
15/**
16 This class catches DbDeadlockException (as emitted by QueryBuilder)
17 and retries execution of the method when it happens, as required by
18 SQL databases.
19*/
21{
22public:
23 template<typename Func>
24 explicit DbDeadlockCatcher(Func &&func)
25 {
26 callFunc(func, 0);
27 }
28
29private:
30 static const int MaxRecursion = 5;
31 template<typename Func>
32 void callFunc(Func &&func, int recursionCounter)
33 {
34 try {
35 func();
36 } catch (const DbDeadlockException &) {
37 if (recursionCounter == MaxRecursion) {
38 throw;
39 } else {
40 callFunc(func, ++recursionCounter); // recurse
41 }
42 }
43 }
44};
45
46} // namespace Server
47} // namespace Akonadi
This class catches DbDeadlockException (as emitted by QueryBuilder) and retries execution of the meth...
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.