File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Web Service and Transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web Service and Transaction" Watch "Web Service and Transaction" New topic

Web Service and Transaction

C Shinde
Ranch Hand

Joined: Oct 22, 2009
Posts: 60

I have a UI (basically a mobile client), which has a Button which when I clicked executes a process in the background. THis background process basically uploads data to the server via a webservice which is loaded into a DB. In the foreground after I click the button it shows a new screen with a progress bar and a cancel button below it. If I click the Cancel Button, I need to undo whatever data I have uploaded to the server via the web service.
The background process is executed via seperate thread in the client side that also calls the webservice.

I have a few questions:
1.Does this process qualify for a transaction kind of scenario?If yes how do I implement Transactions on Server side for this?
2. If this does not qualify for transaction what do I do? As I am building the background process as a seperate thread do I just stop the background thread if the cancel button is clicked, but then again the data already send to the Web Service, how will the webservice behave?

Any help Appreciated

Chetan Shinde
Manan Panchal

Joined: Nov 17, 2008
Posts: 24
Implement a method in webservice which simply set flag which can indicate that process is cancelled or not.
Execute the method when you hit "Cancel"
When your db changes finished check the flag, if process is cancelled then rollback transaction otherwise commit it.

Tom Reilly

Joined: Jun 01, 2010
Posts: 618
I would not attempt long-running transactions over the wild wild web. I would upload the data to a staging database. Once the data is uploaded, in addition to validating that the data is correct, move it to the regular database (using transactions). If the user clicks cancel then remove the loaded data from the staging database.
I agree. Here's the link:
subject: Web Service and Transaction
It's not a secret anymore!