Ignore:
Timestamp:
Mar 9, 2012, 1:09:52 PM (13 years ago)
Author:
chronos
Message:
  • Fixed: Selection of available protocols in profile manager.
  • Modified: Initialization of persistent data structures rewrited to more native structures.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UChronisClient.pas

    r37 r43  
    99
    1010type
     11  EClientNotSet = class(Exception);
     12
    1113  TChronisClient = class;
    1214
     
    5254  end;
    5355
     56  { TChronisType }
     57
    5458  TChronisType = class
    55     OID: Integer;
     59    Client: TChronisClient;
    5660    Name: string;
    57   end;
    58 
    59   TChronisTypeRecordItem = class
    60     Name: string;
    61     ItemType: TChronisType;
    62   end;
    63 
    64   { TChronisTypeRecord }
    65 
    66   TChronisTypeRecord = class(TChronisType)
    67     Items: TListObject; // TListObject<TChronisTypeRecordItem>
     61    DbType: string;
     62    Properties: TDictionaryStringString;
     63    procedure Define;
     64    procedure Undefine;
    6865    constructor Create;
    6966    destructor Destroy; override;
    7067  end;
    7168
     69  { TChronisTypeList }
     70
     71  TChronisTypeList = class(TListObject)
     72    Client: TChronisClient;
     73    function AddType(Name: string; DbType: string = ''): TChronisType;
     74    function SearchByName(Name: string): TChronisType;
     75  end;
     76
    7277  { TChronisClient }
    7378
    7479  TChronisClient = class
     80  private
    7581  protected
     82    procedure InitSystemTypes; virtual;
    7683    function GetConnected: Boolean; virtual;
    7784  public
     
    8188    User: string;
    8289    Password: string;
     90    Types: TChronisTypeList;
    8391    procedure ObjectLoad(AObject: TObjectProxy); virtual; abstract;
    8492    procedure ObjectSave(AObject: TObjectProxy); virtual; abstract;
     
    8795    procedure ListLoad(AList: TListProxy); virtual; abstract;
    8896    procedure ListSave(AList: TListProxy); virtual; abstract;
    89     procedure DefineType(AType: TChronisType); virtual; abstract;
    90     procedure UndefineType(AType: TChronisType); virtual; abstract;
     97    procedure TypeDefine(AType: TChronisType); virtual; abstract;
     98    procedure TypeUndefine(AType: TChronisType); virtual; abstract;
     99    procedure CheckTypes;
    91100    constructor Create; virtual;
     101    destructor Destroy; override;
    92102    procedure Connect; virtual; abstract;
    93103    procedure Disconnect; virtual; abstract;
     
    95105  end;
    96106
     107
    97108implementation
    98109
    99 { TChronisTypeRecord }
    100 
    101 constructor TChronisTypeRecord.Create;
    102 begin
    103   Items := TListObject.Create;
    104 end;
    105 
    106 destructor TChronisTypeRecord.Destroy;
    107 begin
    108   Items.Free;
     110resourcestring
     111  SClientNotSet = 'Client not set';
     112
     113{ TChronisTypeList }
     114
     115function TChronisTypeList.AddType(Name: string; DbType: string = ''): TChronisType;
     116begin
     117  Result := TChronisType(AddNew(TChronisType.Create));
     118  Result.Client := Client;
     119  Result.Name := Name;
     120  Result.DbType := DbType;
     121end;
     122
     123function TChronisTypeList.SearchByName(Name: string): TChronisType;
     124var
     125  I: Integer;
     126begin
     127  I := 0;
     128  while (I < Count) and (TChronisType(Items[I]).Name <> Name) do Inc(I);
     129  if I < Count then Result := TChronisType(Items[I])
     130    else Result := nil;
     131end;
     132
     133procedure TChronisType.Define;
     134begin
     135  if Assigned(Client) then Client.TypeDefine(Self)
     136    else raise EClientNotSet.Create(SClientNotSet);
     137end;
     138
     139procedure TChronisType.Undefine;
     140begin
     141  if Assigned(Client) then Client.TypeUndefine(Self)
     142    else raise EClientNotSet.Create(SClientNotSet);
     143end;
     144
     145constructor TChronisType.Create;
     146begin
     147  Properties := TDictionaryStringString.Create;
     148end;
     149
     150destructor TChronisType.Destroy;
     151begin
     152  Properties.Free;
    109153  inherited Destroy;
    110154end;
     
    114158procedure TObjectProxy.Load;
    115159begin
    116   Client.ObjectLoad(Self);
     160  if Assigned(Client) then Client.ObjectLoad(Self)
     161    else raise EClientNotSet.Create(SClientNotSet);
    117162end;
    118163
    119164procedure TObjectProxy.Save;
    120165begin
    121   Client.ObjectSave(Self);
     166  if Assigned(Client) then Client.ObjectSave(Self)
     167    else raise EClientNotSet.Create(SClientNotSet);
    122168end;
    123169
    124170procedure TObjectProxy.Delete;
    125171begin
    126   Client.ObjectDelete(Self);
     172  if Assigned(Client) then Client.ObjectDelete(Self)
     173    else raise EClientNotSet.Create(SClientNotSet);
    127174end;
    128175
    129176procedure TObjectProxy.Add;
    130177begin
    131   Client.ObjectAdd(Self);
     178  if Assigned(Client) then Client.ObjectAdd(Self)
     179    else raise EClientNotSet.Create(SClientNotSet);
    132180end;
    133181
     
    168216procedure TListProxy.Load;
    169217begin
    170   Client.ListLoad(Self);
     218  if Assigned(Client) then Client.ListLoad(Self)
     219    else raise EClientNotSet.Create(SClientNotSet);
    171220end;
    172221
    173222procedure TListProxy.Save;
    174223begin
    175   Client.ListSave(Self);
     224  if Assigned(Client) then Client.ListSave(Self)
     225    else raise EClientNotSet.Create(SClientNotSet);
    176226end;
    177227
    178228{ TChronisClient }
    179229
     230procedure TChronisClient.InitSystemTypes;
     231begin
     232end;
     233
    180234function TChronisClient.GetConnected: Boolean;
    181235begin
     
    183237end;
    184238
     239procedure TChronisClient.CheckTypes;
     240var
     241  StructureVersion: string;
     242  Data: TDictionaryStringString;
     243  ObjectId: Integer;
     244  Tables: TListString;
     245  I: Integer;
     246  NewProxy: TListProxy;
     247begin
     248  try
     249    Tables := TListString.Create;
     250    Data := TDictionaryStringString.Create;
     251
     252    NewProxy := TListProxy.Create;
     253    NewProxy.Client := Self;
     254    NewProxy.SchemaName := 'information_schema';
     255    NewProxy.ObjectName := 'TABLES';
     256    NewProxy.Condition := 'TABLE_SCHEMA = "' + Schema + '"';
     257    NewProxy.Load;
     258    //Database.Query(DbRows, 'SHOW TABLES');
     259    Tables.Count := NewProxy.Objects.Count;
     260    for I := 0 to NewProxy.Objects.Count - 1 do
     261      Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Values['TABLE_NAME'];
     262
     263    for I := 0 to Types.Count - 1 do
     264    with TChronisType(Types[I]) do begin
     265      if (DbType = '') and (Tables.IndexOf(Name) = -1) then begin
     266        Define;
     267      end;
     268    end;
     269  finally
     270    NewProxy.Free;
     271    Data.Free;
     272    Tables.Free;
     273  end;
     274end;
     275
    185276constructor TChronisClient.Create;
    186277begin
     278  Types := TChronisTypeList.Create;
     279  Types.Client := Self;
     280  InitSystemTypes;
     281end;
     282
     283destructor TChronisClient.Destroy;
     284begin
     285  Types.Free;
     286  inherited Destroy;
    187287end;
    188288
Note: See TracChangeset for help on using the changeset viewer.