1.2.0 permalink Arrow_down_16x16
  • (transaction* func)
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.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/sql/internal.clj:144 top

(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))))
Vars in clojure.contrib.sql.internal/transaction*: *err* = binding defn io! let
Used in 0 other vars

Comments top

No comments for transaction*. Log in to add a comment.