Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The DataManager class is a convenience class for managing structure data
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-12
|
||||
*/
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
#include "reply_message.h"
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
/**
|
||||
* @brief The DataManager class is a convenience class for managing structure data from db
|
||||
* T needs to be of namspace::DatabaseInterface
|
||||
*/
|
||||
template<typename T>
|
||||
class DataManagerBaseDl
|
||||
{
|
||||
protected: // methods
|
||||
/**
|
||||
* @brief DataManager Constructor
|
||||
* @param dbInterface Interface for requesting db-structs data
|
||||
*/
|
||||
explicit DataManagerBaseDl(const std::shared_ptr<T> &dbInterface, NGL::INGLLogger &logger)
|
||||
: m_logger(logger)
|
||||
, m_dbInterface(dbInterface)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief toBaseDataMessageFromDb selects the DbType data from the db and converts it to JSON
|
||||
* @param uuid of the base DL request
|
||||
* @return message send to the requester
|
||||
*/
|
||||
template<typename DbType, typename MessageType>
|
||||
ReplyMessage *toBaseDataMessageFromDb(const QString &uuid) const
|
||||
{
|
||||
QVector<DbType> dataVec;
|
||||
// read all data from database
|
||||
if (!m_dbInterface->select(dataVec))
|
||||
{
|
||||
const QString errorMessage = QStringLiteral("Error reading data from database!");
|
||||
ERROR_LOG(m_logger) << errorMessage;
|
||||
ErrorMessage::ErrorData errData;
|
||||
errData.errorMessage = errorMessage;
|
||||
errData.uuid = uuid;
|
||||
return new ErrorMessage(errData);
|
||||
}
|
||||
|
||||
return new MessageType (m_dbInterface->template toJson<DbType>(dataVec), uuid);
|
||||
}
|
||||
|
||||
protected: // attributes
|
||||
NGL::INGLLogger &m_logger;
|
||||
std::shared_ptr<T> m_dbInterface;
|
||||
}; // class DataManagerBaseDl
|
||||
} // namespace LtsWebSocket
|
||||
Reference in new issue
Block a user