Click here to Skip to main content
15,895,799 members
Articles / Web Development / HTML

QxOrm - C++ ORM (Object Relational Mapping) Library

Rate me:
Please Sign up or sign in to vote.
4.90/5 (61 votes)
24 Apr 2019GPL326 min read 141K   321   140  
QxOrm C++ library: Persistence (based on QtSql Qt library) - Serialization (based on boost::serialization library) - Reflection (introspection)
/****************************************************************************
**
** http://www.qxorm.com/
** http://sourceforge.net/projects/qxorm/
** Original file by Lionel Marty
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software.
**
** GNU Lesser General Public License Usage
** This file must be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file 'license.lgpl.txt' included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you have questions regarding the use of this file, please contact :
** contact@qxorm.com
**
****************************************************************************/

#if _QX_ENABLE_QT_NETWORK_DEPENDENCY
#ifndef _QX_SERVICE_TRANSACTION_H_
#define _QX_SERVICE_TRANSACTION_H_

#ifdef _MSC_VER
#pragma once
#endif

/*!
 * \file QxTransaction.h
 * \author Lionel Marty
 * \ingroup QxService
 * \brief Transaction of QxService module (contains request from client and reply from server)
 */

#include <QtNetwork/qtcpsocket.h>

#include <QxCommon/QxBool.h>

#include <QxRegister/QxRegisterInternalHelper.h>

#include <QxService/IxService.h>
#include <QxService/IxParameter.h>

namespace qx {
namespace service {

/*!
 * \ingroup QxService
 * \brief qx::service::QxTransaction : transaction of QxService module (contains request from client and reply from server)
 *
 * <a href="http://www.qxorm.com/qxorm_en/tutorial_2.html" target="_blank">Click here to access to a tutorial to explain how to work with QxService module.</a>
 */
class QX_DLL_EXPORT QxTransaction
{

   QX_REGISTER_FRIEND_CLASS(qx::service::QxTransaction)

protected:

   QString              m_sTransactionId;                   //!< Transaction id (GUID)
   quint32              m_uiInputTransactionSize;           //!< Input transaction size
   quint32              m_uiOutputTransactionSize;          //!< Output transaction size
   QDateTime            m_dtTransactionBegin;               //!< Date-time transaction begin
   QDateTime            m_dtTransactionRequestSent;         //!< Date-time transaction request sent
   QDateTime            m_dtTransactionRequestReceived;     //!< Date-time transaction request received
   QDateTime            m_dtTransactionReplySent;           //!< Date-time transaction reply sent
   QDateTime            m_dtTransactionReplyReceived;       //!< Date-time transaction reply received
   QDateTime            m_dtTransactionEnd;                 //!< Date-time transaction end
   QString              m_sIpSource;                        //!< Ip address source (request)
   QString              m_sIpTarget;                        //!< Ip address target (reply)
   long                 m_lPortSource;                      //!< Port number source (request)
   long                 m_lPortTarget;                      //!< Port number target (reply)
   QString              m_sServiceName;                     //!< Service name to create using 'QxFactory'
   QString              m_sServiceMethod;                   //!< Service method to call to execute transaction
   qx_bool              m_bMessageReturn;                   //!< Message return to indicate if an error occured
   IxParameter_ptr      m_pInputParameter;                  //!< List of input parameters (request)
   IxParameter_ptr      m_pOutputParameter;                 //!< List of output parameters (reply)
   IxService_ptr        m_pServiceInstance;                 //!< Service instance created by 'm_sServiceName' property

public:

   QxTransaction() : m_uiInputTransactionSize(0), m_uiOutputTransactionSize(0), m_lPortSource(0), m_lPortTarget(0) { ; }
   virtual ~QxTransaction() { ; }

   QString getTransactionId() const                      { return m_sTransactionId; }
   quint32 getInputTransactionSize() const               { return m_uiInputTransactionSize; }
   quint32 getOutputTransactionSize() const              { return m_uiOutputTransactionSize; }
   QDateTime getTransactionBegin() const                 { return m_dtTransactionBegin; }
   QDateTime getTransactionRequestSent() const           { return m_dtTransactionRequestSent; }
   QDateTime getTransactionRequestReceived() const       { return m_dtTransactionRequestReceived; }
   QDateTime getTransactionReplySent() const             { return m_dtTransactionReplySent; }
   QDateTime getTransactionReplyReceived() const         { return m_dtTransactionReplyReceived; }
   QDateTime getTransactionEnd() const                   { return m_dtTransactionEnd; }
   QString getIpSource() const                           { return m_sIpSource; }
   QString getIpTarget() const                           { return m_sIpTarget; }
   long getPortSource() const                            { return m_lPortSource; }
   long getPortTarget() const                            { return m_lPortTarget; }
   QString getServiceName() const                        { return m_sServiceName; }
   QString getServiceMethod() const                      { return m_sServiceMethod; }
   qx_bool getMessageReturn() const                      { return m_bMessageReturn; }
   IxParameter_ptr getInputParameter() const             { return m_pInputParameter; }
   IxParameter_ptr getOutputParameter() const            { return m_pOutputParameter; }

   void setTransactionId(const QString & s)                    { m_sTransactionId = s; }
   void setInputTransactionSize(quint32 ui)                    { m_uiInputTransactionSize = ui; }
   void setOutputTransactionSize(quint32 ui)                   { m_uiOutputTransactionSize = ui; }
   void setTransactionBegin(const QDateTime & dt)              { m_dtTransactionBegin = dt; }
   void setTransactionRequestSent(const QDateTime & dt)        { m_dtTransactionRequestSent = dt; }
   void setTransactionRequestReceived(const QDateTime & dt)    { m_dtTransactionRequestReceived = dt; }
   void setTransactionReplySent(const QDateTime & dt)          { m_dtTransactionReplySent = dt; }
   void setTransactionReplyReceived(const QDateTime & dt)      { m_dtTransactionReplyReceived = dt; }
   void setTransactionEnd(const QDateTime & dt)                { m_dtTransactionEnd = dt; }
   void setIpSource(const QString & s)                         { m_sIpSource = s; }
   void setIpTarget(const QString & s)                         { m_sIpTarget = s; }
   void setPortSource(long l)                                  { m_lPortSource = l; }
   void setPortTarget(long l)                                  { m_lPortTarget = l; }
   void setServiceName(const QString & s)                      { m_sServiceName = s; }
   void setServiceMethod(const QString & s)                    { m_sServiceMethod = s; }
   void setMessageReturn(const qx_bool & b)                    { m_bMessageReturn = b; }
   void setInputParameter(IxParameter_ptr p)                   { m_pInputParameter = p; }
   void setOutputParameter(IxParameter_ptr p)                  { m_pOutputParameter = p; }

public:

   void executeServer();
   void executeClient(IxService * pService, const QString & sMethod);

protected:

   qx_bool writeSocket(QTcpSocket & socket);
   qx_bool readSocket(QTcpSocket & socket);

};

typedef boost::shared_ptr<QxTransaction> QxTransaction_ptr;
QX_DLL_EXPORT void execute_client(IxService * pService, const QString & sMethod);

} // namespace service
} // namespace qx

QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::QxTransaction, 0)

#endif // _QX_SERVICE_TRANSACTION_H_
#endif // _QX_ENABLE_QT_NETWORK_DEPENDENCY

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions