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{
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.
XO("Cut/Copy/Paste")
MessageBoxException for violation of preconditions or assertions.
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
wxString name
Definition: TagsEditor.cpp:166
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
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()