QuickBurro多层分布式架构下的ORM工具

作者在 2010-06-01 16:15:31 发布以下内容
一般的Delphi下的ORM工具都是在ADO组件之上实现,其实也就是在传统两层C/S的中间插入一层而已,这样的数据库实体对象并非是远程数据库实体,其功用相对于Delphi的RAD开发模式并不显著。

在下在实现了QuickBurro分布式多层架构后,在该架构之上实现了远程数据库的对象化(即远程数据库实体类),编写了一个实用的实体类代码生成工具GetEntity.exe,经实际项目中的应用证实,较为实用。

该工具支持“简单实体类、批量实体类、动态实体类、主从实体类”四种代码生成方式,能对任意远程节点上的数据库进行对象化转换,生成可在Delphi下直接编译通过的类单元。生成的主从表实体类能和QuickBurro的应用层数据库事务处理功能结合起来使用,解决多表远程更新处理问题。

下面是该工具的截图:






下面是使用该工具自动生成的一个主从表实体类单元代码的声明部分:

//
// ------------------------------------------------------------------------------------
//
// Entity_Sale.pas -- This entity class unit for table "Sale". 
//
// Generated by QuickBurro V3.2.2.0 Entity Classes Generator
//
// Generate time: 2010-06-01 15:47:01
//
// Copyright (C) Jopher Software Studio, 2006-2010
//
// ------------------------------------------------------------------------------------
//

unit Entity_Sale;

interface

uses
  SysUtils, Classes, db, DBClient, SyncBurro, QBParcel, Entity_SaleDetail;

type
  TSale = class(TPersistent)

  Private
  ff_SaleId: String;
  ff_SaleDate: String;
  ff_CustId: String;
  ff_CustName: String;
  ff_LevelId: String;
  ff_LevelName: String;
  ff_OrderDate: String;
  ff_OrderName: String;
  ff_TransMode: String;
  ff_TransId: String;
  ff_TransName: String;
  ff_TransTelephone: String;
  ff_TransEvidenceId: String;
  ff_TransMoney: Double;
  ff_ReceiveAddress: String;
  ff_ReceiveZip: String;
  ff_ReceiverName: String;
  ff_ReceiverTelephone: String;
  ff_ReceiverFax: String;
  ff_SaleMoney: Double;
  ff_MoneyId: String;
  ff_MoneyName: String;
  ff_EvidenceId: String;
  ff_CreateDate: String;
  ff_CreaterUserId: String;
  ff_CreaterUserName: String;
  ff_OutOk: String;
  ff_SaleDetail_List: TSaleDetailList;

  class function CreateCds: TClientDataset;

  public
  Property f_SaleId: String read ff_SaleId write ff_SaleId;
  Property f_SaleDate: String read ff_SaleDate write ff_SaleDate;
  Property f_CustId: String read ff_CustId write ff_CustId;
  Property f_CustName: String read ff_CustName write ff_CustName;
  Property f_LevelId: String read ff_LevelId write ff_LevelId;
  Property f_LevelName: String read ff_LevelName write ff_LevelName;
  Property f_OrderDate: String read ff_OrderDate write ff_OrderDate;
  Property f_OrderName: String read ff_OrderName write ff_OrderName;
  Property f_TransMode: String read ff_TransMode write ff_TransMode;
  Property f_TransId: String read ff_TransId write ff_TransId;
  Property f_TransName: String read ff_TransName write ff_TransName;
  Property f_TransTelephone: String read ff_TransTelephone write ff_TransTelephone;
  Property f_TransEvidenceId: String read ff_TransEvidenceId write ff_TransEvidenceId;
  Property f_TransMoney: Double read ff_TransMoney write ff_TransMoney;
  Property f_ReceiveAddress: String read ff_ReceiveAddress write ff_ReceiveAddress;
  Property f_ReceiveZip: String read ff_ReceiveZip write ff_ReceiveZip;
  Property f_ReceiverName: String read ff_ReceiverName write ff_ReceiverName;
  Property f_ReceiverTelephone: String read ff_ReceiverTelephone write ff_ReceiverTelephone;
  Property f_ReceiverFax: String read ff_ReceiverFax write ff_ReceiverFax;
  Property f_SaleMoney: Double read ff_SaleMoney write ff_SaleMoney;
  Property f_MoneyId: String read ff_MoneyId write ff_MoneyId;
  Property f_MoneyName: String read ff_MoneyName write ff_MoneyName;
  Property f_EvidenceId: String read ff_EvidenceId write ff_EvidenceId;
  Property f_CreateDate: String read ff_CreateDate write ff_CreateDate;
  Property f_CreaterUserId: String read ff_CreaterUserId write ff_CreaterUserId;
  Property f_CreaterUserName: String read ff_CreaterUserName write ff_CreaterUserName;
  Property f_OutOk: String read ff_OutOk write ff_OutOk;
  Property f_SaleDetail_List: TSaleDetailList read ff_SaleDetail_List write ff_SaleDetail_List;

  constructor Create;
  destructor Destroy; override;
  class function ReadFromCds(aCds: TClientDataset): TSale;
  procedure LoadAppertains(NodeId: String; SBurro: TSyncBurro);
  function SaveToCds(Cds: TClientDataset): Boolean;
  class function ReadFromDB(NodeId: String; SBurro: TSyncBurro; Condition: String): TSale;
  function DeleteFromDB(NodeId: String; SBurro: TSyncBurro; Condition: string): boolean;
  function InsertToDB(NodeId: String; SBurro: TSyncBurro; var NewKeyValue: integer): boolean;
  function UpdateToDB(NodeId: String; SBurro: TSyncBurro; Condition: string): boolean;

  end;

  TSaleList = class(TList)

  public  
  constructor Create;
  destructor Destroy; override;
  class function ReadFromDB(NodeId: String; SBurro: TSyncBurro; Condition: string = ''; OrderBy: string = ''): TSaleList;
  class function ReadFromCDS(Cds: TClientDataset): TSaleList;
  function SaveToCds(aCds: TClientDataset): boolean;
  function SaveToFile(FileName: string; DataFormat: TDataPacketFormat): boolean;
  function LoadFromFile(FileName: string): boolean;
  function SaveToStream(aStream: TMemoryStream; DataFormat: TDataPacketFormat): boolean;
  function LoadFromStream(aStream: TMemoryStream): boolean;
  function SaveToParcel(aParcel: TQBParcel; GoodsName: string): boolean;
  function LoadFromParcel(aParcel: TQBParcel; GoodsName: string): boolean;
   
  end;

implementation

...


下图是使用主从实体类进行应用编程的例子:

QuickBurro开发手记 | 阅读 2108 次
文章评论,共0条
游客请输入验证码