• 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

DAO or Service layer? Which layer should we use?

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yeah, but is it art? What do you think tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic