bogdanpolak / delphi-dataproxy Goto Github PK
View Code? Open in Web Editor NEWProxy component for data access TDataSet with Generator App tool and support for Fake memory datasets
License: MIT License
Proxy component for data access TDataSet with Generator App tool and support for Fake memory datasets
License: MIT License
A above
Change option GenCommentsWithPublicDataSet
to TDataSetAccess
type
TDataSetAccess = (dsaNoAccess, dsaGenComment, dsaFullAccess);
TDataProxyGenerator = class(TComponent)
DataSetAccess: TDataSetAccess;
TGenericDataProxy
procedure TBookProxy.ConnectFields;
var
ExpectedFieldCount: integer;
begin
FISBN := FDataSet.FieldByName('ISBN') as TWideStringField;
...
ExpectedFieldCount := 10;
FFieldCount := FDataSet.Fields.Count;
Assert (FFieldCount=ExpectedFieldCount);
end;
Add new folder: proxy with Data.Proxy.pas
Get file:
https://github.com/bogdanpolak/akademia/blob/master/projects/09-DataSetProxy/Data.DataProxy.pas
ForEach
method to:procedure TDatasetProxy.ForEach(OnElem: TProc);
var
Bookmark: TBookmark;
begin
self.DisableControls;
try
Bookmark := FDataSet.GetBookmark;
try
self.First;
while not FDataSet.Eof do
begin
OnElem();
FDataSet.Next;
end;
finally
if FDataSet.BookmarkValid(Bookmark) then
FDataSet.GotoBookmark(Bookmark);
FDataSet.FreeBookmark(Bookmark);
end;
finally
FDataSet.EnableControls;
end;
end;
Eof
method:function TGenericDataSetProxy.Eof: boolean;
begin
Result := FDataSet.Eof;
end;
Comp.GenerateDataSetCode.pas
to Comp.Generator.DataSetCode.pas
See #16
Describe why to use TProxyDataset descendant component created by GeneratorApp?
New factory structure:
TDataProxyFactory = class
public
class procedure RegisterDataSet(AProxyClass: TDataProxyClass;
const AConfigurationName: string; ADataSetCreateFun: TFun<TDataSet>);
class procedure SetDatasetConfiguration (AProxyClass: TDataProxyClass;
const AConfigurationName: string);
class function CreateProxy (AProxyClass: TDataProxyClass;
AOwner: TComponent);
end;
TDataProxyFactory.RegisterDataSet(TBookProxy, 'FireDAC-dsBook',
function (): TDataSet;
begin
Result := TFDQuery.Create(AOwner);
(Result as TFDQuery).Connection := FDConnection1;
(Result as TFDQuery).SQL.Texr := 'SELECT ISBN, Title, Authors, ' +
'Status, ReleseDate, Pages, Price, Currency, Imported, Description '+
'FROM Books WHERE ReleaseDate > :ReleaseDate';
end);
TDataProxyFactory.RegisterDataSet(TBookProxy, 'Mem-dsBook', CreateMockTableBook);
TDataProxyFactory.SetDatasetConfiguration (TBookProxy, 'Mem-dsBook');
BookProxy := TDataProxyFactory.CreateProxy<TBookProxy>(AOwner)
BookProxy.Open ([EncodeDate(2018,01,01)],[ftDateTime])
DUnitxProxyGeneratorComponent.dpr
Implement empty function: Gen_UnitHeader
in TDataProxyGenerator
add tests (implement with TDD)
Remove
MemDataSet: TFDMemTable;
function Given_Dataset: TDataSet;
TProxyTemplates
(for unit testing) Code generator sholud generate somple code with creation of the fake memory DataSet (TFDMemTable) filled with a random data
Data.DataProxy.pas
with Data.DataProxy.Factory.pas
Data.DataProxy.pas
to Data.Proxy.pas
procedure AppendRecord(const Values: array of const);
/ InsertRecord
procedure PlugInto (ADataSource: TDataSource);
function ConstructDataSource: TDataSource;
[Generated DAO Code]
=> [Generated Proxy]
Correct the descriptions in them main README to make them more readable and clean
type
TDataProxyFactory = class
class function CreateProxy<T: TDataSetProxy> (Owner: TComponent;
ADataSet: TDataSet): T;
end;
RDBMS SQL data set:
function CreateSQLDataSet_Book (AOwner: TComponent; AConnection: TFDConnection);
begin
fdq := TFDQuery.Create(AOwner);
with fdq do begin
Connection := AConnection;
SQL.Text := 'SELECT ISBN, Title, Authors, Status, ReleseDate,' +
' Pages, Price, Currency, Imported, Description FROM Books';
Open;
end;
Result := fdq;
end;
procedure Form1Create (Sender: TObject);
begin
ds := CreateSQLDataSet_Book(Self, FDConnection1);
BookProxy := TDataProxyFactory. CreateProxy<TBookProxy> (Self, ds);
end;
Memory (mock) data set:
procedure Form1Create (Sender: TObject);
begin
ds := CreateMemDataSet_Book(Self);
BookProxy := TDataProxyFactory. CreateProxy<TBookProxy> (Self, ds);
end;
Update:
TDSGenerator
(previously TGenerateDataSetCode
) to most recent version 1.3
Requires external support
More details: #16
In /doc/compare-dataset-vs-proxy.md
finish the description Why using proxy?
Proxy pros and cons,
Continues #18
Redesign a class TDataProxyFactory
stored in the Data.DataProxy.Factory.pas
unit (folder /samples/base/
)
Any sugestions?
Is now:
uses
System.SysUtils,
Database.Connector;
should be:
uses
System.SysUtils,
System.Classes,
FireDAC.Comp.Client; // for them mock FDMemTable (or separate units)
Generate whole unit ready to save with:
unit proxy.{ObjectName};
end.
type
TFieldNamingStyle = (fnsUpperCaseF, fnsLowerCaseF);
TDataSetGenerator =
FieldNamingStyle: TFieldNamingStyle;
This component interface was fully redesign, upgrade will require extensive code refactoring. About new component interface more info is here: GitHub - bogdanpolak - datasetToDelphiCode - issues 13
New dialog form which will allow to select database objects (tables and views) and build SELECT
statement with full field list. Also will allow to add INNER JOIN tables with foreign key verification
Bug: mru menu in not updated (no definition)
TBookProxy
ToString
, CountMoreExpensiveBooks
, LocateISBN
Authors
, Status
, Currency
, Imported
, Description
Data.DataProxy
prefix to TDatasetProxy
function CreateMockTableBook
TDataProxyFactory
: registration, configuration and usageAdding support for FireDAC is in issue #26
Analyze how to exend this support into diffrent DAC packages: AnyDAC, ADO, IBX and other.
Consider using: Chain of Responsibility pattern:
https://refactoring.guru/design-patterns/chain-of-responsibility
In the generated Delphi code should be also code for the SQL and DataProxy
. Something like:
const
SQLSELECT_OneMonthOrders = 'SELECT * FROM Orders '+
'WHERE {month ORDERDATE} = :MONTH AND {year ORDERDATE} = :YEAR';
procedure RegisterSQLProxy;
begin
AppDataProxyFactory.RegisterSQLProxy (TOrdersProxy, SQLSELECT_OneMonthOrders);
end;
And sample DataProxyFactory
construction method, eg.:
var
OrdersProxy: TOrdersProxy;
begin
OrdersProxy := AppDataProxyFactory.ConstructAndOpenProxy (TOrdersProxy, [12, 2018]);
...
In tab: [Generated DAO Code]
[Proxy Name]
Verify which version of Delphi IDE is required to compile the Generator App. Source code was written with Delphi 10.2, but should work with an older versions.
Community feedback is welcome!
Folders:
doc
- (no change)generator
-> tools\generator-app
proxy
-> src
samples
- (no change)tests
- (no change)New (separate ER):
tools\bumper-source
Update documentation according to this changes
README.md
Tasks:
README
TDataSetProxy
TDataProxyFactory
use WithDataSet
proxy
-> src
generator
-> tools\generator-app
Method TGenericDataSetProxy.Open
should be allow to open queries and stored procedures with parameters. Add support for FireDAC in the Open method:
if (FDataSet is TFDRdbmsDataSet) then
(FDataSet as TFDRdbmsDataSet).Open (AParamValues, AParamTypes);
In the generated proxy code is:
procedure T{ObjectName}Proxy.ConnectFields;
begin
ORDERID := FDataSet.FieldByName('ORDERID') as TIntegerField;
CUSTOMERID := FDataSet.FieldByName('CUSTOMERID') as TStringField;
but should be
procedure T{ObjectName}Proxy.ConnectFields;
begin
FORDERID := FDataSet.FieldByName('ORDERID') as TIntegerField;
FCUSTOMERID := FDataSet.FieldByName('CUSTOMERID') as TStringField;
Build SELECT statement with INNER JOIN tables. Fetch foreign key for main table. See more #2
WHEN:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.