source: trunk/Packages/PersistentData/Backend/UPDClientMemory.pas

Last change on this file was 142, checked in by chronos, 2 years ago
File size: 4.4 KB
Line 
1unit UPDClientMemory;
2
3interface
4
5uses
6 Classes, SysUtils, UPDClient, Generics.Collections;
7
8type
9
10 { TPDClientMemory }
11
12 TPDClientMemory = class(TPDClient)
13 protected
14 FLastObjectId: Integer;
15 procedure InitSystemTypes; override;
16 function GetConnected: Boolean; override;
17 procedure Init; override;
18 function GetNewObjectId: Integer;
19 function SearchObject(Id: Integer): TObjectProxy;
20 public
21 Objects: TObjectProxies;
22 procedure ObjectLoad(AObject: TObjectProxy); override;
23 procedure ObjectSave(AObject: TObjectProxy); override;
24 procedure ObjectDelete(AObject: TObjectProxy); override;
25 procedure ListLoad(AList: TListProxy); override;
26 procedure ListSave(AList: TListProxy); override;
27 procedure TypeDefine(AType: TPDType); override;
28 procedure TypeUndefine(AType: TPDType); override;
29 function TypeIsDefined(AType: TPDType): Boolean; override;
30 procedure Install;
31 procedure Uninstall;
32 constructor Create(AOwner: TComponent); override;
33 destructor Destroy; override;
34 procedure Connect; override;
35 procedure Disconnect; override;
36 end;
37
38resourcestring
39 SObjectNotFound = 'Object with id %s not found';
40
41
42implementation
43
44{ TPDClientMemory }
45
46procedure TPDClientMemory.InitSystemTypes;
47begin
48 inherited InitSystemTypes;
49end;
50
51function TPDClientMemory.GetConnected: Boolean;
52begin
53 Result:=inherited GetConnected;
54end;
55
56procedure TPDClientMemory.Init;
57begin
58 inherited Init;
59end;
60
61function TPDClientMemory.GetNewObjectId: Integer;
62begin
63 Inc(FLastObjectId);
64 Result := FLastObjectId;
65end;
66
67function TPDClientMemory.SearchObject(Id: Integer): TObjectProxy;
68var
69 I: Integer;
70begin
71 I := 0;
72 while (I < Objects.Count) and
73 (TObjectProxy(Objects[I]).Id <> Id) do Inc(I);
74 if I < Objects.Count then Result := TObjectProxy(Objects[I])
75 else Result := nil;
76end;
77
78procedure TPDClientMemory.ObjectLoad(AObject: TObjectProxy);
79var
80 Obj: TObjectProxy;
81begin
82 if AObject.Id = 0 then raise Exception.Create(SCantLoadObjectWithoutId);
83 Obj := SearchObject(AObject.Id);
84 if Assigned(Obj) then AObject.Assign(Obj)
85 else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id]);
86end;
87
88procedure TPDClientMemory.ObjectSave(AObject: TObjectProxy);
89var
90 I: Integer;
91 Obj: TObjectProxy;
92begin
93 if AObject.Id = 0 then raise Exception.Create(SCantLoadObjectWithoutId);
94 Obj := SearchObject(AObject.Id);
95 if Assigned(Obj) then Obj.Assign(AObject)
96 else begin
97 AObject.Id := GetNewObjectId;
98 Obj := Objects.AddProxy;
99 Obj.Assign(AObject);
100 end;
101end;
102
103procedure TPDClientMemory.ObjectDelete(AObject: TObjectProxy);
104var
105 Obj: TObjectProxy;
106begin
107 Obj := SearchObject(AObject.Id);
108 if Assigned(Obj) then Objects.Delete(Objects.IndexOf(Obj))
109 else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id])
110end;
111
112procedure TPDClientMemory.ListLoad(AList: TListProxy);
113var
114 Filter: string;
115 DbCondition: string;
116 I: Integer;
117 P: Integer;
118 NewObject: TObjectProxy;
119 Table: string;
120 Item: TPair<string, 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 Item in Properties do
135 if AList.ColumnsFilter.IndexOf(Item.Key) <> -1 then
136 NewObject.Properties.Add(Item.Key, Item.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;
145end;
146
147procedure TPDClientMemory.ListSave(AList: TListProxy);
148begin
149end;
150
151procedure TPDClientMemory.TypeDefine(AType: TPDType);
152begin
153end;
154
155procedure TPDClientMemory.TypeUndefine(AType: TPDType);
156begin
157end;
158
159function TPDClientMemory.TypeIsDefined(AType: TPDType): Boolean;
160begin
161 Result := False;
162end;
163
164procedure TPDClientMemory.Install;
165begin
166end;
167
168procedure TPDClientMemory.Uninstall;
169begin
170end;
171
172constructor TPDClientMemory.Create(AOwner: TComponent);
173begin
174 inherited;
175 Objects := TObjectProxies.Create;
176 BackendName := 'Memory';
177end;
178
179destructor TPDClientMemory.Destroy;
180begin
181 FreeAndNil(Objects);
182 inherited;
183end;
184
185procedure TPDClientMemory.Connect;
186begin
187 inherited;
188end;
189
190procedure TPDClientMemory.Disconnect;
191begin
192 inherited;
193end;
194
195end.
196
Note: See TracBrowser for help on using the repository browser.