/**************************************************************************** ** ** https://www.qxorm.com/ ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) ** ** 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 ** ** Commercial Usage ** Licensees holding valid commercial QxOrm licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Lionel Marty ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file 'license.gpl3.txt' included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met : http://www.gnu.org/copyleft/gpl.html ** ** If you are unsure which license is appropriate for your use, or ** if you have questions regarding the use of this file, please contact : ** contact@qxorm.com ** ****************************************************************************/ /* -- Main page for Doxygen documentation -- */ /*! * \mainpage QxOrm - C++ Object Relational Mapping library * * 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).
* QxOrm engine is based on a simple and non intrusive mapping function per class to provide : * * - Persistence (based on QtSql Qt module) ; * - Serialization (JSON, XML and binary, based on Qt and boost serialization engines) ; * - Reflection or Introspection (invoke dynamically class methods and access to properties) ; * - HTTP web server : standalone multi-threaded HTTP 1.1 web server (support SSL/TLS, persistent connections, cookies, sessions, chunked responses, URL dispatcher/routing) ; * - JSON API : interoperability with other technology than C++/Qt (REST web services, QML applications, scripting language). * * QxOrm is developed by Lionel Marty, a software development engineer since 2003.
* QxOrm library has been accepted into the Qt Ambassador Program.
* QxOrm library is available on GitHub. * * For more information about QxOrm library (quick sample, tutorial and forum), please visit : https://www.qxorm.com/.
* A manual (user guide) to learn how to work with QxOrm library is available on QxOrm website. *

* * \section quick_sample Quick sample using QxOrm library * * 1- drug.h file : drug class definition with 3 properties : id, name and description * \code #ifndef _CLASS_DRUG_H_ #define _CLASS_DRUG_H_ class drug { public: long id; QString name; QString description; drug() : id(0) { ; } virtual ~drug() { ; } }; QX_REGISTER_HPP_MY_TEST_EXE(drug, qx::trait::no_base_class_defined, 1) // This macro is necessary to register 'drug' class in QxOrm context // param 1 : the current class to register => 'drug' // param 2 : the base class, if no base class, use the qx trait => 'qx::trait::no_base_class_defined' // param 3 : the class version used by serialization to provide 'ascendant compatibility' #endif // _CLASS_DRUG_H_ * \endcode * *
* 2- drug.cpp file : setting function implementation - void qx::register_class() * \code #include "precompiled.h" // Precompiled-header with '#include ' and '#include "export.h"' #include "drug.h" // Class definition 'drug' #include // Automatic memory leak detection and boost serialization export macro QX_REGISTER_CPP_MY_TEST_EXE(drug) // This macro is necessary to register 'drug' class in QxOrm context namespace qx { template <> void register_class(QxClass & t) { t.id(& drug::id, "id"); // Register 'drug::id' <=> primary key in your database t.data(& drug::name, "name", 1); // Register 'drug::name' property with key 'name' and version '1' t.data(& drug::description, "desc"); // Register 'drug::description' property with key 'desc' }} * \endcode * *
* 3- main.cpp file : basic functionalities of QxOrm library with drug class * \code #include "precompiled.h" #include "drug.h" #include int main(int argc, char * argv[]) { QApplication app(argc, argv); // Qt application // Create 3 new drugs // It is possible to use 'boost' and 'Qt' smart pointer : 'boost::shared_ptr', 'QSharedPointer', etc... typedef std::shared_ptr drug_ptr; drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1"; drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2"; drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3"; // Insert drugs into container // It is possible to use a lot of containers from 'std', 'boost', 'Qt' and 'qx::QxCollection' typedef std::vector type_lst_drug; type_lst_drug lst_drug; lst_drug.push_back(d1); lst_drug.push_back(d2); lst_drug.push_back(d3); // Init parameters to communicate with a database qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE"); qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db"); qx::QxSqlDatabase::getSingleton()->setHostName("localhost"); qx::QxSqlDatabase::getSingleton()->setUserName("root"); qx::QxSqlDatabase::getSingleton()->setPassword(""); // Create table 'drug' into database to store drugs QSqlError daoError = qx::dao::create_table(); // Insert drugs from container to database // 'id' property of 'd1', 'd2' and 'd3' are auto-updated daoError = qx::dao::insert(lst_drug); // Modify and update the second drug into database d2->name = "name2 modified"; d2->description = "desc2 modified"; daoError = qx::dao::update(d2); // Delete the first drug from database daoError = qx::dao::delete_by_id(d1); // Count drugs into database long lDrugCount = qx::dao::count(); // Fetch drug with id '3' into a new variable drug_ptr d_tmp; d_tmp.reset(new drug()); d_tmp->id = 3; daoError = qx::dao::fetch_by_id(d_tmp); // Export drugs from container to a file under XML format (serialization) qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml"); // Import drugs from XML file into a new container type_lst_drug lst_drug_tmp; qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml"); // Clone a drug drug_ptr d_clone = qx::clone(* d1); // Create a new drug by class name (factory) qx::any d_any = qx::create("drug"); // Insert drugs container into 'qx::cache' qx::cache::set("drugs", lst_drug); // Remove all elements from 'qx::cache' qx::cache::clear(); // Create a dummy memory leak drug * pDummy = new drug(); return 0; } * \endcode * *
* 4- execute program and trace output debug * \code [QxOrm] qx::QxSqlDatabase : create new database connection in thread '3616' with key '{d315250c-b5c9-46e0-9402-f800368a6673}' [QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT) [QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc) [QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis [QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id [QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug [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 [QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74) [QxOrm] **** 1 memory leaks found **** * \endcode * *
* 5- export_drugs.xml file created by the program * \code 3 1 1 name1 desc1 2 name2 modified desc2 modified 3 name3 desc3 * \endcode */ /*! * \brief Root namespace for all QxOrm library features */ namespace qx { /*! * \ingroup QxCache * \brief Provide basic thread-safe cache feature to backup and restore any kind of objects (for example, object fetched from database) */ namespace cache { /*! * \ingroup QxCache * \brief Internal helper tools for qx::cache namespace */ namespace detail { } // namespace detail } // namespace cache /*! * \ingroup QxDao * \brief Database communication used by persistence engine (ORM - Object Relational Mapping) */ namespace dao { /*! * \ingroup QxDao * \brief Internal helper tools for qx::dao namespace */ namespace detail { } // namespace detail } // namespace dao /*! * \ingroup QxFunction * \brief Register function into QxOrm context used by introspection engine */ namespace function { /*! * \ingroup QxFunction * \brief Internal helper tools for qx::function namespace */ namespace detail { } // namespace detail } // namespace function /*! * \ingroup QxMemLeak * \brief QxOrm library memory leak detection (by Wu Yongwei) */ namespace memory { } // namespace memory /*! * \ingroup QxSerialize * \brief QxOrm library serialization engine based on boost::serialization library */ namespace serialization { /*! * \ingroup QxSerialize * \brief Internal helper tools for qx::serialization namespace */ namespace detail { } // namespace detail /*! * \ingroup QxSerialize * \brief QxOrm library serialization engine for wide archive */ namespace wide { } // namespace wide } // namespace serialization /*! * \ingroup QxService * \brief QxOrm library services engine to provide easy and powerful way to create C++ application server (to transfer data over network) */ namespace service { } // namespace service /*! * \ingroup QxTraits * \brief QxOrm library traits (template metaprogramming) not available in boost::type_traits library */ namespace trait { /*! * \ingroup QxTraits * \brief Internal helper tools for qx::trait namespace */ namespace detail { } // namespace detail } // namespace trait /*! * \ingroup QxCollection * \brief Foreach-style (based on BOOST_FOREACH macro) to iterate over all stl, boost and Qt containers + qx::QxCollection QxOrm library container */ namespace foreach { } // namespace foreach /*! * \ingroup QxCommon * \brief Provide global functions to convert any kind of objects to/from QString and QVariant format */ namespace cvt { /*! * \ingroup QxCommon * \brief Internal helper tools for qx::cvt namespace */ namespace detail { } // namespace detail } // namespace cvt } // namespace qx