Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Bean + DAO

 
Tomchi Tang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am desinging an application where I am using Fast Lane Reader Pattern (Stateless Session Bean + DAO) for reports. We have created seperate custom DTOs (Value objects) for each report. Now my question is - where should we place the logic to create the DTOs. Should we create the DTO in the DAO layer and return it to the session bean or create it in the session bean and fill it there. According to Core J2EE patterns, the logic to create the DTO should go in the DAO. I guess this is a good idea when we have to create domain DTOs (the data from one single table), where one single call to the backend will return all the data related to the DTO. But in our case where we have to fire a seperate sql for each DTO field, I think, the logic should go in Session Bean. I am a bit confused. I would like to hear some expert views on that.
Thanks
Tomchi
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create the DTO in DAO.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it would be best to keep *all* SQL stuff inside the DAO layer.
 
Tomchi Tang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your Input. Actually we want to show different reports which have details like
- Total no of Sellers
- Total no of purchase/non-purchase items and their values
- Total no of categorized/non-categorized items and their values
....
....
This information is also required in other reports. I can think of following possible solutions:
1) Create a generic ReportDAO which have queries used in all the reports. When we need to show a specific report, we can call the ReportDAO from our session bean, fill the XXXReportDTO and send it back to the client.
2) Create a generic ReportDAO which have queries used in all the reports. In addition to these queries, DAO also have functions to create, populate and return specific DTO. In this case, Generic ReportDAO will aslo work as what you called "Super DAO". It interact with session bean and internally use query functions to create and populate DTOs.
3) Similar to (2) where the superDAO will be a seperate Factory Class.
4) Create report specific DAOs which have a method to create report specific DTO.
Pls. suggest which option is the best.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about starting out with the one big report DAO and refactoring afterwards if deemed necessary?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic