Giter Club home page Giter Club logo

delphi-dataproxy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

delphi-dataproxy's Issues

Add option DataSetAccess (replace old one)

Change option GenCommentsWithPublicDataSet to TDataSetAccess

type
  TDataSetAccess = (dsaNoAccess, dsaGenComment, dsaFullAccess);

  TDataProxyGenerator = class(TComponent)
    DataSetAccess: TDataSetAccess;

Verify current dataset structure`procedure ConnectFields`

  • Add to Comp.Proxy.CodeGenerator code:
  • Add FFieldCount to 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 Data.Proxy.pas unit

Add new folder: proxy with Data.Proxy.pas

Get file:
https://github.com/bogdanpolak/akademia/blob/master/projects/09-DataSetProxy/Data.DataProxy.pas

  • Change 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;
  • Add Eof method:
function TGenericDataSetProxy.Eof: boolean;
begin
  Result := FDataSet.Eof;
end;

Connection MRU menu stores only 2 items

mru-connection-menu

Steps:

  1. Select 2 different FireDAC connection definition:
    a) select definition, click [Connect] button, click [Disconnect] button
  2. Restart application
  3. Select yet another different (third) connection definition
  4. Restart

Bug: Only two last definition will be visible in the menu

Upgrade TDataProxyFactory registration and usage

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;

Registration sample

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);

Configuration sample

TDataProxyFactory.SetDatasetConfiguration (TBookProxy, 'Mem-dsBook');

Usage sample

BookProxy := TDataProxyFactory.CreateProxy<TBookProxy>(AOwner)
BookProxy.Open ([EncodeDate(2018,01,01)],[ftDateTime])

Start refactoring of Unit Tests & investigate

  1. Start refactoring of Unit Tests:
    • Rename project DUnitxProxyGeneratorComponent.dpr
    • Split tests into smaller units if it is possible
    • Clean 3xA sections in test cases
  2. Refine and add refactoring issues for new sprint
    • For more complicated refactorings

Refactor generator tests

Remove

  1. MemDataSet: TFDMemTable;
    • Use function Given_Dataset: TDataSet;
  2. Copy methods which is comparing multiline strings
  3. Remove: TProxyTemplates
    • rebuild all templates
    • use instead: inplace text
  4. Rebuild wrapper: TTestProxyDataGenerator
    • methods convert to functions

Redesign `Data.DataProxy.pas`

  1. Merge units: Data.DataProxy.pas with Data.DataProxy.Factory.pas
  2. Rename: Data.DataProxy.pas to Data.Proxy.pas
  3. Add: procedure AppendRecord(const Values: array of const); / InsertRecord
  4. Add procedure PlugInto (ADataSource: TDataSource);
  5. Add function ConstructDataSource: TDataSource;

Degin UI: Add proxy generator options

  1. Rename tab [Generated DAO Code] => [Generated Proxy]
  2. Add UI control to change proxy options:
    • property DataSetAccess
    • property FieldNamingStyle
    • other properties added in version 1.0

Upgrade TDataProxyFactory

Factory API

type
  TDataProxyFactory = class
    class function CreateProxy<T: TDataSetProxy> (Owner: TComponent; 
      ADataSet: TDataSet): T;
  end;

Factory usage

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;

Enter / update generated proxy class name

Add edit control to enter proxy name:
place-for-edit
Default text: {ObjectName}

On edit control change:

  • Update generated proxy class name
  • All places in generated code with {ObjectName} code should be updated

Add option FieldNamingStyle

type
  TFieldNamingStyle = (fnsUpperCaseF, fnsLowerCaseF);

  TDataSetGenerator =
    FieldNamingStyle: TFieldNamingStyle;

Add query builder

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

[doc] Fix samples on the main README

TBookProxy

  • Remove functions: ToString, CountMoreExpensiveBooks, LocateISBN
  • Remove properties: Authors, Status, Currency, Imported, Description
  • Add: Data.DataProxy prefix to TDatasetProxy

function CreateMockTableBook

  • Update fields to TBookProxy

New

  • Add sample with TDataProxyFactory: registration, configuration and usage

Add code: TDataProxyFactory registration for SQL and DataProxy

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]);
  ...

Proxy class name is not changing

In tab: [Generated DAO Code]

  1. WHEN:
    • Change text field: [Proxy Name]
  2. THEN:
    • No changes are applied and text field content is reseted

Rebuild project structure

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

Rebuild documentation - main README

Tasks:

  1. Remove Generator App from main README
    • move to Generator App documentation to separate document
    • update diagrams
  2. Merge Using TProxyDataSet in action with main README
  3. Merge TDataSet vs TDataSetProxy with main README as introduction
  4. Separate memory dataset generation as separate subject for unit testing
  5. Describe TDataSetProxy as a tool for extracting logic form legacy projects
  6. Separate two sections:
    • refactoring dataset into TDataSetProxy
    • inserting extracted code into unit test harness
  7. Point DataSet Generator as a supportive project
  8. Remove TDataProxyFactory use WithDataSet
  9. Update docs according to current folder structure:
    • proxy -> src
    • generator -> tools\generator-app
  10. Expnlain fake datasets generator as supportive project

Add support for parameters in TGenericDataSetProxy.Open

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);

[Code generator] Set Fields not Properties

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.