(defn transaction*
"Evaluates func as a transaction on the open database connection. Any
nested transactions are absorbed into the outermost transaction. By
default, all database updates are committed together as a group after
evaluating the outermost body, or rolled back on any uncaught
exception. If rollback is set within scope of the outermost transaction,
the entire transaction will be rolled back rather than committed when
complete."
[func]
(binding [*db* (update-in *db* [:level] inc)]
(if (= (:level *db*) 1)
(let [con (connection*)
auto-commit (.getAutoCommit con)]
(io!
(.setAutoCommit con false)
(try
(func)
(catch BatchUpdateException e
(print-update-counts *err* e)
(print-sql-exception-chain *err* e)
(throw-rollback e))
(catch SQLException e
(print-sql-exception-chain *err* e)
(throw-rollback e))
(catch Exception e
(throw-rollback e))
(finally
(if (rollback)
(.rollback con)
(.commit con))
(rollback false)
(.setAutoCommit con auto-commit)))))
(func))))
Used in 0 other vars
Comments top
No comments for transaction*. Log in to add a comment.