mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-11 00:49:42 +00:00
91 lines
1.8 KiB
C++
91 lines
1.8 KiB
C++
#ifndef SQLDBCASHE_H
|
|
#define SQLDBCASHE_H
|
|
|
|
#include "iobjectprovider.h"
|
|
|
|
#include <QMap>
|
|
#include <QHash>
|
|
#include <QSet>
|
|
#include <QVariantMap>
|
|
#include <clientprotocol.h>
|
|
|
|
namespace ClientProtocol {
|
|
|
|
class SqlDBWriter;
|
|
class DBObject;
|
|
|
|
enum class SqlDBCasheWriteMode: int {
|
|
Default = 0x0,
|
|
On_New_Thread = 0x1,
|
|
Force = 0x2,
|
|
} ;
|
|
|
|
/**
|
|
* @brief The SqlDBCache class it is db cache and bridge for DbWriters
|
|
*/
|
|
class CLIENTPROTOCOLSHARED_EXPORT SqlDBCache: public QObject, public iObjectProvider
|
|
{
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
SqlDBCache(qint64 updateInterval = DEFAULT_UPDATE_INTERVAL);
|
|
~SqlDBCache() override;
|
|
|
|
/**
|
|
* @brief addDbObject
|
|
* @param obj
|
|
* @return
|
|
*/
|
|
bool addDbObject(const DBObject* obj);
|
|
|
|
/**
|
|
* @brief removeDbObject
|
|
* @param obj
|
|
* @return
|
|
*/
|
|
bool removeDbObject(const DBObject* obj);
|
|
|
|
|
|
/**
|
|
* @brief writer
|
|
* @return
|
|
*/
|
|
SqlDBWriter *writer() const;
|
|
|
|
/**
|
|
* @brief setWriter
|
|
* @param writer
|
|
*/
|
|
void setWriter(SqlDBWriter *writer);
|
|
|
|
bool getObject(DBObject *result, const QString &table, int id) const override;
|
|
bool saveObject(DBObject *saveObject) override;
|
|
bool deleteObject(const QString &table, int id) override;
|
|
|
|
protected:
|
|
/**
|
|
* @brief init
|
|
* @return
|
|
*/\
|
|
virtual bool init(const QString &initDbParams = "");
|
|
|
|
private:
|
|
qint64 lastUpdateTime = 0;
|
|
qint64 updateInterval = DEFAULT_UPDATE_INTERVAL;
|
|
|
|
SqlDBWriter *_writer = nullptr;
|
|
|
|
QHash<QString, QHash <int, QSharedPointer<DBObject>>> _cache;
|
|
|
|
void globalUpdateDataBasePrivate(qint64 currentTime);
|
|
void globalUpdateDataBase(SqlDBCasheWriteMode mode = SqlDBCasheWriteMode::Default);
|
|
|
|
signals:
|
|
void sigItemChanged(int id, QWeakPointer<DBObject> obj);
|
|
|
|
};
|
|
|
|
}
|
|
#endif // SQLDBCASHE_H
|