Sunday, August 21, 2005

DAO Example

A couple of days ago I read an article about the Apache Ibatis DAO framework, which got me very interested. I decided to code a small example to get a closer look at the framework.

I use nearly the same domain logic as in the drools example, which is excellent to implement my "Liquor Store Example".... Anyways, I decided to use Apache Ibatis DataMapper, as an O/R-Mapping framework. Both frameworks I use here are Ibatis products, which lets them work perfectly together. Since everything comes from Apache nowadays, I thought Derby, the embedded database engine, is a good choice for a database.

So what does my example do? It implements a simple store application, which I like to call "Liquor Store". As I said, it is kept very simple. I just use a couple of domain classes to get an idea of how things could work in a real application. To get a closer look at the DAO framework, I decided to store the data of two domain objects persistently, for example the data of the "Item" domain object. I use the DAO framework, to manage the data in a persistent store, which is in my case the Derby database. For further information how things work, check out the readme file of the example.

Both frameworks, DAO and DataMapper, left a throughout positive mark! They are well documented with examples and an easy to read manual, which is sometimes a major setback when using free software. Using the DAO framework is very straightfoward and in conjunction with DataMapper very efficient. The configuration of Apache Ibatis DAO is quite simple, you just have to define the persistence mapping mechanism, in my case DataMapper, and the DAO Implementations which are being used to store the data. Configuring Apache Ibatis DataMapper is also very simple, there is one confguration file to define the database that you want to store your data to and for every persistent object there is another file which defines the mapping. The configuration part was the most time consuming task when I was developing this example. I hope there is tool support for configuration out there, which would speed things up. Programming with DAO is very straightforward, since you are programming to interfaces. This makes it easy to test your business logic with mock objects.

All things considered, I think these two frameworks are very useful and they are worth taking a look at.  

No comments: