Changeset 561 for PersistentData
- Timestamp:
- Sep 10, 2022, 6:26:39 PM (2 years ago)
- Location:
- PersistentData
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
PersistentData/Backend/UPDClientINI.pas
r361 r561 1 1 unit UPDClientINI; 2 3 {$mode delphi}4 2 5 3 interface … … 23 21 procedure Disconnect; override; 24 22 end; 23 25 24 26 25 implementation … … 49 48 begin 50 49 Disconnect; 51 inherited Destroy;50 inherited; 52 51 end; 53 52 -
PersistentData/Backend/UPDClientMemory.pas
r387 r561 1 1 unit UPDClientMemory; 2 3 {$mode Delphi}{$H+}4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, UPDClient, SpecializedList;6 Classes, SysUtils, UPDClient, Generics.Collections; 9 7 10 8 type … … 21 19 function SearchObject(Id: Integer): TObjectProxy; 22 20 public 23 Objects: T ListObject;21 Objects: TObjectProxies; 24 22 procedure ObjectLoad(AObject: TObjectProxy); override; 25 23 procedure ObjectSave(AObject: TObjectProxy); override; … … 40 38 resourcestring 41 39 SObjectNotFound = 'Object with id %s not found'; 40 42 41 43 42 implementation … … 97 96 else begin 98 97 AObject.Id := GetNewObjectId; 99 Obj := TObjectProxy(Objects.AddNew(TObjectProxy.Create));98 Obj := Objects.AddProxy; 100 99 Obj.Assign(AObject); 101 100 end; … … 119 118 NewObject: TObjectProxy; 120 119 Table: string; 120 Item: TPair<string, string>; 121 121 begin 122 122 AList.Objects.Clear; … … 132 132 133 133 if AList.ColummsFilterUse then begin 134 for P := 0 to Properties.Count - 1do135 if AList.ColumnsFilter.IndexOf( Properties.Keys[I]) <> -1 then136 NewObject.Properties.Add( Properties.Keys[I], Properties[I].Value);134 for Item in Properties do 135 if AList.ColumnsFilter.IndexOf(Item.Key) <> -1 then 136 NewObject.Properties.Add(Item.Key, Item.Value); 137 137 end else NewObject.Properties.Assign(Properties); 138 138 end; … … 147 147 procedure TPDClientMemory.ListSave(AList: TListProxy); 148 148 begin 149 150 149 end; 151 150 152 151 procedure TPDClientMemory.TypeDefine(AType: TPDType); 153 152 begin 154 155 153 end; 156 154 157 155 procedure TPDClientMemory.TypeUndefine(AType: TPDType); 158 156 begin 159 160 157 end; 161 158 162 159 function TPDClientMemory.TypeIsDefined(AType: TPDType): Boolean; 163 160 begin 164 161 Result := False; 165 162 end; 166 163 167 164 procedure TPDClientMemory.Install; 168 165 begin 169 170 166 end; 171 167 172 168 procedure TPDClientMemory.Uninstall; 173 169 begin 174 175 170 end; 176 171 … … 178 173 begin 179 174 inherited; 180 Objects := T ListObject.Create;175 Objects := TObjectProxies.Create; 181 176 BackendName := 'Memory'; 182 177 end; … … 184 179 destructor TPDClientMemory.Destroy; 185 180 begin 186 Objects.Free;187 inherited Destroy;181 FreeAndNil(Objects); 182 inherited; 188 183 end; 189 184 190 185 procedure TPDClientMemory.Connect; 191 186 begin 192 inherited Connect;187 inherited; 193 188 end; 194 189 195 190 procedure TPDClientMemory.Disconnect; 196 191 begin 197 inherited Disconnect;192 inherited; 198 193 end; 199 194 -
PersistentData/Backend/UPDClientMySQL.pas
r362 r561 1 1 unit UPDClientMySQL; 2 2 3 {$mode delphi}4 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, USqlDatabase, UPDClient, SpecializedDictionary;6 Classes, SysUtils, USqlDatabase, UPDClient, UGenerics; 9 7 10 8 type … … 22 20 function GetConnected: Boolean; override; 23 21 procedure Init; override; 22 function GetConnectionString: string; override; 24 23 public 25 24 procedure ObjectLoad(AObject: TObjectProxy); override; … … 45 44 end; 46 45 46 47 47 implementation 48 49 48 50 49 resourcestring 51 50 SMissingBaseType = 'Missing base typ for %s'; 52 51 SUndefinedType = 'Undefined type in %0:s.%1:s'; 53 54 52 55 53 { TPDClientMySQL } … … 155 153 procedure TPDClientMySQL.ListSave(AList: TListProxy); 156 154 begin 157 158 155 end; 159 156 … … 245 242 end; 246 243 244 function TPDClientMySQL.GetConnectionString: string; 245 begin 246 Result := 'Host:' + Host + ',Port:' + IntToStr(Port) + ',User:' + User + 247 ',Password:' + Password + ',Schema:' + Schema; 248 end; 249 247 250 constructor TPDClientMySQL.Create(AOwner: TComponent); 248 251 begin … … 255 258 begin 256 259 FreeAndNil(FDatabase); 257 inherited Destroy;260 inherited; 258 261 end; 259 262 -
PersistentData/Backend/UPDClientRegistry.pas
r361 r561 1 1 unit UPDClientRegistry; 2 3 {$mode delphi}4 2 5 3 interface … … 13 11 14 12 TPDClientRegistry = class(TPDClient) 13 public 15 14 Reg: TRegistry; 16 15 //procedure GetItemList(Condition: TCondition; ItemList: TItemList); override; … … 19 18 destructor Destroy; override; 20 19 end; 20 21 21 22 22 implementation … … 46 46 begin 47 47 Reg.Free; 48 inherited Destroy;48 inherited; 49 49 end; 50 50 -
PersistentData/Backend/UPDClientXMLRPC.pas
r361 r561 1 1 unit UPDClientXMLRPC; 2 3 {$mode delphi}4 2 5 3 interface … … 16 14 end; 17 15 16 18 17 implementation 19 20 18 21 19 { TPDClientXMLRPC } -
PersistentData/Demo/UFormMain.pas
r361 r561 1 1 unit UFormMain; 2 3 {$mode delphi}{$H+}4 2 5 3 interface … … 22 20 procedure ComboBox1Change(Sender: TObject); 23 21 procedure FormShow(Sender: TObject); 24 private25 { private declarations }26 22 public 27 23 Client: TPDClient; … … 30 26 var 31 27 FormMain: TFormMain; 28 32 29 33 30 implementation -
PersistentData/PersistentData.lpk
r362 r561 1 <?xml version="1.0" ?>1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <CONFIG> 3 <Package Version=" 4">3 <Package Version="5"> 4 4 <PathDelim Value="\"/> 5 5 <Name Value="PersistentData"/> 6 <Type Value="RunAndDesignTime"/> 6 7 <Author Value="Chronos"/> 7 8 <CompilerOptions> … … 10 11 <SearchPaths> 11 12 <OtherUnitFiles Value="Backend"/> 12 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS) "/>13 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(BuildMode)"/> 13 14 </SearchPaths> 14 <CodeGeneration> 15 <Checks> 16 <IOChecks Value="True"/> 17 <RangeChecks Value="True"/> 18 <OverflowChecks Value="True"/> 19 <StackChecks Value="True"/> 20 </Checks> 21 </CodeGeneration> 22 <Other> 23 <CompilerMessages> 24 <MsgFileName Value=""/> 25 </CompilerMessages> 26 <CompilerPath Value="$(CompPath)"/> 27 </Other> 15 <Parsing> 16 <SyntaxOptions> 17 <SyntaxMode Value="Delphi"/> 18 <CStyleOperator Value="False"/> 19 <AllowLabel Value="False"/> 20 <CPPInline Value="False"/> 21 </SyntaxOptions> 22 </Parsing> 23 <Linking> 24 <Debugging> 25 <GenerateDebugInfo Value="False"/> 26 </Debugging> 27 </Linking> 28 28 </CompilerOptions> 29 29 <Description Value="Generic data persistence layer"/> 30 30 <License Value="GNU/GPL"/> 31 <Version Minor=" 1"/>31 <Version Minor="2"/> 32 32 <Files Count="8"> 33 33 <Item1> … … 65 65 </Item8> 66 66 </Files> 67 <Type Value="RunAndDesignTime"/> 67 <CompatibilityMode Value="True"/> 68 <i18n> 69 <EnableI18N Value="True"/> 70 </i18n> 68 71 <RequiredPkgs Count="2"> 69 72 <Item1> -
PersistentData/UPDClient.pas
r362 r561 1 1 unit UPDClient; 2 2 3 {$mode delphi}4 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, SpecializedList, SpecializedDictionary;6 Classes, SysUtils, Generics.Collections, UGenerics; 9 7 10 8 const … … 33 31 destructor Destroy; override; 34 32 procedure Assign(Source: TObjectProxy); 33 end; 34 35 { TObjectProxies } 36 37 TObjectProxies = class(TObjectList<TObjectProxy>) 38 function AddProxy: TObjectProxy; 35 39 end; 36 40 … … 59 63 ObjectName: string; 60 64 Path: string; 61 Objects: T ListObject; // TListObject<TObjectProxy>65 Objects: TObjectList<TObjectProxy>; 62 66 procedure Clear; 63 67 constructor Create; … … 74 78 end; 75 79 76 { TPDTypePropert yList}77 78 TPDTypePropert yList = class(TListObject)80 { TPDTypeProperties } 81 82 TPDTypeProperties = class(TObjectList<TPDTypeProperty>) 79 83 Client: TPDClient; 80 procedureAddSimple(Name: string; TypeName: string; Unique: Boolean = False;81 Index: Boolean = False) ;84 function AddSimple(Name: string; TypeName: string; Unique: Boolean = False; 85 Index: Boolean = False): TPDTypeProperty; 82 86 end; 83 87 … … 91 95 Name: string; 92 96 DbType: string; 93 Properties: TPDTypePropert yList;97 Properties: TPDTypeProperties; 94 98 function IsDefined: Boolean; 95 99 procedure Define; … … 100 104 end; 101 105 102 { TPDType List}103 104 TPDType List = class(TListObject)106 { TPDTypes } 107 108 TPDTypes = class(TObjectList<TPDType>) 105 109 Client: TPDClient; 106 110 function AddType(Name: string; DbType: string = ''): TPDType; … … 121 125 procedure SetConnectionString(AValue: string); virtual; 122 126 public 123 Types: TPDType List;127 Types: TPDTypes; 124 128 Version: string; 125 129 BackendName: string; … … 149 153 TPDClientClass = class of TPDClient; 150 154 151 152 153 154 155 155 resourcestring 156 SClientNotSet = 'Client not set'; 157 SNotSupported = 'Not supported'; 158 SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.'; 159 SCantLoadObjectWithoutId = 'Can''t load object without id'; 156 160 157 161 158 162 implementation 159 163 160 { TPDTypePropertyList } 161 162 procedure TPDTypePropertyList.AddSimple(Name: string; TypeName: string; 163 Unique: Boolean; Index: Boolean); 164 var 165 NewProperty: TPDTypeProperty; 166 begin 167 NewProperty := TPDTypeProperty(AddNew(TPDTypeProperty.Create)); 168 NewProperty.Name := Name; 169 NewProperty.DbType := Client.Types.SearchByName(TypeName); 170 NewProperty.Unique := Unique; 171 NewProperty.Index := Index; 172 end; 173 174 175 { TPDTypeList } 176 177 function TPDTypeList.AddType(Name: string; DbType: string = ''): TPDType; 178 begin 179 Result := TPDType(AddNew(TPDType.Create)); 164 { TObjectProxies } 165 166 function TObjectProxies.AddProxy: TObjectProxy; 167 begin 168 Result := TObjectProxy.Create; 169 Add(Result); 170 end; 171 172 { TPDTypeProperties } 173 174 function TPDTypeProperties.AddSimple(Name: string; TypeName: string; 175 Unique: Boolean = False; Index: Boolean = False): TPDTypeProperty; 176 begin 177 Result := TPDTypeProperty.Create; 178 Result.Name := Name; 179 Result.DbType := Client.Types.SearchByName(TypeName); 180 Result.Unique := Unique; 181 Result.Index := Index; 182 Add(Result); 183 end; 184 185 { TPDTypes } 186 187 function TPDTypes.AddType(Name: string; DbType: string = ''): TPDType; 188 begin 189 Result := TPDType.Create; 180 190 Result.Client := Client; 181 191 Result.Name := Name; 182 192 Result.DbType := DbType; 183 end; 184 185 function TPDTypeList.SearchByName(Name: string): TPDType; 193 Add(Result); 194 end; 195 196 function TPDTypes.SearchByName(Name: string): TPDType; 186 197 var 187 198 I: Integer; … … 220 231 constructor TPDType.Create; 221 232 begin 222 Properties := TPDTypePropert yList.Create;233 Properties := TPDTypeProperties.Create; 223 234 end; 224 235 225 236 destructor TPDType.Destroy; 226 237 begin 227 Properties.Free;228 inherited Destroy;238 FreeAndNil(Properties); 239 inherited; 229 240 end; 230 241 … … 256 267 destructor TObjectProxy.Destroy; 257 268 begin 258 Properties.Free;259 inherited Destroy;269 FreeAndNil(Properties); 270 inherited; 260 271 end; 261 272 … … 282 293 begin 283 294 ColumnsFilter := TListString.Create; 284 Objects := T ListObject.Create;295 Objects := TObjectList<TObjectProxy>.Create; 285 296 end; 286 297 287 298 destructor TListProxy.Destroy; 288 299 begin 289 Objects.Free;290 ColumnsFilter.Free;291 inherited Destroy;300 FreeAndNil(Objects); 301 FreeAndNil(ColumnsFilter); 302 inherited; 292 303 end; 293 304 … … 313 324 procedure TPDClient.SetConnectionString(AValue: string); 314 325 begin 315 316 326 end; 317 327 … … 347 357 NewObject.Load; 348 358 349 DbVersion := NewObject.Properties. Values['Version'];359 DbVersion := NewObject.Properties.Items['Version']; 350 360 if Version <> DbVersion then 351 361 raise Exception.Create(Format(SVersionMismatch, [Version, DbVersion])); … … 397 407 Tables.Count := NewProxy.Objects.Count; 398 408 for I := 0 to NewProxy.Objects.Count - 1 do 399 Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties. Values['TABLE_NAME'];409 Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Items['TABLE_NAME']; 400 410 401 411 for I := 0 to Types.Count - 1 do … … 415 425 begin 416 426 inherited; 417 Types := TPDType List.Create;427 Types := TPDTypes.Create; 418 428 Types.Client := Self; 419 429 InitSystemTypes; … … 422 432 destructor TPDClient.Destroy; 423 433 begin 424 Types.Free;425 inherited Destroy;434 FreeAndNil(Types); 435 inherited; 426 436 end; 427 437 … … 436 446 procedure TPDClient.Install; 437 447 begin 438 439 448 end; 440 449 … … 446 455 procedure TPDClient.Update; 447 456 begin 448 449 457 end; 450 458 -
PersistentData/UPDServer.pas
r340 r561 1 1 unit UPDServer; 2 3 {$mode delphi}4 2 5 3 interface … … 10 8 type 11 9 TPDServer = class 10 end; 12 11 13 end;14 12 15 13 implementation -
PersistentData/UPersistentData.pas
r361 r561 1 1 unit UPersistentData; 2 3 {$mode delphi}{$H+}4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, UPDClient, SpecializedList;6 Classes, SysUtils, UPDClient, Generics.Collections; 9 7 10 8 type … … 14 12 end; 15 13 14 TPDManagerItems = class(TObjectList<TPDManagerItem>) 15 end; 16 16 17 { TPDManager } 17 18 18 19 TPDManager = class(TComponent) 19 Items: TListObject; 20 public 21 Items: TPDManagerItems; 20 22 procedure Register(ClientClass: TPDClientClass); 21 23 procedure LoadToStrings(Strings: TStrings); … … 77 79 begin 78 80 inherited; 79 Items := T ListObject.Create;81 Items := TPDManagerItems.Create; 80 82 end; 81 83 … … 83 85 begin 84 86 FreeAndNil(Items); 85 inherited Destroy;87 inherited; 86 88 end; 87 89
Note:
See TracChangeset
for help on using the changeset viewer.