more robust: exclude accidental nesting (synchronized block is re-entrant);
authorwenzelm
Mon, 17 Jul 2023 20:32:19 +0200
changeset 78383 d032bf604e93
parent 78382 6c211e1c94d5
child 78384 6b6a3e7a0d32
more robust: exclude accidental nesting (synchronized block is re-entrant);
src/Pure/General/sql.scala
--- a/src/Pure/General/sql.scala	Mon Jul 17 20:31:45 2023 +0200
+++ b/src/Pure/General/sql.scala	Mon Jul 17 20:32:19 2023 +0200
@@ -439,7 +439,7 @@
     override def close(): Unit = connection.close()
 
     def transaction[A](body: => A): A = connection.synchronized {
-      val auto_commit = connection.getAutoCommit()
+      require(connection.getAutoCommit(), "transaction already active")
       try {
         connection.setAutoCommit(false)
         val savepoint = connection.setSavepoint()
@@ -450,7 +450,7 @@
         }
         catch { case exn: Throwable => connection.rollback(savepoint); throw exn }
       }
-      finally { connection.setAutoCommit(auto_commit) }
+      finally { connection.setAutoCommit(true) }
     }
 
     def transaction_lock[A](