📄 testjdbcsavepoints.java
字号:
+ "non-originating connection"; assertTrue(msg, false); } catch (Exception e) {} //-- test 5 : Direct execution of a <release savepoint> statement shall // not fail to release an existing indicated savepoint, // regardless of how the indicated savepoint was created msg = "direct execution of <release savepoint> statement failed to " + "release JDBC-created SQL-savepoint with identical savepoint name"; try { conn2.createStatement().executeUpdate( "release savepoint \"savepoint2\""); } catch (Exception e) { try { assertTrue(msg, false); } catch (Exception e2) {} } //-- test 6 : Direct execution of a <rollback to savepoint> statement // shall not fail to roll back to an existing indicated // savepoint due and only due to how the indicated savepoint // was created msg = "direct execution of <rollback to savepoint> statement failed to " + "roll back to existing JDBC-created SQL-savepoint with identical " + "savepoint name"; try { conn2.createStatement().executeUpdate( "rollback to savepoint \"savepoint1\""); } catch (Exception e) { e.printStackTrace(); try { assertTrue(msg, false); } catch (Exception e2) {} } conn1.releaseSavepoint(sp6); //-- test 7 : Releasing an SQL-savepoint shall destroy that savepoint msg = "savepoint released succesfully > 1 times"; try { conn1.releaseSavepoint(sp6); assertTrue(msg, false); } catch (Exception e) {} //-- test 8 : Releasing an SQL-savepoint shall destroy all subsequent SQL- // savepoints in the same savepoint level msg = "savepoint released successfully after preceding savepoint released"; try { conn1.releaseSavepoint(sp7); assertTrue(msg, false); } catch (Exception e) {} //-- test 9 : Releasing an SQL-savepoint shall not affect preceding // savepoints msg = "preceding same-point savepoint destroyed by following savepoint release"; try { conn1.releaseSavepoint(sp5); } catch (Exception e) { try { assertTrue(msg, false); } catch (Exception e2) {} } conn1.rollback(sp4); rs = stmt.executeQuery("select count(*) from t"); rs.next(); rowcount = rs.getInt(1); rs.close(); //-- Test 10 : count of rows matches # rows inserted less the number // of insertions rolled back msg = "select * rowcount after 50 inserts - 10 rolled back:"; try { assertEquals(msg, 40, rowcount); } catch (Exception e) {} //-- test 11 : An SQL-savepoint shall be destroyed in the // process of rolling back to that savepoint msg = "savepoint rolled back succesfully > 1 times"; try { conn1.rollback(sp4); assertTrue(msg, false); } catch (Exception e) {} conn1.rollback(sp3); rs = stmt.executeQuery("select count(*) from t"); rs.next(); rowcount = rs.getInt(1); rs.close(); //-- Test 12 : count of rows matches # rows inserted less the number // of insertions rolled back msg = "select count(*) after 50 inserts - 20 rolled back:"; try { assertEquals(msg, 30, rowcount); } catch (Exception e) {} //-- test 13 : An SQL-savepoint shall be destroyed in the // process of rolling back to that savepoint msg = "savepoint released succesfully after use in rollback"; try { conn1.releaseSavepoint(sp3); assertTrue(msg, false); } catch (Exception e) {} conn1.rollback(sp1); //-- test 14 : All subsequent savepoints (in a savepoint level) // shall be destroyed by the process of rolling back to // a preceeding savepoint (in the same savepoint level) msg = "savepoint rolled back without raising an exception after " + "rollback to a preceeding savepoint"; try { conn1.rollback(sp2); assertTrue(msg, false); } catch (Exception e) {} conn1.rollback(); //-- test 15 : All subsequent savepoints (in a savepoint level) // shall be destroyed by the process of // rolling back the active transaction msg = "savepoint released succesfully when it should have been " + "destroyed by a full rollback"; try { conn1.releaseSavepoint(sp1); assertTrue(msg, false); } catch (Exception e) {} conn1.setAutoCommit(false); sp1 = conn1.setSavepoint("savepoint1"); conn1.rollback(); conn1.setAutoCommit(false); conn1.createStatement().executeUpdate("savepoint \"savepoint1\""); //-- test 16 : A JDBC Savepoint shall be considered invalid if used to // release an SQL-savepoint other than precisely the // one created in correspondence to the creation of that // JDBC Savepoint object // fredt@users - we allow this if the name is valid/* msg = "JDBC Savepoint used to successfully release an identically named " + "savepoint in a transaction distinct from the originating " + "transaction"; try { conn1.releaseSavepoint(sp1); assertTrue(msg, false); } catch (Exception e) {}*/ conn1.setAutoCommit(false); sp1 = conn1.setSavepoint("savepoint1"); conn1.createStatement().executeUpdate("savepoint \"savepoint1\""); //-- test 17 : A JDBC Savepoint shall be considered invalid if used to // release an SQL-savepoint other than precisely the // one created in correspondence to the creation of that // JDBC Savepoint object // fredt@users - we allow this if the name is valid/* msg = "JDBC Savepoint used to successfully release an identically named " + "savepoint in a transaction other than the originating " + "transaction"; try { conn1.releaseSavepoint(sp1); assertTrue(msg, false); } catch (Exception e) {}*/ //-- test 18 : A JDBC Savepoint shall be considered invalid if used to // roll back to an SQL-savepoint other than precisely the // one created in correspondence to the creation of that // JDBC Savepoint object // fredt@users - we allow this if the name is valid/* msg = "JDBC Savepoint used to successfully to roll back to an " + "identically named savepoint in a transaction distinct " + "from the originating transaction"; try { conn1.rollback(sp1); assertTrue(msg, false); } catch (Exception e) {}*/ conn1.setAutoCommit(false); sp1 = conn1.setSavepoint("savepoint1"); conn1.createStatement().executeUpdate("savepoint \"savepoint1\""); //-- test 19 : A JDBC Savepoint shall be considered invalid if used to // roll back to an SQL-savepoint other than precisely the // one created in correspondence to the creation of that // JDBC Savepoint object // fredt@users - we allow this if the name is valid/* msg = "JDBC Savepoint used to successfully release an identically named " + "savepoint in a transaction other than the originating " + "transaction"; try { conn1.releaseSavepoint(sp1); assertTrue(msg, false); } catch (Exception e) {}*/ } /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { TestResult result; TestCase test; java.util.Enumeration failures; int count; result = new TestResult(); test = new TestJDBCSavepoints("testJDBCSavepoints"); test.run(result); count = result.failureCount(); System.out.println("TestJDBCSavepoints failure count: " + count); failures = result.failures(); while (failures.hasMoreElements()) { System.out.println(failures.nextElement()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -