Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDatabaseTransactionLock Class Reference

#include <KisDatabaseTransactionLock.h>

+ Inheritance diagram for KisDatabaseTransactionLock:

Public Types

using BaseClass = KisAdaptedLock<detail::KisDatabaseTransactionLockAdapter>
 

Public Member Functions

void rollback ()
 
- Public Member Functions inherited from KisAdaptedLock< detail::KisDatabaseTransactionLockAdapter >
 KisAdaptedLock (KisAdaptedLock &&rhs)
 
 KisAdaptedLock (Object object)
 
 KisAdaptedLock (Object object, std::adopt_lock_t t)
 
 KisAdaptedLock (Object object, std::defer_lock_t t)
 
 KisAdaptedLock (Object object, std::try_to_lock_t t)
 
KisAdaptedLockoperator= (KisAdaptedLock &&rhs)
 

Additional Inherited Members

- Protected Member Functions inherited from detail::KisDatabaseTransactionLockAdapter
void commit ()
 
 KisDatabaseTransactionLockAdapter (QSqlDatabase database)
 
void lock ()
 
void unlock ()
 

Detailed Description

A RAII-style class for managing transactions over a database.

When the lock is created (and locked) a transaction is started. If the lock is destroyed before the commit() is explicitly called, then the transaction is rolled back.

To successfully finish the transaction the user should explicitly defuse the lock by calling commit() method.

Usage:

 \code{.cpp}

 /// Start the transaction

 KisDatabaseTransactionLock transactionLock(database);

 QSqlQuery q(sql);
 if (!q.exec()) {

     /// on leaving the scope transactionLock will automatically
     /// rollback the transaction

     return false;
 }

 /// explicitly commit the transaction when we know
 /// everything is fine

 transactionLock.commit();

 \endcode

NOTE:

As a rule of thumb, always wrap the actions performing multiple database-modifying steps into a transaction. It will perform much (~10 times) faster in SQLite, because otherwise SQLite will implicitly wrap every single action into its own transaction and it will be slow.

Definition at line 77 of file KisDatabaseTransactionLock.h.

Member Typedef Documentation

◆ BaseClass

Member Function Documentation

◆ rollback()

void KisDatabaseTransactionLock::rollback ( )
inline

The documentation for this class was generated from the following file: