afunms

My Software,My Dream—Forge a more perfect NMS product.

perfect DAO solution

DAO design was revised repeatedly recent days,I am glad of  getting a perfect DAO solution
finally.
  The sticking point in DAO design is where a DB connection is opened and when
to close it. Sometimes,one action executes only one DAO method,the connection
should be closed immediately follow the method. Sometimes, However, one action
may contain many DAOs or a series of methods in a DAO, (in other words, called transaction).
A same connection is used in DAOs,so closing connection after method execution is incorrect.
  Therefore,I wrote two DAO's constructors for above two scenarios.For the first scenario,
opening a connection inside DAO,and close it at once after a method is invoked.For the second
scenario,a connection is created outside DAO, when instantiating a new DAO class,the connection
is passed from outside.We cope with this case (a transaction) in a service,the service invokes more
than one DAOs.DB connection is opened when service starting,and closed at the end of service.

posted on 2008-01-09 10:21 afunms 阅读(149) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

News

留言簿(18)

随笔档案

相册

搜索

最新评论

阅读排行榜