-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMVCBr.FireDAC.Model.pas
96 lines (77 loc) · 2.33 KB
/
MVCBr.FireDAC.Model.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 MVCBr.FireDAC.Model;
{ MVCBr
www.tireideletra.com.br
amarildo lacerda
}
interface
uses Classes, forms, SysUtils,
MVCBr.Interf, MVCBr.Model,
MVCBr.FireDACModel.Interf,
MVCBr.Controller, MVCBr.DatabaseModel,MVCBr.DatabaseModel.Interf,
FireDAC.Comp.Client, FireDAC.Stan.Def;
Type
TFireDACModel = class(TDatabaseModelFactory<TFDConnection, TFDQuery>, IFireDACModel,
IThisAs<TFireDACModel>)
private
protected
public
Constructor Create; override;
Destructor Destroy; override;
class function new(AProc: TProc<IFireDACModel>): IFireDACModel; overload;
class function new(const AController: IController): IFireDACModel; overload;
function ThisAs: TFireDACModel;
// connection
function DriverID(const ADriverID: string): IFireDACModel;
function ConnectionName(const AConn: string): IFireDACModel;
function UserName(const AUser: string): IFireDACModel;
function Password(const APass: string): IFireDACModel;
// Query
//function NewQuery(const AProcChange: TProc<Q>): IQueryModel<Q>; virtual;
end;
Implementation
function TFireDACModel.ConnectionName(const AConn: string): IFireDACModel;
begin
result := Self;
GetConnection.ConnectionName := AConn;
end;
constructor TFireDACModel.Create;
begin
inherited;
SetModelTypes ( [mtPersistent] );
Connection(TFDConnection.Create(nil));
end;
destructor TFireDACModel.Destroy;
begin
inherited;
end;
function TFireDACModel.DriverID(const ADriverID: string): IFireDACModel;
begin
result := Self;
GetConnection.DriverName := ADriverID;
end;
class function TFireDACModel.new(AProc: TProc<IFireDACModel>): IFireDACModel;
begin
result := TFireDACModel.Create;
if Assigned(AProc) then
AProc(result);
end;
function TFireDACModel.ThisAs: TFireDACModel;
begin
result := Self;
end;
function TFireDACModel.UserName(const AUser: string): IFireDACModel;
begin
result := Self;
GetConnection.Params.Values['USER_NAME'] := AUser;
end;
class function TFireDACModel.new(const AController: IController): IFireDACModel;
begin
result := TFireDACModel.Create;
result.Controller(AController);
end;
function TFireDACModel.Password(const APass: string): IFireDACModel;
begin
result := Self;
GetConnection.Params.Values['PASSWORD'] := APass;
end;
end.