• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DAO Pattern and Connection Pooling

 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Evil is afoot. But this tiny ad is just an ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic