I need adjust on Criteria

33 views
Skip to first unread message

mrbar2000

unread,
Feb 9, 2012, 9:57:31 AM2/9/12
to dorm, The Delphi ORM
Hi Daniele,

While refactoring the session, I touch on Load, FindOne, FindAll, List
and Fill(s) methods.
I think that all this routines are very similar then I have a idea to
let this session simpler.

I have mapped all methods that we have on dorm to read object and
collection of objects. this is the results

TSession.Load(ATypeInfo: PTypeInfo; const AValue: TValue):
TObject;
TSession.Load<T>(const Value: TValue): T; ==> CALL 1
TSession.FillList<T>(ACollection: TObject; AItemClassInfo:
PTypeInfo; Criteria: TdormCriteria; FillOptions: TdormFillOptions;
FreeCriteria: Boolean);
TSession.FillList<T>(ACollection: TObject; AdormSearchCriteria:
IdormSearchCriteria; FillOptions: TdormFillOptions);
TSession.FillList<T>(ACollection: TObject; Criteria:
TdormCriteria; FillOptions: TdormFillOptions; FreeCriteria: Boolean);
TSession.FindOne(AItemClassInfo: PTypeInfo; Criteria:
TdormCriteria; FillOptions: TdormFillOptions; FreeCriteria: Boolean):
TObject;
TSession.FindOne<T>(Criteria: TdormCriteria; FillOptions:
TdormFillOptions; FreeCriteria: Boolean): T;
TSession.List<T>(AdormSearchCriteria: IdormSearchCriteria): {$IF
CompilerVersion > 22}TObjectList<T>{$ELSE}TdormObjectList<T>{$IFEND};
TSession.List<T>(AItemClassInfo: PTypeInfo; Criteria:
TdormCriteria; FillOptions: TdormFillOptions; FreeCriteria: Boolean):
{$IF CompilerVersion > 22}TObjectList<T>{$ELSE}
TdormObjectList<T>{$IFEND};
TSession.List<T>(Criteria: TdormCriteria; FreeCriteria: Boolean =
true): {$IF CompilerVersion > 22}TObjectList<T>{$ELSE}
TdormObjectList<T>{$IFEND};
TSession.ListAll<T>(FillOptions: TdormFillOptions = []): {$IF
CompilerVersion > 22}TObjectList<T>{$ELSE}TdormObjectList<T>{$IFEND};


What u think about to use criteria for all! Relax i will explain
better.
On session we could have just
TSession.Load<T>(ICriteria<T>): T
TSession.Load<T>(OidValue): T => internally this call
TSession.Load<T>(ICriteria<T>): T
TSession.NewCriteria<T>: TCriteria<T> or ICriteria<T>

Look that just with this 3 methods we could load anything!

On TSession.NewCriteria we could create a TCriteria passing the
session (self).
ICriteria<T> could have 2 methods GetList<T> and GetOne<T>
so when programmer call one of this 2 methods we could call Result :=
Session.Load<T>(Self).

IdormSearchCriteria (that I would rename to ICustomCriteria) could
inherited from ICriteria, then on Persister.Load we could verify if
that criteria instance implements ICustomCriteria call the rightly
methods.

Any query will be simpler this way!
The only problem here is about circular reference, but this could be
resolved using interfaces OR puting TSession and TCriteria into same
unit.

What u think?

mrbar2000

unread,
Feb 9, 2012, 10:00:57 AM2/9/12
to dorm, The Delphi ORM
Fix: I think that Criteria have to be interface to be freed
automatically when out of scope.

Daniele Teti

unread,
Feb 9, 2012, 11:12:17 AM2/9/12
to dorm-the-...@googlegroups.com
Huge changes! However, this is not a big problem. I didnt understand how will be possibile to fill a list of object. Warning. Fill, not Load list of objects.

Could you explain?

2012/2/9 mrbar2000 <mrba...@gmail.com>
Fix: I think that Criteria have to be interface to be freed
automatically when out of scope.

--
You received this message because you are subscribed to the Google Groups "dorm, The Delphi ORM" group.
To post to this group, send email to dorm-the-...@googlegroups.com.
To unsubscribe from this group, send email to dorm-the-delphi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dorm-the-delphi-orm?hl=en.




--
--------------------------------------------
Daniele Teti
R&D Director & Educational @ bitTime Software
http://www.danieleteti.it

mrbar2000

unread,
Feb 9, 2012, 12:49:56 PM2/9/12
to dorm, The Delphi ORM
we could create methods procedure passing the list
procedure TSession.Load<T>(ICriteria<T>; MyList); overload;
procedure TSession.Load(OidValue; T)
ICriteria.GetList and GetOne could be overload too and receive the
list or the object to fill

Can u make this changes daniele?

Daniele Teti

unread,
Feb 9, 2012, 5:08:53 PM2/9/12
to dorm-the-...@googlegroups.com
Hi,

yes I can do that changes.
However IMHO ICriteria should be a specification and the responsibility should be only for session.
Infaact in the current implementation there is
Session.FillList(Criteria)
Because ICriteria is a specification pattern.

see you

2012/2/9 mrbar2000 <mrba...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "dorm, The Delphi ORM" group.
To post to this group, send email to dorm-the-...@googlegroups.com.
To unsubscribe from this group, send email to dorm-the-delphi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dorm-the-delphi-orm?hl=en.

Reply all
Reply to author
Forward
0 new messages