Results 1 to 20 of 20

Thread: QxOrm : Persistence (ORM), Serialization, Reflection

  1. #1
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default QxOrm : Persistence (ORM), Serialization, Reflection

    Hello,

    QxOrm is a new open source ORM (Object Relational Mapping) C++ library designed to provide :
    * Persistence (based on QtSql Qt module)
    * Serialization (xml and binary, based on boost::serialization)
    * Reflection (invoke class methods and access to properties)

    QxOrm has been tested on Windows (Visual C++ 2008 and 2010) and Linux (GCC 4.4.1).

    QxOrm is based on a simple and non intrusive 'setting function' (that can be compared with Hibernate Xml Mapping file).

    A quick sample (and a tutorial) is avaible on this web site (only in french, an english translation is in progress...) : http://www.qxorm.com

    PS: Sorry for my poor english

    ________

    Quick sample using QxOrm :

    * 1- 'drug.h' file : drug class definition with 3 properties : 'id', 'name' and 'description'
    * 2- 'drug.cpp' file : setting function 'void qx::register_class()'
    * 3- 'main.cpp' file : using QxOrm with drug class
    * 4- Execute test program and print log output
    * 5- 'export_drugs.xml' file created by test program

    * -----------------------------------------------------------------------------------------------------
    * 1- 'drug.h' file : drug class definition with 3 properties : 'id', 'name' and 'description'
    * -----------------------------------------------------------------------------------------------------
    Qt Code:
    1. #ifndef _CLASS_DRUG_H_
    2. #define _CLASS_DRUG_H_
    3.  
    4. class drug
    5. {
    6. public:
    7. long id;
    8. QString name;
    9. QString description;
    10.  
    11. drug() : id(0) { ; }
    12. virtual ~drug() { ; }
    13. };
    14.  
    15. QX_REGISTER_HPP_MY_TEST_EXE(drug, qx::trait::no_base_class_defined, 1)
    16.  
    17. /* This macro is necessary to register 'drug' class in QxOrm context */
    18. /* param 1 : the current class to register => 'drug' */
    19. /* param 2 : the base class, if no base class, use the qx trait => 'qx::trait::no_base_class_defined' */
    20. /* param 3 : the class version used by serialization to provide 'ascendant compatibility' */
    21.  
    22. #endif // _CLASS_DRUG_H_
    To copy to clipboard, switch view to plain text mode 

    * -----------------------------------------------------------------------------------------------------
    * 2- 'drug.cpp' file : setting function 'void qx::register_class()'
    * -----------------------------------------------------------------------------------------------------
    Qt Code:
    1. #include "precompiled.h" // Precompiled-header with '#include <QxOrm.h>' and '#include "export.h"'
    2. #include "drug.h" // Class definition 'drug'
    3. #include <QxMemLeak.h> // Automatic memory leak detection
    4.  
    5. QX_REGISTER_CPP_MY_TEST_EXE(drug) // This macro is necessary to register 'drug' class in QxOrm context
    6.  
    7. namespace qx {
    8. template <> void register_class(QxClass<drug> & t)
    9. {
    10. t.id(& drug::id, "id"); // Register 'drug::id' <=> primary key in your database
    11. t.data(& drug::name, "name", 1); // Register 'drug::name' property with key 'name' and version '1'
    12. t.data(& drug::description, "desc"); // Register 'drug::description' property with key 'desc'
    13. }}
    To copy to clipboard, switch view to plain text mode 


    * -----------------------------------------------------------------------------------------------------
    * 3- 'main.cpp' file : using QxOrm with drug class
    * -----------------------------------------------------------------------------------------------------
    Qt Code:
    1. #include "precompiled.h"
    2. #include "drug.h"
    3. #include <QxMemLeak.h>
    4.  
    5. int main(int argc, char * argv[])
    6. {
    7. QApplication app(argc, argv); // Qt application
    8.  
    9. // Create 3 new drugs
    10. // It is possible to use 'boost' and 'Qt' smart pointer : 'boost::shared_ptr', 'QSharedPointer', etc...
    11. typedef boost::shared_ptr<drug> drug_ptr;
    12. drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1";
    13. drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2";
    14. drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3";
    15.  
    16. // Insert drugs into container
    17. // It is possible to use a lot of containers from 'std', 'boost', 'Qt' and 'qx::QxCollection<Key, Value>'
    18. typedef std::vector<drug_ptr> type_lst_drug;
    19. type_lst_drug lst_drug;
    20. lst_drug.push_back(d1);
    21. lst_drug.push_back(d2);
    22. lst_drug.push_back(d3);
    23.  
    24. // Init parameters to communicate with a database
    25. qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
    26. qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db");
    27. qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
    28. qx::QxSqlDatabase::getSingleton()->setUserName("root");
    29. qx::QxSqlDatabase::getSingleton()->setPassword("");
    30.  
    31. // Create table 'drug' into database to store drugs
    32. QSqlError daoError = qx::dao::create_table<drug>();
    33.  
    34. // Insert drugs from container to database
    35. // 'id' property of 'd1', 'd2' and 'd3' are auto-updated
    36. daoError = qx::dao::insert(lst_drug);
    37.  
    38. // Modify and update the second drug into database
    39. d2->name = "name2 modified";
    40. d2->description = "desc2 modified";
    41. daoError = qx::dao::update(d2);
    42.  
    43. // Delete the first drug from database
    44. daoError = qx::dao::delete_by_id(d1);
    45.  
    46. // Count drugs into database
    47. long lDrugCount = qx::dao::count<drug>();
    48.  
    49. // Fetch drug with id '3' into a new variable
    50. drug_ptr d_tmp; d_tmp.reset(new drug());
    51. d_tmp->id = 3;
    52. daoError = qx::dao::fetch_by_id(d_tmp);
    53.  
    54. // Export drugs from container to a file under xml format (serialization)
    55. qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml");
    56.  
    57. // Import drugs from xml file into a new container
    58. type_lst_drug lst_drug_tmp;
    59. qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml");
    60.  
    61. // Clone a drug
    62. drug_ptr d_clone = qx::clone(* d1);
    63.  
    64. // Create a new drug by class name (factory)
    65. boost::any d_any = qx::create("drug");
    66.  
    67. // Insert drugs container into 'qx::cache'
    68. qx::cache::set("drugs", lst_drug);
    69.  
    70. // Remove all elements from 'qx::cache'
    71. qx::cache::clear();
    72.  
    73. // Create a dummy memory leak
    74. drug * pDummy = new drug();
    75.  
    76. return 0;
    77. }
    To copy to clipboard, switch view to plain text mode 

    * -----------------------------------------------------------------------------------------------------
    * 4- Execute test program and print log output
    * -----------------------------------------------------------------------------------------------------
    Qt Code:
    1. [QxOrm] qx::QxSqlDatabase : create new database connection in thread '3616' with key '{d315250c-b5c9-46e0-9402-f800368a6673}'
    2. [QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)
    3. [QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc)
    4. [QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis
    5. [QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id
    6. [QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug
    7. [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
    8. [QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74)
    9. [QxOrm] **** 1 memory leaks found ****
    To copy to clipboard, switch view to plain text mode 

    * -----------------------------------------------------------------------------------------------------
    * 5- 'export_drugs.xml' file created by test program
    * -----------------------------------------------------------------------------------------------------
    Qt Code:
    1. <std.vector-boost.shared_ptr-drug-- class_id="0" tracking_level="0" version="0">
    2. <count>3</count>
    3. <item_version>1</item_version>
    4. <item class_id="1" tracking_level="0" version="1">
    5. <px class_id="2" tracking_level="1" version="1" object_id="_0">
    6. <id>1</id>
    7. <name class_id="3" tracking_level="0" version="0">name1</name>
    8. <desc>desc1</desc>
    9. </px>
    10. </item>
    11. <item>
    12. <px class_id_reference="2" object_id="_1">
    13. <id>2</id>
    14. <name>name2 modified</name>
    15. <desc>desc2 modified</desc>
    16. </px>
    17. </item>
    18. <item>
    19. <px class_id_reference="2" object_id="_2">
    20. <id>3</id>
    21. <name>name3</name>
    22. <desc>desc3</desc>
    23. </px>
    24. </item>
    25. </std.vector-boost.shared_ptr-drug-->
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hello,

    QxOrm 1.1.2 released.

    ----

    Changes in version 1.1.2:
    - License LGPL
    - Fix compilation problems on Linux and boost > 1.38
    - Fix sql query with MySql database
    - Disable assert when qx::dao functions return an error

    ----

  3. #3
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Looks great just not fond of the non-Qt styling. Shouldn't you use QSharedPointer rather than boost::shared_ptr?
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  4. #4
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    You can use both QSharedPointer, QScopedPointer of Qt library (see 'category' class of the tutorial) or boost::shared_ptr, boost::scoped_ptr of boost library (see 'author' class of the tutorial).
    This is the same thing with containers : you can use containers of stl, boost or Qt library with QxOrm.
    Last edited by QxOrm; 20th October 2010 at 09:24.

  5. #5
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.3 released.

    ----

    Changes in version 1.1.3:
    - This version works fine with MinGW on Windows

    ----

  6. #6
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.4 released :

    ----

    Changes in version 1.1.4:
    - New parameter in functions 'qx::dao::fetch_by_id', 'qx::dao::fetch_all', 'qx::dao::fetch_by_query' and 'qx::dao::update' to define a list of properties to fetch/update (by default, all properties are fetched/updated)
    - Support multi-columns primary key (composite key) : see sample './test/qxBlog_composite_key/'
    - Improve strategy of inheritance : QxOrm supports 'Concrete Table Inheritance' strategy ('Concrete Table Inheritance' becomes default strategy)
    - New smart-pointer 'qx::dao:tr<T>' based on Qt 'QSharedPointer<T>' to provide 2 new features : 'is dirty' and 'update optimized'
    - 'qx::dao:tr<T>' can be used with a simple object and with many containers (stl, boost, Qt and 'qx::QxCollection' containers)
    - 'qx::dao:tr<T>' keeps original values from database and provides a 'isDirty()' method to retrieve all properties changed
    - 'qx::dao::update_optimized' must be used with 'qx::dao:tr<T>' to save into database only properties changed

    ----

  7. #7
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    I'm proud and happy to announce that QxOrm library has been accepted into the Qt Ambassador Program
    http://qt.nokia.com/qt-in-use/ambassadors/qtambassador

    The Qt Ambassador Program is a membership-only program that honors Qt development projects.

    Here the QxOrm web page on Qt and Nokia website :
    http://qt.nokia.com/qt-in-use/ambassado ... 006Kq9LEAS

  8. #8
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.5 released :

    ----

    Changes in version 1.1.5:
    - New feature available : 'QxService' module to create C++ application server
    - 'QxService' provides an easy and powerful way to create services and to transfer data over network
    - New tutorial available to explain how 'QxService' module works
    - New sample available at './test/qxClientServer' directory
    - QxOrm can be built with 'CONFIG += no_keywords' flag in '*.pro' files
    - Bug fix with 'qx::dao::create_table<>' function and relation 'many-to-many'
    - QxOrm should now build fine with GCC <= 4.2

    ----

  9. #9
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.6 released :

    ----

    Changes in version 1.1.6:
    - QxOrm library online documentation available : <http://www.qxorm.com/doxygen/index.html>
    - Possibility to disable QtGui dependency using compilation option in 'QxConfig.h' file : _QX_ENABLE_QT_GUI_DEPENDENCY
    - Possibility to disable QtNetwork dependency (so QxService module too) using compilation option in 'QxConfig.h' file : _QX_ENABLE_QT_NETWORK_DEPENDENCY
    - Provide a new macro to register abstract class into QxOrm context : QX_REGISTER_ABSTRACT_CLASS()

    ----

  10. #10
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.7 released :

    ----


    Changes in version 1.1.7:
    - Add soft delete behavior : see the FAQ (How to define a soft delete behavior ?) for more details about this new feature
    - Add functions into namespace 'qx::dao' to update an element with a SQL condition : update_by_query, update_optimized_by_query, etc.
    - Fix a bug when QVariant type is used for a property of a persistent class : so, it's now possible to insert NULL value into database

    ----

  11. #11
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.8 released :

    ----

    Changes in version 1.1.8:
    - QxOrm library can now be used on Mac (thanks very much to Dominique Billet) : see 'osx_build_all_debug.sh' and 'osx_build_all_release.sh' scripts to build QxOrm library and all samples in './test/' directory
    - Add 'qx::QxSession' class : define a session to manage automatically database transactions (using C++ RAII), see the FAQ for more details
    - Add 'qx::QxDateNeutral', 'qx::QxTimeNeutral' and 'qx::QxDateTimeNeutral' classes : helper classes to store date-time value into database under neutral format => cross database compatibility

    ----

  12. #12
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.1.9 released :

    ----

    Changes in version 1.1.9:
    - Possibility to register automatically Qt meta-properties (using Q_PROPERTY macro) to QxOrm context without writing mapping function per class (void qx::register_class<T>())
    - Strong integration with Qt introspection/moc engine : for more details about this new feature, goto the FAQ 'How to register automatically Qt meta-properties to QxOrm context ?'
    - Improve introspection/reflection engine : see the FAQ (How to use introspection engine (or reflection engine) of QxOrm library ?) for more details
    - Possibility to add meta-data (using a property bag) to introspection engine : see 'IxClass', 'IxDataMember' and 'IxFunction' classes for more details
    - Add function 'qx::QxClassX::dumpSqlSchema()' to explain how to create your own SQL schema based on C++ classes
    - New class 'qx::QxSimpleCrypt' to provide encryption/decryption (thanks very much to Andre Somers) : so it's now possible to store encrypted data into database without using an external library
    - QxService module : new feature to encrypt/decrypt data before transfering it over network

    ----

    For more informations about QxOrm library : http://www.qxorm.com/

  13. #13
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.2.1 released :

    ---

    Changes in version 1.2.1:



    ---

    For more informations about QxOrm library : http://www.qxorm.com/

  14. #14
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.2.2 released :

    ---

    Changes in version 1.2.2:
    - New module to provide a validation engine : QxValidator module
    - For more details about QxValidator module, goto the FAQ of QxOrm library : 'How to use QxValidator module to validate automatically an instance ?'
    - Fix last insert ID with PostgreSQL using 'RETURNING' keyword : fetch inserted ID instead of OID
    - Improve SQL generator providing the good SQL type for all databases
    - Add support for special database keywords using '[', ']' and '"' characters

    ---

    For more informations about QxOrm library : http://www.qxorm.com/

  15. #15
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.2.3 released :

    ---

    Changes in version 1.2.3:

    - New interface qx::IxPersistable (abstract class) to simplify polymorphism using QxOrm library ;
    - For more details about this new interface, goto the FAQ : How to use qx::IxPersistable interface ? ;
    - New methods into qx::IxCollection interface to iterate over each items without knowing its type ;
    - New option into QxOrm.pri file to build QxOrm library statically (see _QX_STATIC_BUILD option) ;
    - New triggers : qx::dao:: on_before_fetch and qx::dao:: on_after_fetch (for more details, goto the FAQ : How to define a Trigger with QxOrm ?) ;
    - Add std::type_info class information to introspection engine ;
    - Some minor bugs fixed (qx::dao::sql_error exception message, SQL query column alias, mutex, etc.).

    ---

    For more informations about QxOrm library : http://www.qxorm.com/

  16. #16
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.2.4 released :

    ----

    Changes in version 1.2.4:
    - New relationship engine to fetch easily many levels of relationships per query ;
    - For more details about this new engine, goto the FAQ : 'How to use relationship engine to fetch datas from many tables ?' ;
    - Add 2 functions : qx::dao::execute_query and qx::dao::call_query to call a stored procedure or a custom SQL query ;
    - For more details about this new feature, goto the FAQ : 'How to execute a stored procedure or a custom SQL query ?' ;
    - Add support for boost:: optional type to manage NULL database value without using QVariant type ;
    - New class : qx::QxDaoAsync to make easier to execute queries in asynchronous way (multi-thread) ;
    - For more details about this new class, goto the FAQ : 'How to use qx::QxDaoAsync class to execute queries in asynchronous way (multi-thread) ?'.

    ----

    For more informations about QxOrm library : http://www.qxorm.com/

  17. #17
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Hi,

    QxOrm 1.2.5 just released !

    ----

    Changes in version 1.2.5:
    - New license : go to download page of QxOrm website for more details
    - Support Qt5
    - New compiler supported : Clang (tested on Mac OS X)
    - Now each QxOrm version will be tested in 32-bit and 64-bit mode
    - Improve QxOrm introspection engine : possibility to register static class methods
    - Improve QxService module : now it's easy to add an authentication process on server side
    - New class qx::exception to get error code + error description with services methods throwing an exception
    - New settings available in QxOrm.pri config file (whithout changing QxConfig.h file)
    - Possibility to implement specifics database SQL functions overriding qx_query class
    - Fix an issue when fetching multiple levels of relationship and NULL pointers
    - Fix a bug with MS SQL Server database and update queries using auto-increment id

    ----

    For more details about QxOrm library : http://www.qxorm.com/

  18. #18
    Join Date
    Nov 2011
    Posts
    2
    Platforms
    Windows

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    can Qxorm automatically generate/reflect objects based from a live database table ?

  19. #19
    Join Date
    May 2010
    Posts
    34
    Thanked 1 Time in 1 Post

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    Yes... soon...
    With the next version (1.2.6), you will be able to generate automatically C++ classes with QxOrm registration context based on an existing database.
    The next version will be released in few days or few weeks in BETA test...

  20. #20
    Join Date
    Nov 2013
    Posts
    2
    Qt products
    Platforms
    Windows

    Default Re: QxOrm : Persistence (ORM), Serialization, Reflection

    good job thanks for the nice sharing.....


    http://plagiarism-checker.info

Similar Threads

  1. QDataStream and serialization
    By pdoria in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2009, 10:42
  2. java reflection
    By mickey in forum General Programming
    Replies: 1
    Last Post: 24th July 2008, 22:17
  3. Making a reflection of a picture
    By desch in forum Qt Programming
    Replies: 2
    Last Post: 17th February 2008, 19:38
  4. reflection and qmetaobject
    By KShots in forum Qt Programming
    Replies: 8
    Last Post: 16th May 2007, 21:53
  5. Serialization
    By donmorr in forum Qt Programming
    Replies: 4
    Last Post: 16th November 2006, 14:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.