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 ff3294f..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 \ @@ -24,7 +25,8 @@ HEADERS += core.h\ context.h \ imetadataplugin.h \ autotablemodel.h \ - autoform.h + autoform.h \ + transaction.h unix { target.path = /usr/lib diff --git a/core/service.h b/core/service.h index 6e22098..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,16 +39,17 @@ 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()); - db->template load(id); + 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