Recent

Author Topic: ANN: hbm2pascal - online source generator for database entities  (Read 10480 times)

mjustin

  • Full Member
  • ***
  • Posts: 167
    • Habarisoft
ANN: hbm2pascal - online source generator for database entities
« on: December 02, 2009, 06:59:17 pm »
December 2, 2009 - starting today, a web application is available at http://hbm2pascal.appspot.com/ which can generate Object Pascal source for database objects based on Hibernate mapping documents.

How to use hbm2pascal:
The web page contains a form which shows an example Hibernate mapping document, and a button to start the code generation. The example document may be edited freely. hbm2pascal will parse the table descriptions (including table relationships) and build Object Pascal source code. The generated sources then will be displayed and can be copied from the results page.

Hibernate mapping documents can be created manually, or extracted from metadata for existing databases using Hibernate Tools, a free toolkit available at http://www.hibernate.org/

hbm2pascal is under development. If you find it useful or have feature suggestions, your feedback is very appreciated.

Best regards
--
Michael Justin
http://www.mikejustin.com/ (see page footer for contact information)

gerardus

  • Jr. Member
  • **
  • Posts: 84
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #1 on: December 03, 2009, 09:47:50 am »
Interesting, thanks. Is the Hibernate framework available for Pascal, or this just generates plain objects with no persistence?

mjustin

  • Full Member
  • ***
  • Posts: 167
    • Habarisoft
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #2 on: December 03, 2009, 11:19:22 am »
Hello, and many thanks for your question!
 
Currently, the Hibernate framework exists only for Java and .Net, but the hbm2pascal code can be customized to generate class sources specifc for O/R mappers like tiOPF, hcOPF, InstantObjects and the G Framework:

tiOPF: http://tiopf.sourceforge.net/
hcOPF: http://www.tpersistent.com/?page_id=44
InstantObjects: http://www.instantobjects.org/
G framework: http://g-framework.org/

The applications which use these object persistency frameworks and hbm2pascal will not need Hibernate. Hibernate is only required in the first step, to reverse engineer the metadata of an existing database to hbm mapping files, which then will be converted by hbm2pascal. I wrote some generator scripts for the G framework already and if time permits future versions of hbm2pascal will support different conversion targets.

Best regards,
Michael

gerardus

  • Jr. Member
  • **
  • Posts: 84
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #3 on: December 03, 2009, 12:29:27 pm »
Hi Michael,

Do you use a XSLT transformation or is it coded by hand? I've been playing with both, and while XSLT seemed attractive at first, learning XSL and the complexity of the templates made me stop after a few tries.

Regards,

Gerard.

mjustin

  • Full Member
  • ***
  • Posts: 167
    • Habarisoft
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #4 on: December 03, 2009, 01:19:40 pm »
Hi Gerard,

currently it is a combination of own code and a template engine. I can not disclose the full details now, but it might be released in an offline version, if it receives positive critical response. The source code will be available then, which allows to switch between different code templates.

Regards,
Michael

mjustin

  • Full Member
  • ***
  • Posts: 167
    • Habarisoft
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #5 on: December 03, 2009, 02:18:10 pm »
Update:


hbm2pascal now also supports to send conversion results by email, if you have a Google user account.

The mail contains the Hibernate mapping document as body. The generated Pascal source files will be attached. Because Google App Enging has some security policies for email attachments, the source file extension is *.pas.txt.


Best regards,
Michael Justin

hbm2pascal page: http://hbm2pascal.appspot.com/

gerardus

  • Jr. Member
  • **
  • Posts: 84
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #6 on: December 03, 2009, 07:46:02 pm »
currently it is a combination of own code and a template engine. I can not disclose the full details now, but it might be released in an offline version, if it receives positive critical response. The source code will be available then, which allows to switch between different code templates.

OK, I'll be watching  :)

mjustin

  • Full Member
  • ***
  • Posts: 167
    • Habarisoft
Re: ANN: hbm2pascal - online source generator for database entities
« Reply #7 on: December 07, 2009, 09:41:09 am »
Update: the hbm2pascal web page at http://hbm2pascal.appspot.com/ now also includes example mapping files for two database systems:

HSQLDB
with three database tables

Firebird with ten database tables:

    * Country.hbm.xml
    * Customer.hbm.xml
    * Department.hbm.xml
    * Employee.hbm.xml
    * Job.hbm.xml
    * PhoneList.hbm.xml
    * ProjDeptBudget.hbm.xml
    * Project.hbm.xml
    * SalaryHistory.hbm.xml
    * Sales.hbm.xml

The conversion creates 15 source files (including interface and composite key class units).

Example: Country.pas, generated code

Code: [Select]
unit Country;

interface

uses
  // Interface declarations
  AllInterfaces,
  // required units
  SysUtils, Classes;


type
 (**
  * Country class.
  *)
  TCountry = class (TInterfacedObject, ICountry)
  private
    FCountry: string;
    FCurrency: string;
    FCustomers: TInterfaceList;
    FJobs: TInterfaceList;

    // getter methods
    function GetCountry: string;
    function GetCurrency: string;
    function GetCustomers: TInterfaceList;
    function GetJobs: TInterfaceList;

    // setter methods
    procedure SetCountry(const Value: string);
    procedure SetCurrency(const Value: string);

  public
    constructor Create;
    destructor Destroy; override;

    // properties
    property Country: string read GetCountry write SetCountry;
    property Currency: string read GetCurrency write SetCurrency;
    property Customers: TInterfaceList read GetCustomers;
    property Jobs: TInterfaceList read GetJobs;

  end;

implementation

{ TCountry }

constructor TCountry.Create;
begin
  inherited;

  FCustomers := TInterfaceList.Create;
  FJobs := TInterfaceList.Create;
end;

destructor TCountry.Destroy;
begin
  FCustomers.Free;
  FJobs.Free;

  inherited;
end;

function TCountry.GetCountry: string;
begin
  Result := FCountry;
end;

function TCountry.GetCurrency: string;
begin
  Result := FCurrency;
end;

function TCountry.GetCustomers: TInterfaceList;
begin
  Result := FCustomers;
end;

function TCountry.GetJobs: TInterfaceList;
begin
  Result := FJobs;
end;

procedure TCountry.SetCountry(const Value: string);
begin
  FCountry := Value;
end;

procedure TCountry.SetCurrency(const Value: string);
begin
  FCurrency := Value;
end;

end.


hbm2pascal is under development. If you find it useful or have feature suggestions, your feedback is very appreciated.

Best regards
--
Michael Justin
http://www.mikejustin.com/ (see page footer for contact information)

 

TinyPortal © 2005-2018