Delphi Dorm Introduction
Delphi Dorm Introduction
Whats DORM?
DORM
The Delphi ORM
Delphi implementation of Data Mapper Enterprise Design Pattern Its not related to RAD, but LiveBindings allows a good RAD compromise
Why DORM?
I dont want (or I cant) change my database I want persistence ignorance I want to access to the metal I want to persist PODO I don't hate SQL, but I know that 90% of it is boilerplate and errors prone
DORMs author is Daniele Teti Contributors are welcome bitTime software is the main sponsor and offer support for DORM custom development, consultancy and so on.
DORM foundation: Data Mapper Pattern A software layer that separe objects from the database Persists/retrieve objects state from/to database Complete separation between domain model and database Objects do not know the mapper
Is it a new idea?
WOW effect slide. How to insert and retrieve an object form a sql database or other persistence systems
var person: TPerson; oid: Integer; begin person := TPerson.Create(Daniele,Teti,32); Session.Save(person); oid := person.id; person.Free; person := Session.Load<TPerson>(oid); WriteLn(Person name is: , person.FirstName); person.Free; end;
DORM features
Open Source Apache License 2.0 Database agnostic Do not require database changes! Has one, has many and belongs to relations support Save and retrieve objects graph, not only single objects Support persistence inheritance (TPerson, TManager) File based configuration Interfaces based! Event based validation (TdormObject) Persistence ignorance
Can persists everythig! So it will be supported and mantained J
DORM features
Very good performances Completely Unit tested SQL script generation from configuration file Multiple environments
Development, Test, Production
has_one, has_many, belongs_to
Lazy Load for related objects Fluent interfaces for queries Unit Of Work for multiple operations (UOW) Use anonymous methods, generics Does not require a particular editor to design classes. Together (in Delphi) in enough. Tested on Delphi XE and XE2 (Win32/Win64)
Should works also on Delphi 2010
Supported databases
Interbase 2009+
DBExpress UIB
SQLServer
DBExpress
SQLite
DORM Samples
SELECT * FROM PEOPLE WHERE ID = 1 UPDATE PEOPLE SET FIRST_NAME = Daniele, LAST_NAME = Teti WHERE ID = 1 DELETE FROM PEOPLE WHERE ID = 1
var p: TPerson; begin p := TPerson.Create(Daniele,Teti); try p.Phones := NewList; //TdormCollection.Create p.Phones.Add(TPhone.Create(328-9823883)); p.Phones.Add(TPhone.Create(328-4242424)); Session.Save(p); Session.Commit; finally p.Free; end; end;
var p: TPerson; begin //Session.SetLazyLoadFor( TypeInfo(TPerson), 'Phones', false); p := Session.Load<TPerson>(12); try for phone in p.Phones do WriteLn(phone.number); finally p.Free; end; end;
var intf: IdormSearchCriteria; SQL: String; begin SQL := 'SELECT * FROM PEOPLE ... a lot of SQL'; intf := TdormSimpleSearchCriteria.Create( TypeInfo(TPerson), SQL); People := Session.List(intf); end;
Useful for new applications Generate SQL script from dorm conf file Its aware to the environment settings Simple to extend
More tools
Create config file from existing databases Create objects from config file
Notes
Currently there are Firebird SQL Interbase SQLServer SQlite Currently there are a CodeSite logger and a flat file logger
Currently there are a sequence based generator and a GUID generator You can create your own queries arbitrary complexes
Persistence
IdormPersistenceStrategy
Logging
Primary key generators Finders
IdormLogger
IdormKeysGenerator
IdormSearchCriteria
DEMOS
Where is DORM?
DORM
The Delphi ORM
http://code.google.com/p/delphi-orm/
DORM
The Delphi ORM
Thank You