• 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

rollback db operations spanning db sessions on operation fail

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to call a db procedure 3 times. All 3 calls will be in 3 different db sessions. The requirement is such that if any of the 3 calls fail, all three transactions should roll back. The respective commits should happen only when all 3 procedures have executed successfully.

Already tried solutions:

Initiate 3 different connections inside a method. Call the procedure on those connections, and when one of them fails, call rollback on all connections. When the execution of 2nd call failed, I called rollback 1st connection. This resulted in a SocketException. I do not have the stacktrace available.

Using IBM WID and WPS: Encapsulated the db service calls in a single WPS server transaction and made 3 calls to database procedure. This resulted in partial commit, that is, the first call resulted in an insert inside database and did not rollback after the failure of 2nd call.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For your IBM WID and WPS approach, do check the vendor doc for things like whether closing connection or flushing or moving to new DB call does a "auto-commit". I'm pretty sure such setting can be set temporarily (eg through coding) or permanently.

Also for each of the procedure, do not have commit, else it will commit after each procedure no matter what happens to the other procedures.

The commit level must be set outside of the 3 procedure calls (eg in server transaction or program explicitly stating tx.begin() .... tx.commit() )

If you haven't tried you may considered using JTA to create a transaction and calling the procedures inside:
 
Abhishk Singh
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could do it using WID and WPS and got it verified.
JTA seems as a good alternative. Will verify it too. Thanks for the input.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic