Another year has just begun… And I start it with the first of a regular blog posting (I hope… new year’s resolutions
). Of course it’s summer… but let’s call it 2007 1/2, if not 2008. The end of summer’s vacations always meant to me the start of another year of hard work, with a small interlude during Christmas and the REAL new year event…
So! In that blog category, called Architecture, I’ll talk about (probably) almost anything that has to do with programming and building systems. I’ll write in English, although I’m an eternal French Canadian. Do not hesitate to leave comments in French, by the way…
Right now, I’m not writing about something interesting I would have come across in the past few days, so I’ll just write on one of my first “architecture” thing I’ve done at my first job. That’s called an ORM, or object-relational mapper. As with anything else, the thing needed a name of its own - that serves two purposes: first, it becomes easier, with a name, to isolate it in a conversation; and second, well, to name a thing always provides with a good self-satisfaction feeling - so I got it a name. It’s been called ObjectSpace. Some of you may recognize it; I’ve stole it from Microsoft, when they where building their ORM. Anyway it was an internal tool, never meant to be marketed; that was more of a code name than a brand name.
That big baby took me 6 months to build, plus another 6 months to optimize and release bug fixes. And it truly made the job. Like, I was impressed myself
The purpose of an ORM is to plug the business layer directly on the data layer, but to hide completely the relational nature of the data. That is, the business layer should be able, with an ORM in place, to query the data layer in terms of objects and properties rather than values and primary or foreign keys. I give an example here in pseudo-English: “Bring me the companies whose headquarter is in Montreal, that has two plants and more that 2000 employees. Oh and by the way, also bring the customers of each company, with their address". In the object language I’ve developed for the ORM, that query translates to : (if I remember correctly)
query.Select.Add("Company.Customers.Address");
query.Where.Add("Company.HeadQuarter.Location", “Montreal");
query.Where.Add("Company.Plants.Count", 2);
query.Where.Add("Company.Employees.Count", 2000, greaterThan);
companies = query.Load();
See what I mean? All that is correctly translated into fully-optimized SQL queries. I was using auto-generated stub code to load the objects into hashtables (with generated key classes), and associate, in that case, each customer with the correct company, and each customer’s addresses with the correct customer. All the load was done in O(n)… I told you, I was impressed myself! 
The magic was done by parsing, when the application started, an xml file that was describing the mapping between objects, properties, and tables, primary and foreign keys. ObjectSpace, of course, was a service that, like any other service in the application, was automatically started and configured at application start. ObjectSpace would then generate the code (if config files have changed or if the dlls didn’t exist yet…) it needed to create, on the fly, the SQL queries necessary to load the data.
The beauty of the thing is that it also made insert, update and delete. And if an object was simply moving from one child collection to another (like, parent A gives a child to parent B ), then there was no delete+insert, but only an update of the foreign key…
Have some of you built or worked with an ORM? I know there’s NHibernate now, but I never toke the time to have a look at it (at that time, I was finalizing ObjectSpace, and I had absolutely no wish to scrap my job for some free, though probably pretty cool, tool on which I didn’t work - I was starting my career and greatly needing the credit I expected or wished to receive with my own product)
Well, I have absolutely no idea if that blog will get some attention, but in all cases, next time, I’ll talk about my conception of services and plugins. I know there’s a lot of hype around SOA by those times, but frankly, I don’t understand why… It’s just a name around a (easy) concept, but well… we need names, don’t we?