Improved transaction handling.
This commit is contained in:
+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;
|
||||
|
||||
Reference in New Issue
Block a user