From 71325fa717eda3a845cca451b1fdbb291aa9c39f Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 10 Nov 2015 16:08:06 +0100 Subject: [PATCH] Improved transaction handling. --- core/context.cpp | 3 ++- core/context.h | 4 ++++ core/core.h | 1 + core/core.pro | 7 +++++-- core/service.h | 8 +++++--- core/transaction.cpp | 12 ++++++++++++ core/transaction.h | 12 ++++++++++++ 7 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 core/transaction.cpp create mode 100644 core/transaction.h diff --git a/core/context.cpp b/core/context.cpp index d9cee66..62be7be 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -19,7 +19,7 @@ QList Context::plugins() void Context::loadPlugins() { - QDir pluginsDir(qApp->applicationDirPath() + "/../plugins"); + QDir pluginsDir(qApp->applicationDirPath() + "/../../plugins"); foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) { QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); @@ -47,4 +47,5 @@ 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 ca06f3d..33e9285 100644 --- a/core/context.h +++ b/core/context.h @@ -3,6 +3,7 @@ #include #include "core_global.h" +#include "transaction.h" #include @@ -18,9 +19,12 @@ public: odb::database *db() { return m_db; } private: + friend class Transaction; + Context(); QList m_plugins; odb::database *m_db; + bool m_inTransaction; }; diff --git a/core/core.h b/core/core.h index 4245fba..b603be4 100644 --- a/core/core.h +++ b/core/core.h @@ -4,5 +4,6 @@ #include "context.h" #include "iplugin.h" #include "imetadataplugin.h" +#include "transaction.h" #endif // CORE_H diff --git a/core/core.pro b/core/core.pro index 514611c..5b20f54 100644 --- a/core/core.pro +++ b/core/core.pro @@ -14,7 +14,8 @@ DEFINES += CORE_LIBRARY SOURCES += \ data/user.cpp \ context.cpp \ - imetadataplugin.cpp + imetadataplugin.cpp \ + transaction.cpp HEADERS += core.h\ core_global.h \ @@ -23,7 +24,9 @@ HEADERS += core.h\ data/user.h \ context.h \ imetadataplugin.h \ - autotablemodel.h + autotablemodel.h \ + autoform.h \ + transaction.h unix { target.path = /usr/lib diff --git a/core/service.h b/core/service.h index a317212..821756d 100644 --- a/core/service.h +++ b/core/service.h @@ -12,6 +12,8 @@ #include "core_global.h" #include "context.h" +#include "transaction.h" + template class Service { @@ -23,7 +25,7 @@ public: Q_ASSERT(db); - odb::transaction tx(db->begin()); + Transaction tx; odb::result res = db->template query(); QList > ret; @@ -37,14 +39,14 @@ public: void save(QSharedPointer entity) { odb::database *db = Context::instance().db(); - odb::transaction tx(db->begin()); + Transaction tx; db->persist(entity); tx.commit(); } QSharedPointer loadById(int id) { odb::database *db = Context::instance().db(); - odb::transaction tx(db->begin()); + Transaction tx; QSharedPointer entity = db->template load(id); tx.commit(); return entity; diff --git a/core/transaction.cpp b/core/transaction.cpp new file mode 100644 index 0000000..26990b2 --- /dev/null +++ b/core/transaction.cpp @@ -0,0 +1,12 @@ +#include "transaction.h" + +Transaction::Transaction() +{ + +} + +Transaction::~Transaction() +{ + +} + diff --git a/core/transaction.h b/core/transaction.h new file mode 100644 index 0000000..7c90e81 --- /dev/null +++ b/core/transaction.h @@ -0,0 +1,12 @@ +#ifndef TRANSACTION_H +#define TRANSACTION_H + + +class Transaction +{ +public: + Transaction(); + ~Transaction(); +}; + +#endif // TRANSACTION_H