diff --git a/core/core.pro b/core/core.pro index bdd8b7e..509247f 100644 --- a/core/core.pro +++ b/core/core.pro @@ -42,7 +42,8 @@ SOURCES += \ samestringvalidator.cpp \ savefilterdialog.cpp \ filterdialog.cpp \ - itablemodel.cpp + itablemodel.cpp \ + iservice.cpp HEADERS += core.h\ core_global.h \ @@ -82,7 +83,8 @@ HEADERS += core.h\ savefilterdialog.h \ filterdialog.h \ itablemodel.h \ - data/core_global.h + data/core_global.h \ + iservice.h unix { target.path = /usr/lib diff --git a/core/iplugin.h b/core/iplugin.h index 990fa44..6a1605b 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -58,7 +58,7 @@ public: protected: QWidget *m_ui; - void *m_service; + IService *m_service; }; #define PluginInterface_iid "cz.itsolved.prodejna.IPlugin" diff --git a/core/iservice.cpp b/core/iservice.cpp new file mode 100644 index 0000000..281d46b --- /dev/null +++ b/core/iservice.cpp @@ -0,0 +1,12 @@ +#include "iservice.h" + +IService::IService(QObject *parent) : QObject(parent) +{ + +} + +IService::~IService() +{ + +} + diff --git a/core/iservice.h b/core/iservice.h new file mode 100644 index 0000000..eabc038 --- /dev/null +++ b/core/iservice.h @@ -0,0 +1,25 @@ +#ifndef ISERVICE_H +#define ISERVICE_H + +#include +#include + +#include "core_global.h" + +class CORESHARED_EXPORT IService : public QObject +{ + Q_OBJECT + +public: + explicit IService(QObject *parent = 0); + virtual ~IService(); + +signals: + void dbError(QString errMsg); + void dataChanged(); + void permissionDenied(); + +public slots: +}; + +#endif // ISERVICE_H diff --git a/core/service.h b/core/service.h index f56207e..e6d1f48 100644 --- a/core/service.h +++ b/core/service.h @@ -12,14 +12,15 @@ #include "core_global.h" #include "context.h" +#include "iservice.h" #include "transaction.h" template -class Service +class Service : public IService { public: - Service() { } + explicit Service(QObject *parent = NULL) :IService(parent) { } explicit Service(const QString &pluginId) { m_pluginId = pluginId; @@ -31,14 +32,23 @@ public: 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()); + + try + { + odb::result res = db->template query(); + + for (typename odb::result::iterator it = res.begin(); it != res.end(); it++) { + ret.append(it.load()); + } + + tx.commit(); + } + catch (const odb::exception &ex) + { + emit dbError(ex.what()); } - tx.commit(); return ret; } @@ -48,8 +58,19 @@ public: Q_ASSERT(db); Transaction tx; - db->persist(entity); - tx.commit(); + + try + { + db->persist(entity); + tx.commit(); + } + catch (const odb::exception &ex) + { + emit dbError(ex.what()); + return; + } + + emit dataChanged(); } void update(QSharedPointer entity) { @@ -58,8 +79,18 @@ public: Q_ASSERT(db); Transaction tx; - db->update(entity); - tx.commit(); + + try + { + db->update(entity); + tx.commit(); + } + catch (const odb::exception &ex) + { + emit dbError(ex.what()); + } + + emit dataChanged(); } QSharedPointer loadById(int id) { @@ -68,8 +99,18 @@ public: Q_ASSERT(db); Transaction tx; - QSharedPointer entity = db->template load(id); - tx.commit(); + QSharedPointer entity; + + try + { + entity = db->template load(id); + tx.commit(); + } + catch (const odb::exception &ex) + { + emit dbError(ex.what()); + } + return entity; } @@ -79,8 +120,16 @@ public: Q_ASSERT(db); Transaction tx; - db->erase(entity); - tx.commit(); + + try + { + db->erase(entity); + tx.commit(); + } + catch (const odb::exception &ex) + { + emit dbError(ex.what()); + } } void setPluginId(const QString &pluginId) {