Marcos Barreto
unread,Feb 1, 2012, 1:29:25 PM2/1/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to dorm-the-...@googlegroups.com
Daniele would like that I just change the methods of PersistentStrategy to receive just the mapping tables. But I think that adapters need a a liltle more refactory. But for while I think to follow him ideas.
My idea:
function TSession.Load(ATypeInfo: PTypeInfo; const Value: TValue): TObject;
var
rt: TRttiType;
_table: TMappingTable;
_fields: TMappingFieldList;
_idValue: TValue;
begin
rt := FCTX.GetType(ATypeInfo);
GetLogger.EnterLevel('Load ' + rt.ToString);
_table := FMappingStrategy.GetMapping(rt);
_fields := _table.Fields;
Result := FPersistStrategy.Load(rt, _table.TableName, _fields, Value);
if assigned(Result) then
begin
_idValue := GetIdValue(_table.Id, Result);
LoadBelongsToRelation(_table, _idValue, rt, Result);
LoadHasManyRelation(_table, _idValue, rt, Result);
LoadHasOneRelation(_table, _idValue, rt, Result);
end;
DoOnAfterLoad(Result);
GetLogger.ExitLevel('Load ' + rt.ToString);
end;
To turn this:
function TSession.Load(ATypeInfo: PTypeInfo; const Value: TValue): TObject;
var
rt: TRttiType;
begin
rt := FCTX.GetType(ATypeInfo);
GetLogger.EnterLevel('Load ' + rt.ToString);
Result := FPersistStrategy.Load(rt, Value);
DoOnAfterLoad(Result);
GetLogger.ExitLevel('Load ' + rt.ToString);
end;
FPersistStrategy could receive Session itself, and FMappingStrategy so FPersistStrategy could have
LoadBelongsToRelation, LoadHasManyRelation, LoadHasOneRelation and this methods could call the session.load to your relations.
With changes like this on session we can decide after load the objects with inner or left joins in future.
Other think cascade update/deletes and inserts.
I think that session have many responsabilities, but just play this thing on adapterbase too will turn it with many responsabilities
I think that we need break this way
Session ----> FPersistentStrategy -------> Driver ----> BaseAdapter and descendents (not sure yet just a idea)