1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2010-10-12
7  * Description : Core database convenience object for grouping operations
8  *
9  * Copyright (C) 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_CORE_DB_OPERATION_GROUP_H
25 #define DIGIKAM_CORE_DB_OPERATION_GROUP_H
26 
27 // Qt includes
28 
29 #include <QVariant>
30 
31 // Local includes
32 
33 #include "digikam_export.h"
34 
35 namespace Digikam
36 {
37 
38 class CoreDbAccess;
39 
40 /**
41  * When you intend to execute a number of write operations to the database,
42  * group them while holding a CoreDbOperationGroup.
43  * For some database systems (SQLite), keeping a transaction across write operations
44  * occurring in short time results in enormous speedup (800x).
45  * For system that do not need this optimization, this class is a no-op.
46  */
47 class DIGIKAM_DATABASE_EXPORT CoreDbOperationGroup
48 {
49 public:
50 
51     /**
52      * Retrieve a CoreDbAccess object each time when constructing and destructing.
53      */
54     CoreDbOperationGroup();
55 
56     /**
57      * Use an existing CoreDbAccess object, which must live as long as this object exists.
58      */
59     explicit CoreDbOperationGroup(CoreDbAccess* const access);
60     ~CoreDbOperationGroup();
61 
62     /**
63      * This will - if a transaction is held - commit the transaction and acquire a new one.
64      * This may improve concurrent access.
65      */
66     void lift();
67 
68     void setMaximumTime(int msecs);
69 
70     /**
71      * Resets to 0 the time used by allowLift()
72      */
73     void resetTime();
74 
75     /**
76      * Allows to lift(). The transaction will be lifted if the time set by setMaximumTime()
77      * has expired.
78      */
79     void allowLift();
80 
81 private:
82 
83     // Disable
84     CoreDbOperationGroup(const CoreDbOperationGroup&)            = delete;
85     CoreDbOperationGroup& operator=(const CoreDbOperationGroup&) = delete;
86 
87     class Private;
88     Private* const d;
89 };
90 
91 } // namespace Digikam
92 
93 #endif // DIGIKAM_CORE_DB_OPERATION_GROUP_H
94