Audacity 3.2.0
Classes | Public Member Functions | Private Attributes | List of all members
TransactionScope Class Reference

RAII for a database transaction, possibly nested. More...

#include <TransactionScope.h>

Collaboration diagram for TransactionScope:
[legend]

Classes

struct  Factory
 Type of function supplying implementation of steps. More...
 

Public Member Functions

 TransactionScope (AudacityProject &project, const char *name)
 Construct from a project. More...
 
 ~TransactionScope ()
 Rollback transaction if it was not yet committed. More...
 
bool Commit ()
 Commit the transaction. More...
 

Private Attributes

std::unique_ptr< TransactionScopeImplmpImpl
 
bool mInTrans
 
wxString mName
 

Detailed Description

RAII for a database transaction, possibly nested.

Make a savepoint (a transaction, possibly nested) with the given name; roll it back at destruction time, unless an explicit Commit() happened first. Commit() must not be called again after one successful call. An exception is thrown from the constructor if the transaction cannot open.

Definition at line 27 of file TransactionScope.h.

Constructor & Destructor Documentation

◆ TransactionScope()

TransactionScope::TransactionScope ( AudacityProject project,
const char *  name 
)

Construct from a project.

If no implementation factory is installed, or the factory returns null, then this object does nothing

Definition at line 17 of file TransactionScope.cpp.

19: mName(name)
20{
22 if (!mpImpl)
23 return;
24
25 mInTrans = mpImpl->TransactionStart(mName);
26 if ( !mInTrans )
27 // To do, improve the message
29 XO("Database error. Sorry, but we don't have more details."),
30 XO("Warning"),
31 "Error:_Disk_full_or_not_writable"
32 );
33}
@ Internal
Indicates internal failure from Audacity.
XO("Cut/Copy/Paste")
wxString name
Definition: TagsEditor.cpp:166
const auto project
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
A MessageBoxException that shows a given, unvarying string.
std::unique_ptr< TransactionScopeImpl > mpImpl

References GlobalHook< Factory, std::unique_ptr< TransactionScopeImpl >(AudacityProject &) >::Call(), Internal, mInTrans, mName, mpImpl, project, and XO().

Here is the call graph for this function:

◆ ~TransactionScope()

TransactionScope::~TransactionScope ( )

Rollback transaction if it was not yet committed.

Definition at line 35 of file TransactionScope.cpp.

36{
37 if (mpImpl && mInTrans)
38 {
39 if (!mpImpl->TransactionRollback(mName))
40 {
41 // Do not throw from a destructor!
42 // This has to be a no-fail cleanup that does the best that it can.
43 wxLogMessage("Transaction active at scope destruction");
44 }
45 }
46}

References mInTrans, mName, and mpImpl.

Member Function Documentation

◆ Commit()

bool TransactionScope::Commit ( )

Commit the transaction.

Definition at line 48 of file TransactionScope.cpp.

49{
50 if (mpImpl && !mInTrans) {
51 wxLogMessage("No active transaction to commit");
52 // Misuse of this class
54 }
55
56 // If commit is unsuccessful, consider us still in a commit, for the dtor
57 // later
58 mInTrans = !mpImpl->TransactionCommit(mName);
59
60 return !mInTrans;
61}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.

References mInTrans, mName, mpImpl, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by EffectBase::DoEffect(), and ProjectFileIO::WriteDoc().

Here is the caller graph for this function:

Member Data Documentation

◆ mInTrans

bool TransactionScope::mInTrans
private

Definition at line 49 of file TransactionScope.h.

Referenced by Commit(), TransactionScope(), and ~TransactionScope().

◆ mName

wxString TransactionScope::mName
private

Definition at line 50 of file TransactionScope.h.

Referenced by Commit(), TransactionScope(), and ~TransactionScope().

◆ mpImpl

std::unique_ptr<TransactionScopeImpl> TransactionScope::mpImpl
private

Definition at line 48 of file TransactionScope.h.

Referenced by Commit(), TransactionScope(), and ~TransactionScope().


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