diff options
-rw-r--r-- | src/clojure/contrib/sql.clj | 12 | ||||
-rw-r--r-- | src/clojure/contrib/sql/internal.clj | 20 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/clojure/contrib/sql.clj b/src/clojure/contrib/sql.clj index c3615efd..f4e1ac3f 100644 --- a/src/clojure/contrib/sql.clj +++ b/src/clojure/contrib/sql.clj @@ -41,9 +41,17 @@ [& body] `(transaction* (fn [] ~@body))) -(defalias set-rollback-only set-rollback-only*) +(defn set-rollback-only + "Marks the outermost transaction such that it will rollback rather than + commit when complete" + [] + (rollback-only true)) -(defalias is-rollback-only is-rollback-only*) +(defn is-rollback-only + "Returns true if the outermost transaction will rollback rather than + commit when complete" + [] + (rollback-only)) (defn do-commands "Executes SQL commands on the open database connection." diff --git a/src/clojure/contrib/sql/internal.clj b/src/clojure/contrib/sql/internal.clj index ff1d7ad2..207ccd3b 100644 --- a/src/clojure/contrib/sql/internal.clj +++ b/src/clojure/contrib/sql/internal.clj @@ -38,17 +38,12 @@ (or (:connection *db*) (throw (Exception. "no current database connection")))) -(defn set-rollback-only* - "Marks the current stack of nested transactions such that they will - rollback rather than commit when complete" - [] - (update-in *db* [:rollback-only] swap! (fn [_] true))) - -(defn is-rollback-only* - "Returns true if the current stack of nested transactions will rollback - rather than commit when complete" - [] - @(:rollback-only *db*)) +(defn rollback-only + "Accessor for the rollback-only flag on the current connection" + ([] + @(:rollback-only *db*)) + ([val] + (update-in *db* [:rollback-only] swap! (fn [_] val)))) (defn with-connection* "Evaluates func in the context of a new connection to a database then @@ -86,7 +81,7 @@ (try (let [value (func)] (when outermost - (if (is-rollback-only*) + (if (rollback-only) (.rollback con) (.commit con))) value) @@ -100,6 +95,7 @@ (throw e))) (finally (when outermost + (rollback-only false) (.setAutoCommit con auto-commit)))))))) (defn with-query-results* |