09-09-2008, 4:31 PM
|
Marco
Joined on 09-10-2008
Posts 2
|
Checking for object equality
|
 
 
|
|
|
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
|
|
|
|