Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Connection managment  RSS feed

John Burton
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on an application where the main concern is speed. They are using jsf and the existing controllers are filled with multiple database calls with a connection that is being passed from call to call. It's very quick, but a complete mess with many of the same calls rewritten on every page.

I have introduced a dao layer for better maintainability and reuse, but it's just not as fast. The problem is that my connections are on a method level and creating a db2 connection is expensive. I need to create a connection and use it for all the daos in a page view. What is the best way to do that?

I was thinking of creating a DAOManager and in it's constructor having it create a connection and use the DAOMannager to get each dao and pass it the connection the constructor such as

I have not seen this documented anywhere so I am wondering if there is a better way to do it? We are not using any sort of persistence framework, just straight jdbc calls.

Thanks for your help!
Murali Ranga
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing connection objects to constructor you will be losing extendibility of the code

My suggestion
Create a BaseDAO which has setConnection and getConnection methods
And also closeConnection
Each DAO extending the BaseDAO
1.create connection object
2. setting the connection objects to DAO
PersonDAO personDAO = new PersonDAO()
personDAO. setConnection(connection)
your DAO Method(){
// will call getConnection to get connection object

This way tomorrow if you don’t want to pass connection objects to methods then no need for changing the method signature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!