@@ -33,24 +33,22 @@ TEntityMapTest = class(TTestCase)
33
33
implementation
34
34
35
35
uses
36
- SysUtils
37
- ,Spring.Persistence.Mapping.Attributes
38
- ,Spring.Persistence.Mapping.RttiExplorer
39
- ,Spring.Persistence.Core.EntityCache
40
- ,Spring.Persistence.Core.EntityWrapper
41
- ,Spring.Persistence.Core.Interfaces
42
- ,Diagnostics
43
- ,Generics.Collections
44
- ;
36
+ Diagnostics,
37
+ Generics.Collections,
38
+ SysUtils,
39
+ Spring.Persistence.Core.EntityCache,
40
+ Spring.Persistence.Mapping.Attributes;
45
41
46
42
type
43
+ [Table]
47
44
TTest1 = class
48
45
public
49
46
[Column(' TESTID' , [cpRequired, cpPrimaryKey, cpNotNull], 0 , 0 , 0 , ' Primary Key' )]
50
47
[AutoGenerated]
51
48
FId: Integer;
52
49
end ;
53
50
51
+ [Table]
54
52
TTest2 = class
55
53
public
56
54
[Column(' TESTID' , [cpRequired, cpPrimaryKey, cpNotNull], 0 , 0 , 0 , ' Primary Key' )]
@@ -89,7 +87,6 @@ procedure TEntityMapTest.TestIsMapped;
89
87
ReturnValue: Boolean;
90
88
AObject, LClone: TCustomer;
91
89
LCompany, LClonedCompany: TCompany;
92
- entityWrapper: IEntityWrapper;
93
90
begin
94
91
AObject := CreateCustomer;
95
92
LCompany := CreateCompany;
@@ -98,15 +95,13 @@ procedure TEntityMapTest.TestIsMapped;
98
95
try
99
96
ReturnValue := FEntityMap.IsMapped(AObject);
100
97
CheckFalse(ReturnValue);
101
- entityWrapper := TEntityWrapper.Create(LClone);
102
- FEntityMap.AddOrReplace(entityWrapper);
98
+ FEntityMap.AddOrReplace(LClone);
103
99
ReturnValue := FEntityMap.IsMapped(AObject);
104
100
CheckTrue(ReturnValue);
105
101
106
102
ReturnValue := FEntityMap.IsMapped(LCompany);
107
103
CheckFalse(ReturnValue);
108
- entityWrapper := TEntityWrapper.Create(LClonedCompany);
109
- FEntityMap.AddOrReplace(entityWrapper);
104
+ FEntityMap.AddOrReplace(LClonedCompany);
110
105
111
106
ReturnValue := FEntityMap.IsMapped(LCompany);
112
107
CheckTrue(ReturnValue);
@@ -121,13 +116,11 @@ procedure TEntityMapTest.TestIsMapped;
121
116
procedure TEntityMapTest.TestAdd ;
122
117
var
123
118
LCustomer: TCustomer;
124
- entityWrapper: IEntityWrapper;
125
119
begin
126
120
LCustomer := CreateCustomer;
127
121
try
128
122
CheckFalse(FEntityMap.IsMapped(LCustomer));
129
- entityWrapper := TEntityWrapper.Create(LCustomer);
130
- FEntityMap.AddOrReplace(entityWrapper);
123
+ FEntityMap.AddOrReplace(LCustomer);
131
124
CheckTrue(FEntityMap.IsMapped(LCustomer));
132
125
finally
133
126
LCustomer.Free;
@@ -137,15 +130,13 @@ procedure TEntityMapTest.TestAdd;
137
130
procedure TEntityMapTest.TestAddOrReplace ;
138
131
var
139
132
LCustomer: TCustomer;
140
- entityWrapper: IEntityWrapper;
141
133
begin
142
134
LCustomer := CreateCustomer;
143
135
try
144
136
CheckFalse(FEntityMap.IsMapped(LCustomer));
145
- entityWrapper := TEntityWrapper.Create(LCustomer);
146
- FEntityMap.AddOrReplace(entityWrapper);
137
+ FEntityMap.AddOrReplace(LCustomer);
147
138
CheckTrue(FEntityMap.IsMapped(LCustomer));
148
- FEntityMap.AddOrReplace(entityWrapper );
139
+ FEntityMap.AddOrReplace(LCustomer );
149
140
CheckTrue(FEntityMap.IsMapped(LCustomer));
150
141
finally
151
142
LCustomer.Free;
@@ -163,7 +154,6 @@ procedure TEntityMapTest.TestAddOrReplace_Clone_Speed;
163
154
LObjectDict: IDictionary<string,TObject>;
164
155
LNativeDict: TDictionary<string,TValue>;
165
156
LValue: TValue;
166
- entityWrapper: IEntityWrapper;
167
157
begin
168
158
iCount := 50000 ;
169
159
LCustomers := TCollections.CreateObjectList<TCustomer>(True);
@@ -174,24 +164,21 @@ procedure TEntityMapTest.TestAddOrReplace_Clone_Speed;
174
164
175
165
sw := TStopwatch.StartNew;
176
166
for i := 0 to iCount - 1 do
177
- begin
178
- entityWrapper := TEntityWrapper.Create(LCustomers[i]);
179
- FEntityMap.AddOrReplace(entityWrapper);
180
- end ;
167
+ FEntityMap.AddOrReplace(LCustomers[i]);
181
168
sw.Stop;
182
169
183
170
Status(Format(' %D items in %D ms' , [iCount, sw.ElapsedMilliseconds]));
184
171
185
- // previous implementation
186
- LObjectDict := TCollections.CreateDictionary<string, TObject>([doOwnsValues]);
187
- sw := TStopwatch.StartNew;
188
- for i := 0 to iCount - 1 do
189
- begin
190
- LObjectDict.AddOrSetValue(' some random key' , TRttiExplorer.Clone(LCustomers[i]));
191
- end ;
192
- sw.Stop;
193
-
194
- Status(Format(' Previous implementation: %D items in %D ms' , [iCount, sw.ElapsedMilliseconds]));
172
+ // //previous implementation
173
+ // LObjectDict := TCollections.CreateDictionary<string, TObject>([doOwnsValues]);
174
+ // sw := TStopwatch.StartNew;
175
+ // for i := 0 to iCount - 1 do
176
+ // begin
177
+ // LObjectDict.AddOrSetValue('some random key', TRttiExplorer.Clone(LCustomers[i]));
178
+ // end;
179
+ // sw.Stop;
180
+ //
181
+ // Status(Format('Previous implementation: %D items in %D ms', [iCount, sw.ElapsedMilliseconds]));
195
182
196
183
iCount := iCount * 10 ;
197
184
sw := TStopwatch.StartNew;
@@ -220,7 +207,6 @@ procedure TEntityMapTest.TestHash;
220
207
var
221
208
LTest1: TTest1;
222
209
LTest2: TTest2;
223
- entityWrapper: IEntityWrapper;
224
210
begin
225
211
LTest1 := TTest1.Create;
226
212
LTest2 := TTest2.Create;
@@ -229,8 +215,7 @@ procedure TEntityMapTest.TestHash;
229
215
230
216
CheckFalse(FEntityMap.IsMapped(LTest1));
231
217
CheckFalse(FEntityMap.IsMapped(LTest2));
232
- entityWrapper := TEntityWrapper.Create(LTest1);
233
- FEntityMap.AddOrReplace(entityWrapper);
218
+ FEntityMap.AddOrReplace(LTest1);
234
219
CheckTrue(FEntityMap.IsMapped(LTest1));
235
220
CheckFalse(FEntityMap.IsMapped(LTest2));
236
221
finally
@@ -242,12 +227,10 @@ procedure TEntityMapTest.TestHash;
242
227
procedure TEntityMapTest.TestRemove ;
243
228
var
244
229
LCustomer: TCustomer;
245
- entityWrapper: IEntityWrapper;
246
230
begin
247
231
LCustomer := CreateCustomer;
248
232
try
249
- entityWrapper := TEntityWrapper.Create(LCustomer);
250
- FEntityMap.AddOrReplace(entityWrapper);
233
+ FEntityMap.AddOrReplace(LCustomer);
251
234
CheckTrue(FEntityMap.IsMapped(LCustomer));
252
235
FEntityMap.Remove(LCustomer);
253
236
CheckFalse(FEntityMap.IsMapped(LCustomer));
@@ -260,11 +243,9 @@ procedure TEntityMapTest.When_Changed_One_Property_GetChangedMembers_Returns_It;
260
243
var
261
244
LCustomer: TCustomer;
262
245
LChangedColumns: IList<ColumnAttribute>;
263
- entityWrapper: IEntityWrapper;
264
246
begin
265
247
LCustomer := CreateCustomer;
266
- entityWrapper := TEntityWrapper.Create(LCustomer);
267
- FEntityMap.AddOrReplace(entityWrapper);
248
+ FEntityMap.AddOrReplace(LCustomer);
268
249
LCustomer.Name := ' Changed' ;
269
250
LChangedColumns := FEntityMap.GetChangedMembers(LCustomer, TEntityCache.Get(LCustomer.ClassType));
270
251
CheckEquals(1 , LChangedColumns.Count);
@@ -275,14 +256,12 @@ procedure TEntityMapTest.When_Changed_One_Property_GetChangedMembers_Returns_It;
275
256
procedure TEntityMapTest.When_Replaced_Entity_No_MemoryLeaks ;
276
257
var
277
258
company: TCompany;
278
- entityWrapper: IEntityWrapper;
279
259
begin
280
260
company := TCompany.Create;
281
261
try
282
- entityWrapper := TEntityWrapper.Create(company);
283
- FEntityMap.AddOrReplace(entityWrapper);
262
+ FEntityMap.AddOrReplace(company);
284
263
company.Logo.LoadFromFile(PictureFilename);
285
- FEntityMap.AddOrReplace(entityWrapper );
264
+ FEntityMap.AddOrReplace(company );
286
265
finally
287
266
company.Free;
288
267
end ;
@@ -293,12 +272,10 @@ procedure TEntityMapTest.When_Replaced_Entity_No_MemoryLeaks;
293
272
procedure TEntityMapTest.TestClear ;
294
273
var
295
274
LCustomer: TCustomer;
296
- entityWrapper: IEntityWrapper;
297
275
begin
298
276
LCustomer := CreateCustomer;
299
277
try
300
- entityWrapper := TEntityWrapper.Create(LCustomer);
301
- FEntityMap.AddOrReplace(entityWrapper);
278
+ FEntityMap.AddOrReplace(LCustomer);
302
279
CheckTrue(FEntityMap.IsMapped(LCustomer));
303
280
FEntityMap.Clear;
304
281
CheckFalse(FEntityMap.IsMapped(LCustomer));
0 commit comments