Improved transaction handling.
This commit is contained in:
+2
-1
@@ -19,7 +19,7 @@ QList<IPlugin *> 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;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QList>
|
||||
#include "core_global.h"
|
||||
#include "transaction.h"
|
||||
|
||||
#include <odb/database.hxx>
|
||||
|
||||
@@ -18,9 +19,12 @@ public:
|
||||
odb::database *db() { return m_db; }
|
||||
|
||||
private:
|
||||
friend class Transaction;
|
||||
|
||||
Context();
|
||||
QList<IPlugin*> m_plugins;
|
||||
odb::database *m_db;
|
||||
bool m_inTransaction;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
#include "context.h"
|
||||
#include "iplugin.h"
|
||||
#include "imetadataplugin.h"
|
||||
#include "transaction.h"
|
||||
|
||||
#endif // CORE_H
|
||||
|
||||
+5
-2
@@ -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
|
||||
|
||||
+5
-3
@@ -12,6 +12,8 @@
|
||||
#include "core_global.h"
|
||||
#include "context.h"
|
||||
|
||||
#include "transaction.h"
|
||||
|
||||
template<class T>
|
||||
class Service
|
||||
{
|
||||
@@ -23,7 +25,7 @@ public:
|
||||
|
||||
Q_ASSERT(db);
|
||||
|
||||
odb::transaction tx(db->begin());
|
||||
Transaction tx;
|
||||
odb::result<T> res = db->template query<T>();
|
||||
|
||||
QList<QSharedPointer<T> > ret;
|
||||
@@ -37,14 +39,14 @@ public:
|
||||
|
||||
void save(QSharedPointer<T> entity) {
|
||||
odb::database *db = Context::instance().db();
|
||||
odb::transaction tx(db->begin());
|
||||
Transaction tx;
|
||||
db->persist(entity);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
QSharedPointer<T> loadById(int id) {
|
||||
odb::database *db = Context::instance().db();
|
||||
odb::transaction tx(db->begin());
|
||||
Transaction tx;
|
||||
QSharedPointer<T> entity = db->template load<T>(id);
|
||||
tx.commit();
|
||||
return entity;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "transaction.h"
|
||||
|
||||
Transaction::Transaction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Transaction::~Transaction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef TRANSACTION_H
|
||||
#define TRANSACTION_H
|
||||
|
||||
|
||||
class Transaction
|
||||
{
|
||||
public:
|
||||
Transaction();
|
||||
~Transaction();
|
||||
};
|
||||
|
||||
#endif // TRANSACTION_H
|
||||
Reference in New Issue
Block a user