Fixed Transaction class.

This commit is contained in:
2015-11-10 20:31:23 +01:00
parent f208120799
commit 6bc7fd8762
4 changed files with 30 additions and 7 deletions
-1
View File
@@ -47,5 +47,4 @@ void Context::openDb(const QString &path)
Context::Context()
{
m_db = NULL;
m_inTransaction = false;
}
-4
View File
@@ -19,13 +19,9 @@ public:
odb::database *db() { return m_db; }
private:
friend class Transaction;
Context();
QList<IPlugin*> m_plugins;
odb::database *m_db;
bool m_inTransaction;
};
#endif // CONTEXT_H
+22 -2
View File
@@ -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();
}
}
+8
View File
@@ -1,12 +1,20 @@
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <odb/database.hxx>
#include <odb/transaction.hxx>
class Transaction
{
public:
Transaction();
~Transaction();
void commit();
private:
odb::transaction *m_tr;
static bool m_inTransaction;
};
#endif // TRANSACTION_H