-
Notifications
You must be signed in to change notification settings - Fork 4
/
transfORM.Entity.pas
72 lines (60 loc) · 2.06 KB
/
transfORM.Entity.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
unit transfORM.Entity;
interface
uses
FireDAC.Stan.Intf,
Spring.Collections;
type
TInterfaceField = class
private
fFieldName : string;
fMappedToColumn : string;
fPK : Boolean;
fColumnAttributes: TFDDataAttributes;
public
constructor Create(const aFieldName : string; const aMappedToColumn : string; aPK : Boolean; aColumnAttributes: TFDDataAttributes);
property FieldName: string read fFieldName;
property MappedToColumn: string read fMappedToColumn;
property PK: Boolean read fPK;
property ColumnAttributes: TFDDataAttributes read fColumnAttributes;
end;
TInterfaceEntity = class
private
fFields : IDictionary<string, TInterfaceField>;
fPrimaryKeyName : string;
fTableName: string;
public
constructor Create(const aTableName : string);
function AddField(const aFieldName : string; const aMappedToColumn : string; aPK : Boolean; aColumnAttributes: TFDDataAttributes):
TInterfaceField;
property Fields: IDictionary<string, TInterfaceField> read fFields;
property PrimaryKeyName: string read fPrimaryKeyName;
property TableName: string read fTableName;
end;
implementation
constructor TInterfaceField.Create(const aFieldName : string; const aMappedToColumn : string; aPK : Boolean; aColumnAttributes:
TFDDataAttributes);
begin
inherited Create();
fFieldName := aFieldName;
fMappedToColumn := aMappedToColumn;
fPK := aPK;
fColumnAttributes := aColumnAttributes;
end;
constructor TInterfaceEntity.Create(const aTableName : string);
begin
inherited Create();
fPrimaryKeyName := '';
fTableName := aTableName;
fFields := TCollections.CreateDictionary<string, TInterfaceField>([doOwnsValues]);
end;
function TInterfaceEntity.AddField(const aFieldName : string; const aMappedToColumn : string; aPK : Boolean; aColumnAttributes:
TFDDataAttributes): TInterfaceField;
begin
Result := TInterfaceField.Create(aFieldName, aMappedToColumn, aPK, aColumnAttributes);
fFields.AddOrSetValue(aFieldName, Result);
if aPK then
begin
fPrimaryKeyName := aMappedToColumn;
end;
end;
end.