QxMainPage.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. /* -- Main page for Doxygen documentation -- */
  32. /*!
  33. * \mainpage QxOrm - C++ Object Relational Mapping library
  34. *
  35. * QxOrm is a C++ library designed to provide Object Relational Mapping (ORM) feature to C++/Qt developers (like Hibernate in Java, or NHibernate in .Net).<br>
  36. * QxOrm engine is based on a simple and non intrusive mapping function per class to provide :
  37. *
  38. * - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_30" target="_blank"><b>Persistence</b></a> (based on QtSql Qt module) ;
  39. * - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_60" target="_blank"><b>Serialization</b></a> (JSON, XML and binary, based on Qt and boost serialization engines) ;
  40. * - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Reflection</b></a> or <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Introspection</b></a> (invoke dynamically class methods and access to properties) ;
  41. * - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_96" target="_blank"><b>HTTP web server</b></a> : standalone multi-threaded HTTP 1.1 web server (support SSL/TLS, persistent connections, cookies, sessions, chunked responses, URL dispatcher/routing) ;
  42. * - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_97" target="_blank"><b>JSON API</b></a> : interoperability with other technology than C++/Qt (REST web services, QML applications, scripting language).
  43. *
  44. * QxOrm is developed by Lionel Marty, a software development engineer since 2003.<br>
  45. * QxOrm library has been accepted into the <a href="http://forum.qt.io/category/24/qt-ambassador-program" target="_blank">Qt Ambassador Program</a>.<br>
  46. * QxOrm library is available on <a href="https://github.com/QxOrm/QxOrm" target="_blank">GitHub</a>.
  47. *
  48. * For more information about QxOrm library (quick sample, tutorial and forum), please visit : <a href="https://www.qxorm.com/" target="_blank">https://www.qxorm.com/</a>.<br>
  49. * <a href="https://www.qxorm.com/qxorm_en/manual.html" target="_blank">A manual (user guide) to learn how to work with QxOrm library is available on QxOrm website</a>.
  50. * <br><br>
  51. *
  52. * \section quick_sample Quick sample using QxOrm library
  53. *
  54. * 1- <i>drug.h</i> file : drug class definition with 3 properties : <i>id</i>, <i>name</i> and <i>description</i>
  55. * \code
  56. #ifndef _CLASS_DRUG_H_
  57. #define _CLASS_DRUG_H_
  58. class drug
  59. {
  60. public:
  61. long id;
  62. QString name;
  63. QString description;
  64. drug() : id(0) { ; }
  65. virtual ~drug() { ; }
  66. };
  67. QX_REGISTER_HPP_MY_TEST_EXE(drug, qx::trait::no_base_class_defined, 1)
  68. // This macro is necessary to register 'drug' class in QxOrm context
  69. // param 1 : the current class to register => 'drug'
  70. // param 2 : the base class, if no base class, use the qx trait => 'qx::trait::no_base_class_defined'
  71. // param 3 : the class version used by serialization to provide 'ascendant compatibility'
  72. #endif // _CLASS_DRUG_H_
  73. * \endcode
  74. *
  75. * <br>
  76. * 2- <i>drug.cpp</i> file : setting function implementation - <i>void qx::register_class()</i>
  77. * \code
  78. #include "precompiled.h" // Precompiled-header with '#include <QxOrm.h>' and '#include "export.h"'
  79. #include "drug.h" // Class definition 'drug'
  80. #include <QxOrm_Impl.h> // Automatic memory leak detection and boost serialization export macro
  81. QX_REGISTER_CPP_MY_TEST_EXE(drug) // This macro is necessary to register 'drug' class in QxOrm context
  82. namespace qx {
  83. template <> void register_class(QxClass<drug> & t)
  84. {
  85. t.id(& drug::id, "id"); // Register 'drug::id' <=> primary key in your database
  86. t.data(& drug::name, "name", 1); // Register 'drug::name' property with key 'name' and version '1'
  87. t.data(& drug::description, "desc"); // Register 'drug::description' property with key 'desc'
  88. }}
  89. * \endcode
  90. *
  91. * <br>
  92. * 3- <i>main.cpp</i> file : basic functionalities of QxOrm library with drug class
  93. * \code
  94. #include "precompiled.h"
  95. #include "drug.h"
  96. #include <QxOrm_Impl.h>
  97. int main(int argc, char * argv[])
  98. {
  99. QApplication app(argc, argv); // Qt application
  100. // Create 3 new drugs
  101. // It is possible to use 'boost' and 'Qt' smart pointer : 'boost::shared_ptr', 'QSharedPointer', etc...
  102. typedef std::shared_ptr<drug> drug_ptr;
  103. drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1";
  104. drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2";
  105. drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3";
  106. // Insert drugs into container
  107. // It is possible to use a lot of containers from 'std', 'boost', 'Qt' and 'qx::QxCollection<Key, Value>'
  108. typedef std::vector<drug_ptr> type_lst_drug;
  109. type_lst_drug lst_drug;
  110. lst_drug.push_back(d1);
  111. lst_drug.push_back(d2);
  112. lst_drug.push_back(d3);
  113. // Init parameters to communicate with a database
  114. qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
  115. qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db");
  116. qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
  117. qx::QxSqlDatabase::getSingleton()->setUserName("root");
  118. qx::QxSqlDatabase::getSingleton()->setPassword("");
  119. // Create table 'drug' into database to store drugs
  120. QSqlError daoError = qx::dao::create_table<drug>();
  121. // Insert drugs from container to database
  122. // 'id' property of 'd1', 'd2' and 'd3' are auto-updated
  123. daoError = qx::dao::insert(lst_drug);
  124. // Modify and update the second drug into database
  125. d2->name = "name2 modified";
  126. d2->description = "desc2 modified";
  127. daoError = qx::dao::update(d2);
  128. // Delete the first drug from database
  129. daoError = qx::dao::delete_by_id(d1);
  130. // Count drugs into database
  131. long lDrugCount = qx::dao::count<drug>();
  132. // Fetch drug with id '3' into a new variable
  133. drug_ptr d_tmp; d_tmp.reset(new drug());
  134. d_tmp->id = 3;
  135. daoError = qx::dao::fetch_by_id(d_tmp);
  136. // Export drugs from container to a file under XML format (serialization)
  137. qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml");
  138. // Import drugs from XML file into a new container
  139. type_lst_drug lst_drug_tmp;
  140. qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml");
  141. // Clone a drug
  142. drug_ptr d_clone = qx::clone(* d1);
  143. // Create a new drug by class name (factory)
  144. qx::any d_any = qx::create("drug");
  145. // Insert drugs container into 'qx::cache'
  146. qx::cache::set("drugs", lst_drug);
  147. // Remove all elements from 'qx::cache'
  148. qx::cache::clear();
  149. // Create a dummy memory leak
  150. drug * pDummy = new drug();
  151. return 0;
  152. }
  153. * \endcode
  154. *
  155. * <br>
  156. * 4- execute program and trace output debug
  157. * \code
  158. [QxOrm] qx::QxSqlDatabase : create new database connection in thread '3616' with key '{d315250c-b5c9-46e0-9402-f800368a6673}'
  159. [QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)
  160. [QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc)
  161. [QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis
  162. [QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id
  163. [QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug
  164. [QxOrm] sql query (0 ms) : SELECT drug.id AS drug_id_0, drug.name AS drug_name_0, drug.desc AS drug_desc_0 FROM drug WHERE drug_id_0 = :id
  165. [QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74)
  166. [QxOrm] **** 1 memory leaks found ****
  167. * \endcode
  168. *
  169. * <br>
  170. * 5- <i>export_drugs.xml</i> file created by the program
  171. * \code
  172. <std.vector-boost.shared_ptr-drug-- class_id="0" tracking_level="0" version="0">
  173. <count>3</count>
  174. <item_version>1</item_version>
  175. <item class_id="1" tracking_level="0" version="1">
  176. <px class_id="2" tracking_level="1" version="1" object_id="_0">
  177. <id>1</id>
  178. <name class_id="3" tracking_level="0" version="0">name1</name>
  179. <desc>desc1</desc>
  180. </px>
  181. </item>
  182. <item>
  183. <px class_id_reference="2" object_id="_1">
  184. <id>2</id>
  185. <name>name2 modified</name>
  186. <desc>desc2 modified</desc>
  187. </px>
  188. </item>
  189. <item>
  190. <px class_id_reference="2" object_id="_2">
  191. <id>3</id>
  192. <name>name3</name>
  193. <desc>desc3</desc>
  194. </px>
  195. </item>
  196. </std.vector-boost.shared_ptr-drug-->
  197. * \endcode
  198. */
  199. /*!
  200. * \brief Root namespace for all QxOrm library features
  201. */
  202. namespace qx {
  203. /*!
  204. * \ingroup QxCache
  205. * \brief Provide basic thread-safe cache feature to backup and restore any kind of objects (for example, object fetched from database)
  206. */
  207. namespace cache {
  208. /*!
  209. * \ingroup QxCache
  210. * \brief Internal helper tools for qx::cache namespace
  211. */
  212. namespace detail {
  213. } // namespace detail
  214. } // namespace cache
  215. /*!
  216. * \ingroup QxDao
  217. * \brief Database communication used by persistence engine (ORM - Object Relational Mapping)
  218. */
  219. namespace dao {
  220. /*!
  221. * \ingroup QxDao
  222. * \brief Internal helper tools for qx::dao namespace
  223. */
  224. namespace detail {
  225. } // namespace detail
  226. } // namespace dao
  227. /*!
  228. * \ingroup QxFunction
  229. * \brief Register function into QxOrm context used by introspection engine
  230. */
  231. namespace function {
  232. /*!
  233. * \ingroup QxFunction
  234. * \brief Internal helper tools for qx::function namespace
  235. */
  236. namespace detail {
  237. } // namespace detail
  238. } // namespace function
  239. /*!
  240. * \ingroup QxMemLeak
  241. * \brief QxOrm library memory leak detection (by Wu Yongwei)
  242. */
  243. namespace memory {
  244. } // namespace memory
  245. /*!
  246. * \ingroup QxSerialize
  247. * \brief QxOrm library serialization engine based on boost::serialization library
  248. */
  249. namespace serialization {
  250. /*!
  251. * \ingroup QxSerialize
  252. * \brief Internal helper tools for qx::serialization namespace
  253. */
  254. namespace detail {
  255. } // namespace detail
  256. /*!
  257. * \ingroup QxSerialize
  258. * \brief QxOrm library serialization engine for wide archive
  259. */
  260. namespace wide {
  261. } // namespace wide
  262. } // namespace serialization
  263. /*!
  264. * \ingroup QxService
  265. * \brief QxOrm library services engine to provide easy and powerful way to create C++ application server (to transfer data over network)
  266. */
  267. namespace service {
  268. } // namespace service
  269. /*!
  270. * \ingroup QxTraits
  271. * \brief QxOrm library traits (template metaprogramming) not available in boost::type_traits library
  272. */
  273. namespace trait {
  274. /*!
  275. * \ingroup QxTraits
  276. * \brief Internal helper tools for qx::trait namespace
  277. */
  278. namespace detail {
  279. } // namespace detail
  280. } // namespace trait
  281. /*!
  282. * \ingroup QxCollection
  283. * \brief Foreach-style (based on BOOST_FOREACH macro) to iterate over all stl, boost and Qt containers + qx::QxCollection<Key, Value> QxOrm library container
  284. */
  285. namespace foreach {
  286. } // namespace foreach
  287. /*!
  288. * \ingroup QxCommon
  289. * \brief Provide global functions to convert any kind of objects to/from QString and QVariant format
  290. */
  291. namespace cvt {
  292. /*!
  293. * \ingroup QxCommon
  294. * \brief Internal helper tools for qx::cvt namespace
  295. */
  296. namespace detail {
  297. } // namespace detail
  298. } // namespace cvt
  299. } // namespace qx