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"
12 #include "InconsistencyException.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 }
TransactionScope.h
InconsistencyException.h
MessageBoxException for violation of preconditions or assertions.
TransactionScope::~TransactionScope
~TransactionScope()
Rollback transaction if it was not yet committed.
Definition: TransactionScope.cpp:35
XO
#define XO(s)
Definition: Internat.h:31
TransactionScope::TransactionScope
TransactionScope(AudacityProject &project, const char *name)
Construct from a project.
Definition: TransactionScope.cpp:17
name
const TranslatableString name
Definition: Distortion.cpp:98
TransactionScope::mpImpl
std::unique_ptr< TransactionScopeImpl > mpImpl
Definition: TransactionScope.h:48
THROW_INCONSISTENCY_EXCEPTION
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
Definition: InconsistencyException.h:79
TransactionScopeImpl::~TransactionScopeImpl
virtual ~TransactionScopeImpl()
TransactionScope::mName
wxString mName
Definition: TransactionScope.h:50
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
GlobalHook< Factory, std::unique_ptr< TransactionScopeImpl >(AudacityProject &) >::Call
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
Definition: GlobalVariable.h:158
TransactionScope::Commit
bool Commit()
Commit the transaction.
Definition: TransactionScope.cpp:48
TransactionScope::mInTrans
bool mInTrans
Definition: TransactionScope.h:49
SimpleMessageBoxException
A MessageBoxException that shows a given, unvarying string.
Definition: AudacityException.h:95