Akonadi

dbdeadlockcatcher.h
1 /*
2  SPDX-FileCopyrightText: 2019 David Faure <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "dbexception.h"
10 
11 namespace Akonadi
12 {
13 namespace 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 {
22 public:
23  template<typename Func> explicit DbDeadlockCatcher(Func &&func)
24  {
25  callFunc(func, 0);
26  }
27 
28 private:
29  static const int MaxRecursion = 5;
30  template<typename Func> void callFunc(Func &&func, int recursionCounter)
31  {
32  try {
33  func();
34  } catch (const DbDeadlockException &) {
35  if (recursionCounter == MaxRecursion) {
36  throw;
37  } else {
38  callFunc(func, ++recursionCounter); // recurse
39  }
40  }
41  }
42 };
43 
44 } // namespace Server
45 } // namespace Akonadi
46 
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-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.