Changeset 43 for trunk/Application/UChronisClient.pas
- Timestamp:
- Mar 9, 2012, 1:09:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UChronisClient.pas
r37 r43 9 9 10 10 type 11 EClientNotSet = class(Exception); 12 11 13 TChronisClient = class; 12 14 … … 52 54 end; 53 55 56 { TChronisType } 57 54 58 TChronisType = class 55 OID: Integer;59 Client: TChronisClient; 56 60 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; 68 65 constructor Create; 69 66 destructor Destroy; override; 70 67 end; 71 68 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 72 77 { TChronisClient } 73 78 74 79 TChronisClient = class 80 private 75 81 protected 82 procedure InitSystemTypes; virtual; 76 83 function GetConnected: Boolean; virtual; 77 84 public … … 81 88 User: string; 82 89 Password: string; 90 Types: TChronisTypeList; 83 91 procedure ObjectLoad(AObject: TObjectProxy); virtual; abstract; 84 92 procedure ObjectSave(AObject: TObjectProxy); virtual; abstract; … … 87 95 procedure ListLoad(AList: TListProxy); virtual; abstract; 88 96 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; 91 100 constructor Create; virtual; 101 destructor Destroy; override; 92 102 procedure Connect; virtual; abstract; 93 103 procedure Disconnect; virtual; abstract; … … 95 105 end; 96 106 107 97 108 implementation 98 109 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; 110 resourcestring 111 SClientNotSet = 'Client not set'; 112 113 { TChronisTypeList } 114 115 function TChronisTypeList.AddType(Name: string; DbType: string = ''): TChronisType; 116 begin 117 Result := TChronisType(AddNew(TChronisType.Create)); 118 Result.Client := Client; 119 Result.Name := Name; 120 Result.DbType := DbType; 121 end; 122 123 function TChronisTypeList.SearchByName(Name: string): TChronisType; 124 var 125 I: Integer; 126 begin 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; 131 end; 132 133 procedure TChronisType.Define; 134 begin 135 if Assigned(Client) then Client.TypeDefine(Self) 136 else raise EClientNotSet.Create(SClientNotSet); 137 end; 138 139 procedure TChronisType.Undefine; 140 begin 141 if Assigned(Client) then Client.TypeUndefine(Self) 142 else raise EClientNotSet.Create(SClientNotSet); 143 end; 144 145 constructor TChronisType.Create; 146 begin 147 Properties := TDictionaryStringString.Create; 148 end; 149 150 destructor TChronisType.Destroy; 151 begin 152 Properties.Free; 109 153 inherited Destroy; 110 154 end; … … 114 158 procedure TObjectProxy.Load; 115 159 begin 116 Client.ObjectLoad(Self); 160 if Assigned(Client) then Client.ObjectLoad(Self) 161 else raise EClientNotSet.Create(SClientNotSet); 117 162 end; 118 163 119 164 procedure TObjectProxy.Save; 120 165 begin 121 Client.ObjectSave(Self); 166 if Assigned(Client) then Client.ObjectSave(Self) 167 else raise EClientNotSet.Create(SClientNotSet); 122 168 end; 123 169 124 170 procedure TObjectProxy.Delete; 125 171 begin 126 Client.ObjectDelete(Self); 172 if Assigned(Client) then Client.ObjectDelete(Self) 173 else raise EClientNotSet.Create(SClientNotSet); 127 174 end; 128 175 129 176 procedure TObjectProxy.Add; 130 177 begin 131 Client.ObjectAdd(Self); 178 if Assigned(Client) then Client.ObjectAdd(Self) 179 else raise EClientNotSet.Create(SClientNotSet); 132 180 end; 133 181 … … 168 216 procedure TListProxy.Load; 169 217 begin 170 Client.ListLoad(Self); 218 if Assigned(Client) then Client.ListLoad(Self) 219 else raise EClientNotSet.Create(SClientNotSet); 171 220 end; 172 221 173 222 procedure TListProxy.Save; 174 223 begin 175 Client.ListSave(Self); 224 if Assigned(Client) then Client.ListSave(Self) 225 else raise EClientNotSet.Create(SClientNotSet); 176 226 end; 177 227 178 228 { TChronisClient } 179 229 230 procedure TChronisClient.InitSystemTypes; 231 begin 232 end; 233 180 234 function TChronisClient.GetConnected: Boolean; 181 235 begin … … 183 237 end; 184 238 239 procedure TChronisClient.CheckTypes; 240 var 241 StructureVersion: string; 242 Data: TDictionaryStringString; 243 ObjectId: Integer; 244 Tables: TListString; 245 I: Integer; 246 NewProxy: TListProxy; 247 begin 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; 274 end; 275 185 276 constructor TChronisClient.Create; 186 277 begin 278 Types := TChronisTypeList.Create; 279 Types.Client := Self; 280 InitSystemTypes; 281 end; 282 283 destructor TChronisClient.Destroy; 284 begin 285 Types.Free; 286 inherited Destroy; 187 287 end; 188 288
Note:
See TracChangeset
for help on using the changeset viewer.