Welcome to Macrobject Community Login | Register | Faq  

    Macrobject Community
  Macrobject Software Knowledge Management and Collaboration Platform
Search    
   

Re: Checking for object equality
Started by Marco at 09-09-2008 4:31 PM. Topic has 1 replies.

Print Search « Previous Thread Next Thread »
  09-09-2008, 4:31 PM
Marco is not online. Last active: 9/29/2008 4:57:11 PM Marco

Top 75 Posts
Joined on 09-10-2008
Posts 2
Checking for object equality
Reply Quote
Hi

First of all: Congratulations!! DObject is by far the best ORM framework I've seen for Delphi. I'm currently using the trial version. I have two questons so far:

First question:
When I load the same object from the DB twice, the two variables do not reference the same object in memory. Example:

-------
user1 := TUser.GetByCriteria( ObjectManager, OQL.Criteria(KM.User.Username).Equal('admin'));
user2 := TUser.GetByCriteria( ObjectManager, OQL.Criteria(KM.User.Username).Equal('admin'));
if (user1<>user2) then
ShowMessage('Error: should be exactly the same instance!');
--------
I tried using TLocalCache to solve this problem, but it didn't help. Is there a way to make this work? If not: I suggest that you use a TList to store a reference to all previously retrieved objects. When ever an object should be retrieved from the DB, you first check the TList if the desired object is already in the memory. If it's not, then - AND ONLY THEN - you physically load it from the DB as a new object and append it to the central TList.

Second question:
DObject creates a unit for business logic... e.g. NW_DO.pas. I tried overriding a persistent property in one of my business classes and put a breakpoint into the setter method:

-------
procedure TUser.SetUsername(const Value: string);
begin
ShowMessage('BREAKPOINT');
inherited Username := Value;
end;
--------
This works fine if I use the property in my own code. But when DObject loads a User-object from the DB, my setter never gets called. Sometimes it's necessary to correct values that are read from the DB... do you have any other way so that an object can check and correct its state after it has been loaded from the DB? If not: I suggest you implement a virtual protected method in TDataObject for this purpose: Something like

TDataObject = class .....
protected
procedure AfterLoad(); virtual;

On a side note, similar methods would be very useful for other stuff:
protected
procedure AfterLoad(); virtual;
procedure BeforeSave(); virtual;
procedure AfterSave(); virtual;
etc.

Thanks for your help and keep up the good work!!
Regards
Marco
   Report 
  09-10-2008, 10:12 AM
Bill is not online. Last active: 12/18/2009 11:43:49 PM Bill

Top 10 Posts
Joined on 06-28-2008
Posts 15
Re: Checking for object equality
Reply Quote
to First question

TLocalCache have limitations:
1. Before using TLocalCache, you need to set the CacheType of the specified tables to "Local" in code and re-generate the code. Only tables with "Local" CacheType will be cached. Do not cache tables with large amount of rows, that will have performance problems.
2. It not supports IQueryCondition, ISelectQuery and SQL string. If IQueryCondition, ISelectQuery or SQL string are used, it will load objects again from DB.

TLocalCache can:
1. Get the whole object set, or filtered by a filter object.
2. Get a single object filtered by a filter object (GetByPrimarykey using a filter object).
3. New objects will add to the cache.

TLocalCache will supports IQueryCondition later and so your code example will working.


to Second question
We'll test it.
   Report 
Post
Macrobject Comm... » Developing Tool... » DObject O/R Map... » Re: Checking for object equality

Powered by Community Server, by Telligent Systems