#ifndef SERVICE_H #define SERVICE_H #include #include #include #include #include #include #include #include "core_global.h" #include "context.h" #include "transaction.h" template class Service { public: Service() { } QList > all() { odb::database *db = Context::instance().db(); Q_ASSERT(db); Transaction tx; odb::result res = db->template query(); QList > ret; for (typename odb::result::iterator it = res.begin(); it != res.end(); it++) { ret.append(it.load()); } tx.commit(); return ret; } void save(QSharedPointer entity) { odb::database *db = Context::instance().db(); Q_ASSERT(db); Transaction tx; db->persist(entity); tx.commit(); } QSharedPointer loadById(int id) { odb::database *db = Context::instance().db(); Q_ASSERT(db); Transaction tx; QSharedPointer entity = db->template load(id); tx.commit(); return entity; } void setPluginId(const QString &pluginId) { m_pluginId = pluginId; } private: QString m_pluginId; }; #endif // SERVICE_H