Skip to content

Commit 2acbf27

Browse files
committed
Fix JDBC-179 by only resetting auto-commit conditionally
1 parent 47a8703 commit 2acbf27

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Changes in 0.7.11
2+
3+
* Address edge case in transaction rollback failure [JDBC-179](https://clojure.atlassian.net/browse/JDBC-179).
4+
15
Changes in 0.7.10
26

37
* Use a US-locale `lower-case` function to avoid problems in certain locales (e.g., Turkish). A similar issue has been fixed recently in both HoneySQL and `next.jdbc`.

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
clojure.java.jdbc
22
========================================
33

4-
A low-level Clojure wrapper for JDBC-based access to databases. This project is "Stable" (no longer "Active"). It has effectively been superseded by [seancorfield/next.jdbc](https://github.com/seancorfield/next-jdbc).
4+
A low-level Clojure wrapper for JDBC-based access to databases. This project is "Stable" (no longer "Active"). It has effectively been superseded by [seancorfield/next.jdbc](https://github.com/seancorfield/next-jdbc).
55

66
For higher level DSLs and migration libraries that are compatible, see the [documentation](http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html).
77

@@ -26,22 +26,22 @@ Support
2626
Releases and Dependency Information
2727
========================================
2828

29-
Latest stable release: 0.7.10 -- requires Clojure 1.7 or later!
29+
Latest stable release: 0.7.11 -- requires Clojure 1.7 or later!
3030

3131
* [All Released Versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22java.jdbc%22)
3232

3333
* [Development Snapshot Versions](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~java.jdbc~~~)
3434

3535
[Leiningen](https://github.com/technomancy/leiningen) dependency information:
3636
```clojure
37-
[org.clojure/java.jdbc "0.7.10"]
37+
[org.clojure/java.jdbc "0.7.11"]
3838
```
3939
[Maven](http://maven.apache.org/) dependency information:
4040
```xml
4141
<dependency>
4242
<groupId>org.clojure</groupId>
4343
<artifactId>java.jdbc</artifactId>
44-
<version>0.7.10</version>
44+
<version>0.7.11</version>
4545
</dependency>
4646
```
4747
_Note: Earlier versions of Clojure are supported by older versions of `clojure.java.jdbc`: e.g., version 0.6.1 supports Clojure 1.4 and later._
@@ -140,6 +140,9 @@ Developer Information
140140
Change Log
141141
====================
142142

143+
* Release 0.7.11 on 2019-12-24
144+
* Address edge case in transaction rollback failure [JDBC-179](https://clojure.atlassian.net/browse/JDBC-179).
145+
143146
* Release 0.7.10 on 2019-08-24
144147
* Use a US-locale `lower-case` function to avoid problems in certain locales (e.g., Turkish). A similar issue has been fixed recently in both HoneySQL and `next.jdbc`.
145148
* Clean up `db-spec` options that are passed to the JDBC connection manager as properties [JDBC-178](https://clojure.atlassian.net/browse/JDBC-178).

src/main/clojure/clojure/java/jdbc.clj

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,10 @@ http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html"}
793793
(if (zero? (get-level db))
794794
(if-let [con (db-find-connection db)]
795795
(let [nested-db (inc-level db)
796-
auto-commit (.getAutoCommit con)
796+
auto-commit (.getAutoCommit con)
797797
old-isolation (.getTransactionIsolation con)
798-
old-readonly (.isReadOnly con)]
798+
old-readonly (.isReadOnly con)
799+
restore-ac? (volatile! true)]
799800
(io!
800801
(when isolation
801802
(.setTransactionIsolation con (isolation isolation-levels)))
@@ -805,12 +806,21 @@ http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html"}
805806
(try
806807
(let [result (func nested-db)]
807808
(if (db-is-rollback-only nested-db)
808-
(.rollback con)
809+
(do
810+
;; per JDBC-179: if the rollback operation fails, we do not
811+
;; want to try to restore auto-commit...
812+
(vreset! restore-ac? false)
813+
(.rollback con)
814+
(vreset! restore-ac? true))
809815
(.commit con))
810816
result)
811817
(catch Throwable t
812818
(try
819+
;; per JDBC-179: if the rollback operation fails, we do not
820+
;; want to try to restore auto-commit...
821+
(vreset! restore-ac? false)
813822
(.rollback con)
823+
(vreset! restore-ac? true)
814824
(catch Throwable rb
815825
;; combine both exceptions
816826
(throw (ex-info (str "Rollback failed handling \""
@@ -825,9 +835,10 @@ http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html"}
825835
;; want those to replace any exception currently being
826836
;; handled -- and if the connection got closed, we just
827837
;; want to ignore exceptions here anyway
828-
(try
829-
(.setAutoCommit con auto-commit)
830-
(catch Exception _))
838+
(when @restore-ac?
839+
(try ; only restore auto-commit if rollback did not fail
840+
(.setAutoCommit con auto-commit)
841+
(catch Exception _)))
831842
(when isolation
832843
(try
833844
(.setTransactionIsolation con old-isolation)

0 commit comments

Comments
 (0)