Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn begin
- "Begin, invoke, commit, rollback if error"
- [func]
- (binding [clojure.java.jdbc/xa-transaction* (fn [f] (f))]
- (.begin manager)
- (try
- (let [result (func)]
- (.commit manager)
- result)
- (catch Throwable e
- (.rollback manager)
- (throw e)))))
- (defn suspend
- "Suspend, invoke, resume"
- [func]
- (let [tx (.suspend manager)]
- (try
- (func)
- (finally
- (.resume manager tx)))))
- (defmacro required
- "JEE Required"
- [& body]
- (let [f `(fn [] ~@body)]
- `(if (active?)
- (~f)
- (begin ~f))))
- (defmacro requires-new
- "JEE RequiresNew"
- [& body]
- (let [f `(fn [] ~@body)]
- `(if (active?)
- (suspend #(begin ~f))
- (begin ~f))))
- (defmacro mandatory
- "JEE Mandatory"
- [& body]
- (let [f `(fn [] ~@body)]
- `(if (active?)
- (~f)
- (throw (Exception. "No active transaction")))))
- (defmacro not-supported
- "JEE NotSupported"
- [& body]
- (let [f `(fn [] ~@body)]
- `(if (active?)
- (suspend ~f)
- (~f))))
- (defmacro supports
- "JEE Supports (kinda silly)"
- [& body]
- (let [f `(fn [] ~@body)]
- `(~f)))
- (defmacro never
- "JEE Never"
- [& body]
- (let [f `(fn [] ~@body)]
- `(if (active?)
- (throw (Exception. "Active transaction detected"))
- (~f))))
Add Comment
Please, Sign In to add comment