QxMongoDB_Helper.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. #ifdef _QX_ENABLE_MONGODB
  32. #ifndef _QX_DAO_MONGODB_HELPER_H_
  33. #define _QX_DAO_MONGODB_HELPER_H_
  34. #ifdef _MSC_VER
  35. #pragma once
  36. #endif
  37. /*!
  38. * \file QxMongoDB_Helper.h
  39. * \author Lionel Marty
  40. * \ingroup QxDao
  41. * \brief Helper class to store all QxOrm registered classes in a MongoDB database : qx::QxSqlDatabase::getSingleton()->setDriverName("QXMONGODB");
  42. */
  43. #include <QtSql/qsqlerror.h>
  44. #include <QxSingleton/QxSingleton.h>
  45. namespace qx {
  46. class IxClass;
  47. class QxSqlQuery;
  48. } // namespace qx
  49. namespace qx {
  50. namespace dao {
  51. namespace detail {
  52. class IxDao_Helper;
  53. } // namespace detail
  54. } // namespace dao
  55. } // namespace qx
  56. namespace qx {
  57. namespace dao {
  58. namespace mongodb {
  59. struct QxMongoDB_Fetcher;
  60. /*!
  61. * \ingroup QxDao
  62. * \brief qx::dao::mongodb::QxMongoDB_Helper : helper class to store all QxOrm registered classes in a MongoDB database : qx::QxSqlDatabase::getSingleton()->setDriverName("QXMONGODB");
  63. */
  64. class QX_DLL_EXPORT QxMongoDB_Helper : public QxSingleton<QxMongoDB_Helper>
  65. {
  66. friend class QxSingleton<QxMongoDB_Helper>;
  67. public:
  68. enum opts { opts_collection_insert_one, opts_collection_insert_many, opts_collection_update_one, opts_collection_update_many,
  69. opts_collection_delete_one, opts_collection_delete_many, opts_collection_find, opts_collection_command, opts_collection_count,
  70. opts_collection_create_bulk_operation, opts_bulk_operation_update_one, opts_bulk_operation_remove_one, opts_collection_aggregate };
  71. private:
  72. struct QxMongoDB_HelperImpl;
  73. std::unique_ptr<QxMongoDB_HelperImpl> m_pImpl; //!< Private implementation idiom
  74. QxMongoDB_Helper();
  75. virtual ~QxMongoDB_Helper();
  76. public:
  77. static QSqlError insertOne(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, const QString & json, QString & insertedId);
  78. static QSqlError insertMany(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, const QStringList & json, QStringList & insertedId);
  79. static QSqlError updateOne(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, const QString & json, const qx::QxSqlQuery * query = NULL);
  80. static QSqlError updateMany(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, const QStringList & json, const qx::QxSqlQuery * query = NULL);
  81. static QSqlError deleteOne(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, const QString & json, const qx::QxSqlQuery * query = NULL);
  82. static QSqlError deleteMany(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, const QStringList & json, const qx::QxSqlQuery * query = NULL);
  83. static QSqlError findOne(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, QString & json, const qx::QxSqlQuery * query = NULL);
  84. static QSqlError findMany(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, QStringList & json, const qx::QxSqlQuery * query = NULL, QxMongoDB_Fetcher * pFetcher = NULL);
  85. static QSqlError aggregate(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, QStringList & json, const qx::QxSqlQuery * query = NULL, const QString & lookup = QString(), QxMongoDB_Fetcher * pFetcher = NULL);
  86. static QSqlError count(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, long & cnt, const qx::QxSqlQuery * query = NULL);
  87. static QSqlError executeCommand(qx::dao::detail::IxDao_Helper * pDaoHelper, qx::IxClass * pClass, qx::QxSqlQuery * query);
  88. static QSqlError autoCreateIndexes(bool log = true);
  89. static bool setOptions(opts e, const QString & optsAsJson);
  90. static void setLogDatabaseReply(bool b);
  91. static void setLogDatabaseInfo(bool b);
  92. static void clearPoolConnection();
  93. };
  94. /*!
  95. * \ingroup QxDao
  96. * \brief qx::dao::mongodb::QxMongoDB_Fetcher : used to fetch a list of items from MongoDB database without having to put them in a buffer before fetching
  97. */
  98. struct QX_DLL_EXPORT QxMongoDB_Fetcher
  99. {
  100. QxMongoDB_Fetcher();
  101. virtual ~QxMongoDB_Fetcher();
  102. virtual void fetch(const QString & json) = 0;
  103. };
  104. } // namespace mongodb
  105. } // namespace dao
  106. } // namespace qx
  107. QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::dao::mongodb::QxMongoDB_Helper)
  108. #endif // _QX_DAO_MONGODB_HELPER_H_
  109. #endif // _QX_ENABLE_MONGODB