Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how many DAO's should be there in applciation.

 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going over the DAO pattern example..Its about Movies.. so basically i have MovieDAO ,MovieDAOFactory ,MoviDAOImpl .. this 3 classes..so i f i have user registration in my app then there should be Registration DAO also .. right .. How may DAO's should be there in application .. is it like similar to the number of controllers in the applciation .. for ex. CartController,LoginController...and finally where should the database conncetion related logic should be ideally ..Inside the DAO implementation class or anywhere else..what should be the ideal scenario for Movie Rental application ..??how the sturcture should be ..
 
Masoud Kalali
Author
Ranch Hand
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-we usually create one DAO per our database table or view that we need , usually DAO are used to encapsulate data access in a seperate layer.

-there are some conditions that we have one DAO for more than one table , for example when you need to update multiple tables per operation.

-DAO is just for data access and Logic should not be pushed into DAO layer
business rules should be handled in business service entities .

-connections come from a resource manager , where ever in our DAOimpl that we need a connection we get the connection from resource manager and resource manager should know where to get connection from (a connection pool / using a singletone pattern and plain jdbc and driver manager ...)

take a look at http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
for more information
hth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic