File indexing completed on 2025-01-05 03:53:59

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-10-12
0007  * Description : Core database convenience object for grouping operations
0008  *
0009  * SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_CORE_DB_OPERATION_GROUP_H
0016 #define DIGIKAM_CORE_DB_OPERATION_GROUP_H
0017 
0018 // Qt includes
0019 
0020 #include <QVariant>
0021 
0022 // Local includes
0023 
0024 #include "digikam_export.h"
0025 
0026 namespace Digikam
0027 {
0028 
0029 class CoreDbAccess;
0030 
0031 /**
0032  * When you intend to execute a number of write operations to the database,
0033  * group them while holding a CoreDbOperationGroup.
0034  * For some database systems (SQLite), keeping a transaction across write operations
0035  * occurring in short time results in enormous speedup (800x).
0036  * For system that do not need this optimization, this class is a no-op.
0037  */
0038 class DIGIKAM_DATABASE_EXPORT CoreDbOperationGroup
0039 {
0040 public:
0041 
0042     /**
0043      * Retrieve a CoreDbAccess object each time when constructing and destructing.
0044      */
0045     CoreDbOperationGroup();
0046 
0047     /**
0048      * Use an existing CoreDbAccess object, which must live as long as this object exists.
0049      */
0050     explicit CoreDbOperationGroup(CoreDbAccess* const access);
0051     ~CoreDbOperationGroup();
0052 
0053     /**
0054      * This will - if a transaction is held - commit the transaction and acquire a new one.
0055      * This may improve concurrent access.
0056      */
0057     void lift();
0058 
0059     void setMaximumTime(int msecs);
0060 
0061     /**
0062      * Resets to 0 the time used by allowLift()
0063      */
0064     void resetTime();
0065 
0066     /**
0067      * Allows to lift(). The transaction will be lifted if the time set by setMaximumTime()
0068      * has expired.
0069      */
0070     void allowLift();
0071 
0072 private:
0073 
0074     // Disable
0075     CoreDbOperationGroup(const CoreDbOperationGroup&)            = delete;
0076     CoreDbOperationGroup& operator=(const CoreDbOperationGroup&) = delete;
0077 
0078     class Private;
0079     Private* const d;
0080 };
0081 
0082 } // namespace Digikam
0083 
0084 #endif // DIGIKAM_CORE_DB_OPERATION_GROUP_H