22class ISubscribableData;
42class HEARTSHARED_EXPORT
DataBase:
public QObject
60 virtual bool initSqlDb( QString DBparamsFile =
"",
108 QVariant
getDBAttribute(
const QString& key,
const QVariant& defaultVal);
115 bool setDBAttribute(
const QString& key,
const QVariant& newValue);
144 QString
backUp(
int version)
const;
242 virtual void objectChanged(
const QSharedPointer<PKG::DBObject>& obj);
334 template <
class Object,
class Id,
class Setter>
335 QSharedPointer<Object>
getById(
const Id&
id, Setter setter,
bool ifNotExistsCreate =
false) {
336 if (
auto&& database =
db()) {
337 auto&& request = QSharedPointer<Object>::create();
338 (*request.*setter)(
id);
340 if (
auto&& result = database->getObject(*request)) {
344 if (ifNotExistsCreate)
370 template <
class Object,
class Id,
class Setter>
372 if (
auto&& database =
db()) {
373 auto&& request = QSharedPointer<Object>::create();
374 (*request.*setter)(
id);
375 return database->deleteObject(request);
396 template <
class Object>
398 if (
auto&& database =
db()) {
399 return database->replaceObject(obj);
419 template <
class Object>
420 bool insertObj(
const Object& obj,
const QWeakPointer<unsigned int>& resultId = {}) {
421 if (
auto&& database = db()) {
422 return database->insertObject(obj, !resultId.isNull(), resultId);
445 template<
class Object>
446 QList<QSharedPointer<Object>>
getAll(
const QString& table,
const QString& condition =
"")
const {
449 auto&& response =
db()->getObject(request);
454 return response->data();
464 bool workWithSubscribe(
const PKG::WebSocket &rec,
465 const QVariant &clientOrNodeid,
469 bool isForbidenTable(
const QString& table);
472 unsigned short _targetDBVersion = 0;
474 QString _localNodeName;
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
void sigObjectChanged(const QSharedPointer< QH::PKG::DBObject > &obj)
sigItemChanged This signal emitted when database object is changed.
bool isSqlInited() const
isSqlInited This method return true if database initialized successful.
bool deleteById(const Id &id, Setter setter)
Delete an object by its identifier.
void stop()
stop This method stop and diskonnect the database.
bool insertObj(const Object &obj, const QWeakPointer< unsigned int > &resultId={})
insert a new value into database, and save into resultId autoincremented id of inserted object.
virtual bool upgradeDataBase()
upgradeDataBase This method upgrade data base to actyaly database version.
void setLocalNodeName(const QString &newLocalNodeName)
setLocalNodeName This method sets new local name of database file.
friend class DataBaseNode
DataBase(QObject *ptr=nullptr)
bool run()
run This method start and initialize the data base connection.
QVariant getDBAttribute(const QString &key, const QVariant &defaultVal)
getDBAttribute This method gets value from the default of QH DB table "DataBaseAttributes".
virtual void initDefaultDbObjects(ISqlDB *cache, SqlDBWriter *writer)
initDefaultDbObjects This method create a default cache and database writer objects if the input poin...
bool setDBAttribute(const QString &key, const QVariant &newValue)
setDBAttribute This method sets value for the default of QH DB table "DataBaseAttributes".
bool saveObj(const Object &obj)
Save an object in the database.
virtual const DBPatchMap dbPatches() const
dbPatches This method should be return map with functions that upgrade production data base....
virtual QVariantMap defaultDbParams() const
defaultDbParams This method return default database parameters for this node. Override this method fo...
void sigObjectDeleted(const QH::DbAddress &obj)
sigItemDeleted This signal emitted when database object is deleted.
QSharedPointer< Object > getById(const Id &id, Setter setter, bool ifNotExistsCreate=false)
Get an object by its identifier.
virtual QStringList SQLSources() const
SQLSources This method contains list of sqldatabase sources. This method will be invoked into initial...
virtual bool welcomeAddress(AbstractNodeInfo *node)
welcomeAddress This method send to the node information about self. Override this method if you want ...
const QString & localNodeName() const
localNodeName This method return local node name.
virtual void objectRemoved(const DbAddress &address)
objectRemoved This method invoked when object with address removed from database. Oberride this metho...
QString dbLocation() const
dbLocation This method return location of nodes or clients database.
void addDBPatch(const DBPatch &patch)
addDBPatch This method add database patch to the data base object.
virtual QSet< QString > systemTables() const
systemTables This method return the set of tables that forbidden for users. By default is NetworkMemb...
ISqlDB * db() const
db This node return pointer to database object.
virtual void objectChanged(const QSharedPointer< PKG::DBObject > &obj)
objectChanged This method invoked when object with address changed in database. Override this method ...
virtual void onBeforeDBUpgrade(int currentVerion, int tergetVersion) const
onBeforeDBUpgrade This method will be invoked before upgrade database.
QList< QSharedPointer< Object > > getAll(const QString &table, const QString &condition="") const
Get a list of all objects from a specified table.
QString backUp(int version) const
backUp This method make a backup of database.
virtual bool initSqlDb(QString DBparamsFile="", ISqlDB *cache=nullptr, SqlDBWriter *writer=nullptr)
intSqlDb This method initalize database of this node or server.
The DbAddress class use to work with database addresses. Database Address it is structure with 2 valu...
The ISqlDB class it is db cache and bridge for DbWriters. Work Scheme of the database cache:
The DBObjectsRequest class is template class for get array of TEMPLATE Objects from database.
The SqlDBWriter class. This class write and read objects from database (hard level)....
The iObjectProvider class is base interface for work with database objects. Using on database writers...
Q_DECLARE_METATYPE(QH::HostAddress)
The PKG namesapce - this namespace contains all default packages of the Heart library....
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
QMap< unsigned short, QMap< unsigned short, DBPatch > > DBPatchMap
DBPatchMap This is 2 depch map of the DBPatch structure when the first key it is version (from) and s...
DBPatch This is function that should be upgrade database.