use of java.sql.Savepoint in project derby by apache.
the class SavepointJdbc30Test method testRollbackMultipleTimes.
/**
* Test 11 rolling back a savepoint multiple times - should work
*/
public void testRollbackMultipleTimes() throws SQLException {
Connection con = getConnection();
Savepoint savepoint1 = con.setSavepoint("MyName");
con.rollback(savepoint1);
con.rollback(savepoint1);
con.rollback();
}
use of java.sql.Savepoint in project derby by apache.
the class SavepointJdbc30Test method testReleaseMultipleTimes.
/**
* Test 12 releasing a savepoint multiple times - should not work
*/
public void testReleaseMultipleTimes() throws SQLException {
Connection con = getConnection();
Savepoint savepoint1 = con.setSavepoint("MyName");
con.releaseSavepoint(savepoint1);
try {
con.releaseSavepoint(savepoint1);
fail("FAIL 12 releasing a savepoint multiple times should fail");
} catch (SQLException se) {
// Expected exception.
assertSQLState("3B001", se);
}
con.rollback();
}
use of java.sql.Savepoint in project derby by apache.
the class SavepointJdbc30Test method testBug4465.
/**
* TEST 5a and 5b for bug 4465 test 5a - create two savepoints in two
* different transactions and release the first one in the subsequent
* transaction
*/
public void testBug4465() throws SQLException {
Connection con = getConnection();
Savepoint savepoint1 = con.setSavepoint("s1");
con.commit();
// The following savepoint was earlier named s1. Changed it to s2 while
// working on DRDA support
// for savepoints. The reason for that is as follows
// The client translates all savepoint jdbc calls to equivalent sql and
// hence
// if the 2 savepoints in
// different connections are named the same, then the release savepoint
// below will get converted to
// RELEASE TO SAVEPOINT s1 and that succeeds because the 2nd connection
// does have a savepoint named s1.
// Hence we don't really check what we intended to check which is trying
// to release a savepoint created
// in a different transaction
con.setSavepoint("s2");
Statement s = createStatement();
s.executeUpdate("INSERT INTO T1 VALUES(2,1)");
try {
con.releaseSavepoint(savepoint1);
fail("FAIL 5a - release savepoint from a different transaction " + "did not raise error");
} catch (SQLException se) {
// Expected exception.
assertSQLState("3B001", se);
}
con.commit();
// test 5b - create two savepoints in two different transactions
// and rollback the first one in the subsequent transaction
savepoint1 = con.setSavepoint("s1");
con.commit();
// The following savepoint was earlier named s1. Changed it to s2 while
// working on DRDA support
// for savepoints. The reason for that is as follows
// The client translates all savepoint jdbc calls to equivalent sql and
// hence
// if the 2 savepoints in
// different connections are named the same, then the rollback savepoint
// below will get converted to
// ROLLBACK TO SAVEPOINT s1 and that succeeds because the 2nd connection
// does have a savepoint named s1.
// Hence we don't really check what we intended to check which is trying
// to rollback a savepoint created
// in a different transaction
con.setSavepoint("s2");
s.executeUpdate("INSERT INTO T1 VALUES(2,1)");
try {
con.rollback(savepoint1);
fail("FAIL 5b - rollback savepoint from a different transaction " + "did not raise error");
} catch (SQLException se) {
// Expected exception.
assertSQLState("3B001", se);
}
con.commit();
}
use of java.sql.Savepoint in project derby by apache.
the class SavepointJdbc30Test method testSavepointName.
/*
* following section attempts to call statement in a method to do a negative
* test because savepoints are not supported in a trigger however, this
* cannot be done because a call is not supported in a trigger. leaving the
* test here for later reference for when we support the SQL version // bug
* 4507 - Test 8 test all 4 savepoint commands inside the trigger code
* System.out.println("Test 8a set savepoint(unnamed) command inside the
* trigger code"); s.executeUpdate("create trigger trig1 before insert on t1
* for each statement call
* org.apache.derbyTesting.functionTests.tests.jdbcapi.savepointJdbc30::doConnectionSetSavepointUnnamed()");
* try {
*
* s.executeUpdate("insert into t1 values(1,1)"); System.out.println("FAIL
* 8a set savepoint(unnamed) command inside the trigger code"); } catch
* (SQLException se) { System.out.println("Expected Exception is " +
* se.getMessage()); } s.executeUpdate("drop trigger trig1");
*
* System.out.println("Test 8b set savepoint(named) command inside the
* trigger code"); s.executeUpdate("create trigger trig2 before insert on t1
* for each statement call
* org.apache.derbyTesting.functionTests.tests.jdbcapi.savepointJdbc30::doConnectionSetSavepointNamed()");
* try { s.executeUpdate("insert into t1 values(1,1)");
* System.out.println("FAIL 8b set savepoint(named) command inside the
* trigger code"); } catch (SQLException se) { System.out.println("Expected
* Exception is " + se.getMessage()); } s.executeUpdate("drop trigger
* trig2");
*
* System.out.println("Test 8c release savepoint command inside the trigger
* code"); s.executeUpdate("create trigger trig3 before insert on t1 for
* each statement call
* org.apache.derbyTesting.functionTests.tests.jdbcapi.savepointJdbc30::doConnectionReleaseSavepoint()");
* try { s.executeUpdate("insert into t1 values(1,1)");
* System.out.println("FAIL 8c release savepoint command inside the trigger
* code"); } catch (SQLException se) { System.out.println("Expected
* Exception is " + se.getMessage()); } s.executeUpdate("drop trigger
* trig3");
*
* System.out.println("Test 8d rollback savepoint command inside the trigger
* code"); s.executeUpdate("create trigger trig4 before insert on t1 for
* each statement call
* org.apache.derbyTesting.functionTests.tests.jdbcapi.savepointJdbc30::doConnectionRollbackSavepoint()");
* try { s.executeUpdate("insert into t1 values(1,1)");
* System.out.println("FAIL 8d rollback savepoint command inside the trigger
* code"); } catch (SQLException se) { System.out.println("Expected
* Exception is " + se.getMessage()); } s.executeUpdate("drop trigger
* trig4"); con.rollback();
*/
// end commented out test 8
/**
* Test 9 test savepoint name and verify case sensitivity
*/
public void testSavepointName() throws SQLException {
Connection con = getConnection();
Savepoint savepoint1 = con.setSavepoint("myname");
String savepointName = savepoint1.getSavepointName();
assertEquals(savepointName, "myname");
con.rollback();
}
use of java.sql.Savepoint in project derby by apache.
the class SavepointJdbc30Test method testReusingSavepoints.
/**
* Test2 - After releasing a savepoint, should be able to reuse it.
*/
public void testReusingSavepoints() throws SQLException {
Connection con = getConnection();
Savepoint savepoint1 = con.setSavepoint("s1");
con.releaseSavepoint(savepoint1);
con.setSavepoint("s1");
con.rollback();
}
Aggregations