Akonadi::TransactionSequence Class

class Akonadi::TransactionSequence

Base class for jobs that need to run a sequence of sub-jobs in a transaction. More...

Header: #include <Akonadi/TransactionSequence>
CMake: find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore)
Inherits: Akonadi::Job
Inherited By:

Akonadi::SpecialCollectionsRequestJob

Public Functions

TransactionSequence(QObject *parent = nullptr)
virtual ~TransactionSequence() override
void commit()
void rollback()
void setAutomaticCommittingEnabled(bool enable)
void setIgnoreJobFailure(KJob *job)

Detailed Description

As soon as the first subjob is added, the transaction is started. As soon as the last subjob has successfully finished, the transaction is committed. If any subjob fails, the transaction is rolled back.

Alternatively, a TransactionSequence object can be used as a parent object for a set of jobs to achieve the same behaviour without subclassing.

Example:

 // Delete a couple of items inside a transaction
 Akonadi::TransactionSequence *transaction = new Akonadi::TransactionSequence;
 connect(transaction, &KJob::result, this, &MyClass::transactionFinished);

 const Akonadi::Item::List items = ...

 for( const Akonadi::Item &item : items ) {
   new Akonadi::ItemDeleteJob( item, transaction );
 }

 ...

 MyClass::transactionFinished( KJob *job )
 {
   if ( job->error() )
     qDebug() << "Error occurred";
   else
     qDebug() << "Items deleted successfully";
 }

Author: Volker Krause <vkrause@kde.org>

Member Function Documentation

[explicit] TransactionSequence::TransactionSequence(QObject *parent = nullptr)

Creates a new transaction sequence.

parent The parent object.

[override virtual noexcept] TransactionSequence::~TransactionSequence()

Destroys the transaction sequence.

void TransactionSequence::commit()

Commits the transaction as soon as all pending sub-jobs finished successfully.

void TransactionSequence::rollback()

Rolls back the current transaction as soon as possible. You only need to call this method when you want to roll back due to external reasons (e.g. user cancellation), the transaction is automatically rolled back if one of its subjobs fails.

void TransactionSequence::setAutomaticCommittingEnabled(bool enable)

Disable automatic committing. Use this when you want to add jobs to this sequence after execution has been started, usually that is outside of the constructor or the method that creates this transaction sequence.

Note: Calling this method after execution of this job has been started has no effect. enable \ true to enable autocommitting (default), \ false to disable it

void TransactionSequence::setIgnoreJobFailure(KJob *job)

Sets which job of the sequence might fail without rolling back the complete transaction. job a job to ignore errors from