Issue #117 sketch of dynamic nested transaction behavior
This commit is contained in:
parent
4342bb76da
commit
7c0cee09bf
1 changed files with 31 additions and 5 deletions
|
|
@ -79,15 +79,41 @@
|
||||||
(.setReadOnly con old-readonly)
|
(.setReadOnly con old-readonly)
|
||||||
(catch Exception _))))))))
|
(catch Exception _))))))))
|
||||||
|
|
||||||
|
(defonce ^:dynamic ^{:doc ""} *nested-tx* :allow)
|
||||||
|
(defonce ^:private ^:dynamic ^{:doc ""} *active-tx* false)
|
||||||
|
|
||||||
(extend-protocol p/Transactable
|
(extend-protocol p/Transactable
|
||||||
java.sql.Connection
|
java.sql.Connection
|
||||||
(-transact [this body-fn opts]
|
(-transact [this body-fn opts]
|
||||||
(locking this
|
(cond (or (not *active-tx*) (= :allow *nested-tx*))
|
||||||
(transact* this body-fn opts)))
|
(locking this
|
||||||
|
(binding [*active-tx* true]
|
||||||
|
(transact* this body-fn opts)))
|
||||||
|
(= :ignore *nested-tx*)
|
||||||
|
(body-fn this)
|
||||||
|
(= :prohibit *nested-tx*)
|
||||||
|
(throw (IllegalStateException. "Nested transactions are prohibited"))
|
||||||
|
:else
|
||||||
|
(throw (IllegalArgumentException.
|
||||||
|
(str "*nested-tx* ("
|
||||||
|
*nested-tx*
|
||||||
|
") was not :allow, :ignore, or :prohibit")))))
|
||||||
javax.sql.DataSource
|
javax.sql.DataSource
|
||||||
(-transact [this body-fn opts]
|
(-transact [this body-fn opts]
|
||||||
(with-open [con (p/get-connection this opts)]
|
(cond (or (not *active-tx*) (= :allow *nested-tx*))
|
||||||
(transact* con body-fn opts)))
|
(binding [*active-tx* true]
|
||||||
|
(with-open [con (p/get-connection this opts)]
|
||||||
|
(transact* con body-fn opts)))
|
||||||
|
(= :ignore *nested-tx*)
|
||||||
|
(with-open [con (p/get-connection this opts)]
|
||||||
|
(body-fn con))
|
||||||
|
(= :prohibit *nested-tx*)
|
||||||
|
(throw (IllegalStateException. "Nested transactions are prohibited"))
|
||||||
|
:else
|
||||||
|
(throw (IllegalArgumentException.
|
||||||
|
(str "*nested-tx* ("
|
||||||
|
*nested-tx*
|
||||||
|
") was not :allow, :ignore, or :prohibit")))))
|
||||||
Object
|
Object
|
||||||
(-transact [this body-fn opts]
|
(-transact [this body-fn opts]
|
||||||
(p/-transact (p/get-datasource this) body-fn opts)))
|
(p/-transact (p/get-datasource this) body-fn opts)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue