diff --git a/core/context.cpp b/core/context.cpp index 62be7be..5e20837 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -47,5 +47,4 @@ void Context::openDb(const QString &path) Context::Context() { m_db = NULL; - m_inTransaction = false; } diff --git a/core/context.h b/core/context.h index 33e9285..b398680 100644 --- a/core/context.h +++ b/core/context.h @@ -19,13 +19,9 @@ public: odb::database *db() { return m_db; } private: - friend class Transaction; - Context(); QList m_plugins; odb::database *m_db; - bool m_inTransaction; - }; #endif // CONTEXT_H diff --git a/core/transaction.cpp b/core/transaction.cpp index 26990b2..8090274 100644 --- a/core/transaction.cpp +++ b/core/transaction.cpp @@ -1,12 +1,32 @@ #include "transaction.h" +#include "context.h" + +bool Transaction::m_inTransaction = false; + Transaction::Transaction() { - + if (!Transaction::m_inTransaction) + { + m_tr = new odb::transaction(Context::instance().db()->begin()); + Transaction::m_inTransaction = true; + } } Transaction::~Transaction() { + if (m_tr != NULL) + { + delete m_tr; + Transaction::m_inTransaction = false; + } +} +void Transaction::commit() +{ + if (m_tr != NULL) + { + m_tr->commit(); + } } diff --git a/core/transaction.h b/core/transaction.h index 7c90e81..2fd84c0 100644 --- a/core/transaction.h +++ b/core/transaction.h @@ -1,12 +1,20 @@ #ifndef TRANSACTION_H #define TRANSACTION_H +#include +#include class Transaction { public: Transaction(); ~Transaction(); + + void commit(); + +private: + odb::transaction *m_tr; + static bool m_inTransaction; }; #endif // TRANSACTION_H