The moose likes OO, Patterns, UML and Refactoring and the fly likes DAO Pattern and Connection Pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "DAO Pattern and Connection Pooling" Watch "DAO Pattern and Connection Pooling" New topic

DAO Pattern and Connection Pooling

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
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!

SCJP 1.5
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
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?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
graham king
Ranch Hand

Joined: Dec 30, 2004
Posts: 133
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:

write, revise, re-write, revise, again...<br />write, revise, re-write, revise, again...
I agree. Here's the link:
subject: DAO Pattern and Connection Pooling
It's not a secret anymore!