1 | unit UPDClientMemory;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, UPDClient, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
38 | resourcestring
|
---|
39 | SObjectNotFound = 'Object with id %s not found';
|
---|
40 |
|
---|
41 |
|
---|
42 | implementation
|
---|
43 |
|
---|
44 | { TPDClientMemory }
|
---|
45 |
|
---|
46 | procedure TPDClientMemory.InitSystemTypes;
|
---|
47 | begin
|
---|
48 | inherited InitSystemTypes;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | function TPDClientMemory.GetConnected: Boolean;
|
---|
52 | begin
|
---|
53 | Result:=inherited GetConnected;
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure TPDClientMemory.Init;
|
---|
57 | begin
|
---|
58 | inherited Init;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | function TPDClientMemory.GetNewObjectId: Integer;
|
---|
62 | begin
|
---|
63 | Inc(FLastObjectId);
|
---|
64 | Result := FLastObjectId;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | function TPDClientMemory.SearchObject(Id: Integer): TObjectProxy;
|
---|
68 | var
|
---|
69 | I: Integer;
|
---|
70 | begin
|
---|
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;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TPDClientMemory.ObjectLoad(AObject: TObjectProxy);
|
---|
79 | var
|
---|
80 | Obj: TObjectProxy;
|
---|
81 | begin
|
---|
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]);
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TPDClientMemory.ObjectSave(AObject: TObjectProxy);
|
---|
89 | var
|
---|
90 | I: Integer;
|
---|
91 | Obj: TObjectProxy;
|
---|
92 | begin
|
---|
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;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TPDClientMemory.ObjectDelete(AObject: TObjectProxy);
|
---|
104 | var
|
---|
105 | Obj: TObjectProxy;
|
---|
106 | begin
|
---|
107 | Obj := SearchObject(AObject.Id);
|
---|
108 | if Assigned(Obj) then Objects.Delete(Objects.IndexOf(Obj))
|
---|
109 | else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id])
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TPDClientMemory.ListLoad(AList: TListProxy);
|
---|
113 | var
|
---|
114 | Filter: string;
|
---|
115 | DbCondition: string;
|
---|
116 | I: Integer;
|
---|
117 | P: Integer;
|
---|
118 | NewObject: TObjectProxy;
|
---|
119 | Table: string;
|
---|
120 | Item: TPair<string, string>;
|
---|
121 | begin
|
---|
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;
|
---|
145 | end;
|
---|
146 |
|
---|
147 | procedure TPDClientMemory.ListSave(AList: TListProxy);
|
---|
148 | begin
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TPDClientMemory.TypeDefine(AType: TPDType);
|
---|
152 | begin
|
---|
153 | end;
|
---|
154 |
|
---|
155 | procedure TPDClientMemory.TypeUndefine(AType: TPDType);
|
---|
156 | begin
|
---|
157 | end;
|
---|
158 |
|
---|
159 | function TPDClientMemory.TypeIsDefined(AType: TPDType): Boolean;
|
---|
160 | begin
|
---|
161 | Result := False;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TPDClientMemory.Install;
|
---|
165 | begin
|
---|
166 | end;
|
---|
167 |
|
---|
168 | procedure TPDClientMemory.Uninstall;
|
---|
169 | begin
|
---|
170 | end;
|
---|
171 |
|
---|
172 | constructor TPDClientMemory.Create(AOwner: TComponent);
|
---|
173 | begin
|
---|
174 | inherited;
|
---|
175 | Objects := TObjectProxies.Create;
|
---|
176 | BackendName := 'Memory';
|
---|
177 | end;
|
---|
178 |
|
---|
179 | destructor TPDClientMemory.Destroy;
|
---|
180 | begin
|
---|
181 | FreeAndNil(Objects);
|
---|
182 | inherited;
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TPDClientMemory.Connect;
|
---|
186 | begin
|
---|
187 | inherited;
|
---|
188 | end;
|
---|
189 |
|
---|
190 | procedure TPDClientMemory.Disconnect;
|
---|
191 | begin
|
---|
192 | inherited;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | end.
|
---|
196 |
|
---|