• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO or Service layer? Which layer should we use?

 
kuldeep sidhu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question has been asked in an interview.
The task is we need to do the following -
1. persisting some data to mysql db
2. persisting same data to oracle db
3. calling third party webservice using same data.

And the condition is either all the three should happen or none . If one fails, we need to roll back all others.

The question was in which layer you will do the implementation.
I told DAO layer for first 2 tasks (persisting to db) and calling webservice from Service layer. But in this case if webservice fails, we cannot rollback db transactions.
So what will be the preferred way of achieving the same and which all layers will be used?
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to do all that in the service layer. Actual DB operations (CRUD) can be done in DAO layer.
 
kuldeep sidhu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok but in case if third party webservice fails then how can we rollback the transactions done in DAO layer?
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't do commit in DAO layer. Any action can be taken only after the three steps are completed successfully.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic