-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtransfORM.DB.pas
97 lines (80 loc) · 2.73 KB
/
transfORM.DB.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit transfORM.DB;
interface
uses
FireDAC.Comp.Client,
FireDAC.Stan.Intf,
Spring.Collections;
type
TDBColumnInfo = class
private
fDataType: TFDDataType;
fPrimaryKey: Boolean;
fColumnAttributes : TFDDataAttributes;
fColumnName: string;
protected
public
constructor Create(const aColumnName: string; const aDataType: TFDDataType; aColumnAttributes: TFDDataAttributes);
property ColumnAttributes: TFDDataAttributes read fColumnAttributes;
property ColumnName: string read fColumnName;
property DataType: TFDDataType read fDataType;
property PrimaryKey: Boolean read fPrimaryKey write fPrimaryKey;
end;
TDBTableInfo = class
private
fColumns : IDictionary<string, TDBColumnInfo>;
fTableName: string;
protected
function GetColumn(const aColumnName : string): TDBColumnInfo;
function GetColumns(): IReadOnlyCollection<TDBColumnInfo>;
function GetTableName(): string;
procedure SetTableName(const aValue: string);
public
constructor Create(const aTableName : string);
function AddColumnInfo(const aColumnName: string; const aDataType: TFDDataType; aColumnAttributes: TFDDataAttributes): TDBColumnInfo;
property Column[const aColumnName : string]: TDBColumnInfo read GetColumn; default;
property Columns: IReadOnlyCollection<TDBColumnInfo> read GetColumns;
property TableName: string read GetTableName write SetTableName;
end;
implementation
uses
System.SysUtils;
constructor TDBTableInfo.Create(const aTableName : string);
begin
inherited Create();
fTableName := aTableName;
fColumns := TCollections.CreateDictionary<string, TDBColumnInfo>([doOwnsValues]);
end;
function TDBTableInfo.AddColumnInfo(const aColumnName: string; const aDataType: TFDDataType; aColumnAttributes: TFDDataAttributes):
TDBColumnInfo;
begin
Result := TDBColumnInfo.Create(aColumnName, aDataType, aColumnAttributes);
fColumns.Add(aColumnName, Result);
end;
function TDBTableInfo.GetColumn(const aColumnName : string): TDBColumnInfo;
begin
if not fColumns.TryGetValue(aColumnName, Result) then
begin
raise Exception.CreateFmt('Column %s not exists in table %s', [aColumnName, fTableName]);
end;
end;
function TDBTableInfo.GetColumns(): IReadOnlyCollection<TDBColumnInfo>;
begin
Result := fColumns.Values;
end;
function TDBTableInfo.GetTableName(): string;
begin
Result := fTableName;
end;
procedure TDBTableInfo.SetTableName(const aValue: string);
begin
fTableName := aValue;
end;
constructor TDBColumnInfo.Create(const aColumnName: string; const aDataType: TFDDataType; aColumnAttributes: TFDDataAttributes);
begin
inherited Create();
fColumnName := aColumnName;
fDataType := aDataType;
fColumnAttributes := aColumnAttributes;
fPrimaryKey := False;
end;
end.