Changeset 362 for PersistentData/Backend


Ignore:
Timestamp:
May 10, 2012, 1:18:25 PM (12 years ago)
Author:
chronos
Message:
  • Modified: PersistentData Memory backend partial implementation.
  • Modified: Some persistent type system modifications.
Location:
PersistentData/Backend
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • PersistentData/Backend/UPDClientMemory.pas

    r361 r362  
    1414  TPDClientMemory = class(TPDClient)
    1515  protected
     16    FLastObjectId: Integer;
    1617    procedure InitSystemTypes; override;
    1718    function GetConnected: Boolean; override;
    1819    procedure Init; override;
     20    function GetNewObjectId: Integer;
     21    function SearchObject(Id: Integer): TObjectProxy;
    1922  public
    2023    Objects: TListObject;
     
    3538  end;
    3639
     40resourcestring
     41  SObjectNotFound = 'Object with id %s not found';
     42
    3743implementation
    3844
     
    5460end;
    5561
     62function TPDClientMemory.GetNewObjectId: Integer;
     63begin
     64  Inc(FLastObjectId);
     65  Result := FLastObjectId;
     66end;
     67
     68function TPDClientMemory.SearchObject(Id: Integer): TObjectProxy;
     69var
     70  I: Integer;
     71begin
     72  I := 0;
     73  while (I < Objects.Count) and
     74    (TObjectProxy(Objects[I]).Id <> Id) do Inc(I);
     75  if I < Objects.Count then Result := TObjectProxy(Objects[I])
     76    else Result := nil;
     77end;
     78
    5679procedure TPDClientMemory.ObjectLoad(AObject: TObjectProxy);
    57 begin
    58 
     80var
     81  Obj: TObjectProxy;
     82begin
     83  if AObject.Id = 0 then raise Exception.Create(SCantLoadObjectWithoutId);
     84  Obj := SearchObject(AObject.Id);
     85  if Assigned(Obj) then AObject.Assign(Obj)
     86    else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id]);
    5987end;
    6088
    6189procedure TPDClientMemory.ObjectSave(AObject: TObjectProxy);
    62 begin
    63 
     90var
     91  I: Integer;
     92  Obj: TObjectProxy;
     93begin
     94  if AObject.Id = 0 then raise Exception.Create(SCantLoadObjectWithoutId);
     95  Obj := SearchObject(AObject.Id);
     96  if Assigned(Obj) then Obj.Assign(AObject)
     97    else begin
     98      AObject.Id := GetNewObjectId;
     99      Obj := TObjectProxy(Objects.AddNew(TObjectProxy.Create));
     100      Obj.Assign(AObject);
     101    end;
    64102end;
    65103
    66104procedure TPDClientMemory.ObjectDelete(AObject: TObjectProxy);
    67 begin
    68 
     105var
     106  Obj: TObjectProxy;
     107begin
     108  Obj := SearchObject(AObject.Id);
     109  if Assigned(Obj) then Objects.Delete(Objects.IndexOf(Obj))
     110    else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id])
    69111end;
    70112
    71113procedure TPDClientMemory.ListLoad(AList: TListProxy);
    72 begin
    73 
     114var
     115  Filter: string;
     116  DbCondition: string;
     117  I: Integer;
     118  P: Integer;
     119  NewObject: TObjectProxy;
     120  Table: string;
     121begin
     122  AList.Objects.Clear;
     123  for I := 0 to Objects.Count - 1 do
     124  with TObjectProxy(Objects[I]) do begin
     125    if 1 = 1 then begin
     126      NewObject := TObjectProxy.Create;
     127      NewObject.Properties.Assign(Properties);
     128      NewObject.Client := AList.Client;
     129      NewObject.ObjectName := AList.ObjectName;
     130      NewObject.Path := AList.Path;
     131      AList.Objects.Add(NewObject);
     132
     133      if AList.ColummsFilterUse then begin
     134        for P := 0 to Properties.Count - 1 do
     135        if AList.ColumnsFilter.IndexOf(Properties.Keys[I]) <> -1 then
     136          NewObject.Properties.Add(Properties.Keys[I], Properties[I].Value);
     137      end else NewObject.Properties.Assign(Properties);
     138    end;
     139  end;
     140  if AList.OrderUse then begin
     141
     142  end;
     143  if AList.PageUse then begin
     144  end;
    74145end;
    75146
  • PersistentData/Backend/UPDClientMySQL.pas

    r361 r362  
    5050resourcestring
    5151  SMissingBaseType = 'Missing base typ for %s';
    52   SUndefinedType = 'Undefinned type %s';
    53   SCantLoadObjectWithoutId = 'Can''t load object without id';
     52  SUndefinedType = 'Undefined type in %0:s.%1:s';
    5453
    5554
     
    172171    for I := 0 to AType.Properties.Count - 1 do
    173172    with AType.Properties do begin
    174       RefType := Types.SearchByName(Items[I].Value);
     173      RefType := TPDTypeProperty(Items[I]).DbType;
    175174      if not Assigned(RefType) then
    176         raise Exception.Create(Format(SUndefinedType, [Items[I].Value]));
     175        raise Exception.Create(Format(SUndefinedType, [AType.Name, TPDTypeProperty(Items[I]).Name]));
    177176      if RefType.DbType = '' then
    178177        raise Exception.Create(Format(SMissingBaseType, [RefType.Name]));
    179178
    180       Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' NULL,';
     179      Query := Query + '`' + TPDTypeProperty(Items[I]).Name + '` ' + RefType.DbType + ' NULL,';
    181180    end;
    182181    Query := Query + 'PRIMARY KEY (`Id`)' +
Note: See TracChangeset for help on using the changeset viewer.