Fetching the same instance...

Forum for posting problems using QxOrm library

Fetching the same instance...

Postby gianks » Thu Jul 28, 2016 5:29 pm

Hi all,
while moving on with QxOrm i've found it really powerfull but now i'm unsure about a behaviour of the library because even if it is desirable probably most of the time, it's creating a lot of troubles in my design.
Is possible to fetch an object multiple times obtaining the same underlaying instance?
In my case i need to fetch a series of objects which become unique at runtime because they are providing access to runtime objects that are not stored in the DB. This is fine.
Later i need to fetch a new series of objects with a 2 levels of relationships, which are in the last one pointing to the first table used before.

My app crashes since now i would expect to have a QSharedPointer<FirstObject> different from the one in the 1st level relationship, but both should point to the same real object; that's not true since now i have two different C++ Objects with same ID. The one obtained later is just a copy of what in the DB, obviously.

Can QxOrm keep track of already fetched objects in order to provide a copy of the shared pointer instead of a new object, at least when the object is just referred as a relationship?

My design relies on the idea of references that are used at runtime, if i fetch an object that's just a multiple format container to access the final object i need the object i'm already working with, otherwise having relationships is just making things harder :mrgreen:
gianks
 
Posts: 45
Joined: Mon Jul 04, 2016 1:04 pm

Re: Fetching the same instance...

Postby qxorm » Thu Jul 28, 2016 6:45 pm

Hello,

Maybe you could use the QxCache module, more details :
- here : https://www.qxorm.com/qxorm_en/manual.html#manual_490
- and here : https://www.qxorm.com/doxygen/html/grou ... cache.html

The idea would be :
- before fetching an instance, just check if it has already been fetched (so it is in the cache or not) ;
- if yes, then get the instance from the cache ;
- if no, then fetch from database, then insert it in the cache.

You can even create your own fetch() function with this process.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Fetching the same instance...

Postby gianks » Sat Jul 30, 2016 4:13 pm

Hi and thanks for the suggestion.
I've read the documentation but even if the 'cache' word seems appropriate the way is implemented in QxOrm is not solving the problem.

Would be perfect if the cache module could be activated and used in a transparent way, i mean caching automatically object (using shared pointers is ideal) based on TYPE+ID.
Working with strings to store manually objects can be satisfacting in small contexts but in my case i have to manually implement my complete caching system (based on the previous idea) avoiding direct Qx operations outside of it... which is frustrating, it's gonna cost a huge amount of work and i'm suspecting that the resulting overhead will be much higher and last but not least the application design will result less clear. Consider a complex series of relationships which are used at runtime up to the 5th level: it becomes anyway my responsibility to adjust the pointers of each referred object, on each level, causing a huge number of meaningless construction and deletion of objects during queries. On the other side the only simple solution that can fit is to load all the DB in memory during the startup, which again is a sustainable approach just for minor applications and for sure is not scalable on multiple systems.

So, if no other ways are built-in to accomplish this, the only think i can do is to suggest to the developers to extend the capability of the cache module letting the final programmer to work with cached object in a transparent way, optimizing the caching process already in QxOrm.

This is not a criticism, just an opinion, a point of view.
By the way QxOrm is a great library, thanks for the excellent job.
gianks
 
Posts: 45
Joined: Mon Jul 04, 2016 1:04 pm

Re: Fetching the same instance...

Postby qxorm » Sat Jul 30, 2016 8:50 pm

Hello,

You are not the first one to ask for this kind of feature, so I think I will try to implement it for QxOrm 1.4.4 (not QxOrm 1.4.3 because this version is in test mode now).

By the way, if you want to test QxOrm 1.4.3 BETA version, here is a link : https://www.qxorm.com/version/QxOrm_1.4.3_BETA_41.zip
And here is the changes log :
- Support CMake : new CMakeLists.txt file added to build QxOrm library with CMake
- Improve SQL error messages when qx::dao functions return a database error
- New parameter in singleton class qx::QxSqlDatabase to log SQL bound values (setTraceSqlBoundValues) : by default, bound values are logged when an error occurred
- New syntax to select columns to not fetch : -{ col_1, col_2, etc... }
- New function qx::dao::call_query_without_prepare() to execute specific SQL queries without prepared statement
- Improve QxModelView module : all QxOrm models (based on qx::IxModel interface) can be serialized to JSON format (including all relationships levels) : this is now another way to work with relationships and QML (thanks to JSON.parse() and JSON.stringify() javascript functions) without using nested models concept (so without using QxEntityEditor model/view generated classes)
- Improve qxBlogModelView sample project and QxOrm manual to show how to access to relationships data in QML (nested models or JSON)
- Fix a memory leak in qx::QxSqlRelation class
- Reduce output binary size (~20%) and compilation times (~20%) to build persistent classes based on QxOrm library
- Support unity build concept to reduce compilation times to build QxOrm library and C++ persistent classes generated by QxEntityEditor application : for more details, see _QX_UNITY_BUILD compilation option in QxOrm.pri or QxOrm.cmake configuration file


By the way QxOrm is a great library, thanks for the excellent job.

Thx !
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Fetching the same instance...

Postby gianks » Sat Aug 13, 2016 1:25 pm

Maybe i've overstated the complexity in the beginning, with a not so easy combination of C++ templates and inheritance it's achievable. 8-)
Thanks for the support, till now excellent!

Gianks
gianks
 
Posts: 45
Joined: Mon Jul 04, 2016 1:04 pm


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron