Sneak peek to simple integration between DMVCFramework and DORM

This is a really simple (not optimized and dirty) integration between the upcoming DMVCFramework (WebBroker based MVC framework) and DORM, “the Delphi ORM”.

This is the DMVCFramework controller with the relative mapping and methods. In the method “GetUsers” dorm is used to execute a select to the database using the sanitized parameter passed on the url.

unit UsersControllerU;

interface

uses MVCFramework, dorm;

type

  [MVCPath('/users')]
  TUsersController = class(TMVCController)
  strict private
    dormSession: TSession;

  strict protected
    procedure MVCControllerAfterCreate; override;
    procedure MVCControllerBeforeDestroy; override;

  public
    [MVCPath('/($id)')]
    [MVCHTTPMethod([httpGET])]
    procedure GetUsers(CTX: TWebContext);
  end;

implementation

uses
  dorm.loggers, dorm.adapters, dorm.Commons, UsersBO;

{ TUsersController }

procedure TUsersController.GetUsers(CTX: TWebContext);
var
  User: TUser;
begin
  User := dormSession.Load < TUser > (CTX.Request.ParamsAsInteger['id']);
  Render(User);
end;

procedure TUsersController.MVCControllerAfterCreate;
begin
  inherited;
  dormSession := TSession.CreateConfigured('dorm.conf', TdormEnvironment.deDevelopment);
end;

procedure TUsersController.MVCControllerBeforeDestroy;
begin
  dormSession.Free;
  inherited;
end;

end.

Now, if you run the application and go to http://localhost/users/1 (the server is running on port 80), you’ll get the following:

Stay tuned.

#3 “dorm, the Delphi ORM” bullettin

A veeery log time after the last dorm bullettin. But, as usual, I was been very busy on some projects (not only dorm) and the time goes by…

However, dorm has been extended, polished and improved over the last few months. Has been used in a couple other projects in my compoany (www.bittime.it).

So, here’s a small list of improvements and some other tips:

– ObjStatus support (more to come)

– TdormSession non-visual component. Check “samplesDelphiXE3TdormSession_Sample01formSample1.dproj”

– dorm is now in Continuous Integration (not for all supported databases, but I’m improving that)

– I’m integrating a JSON/DataSet/ObjectList mapper into dorm to be used in RESTful DataSnap/WebBroker (or not) http servers. More to come.

– Delphi XE3 Support

– Removes SuperObject as external lib. Now dorm uses an internal patched version.

– More demos added (Most noticeably id under “samplesDelphiXE3TODOManagerTODOManager.dproj”)

– Added samples using the new Visual LiveBinding feature in Delphi XE3

About the ObjSupport it’s worth to spend some words about it.

Since the beginning, dorm is completely “perisstence ignorant”: In other words, you can persiste what you want, you dont need to inherit from a specific class or implement a specific interface. This is a very powerful feature but make some internal dorm mechanism very complex. But I really WANT to have this feature, so I’ve added another “mode” to work with dorm: ObjStatus.

If dorm engine finds a property nemed “ObjStatus” of a specific type, it’ll use that property to track the object status (Clean, Dirty, Deleted).

In this way, I gained a *LOT* of speed compared to the prior version regarding persistence of complex objects graph.

eg.

procedure DoSomethingOnPersonByID(ID: Integer);
var
  p: TPerson;
begin
	p := Session.Load(ID);
	p.FirstName := 'Daniele';
	p.Car.Model := 'Civic';
	p.Phones.Add(TPhone.Create('555-555-33-22', 'Home'))
	Session.Persist(p); //generates insert, update, delete for related objects too
	p.Free;
end;

As Usual you can find the project code here https://code.google.com/p/delphi-orm/