Audacity 3.2.0
TransactionScope.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file TransactionScope.cpp
6
7 Paul Licameli split from DBConnection.cpp
8
9**********************************************************************/
10
11#include "TransactionScope.h"
13#include <wx/log.h>
14
16
18 AudacityProject &project, const char *name)
19: mName(name)
20{
21 mpImpl = Factory::Call(project);
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}
34
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}
47
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}
@ Internal
Indicates internal failure from Audacity.
const TranslatableString name
Definition: Distortion.cpp:82
MessageBoxException for violation of preconditions or assertions.
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
#define XO(s)
Definition: Internat.h:31
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
A MessageBoxException that shows a given, unvarying string.
~TransactionScope()
Rollback transaction if it was not yet committed.
std::unique_ptr< TransactionScopeImpl > mpImpl
TransactionScope(AudacityProject &project, const char *name)
Construct from a project.
bool Commit()
Commit the transaction.
virtual ~TransactionScopeImpl()