[
]在下在实现了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;interfaceuses 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:do
uble;
ff_ReceiveAddress: String;
ff_ReceiveZip: String;
ff_ReceiverName: String;
ff_ReceiverTelephone: String;
ff_ReceiverFax: String;
ff_SaleMoney:do
uble;
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:do
uble 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:do
uble 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...GetEntity.exe工具所生成的实体类代码基于QuickBurro的数据集读服务、记录新增服务、记录更新服务、运行SQL命令等几个基本的服务,而这些服务都在QuickBurro的数据库事务控制服务内,所以,您在使用实体类的方法时,可以在自己的程序里使用QuickBurro的数据库事务,使之包含实体类读写的方法,这对于提高系统的可靠性有重要意义。本工具的最新版本支持单个实体类、批量实体类、动态实体类、主从关系实体类等四种代码生成方式,使应用程序对远程的普通二维表、主从关系多数据表等多种数据的远程交互编程时,都能获得最大的编程效率。下面是基于主从实体类的主从表记录增删改编程方法示例://// 新增:单据保存到数据库,因主从类实体,最好用事务处理方式进行...... SyncBurro1.begin
Trans(form1.QBConnection1.NodeId);
if Order.InsertToDB(QBConnection1.NodeId,SyncBurro1,j) then
begin
if not SyncBurro1.CommitTrans(j) then
begin
SyncBurro1.RollbackTrans;
application.MessageBox('对不起,写入数据库失败,请检查数据的有效性!','操作提示',mb_ok+mb_iconinformation);
exit;
end;
end;
......//// 修改:单据更新到数据库,因主从类实体,最好用事务处理方式进行...... SyncBurro1.begin
Trans(QBConnection1.NodeId);
if order.UpdateToDB(QBConnection1.NodeId,SyncBurro1,'orderid='+inttostr(order.f_OrderId));
begin
if not SyncBurro1.CommitTrans(j) then
begin
SyncBurro1.RollbackTrans;
application.MessageBox('对不起,更新数据库失败,请检查数据的有效性!','操作提示',mb_ok+mb_iconinformation);
exit;
end;
end;
......//// 删除:开始执行删除,因主从类实体,最好用事务处理方式更新数据库... SyncBurro1.begin
Trans(QBConnection1.NodeId);
if Order.DeleteFromDB(QBConnection1.NodeId,SyncBurro1,'OrderId='+inttostr(Order.f_OrderId)) then
begin
if not SyncBurro1.CommitTrans(j) then
begin
SyncBurro1.RollbackTrans;
application.MessageBox('对不起,删除销售单据出现错误!','错误信息',mb_ok+mb_iconerror);
exit;
end;
end;
以上三个代码段均为多表操作,使用了QuickBurro开发包所支持的事务处理,可靠性高但写法非常简单