Search in sources :

Example 26 with Savepoint

use of java.sql.Savepoint in project derby by apache.

the class SavepointJdbc30Test method testNoNestedSavepointsInsideJdbcSavepoint.

/**
 * Test 18
 */
public void testNoNestedSavepointsInsideJdbcSavepoint() throws SQLException {
    Connection con = getConnection();
    Savepoint savepoint1 = con.setSavepoint();
    Statement s = getConnection().createStatement();
    // inside JDBC savepoint
    try {
        s.executeUpdate("SAVEPOINT s1 ON ROLLBACK RETAIN LOCKS ON ROLLBACK" + " RETAIN CURSORS");
        fail("FAIL 18 shouldn't be able set SQL savepoint nested inside " + "JDBC savepoints");
    } catch (SQLException se) {
        // Expected exception.
        assertSQLState("3B002", se);
    }
    // rollback the JDBC savepoint. Now since there are no user defined
    // savepoints, we can define SQL savepoint
    con.releaseSavepoint(savepoint1);
    s.executeUpdate("SAVEPOINT s1 ON ROLLBACK RETAIN LOCKS ON " + "ROLLBACK RETAIN CURSORS");
    con.rollback();
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Savepoint(java.sql.Savepoint)

Example 27 with Savepoint

use of java.sql.Savepoint in project derby by apache.

the class SavepointJdbc30Test method xtestRollbackWillReleaseActiveSavepoints.

/**
 * Test42 - Rollback on a connection will release all the savepoints created
 * for that transaction
 */
public void xtestRollbackWillReleaseActiveSavepoints() throws SQLException {
    Connection con = getConnection();
    Savepoint savepoint1 = con.setSavepoint();
    con.rollback();
    try {
        con.rollback(savepoint1);
        fail("FAIL 42 release of rolled back savepoint");
    } catch (SQLException se) {
        // Expected exception.
        assertSQLState("3B001", se);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) Savepoint(java.sql.Savepoint)

Example 28 with Savepoint

use of java.sql.Savepoint in project derby by apache.

the class SavepointJdbc30Test method xtestReuseNameAfterRollback.

/**
 * Test 45 reuse savepoint name after rollback - should not work
 */
public void xtestReuseNameAfterRollback() throws SQLException {
    Connection con = getConnection();
    Savepoint savepoint1 = con.setSavepoint("MyName");
    con.rollback(savepoint1);
    try {
        con.setSavepoint("MyName");
        fail("FAIL 45 reuse of savepoint name after rollback should fail");
    } catch (SQLException se) {
        // Expected exception.
        if (usingEmbedded()) {
            assertSQLState("3B501", se);
        } else if (usingDerbyNetClient()) {
            assertSQLState("3B002", se);
        }
    }
    con.rollback();
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) Savepoint(java.sql.Savepoint)

Example 29 with Savepoint

use of java.sql.Savepoint in project derby by apache.

the class SavepointJdbc30Test method xtestCursorsCloseOnRollback.

/**
 * Test 46 bug 5145 Cursors declared before and within the savepoint unit
 * will be closed when rolling back the savepoint
 */
public void xtestCursorsCloseOnRollback() throws SQLException {
    Connection con = getConnection();
    Statement sWithHold = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
    Statement s = createStatement();
    s.executeUpdate("DELETE FROM T1");
    s.executeUpdate("INSERT INTO T1 VALUES(19,1)");
    s.executeUpdate("INSERT INTO T1 VALUES(19,2)");
    s.executeUpdate("INSERT INTO T1 VALUES(19,3)");
    ResultSet rs1 = s.executeQuery("select * from t1");
    rs1.next();
    ResultSet rs1WithHold = sWithHold.executeQuery("select * from t1");
    rs1WithHold.next();
    Savepoint savepoint1 = con.setSavepoint();
    ResultSet rs2 = s.executeQuery("select * from t1");
    rs2.next();
    ResultSet rs2WithHold = sWithHold.executeQuery("select * from t1");
    rs2WithHold.next();
    con.rollback(savepoint1);
    try {
        // resultset declared outside the savepoint unit should be
        // closed at this point after the rollback to savepoint
        rs1.next();
        fail("FAIL 46 shouldn't be able to use a resultset (declared " + "before the savepoint unit) after the rollback to savepoint");
    } catch (SQLException se) {
        // Expected exception.
        assertSQLState("XCL16", se);
    }
    try {
        // holdable resultset declared outside the savepoint unit should
        // be closed at this point after the rollback to savepoint
        rs1WithHold.next();
        fail("FAIL 46 shouldn't be able to use a holdable resultset " + "(declared before the savepoint unit) after the rollback " + "to savepoint");
    } catch (SQLException se) {
        // Expected exception.
        assertSQLState("XCL16", se);
    }
    try {
        // resultset declared within the savepoint unit should be closed
        // at this point after the rollback to savepoint
        rs2.next();
        fail("FAIL 46 shouldn't be able to use a resultset (declared within " + "the savepoint unit) after the rollback to savepoint");
    } catch (SQLException se) {
        // Expected exception.
        assertSQLState("XCL16", se);
    }
    try {
        // holdable resultset declared within the savepoint unit should
        // be closed at this point after the rollback to savepoint
        rs2WithHold.next();
        fail("FAIL 46 shouldn't be able to use a holdable resultset " + "(declared within the savepoint unit) after the rollback " + "to savepoint");
    } catch (SQLException se) {
        // Expected exception.
        assertSQLState("XCL16", se);
    }
    con.rollback();
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Savepoint(java.sql.Savepoint)

Example 30 with Savepoint

use of java.sql.Savepoint in project derby by apache.

the class SavepointJdbc30Test method testReleaseSavepointFromOtherTransaction.

/**
 * Test 6c: TEST case just for bug 4467 // Test 10 - create a named
 * savepoint with the a generated name savepoint1 =
 * con2.setSavepoint("SAVEPT0"); // what exactly is the correct behaviour
 * here? try { savepoint2 = con2.setSavepoint(); } catch (SQLException se) {
 * System.out.println("Expected Exception is " + se.getMessage()); }
 * con2.commit();
 */
public void testReleaseSavepointFromOtherTransaction() throws SQLException {
    Connection con = getConnection();
    Savepoint savepoint1 = con.setSavepoint("s1");
    Statement s = createStatement();
    s.executeUpdate("INSERT INTO T1 VALUES(2,1)");
    Connection con2 = openDefaultConnection();
    try {
        con2.releaseSavepoint(savepoint1);
        fail("FAIL 6c - releasing another transaction's savepoint did " + "not raise error");
    } catch (SQLException se) {
        // Expected exception.
        if (usingEmbedded()) {
            assertSQLState("XJ010", se);
        } else if (usingDerbyNetClient()) {
            assertSQLState("XJ008", se);
        }
    }
    con.commit();
    con2.commit();
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Savepoint(java.sql.Savepoint)

Aggregations

Savepoint (java.sql.Savepoint)159 Statement (java.sql.Statement)61 Connection (java.sql.Connection)56 SQLException (java.sql.SQLException)55 PreparedStatement (java.sql.PreparedStatement)32 Test (org.junit.Test)31 ResultSet (java.sql.ResultSet)26 DatabaseMetaData (java.sql.DatabaseMetaData)13 UnitTest (nl.topicus.jdbc.test.category.UnitTest)13 TransactionStatus (org.springframework.transaction.TransactionStatus)12 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)12 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)12 ArrayList (java.util.ArrayList)11 Vector (java.util.Vector)11 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 SQLClientInfoException (java.sql.SQLClientInfoException)7 HashMap (java.util.HashMap)5 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)4 Random (java.util.Random)3