Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
iobjectprovider.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef IOBJECTPROVIDER_H
9#define IOBJECTPROVIDER_H
10#include "heart_global.h"
11
12#include <QSharedPointer>
13#include <dbobject.h>
14#include <quasarapp.h>
15
16namespace QH {
17namespace PKG {
18class AbstractData;
19}
20
26{
27public:
28
38 template<class TYPE>
39 QSharedPointer<TYPE> getObject(const TYPE &templateVal) {
40
41 static_assert (std::is_base_of_v<PKG::DBObject, TYPE>,
42 "The getObject must be work with DBObject child types only");
43
44 static_assert (!std::is_pointer_v<TYPE>,
45 "The getObject must be work with non pointer types.");
46
47
48 auto val = getObjectRaw(templateVal);
49 auto result = val.template dynamicCast<TYPE>();
50 if (!result && !val.isNull()) {
51 QuasarAppUtils::Params::log("getObject method returned object with deffirent type of TYPE,"
52 " check getAllObjects merhod",
53 QuasarAppUtils::Error);
54
55 }
56
57 return result;
58 }
59
66 QSharedPointer<PKG::DBObject> getObjectRaw(const PKG::DBObject &templateVal);
67
74 virtual bool getAllObjects(const PKG::DBObject &templateObject,
75 QList<QSharedPointer<PKG::DBObject>> &result) = 0;
76
84 virtual bool replaceObject(const QSharedPointer<PKG::DBObject>& saveObject, bool wait) = 0;
85
94 virtual bool updateObject(const QSharedPointer<PKG::DBObject>& saveObject, bool wait) = 0;
95
105 virtual bool insertObject(const QSharedPointer<PKG::DBObject>& saveObject,
106 bool wait,
107 const QWeakPointer<unsigned int>& autoincrementIdResult) = 0;
108
115 virtual bool deleteObject(const QSharedPointer<PKG::DBObject>& obj, bool wait) = 0;
116
123 virtual void setSQLSources(const QStringList& list) = 0;
124
133 virtual bool doQuery(const QString& query, const QVariantMap& bindValues = {},
134 bool wait = false, QSqlQuery* result = nullptr) const = 0;
135
141 virtual bool doSql(const QString& sqlFile, bool wait = true) const = 0;
142};
143
144}
145#endif // IOBJECTPROVIDER_H
The DBObject class- main class for work with data base.
Definition dbobject.h:94
The iObjectProvider class is base interface for work with database objects. Using on database writers...
virtual bool insertObject(const QSharedPointer< PKG::DBObject > &saveObject, bool wait, const QWeakPointer< unsigned int > &autoincrementIdResult)=0
insertObject This method execute a insert method of the saveObject and insert it into database.
virtual bool doQuery(const QString &query, const QVariantMap &bindValues={}, bool wait=false, QSqlQuery *result=nullptr) const =0
doQuery This method execute a query in this database.
virtual bool updateObject(const QSharedPointer< PKG::DBObject > &saveObject, bool wait)=0
updateObject This method execute a update method of the saveObject and save all changes into database...
virtual void setSQLSources(const QStringList &list)=0
setSQLSources This method set sql sources for deployed database.
virtual bool replaceObject(const QSharedPointer< PKG::DBObject > &saveObject, bool wait)=0
replaceObject This method execute a replace method of the saveObject and insert or save if not exists...
virtual bool deleteObject(const QSharedPointer< PKG::DBObject > &obj, bool wait)=0
deleteObject This method execute a delete method of obj and remove current object from database.
QSharedPointer< TYPE > getObject(const TYPE &templateVal)
getObject this method return a strong pointer to DBObject created by select method of the template ob...
virtual bool doSql(const QString &sqlFile, bool wait=true) const =0
doSql This method execute a query in this database.
virtual bool getAllObjects(const PKG::DBObject &templateObject, QList< QSharedPointer< PKG::DBObject > > &result)=0
getAllObjects This method execute a select method of the templateObject and return list of all select...
#define HEARTSHARED_EXPORT
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13