@@ -322,58 +322,57 @@ public void testIsolationLevel() throws Exception {
322322 */
323323 @ Test
324324 public void testSavepoint () throws Exception {
325- DatabaseMetaData dbmd = this .conn .getMetaData ();
325+ assumeTrue ( this .conn .getMetaData (). supportsSavepoints (), "Savepoints not supported" );
326326
327- if ( dbmd . supportsSavepoints ()) {
328- System . out . println ( "Testing SAVEPOINTs" );
327+ try {
328+ this . conn . setAutoCommit ( true );
329329
330- try {
331- this .conn .setAutoCommit (true );
332-
333- createTable ("testSavepoints" , "(field1 int)" , "InnoDB" );
334-
335- // Try with named save points
336- this .conn .setAutoCommit (false );
337- this .stmt .executeUpdate ("INSERT INTO testSavepoints VALUES (1)" );
338-
339- Savepoint afterInsert = this .conn .setSavepoint ("afterInsert" );
340- this .stmt .executeUpdate ("UPDATE testSavepoints SET field1=2" );
341-
342- Savepoint afterUpdate = this .conn .setSavepoint ("afterUpdate" );
343- this .stmt .executeUpdate ("DELETE FROM testSavepoints" );
344-
345- assertTrue (getRowCount ("testSavepoints" ) == 0 , "Row count should be 0" );
346- this .conn .rollback (afterUpdate );
347- assertTrue (getRowCount ("testSavepoints" ) == 1 , "Row count should be 1" );
348- assertTrue ("2" .equals (getSingleValue ("testSavepoints" , "field1" , null ).toString ()), "Value should be 2" );
349- this .conn .rollback (afterInsert );
350- assertTrue ("1" .equals (getSingleValue ("testSavepoints" , "field1" , null ).toString ()), "Value should be 1" );
351- this .conn .rollback ();
352- assertTrue (getRowCount ("testSavepoints" ) == 0 , "Row count should be 0" );
353-
354- // Try with 'anonymous' save points
355- this .conn .rollback ();
356-
357- this .stmt .executeUpdate ("INSERT INTO testSavepoints VALUES (1)" );
358- afterInsert = this .conn .setSavepoint ();
359- this .stmt .executeUpdate ("UPDATE testSavepoints SET field1=2" );
360- afterUpdate = this .conn .setSavepoint ();
361- this .stmt .executeUpdate ("DELETE FROM testSavepoints" );
362-
363- assertTrue (getRowCount ("testSavepoints" ) == 0 , "Row count should be 0" );
364- this .conn .rollback (afterUpdate );
365- assertTrue (getRowCount ("testSavepoints" ) == 1 , "Row count should be 1" );
366- assertTrue ("2" .equals (getSingleValue ("testSavepoints" , "field1" , null ).toString ()), "Value should be 2" );
367- this .conn .rollback (afterInsert );
368- assertTrue ("1" .equals (getSingleValue ("testSavepoints" , "field1" , null ).toString ()), "Value should be 1" );
369- this .conn .rollback ();
370-
371- this .conn .releaseSavepoint (this .conn .setSavepoint ());
372- } finally {
373- this .conn .setAutoCommit (true );
374- }
375- } else {
376- System .out .println ("MySQL version does not support SAVEPOINTs" );
330+ createTable ("testSavepoints" , "(field1 int)" , "InnoDB" );
331+
332+ // Try with named save points
333+ this .conn .setAutoCommit (false );
334+ this .stmt .executeUpdate ("INSERT INTO testSavepoints VALUES (1)" );
335+
336+ Savepoint afterInsert = this .conn .setSavepoint ("afterInsert" );
337+ this .stmt .executeUpdate ("UPDATE testSavepoints SET field1=2" );
338+
339+ Savepoint afterUpdate = this .conn .setSavepoint ("afterUpdate" );
340+ this .stmt .executeUpdate ("DELETE FROM testSavepoints" );
341+
342+ assertEquals (0 , getRowCount ("testSavepoints" ), "Row count should be 0" );
343+ this .conn .rollback (afterUpdate );
344+ assertEquals (1 , getRowCount ("testSavepoints" ), "Row count should be 1" );
345+ assertEquals ("2" , getSingleValue ("testSavepoints" , "field1" , null ).toString (), "Value should be 2" );
346+ this .conn .rollback (afterInsert );
347+ assertEquals ("1" , getSingleValue ("testSavepoints" , "field1" , null ).toString (), "Value should be 1" );
348+ this .conn .rollback ();
349+ assertEquals (0 , getRowCount ("testSavepoints" ), "Row count should be 0" );
350+
351+ // Try with 'anonymous' save points
352+ this .conn .rollback ();
353+
354+ this .stmt .executeUpdate ("INSERT INTO testSavepoints VALUES (1)" );
355+ afterInsert = this .conn .setSavepoint ();
356+ this .stmt .executeUpdate ("UPDATE testSavepoints SET field1=2" );
357+ afterUpdate = this .conn .setSavepoint ();
358+ this .stmt .executeUpdate ("DELETE FROM testSavepoints" );
359+
360+ assertEquals (0 , getRowCount ("testSavepoints" ), "Row count should be 0" );
361+ this .conn .rollback (afterUpdate );
362+ assertEquals (1 , getRowCount ("testSavepoints" ), "Row count should be 1" );
363+ assertEquals ("2" , getSingleValue ("testSavepoints" , "field1" , null ).toString (), "Value should be 2" );
364+ this .conn .rollback (afterInsert );
365+ assertEquals ("1" , getSingleValue ("testSavepoints" , "field1" , null ).toString (), "Value should be 1" );
366+ this .conn .rollback ();
367+
368+ Savepoint savepoint = this .conn .setSavepoint ();
369+ this .conn .releaseSavepoint (savepoint );
370+ assertThrows (SQLException .class , "SAVEPOINT .* does not exist" , () -> {
371+ this .conn .rollback (savepoint );
372+ return null ;
373+ });
374+ } finally {
375+ this .conn .setAutoCommit (true );
377376 }
378377 }
379378
0 commit comments