1

I am a newbie to webservices and I was thinking of using savepoint mechanism in the test automation using webServices. Below is a code snippet

Connection con = 
    DriverManager.getConnection("jdbc:derby://localhost:1527/testDb", 
                                "name","pass");
con.setAutoCommit(false);
Savepoint spt1 = con.setSavepoint("svpt1");
WebService.Post() method for various CRUD operations.....
con.rollback(spt1);
con.commit();

The operations in between setting the savepoint and rolling back to it are various CRUD operations using webServices, so that when the savepoint is rolled back, the dirty data created during the automation shall be wiped off. I am curious to know if it is a good practice to use savepoint mechanism here and if it is ok to use, then what would be the average time for creating + rolling back the savepoint?

Vikdor
  • 23,934
  • 10
  • 61
  • 84
Sammy
  • 51
  • 1
  • 5

2 Answers2

0

Unless I misunderstood the question, you can't rollback something that has been done in another transaction. So what you're doing here doesn't make much sense.

A savepoint and a rollback can be used to rollback the operations done since the save point with the connection that you rollback. Everything else is not concerned by the savepoint, and can't be undone.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Hi JB. Thanks for the reply. the savepoint name in the SetSavepoint method and rollback was different. very sorry that was a typo. So i can create a savepoint "ABC" and rollback to "ABC" and whatever operations happened inbetween will be undone? so that the database will come back to a clean state environment to match to the environment how it was prior to the test case execution? – Sammy Sep 25 '12 at 18:58
  • No. As I said. A SavePoint is not some snapshot of the whole database. It can only be used to rollback (or undo, if you prefer) all the operations that have been made using the connection that you rollback. If another connection (i.e. the one used by your web service) has done inserted, update or deleted rows using its own, different connection, these operations can't be rolled back. Once committed, they're in the database. Transactions run in isolation from each other. – JB Nizet Sep 25 '12 at 19:23
0

Sounds like a perfect use case for DBUnit - it can recreate your entire database before each test execution.

TrueDub
  • 5,000
  • 1
  • 27
  • 33