• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO Pattern and Connection Pooling

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I'm a little confused on how to implement the two together... Suppose I have the following classes and interface










I'm just a little confused where I should be getting a Connection object... Which class... Which method... Static... or non static...? What do you think guys? Thanks!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would probably pass the connection pool into the DAO factory. The factory then would pass it on to the DAO when it gets created. When the DAO needs a connection, i.e. in one of the insert or update methods, it gets a connection from the pool, uses it, and releases it back to the pool.

Does that make sense?
 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have the main MySQLDAOFactory class create the connection object since it knows that it wants to connect to MySQL. Then if you had to create a connection to another type of db you would have that factory implementation create the connection as well.

So, if you have a delegate calling the DAO's you could do something like this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic