• 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

temporary Connection or connection pool?

 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in a DAO, we keep a connection open through out an instance or we only get a
connection and close it in a data access method? Thanks.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Damu,
If there is more than user user, a connection pool is usually best.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,Jeanne.

Say, in a web application (no EJB layer), for MVC model, the controller(filter or servlet) will delegate the requests to corresponding model, and the model will do the business, like getting the date from database, then, my question is:

Where should we keep the connection pool? in controller or in model.

If we keep the connection pool in controller, I think it might be easy to manage all the connection in one class(not sure). but we have to pass the connection reference to the model. this seems violating the isolation.
[ March 20, 2007: Message edited by: damu liu ]
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
most servers will actually support connection pooling themselves. You should look into your particular servers details to find out how it is set up. Your web app would then access a connection via a JNDI lookup. Certainly you can do this in the Sun One webserver. I'm 99.9% certain that you can do it in tomcat by fiddling with the xml config files - though I've never done it.

Hope that helps,
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by damu liu:
Where should we keep the connection pool? in controller or in model.


Neither. You should keep it in the connection pool. If you server supports datasources, the server takes care of it as Daniel described. If not, you can use an open source connection pool like DBCP.

Either way, you request the connection from the pool in your data access code. It goes where you would have asked DriverManager for a connection if you weren't using pooling - in your data access class. While the connection pool is called from your model, technically it isn't in your model. And it certainly isn't in the controller - the controller should just be delegating requests.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Daniel and Jeanne.
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic