Skip to content

Commit

Permalink
Remove executing forms from top-level to fix [IMMUTANT-553]
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrossley3 committed Apr 10, 2015
1 parent 68cdb88 commit 1b8b8f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions docs/guides/transactions.md
Expand Up @@ -28,12 +28,12 @@ single component of an XA transaction fails, all of them rollback.
## Defining a transaction

If you're familiar with [JTA], we make a `TransactionManager`
available via the [[manager]] var, and everything else provided by the
library is mostly a syntactic sugary glaze slathered on that instance.
For example, the [[transaction]] macro will query the manager to see
if a transaction is active. If so, it'll simply invoke its body.
Otherwise, it'll start a new transaction, execute its body, and commit
the transaction unless either an exception is caught or
available via the [[manager]] function, and everything else provided
by the library is mostly a syntactic sugary glaze slathered on that
instance. For example, the [[transaction]] macro will query the
manager to see if a transaction is active. If so, it'll simply invoke
its body. Otherwise, it'll start a new transaction, execute its body,
and commit the transaction unless either an exception is caught or
[[set-rollback-only]] is called, in which case the transaction is
rolled back. Either way, it relies on the transactional components
within the body to automatically enlist themselves as XA resources.
Expand Down
16 changes: 8 additions & 8 deletions transactions/src/immutant/transactions.clj
Expand Up @@ -17,12 +17,12 @@
(:import [org.projectodd.wunderboss WunderBoss]
[org.projectodd.wunderboss.transactions Transaction]))

(def ^:no-doc ^Transaction tx (WunderBoss/findOrCreateComponent Transaction))
(def ^:no-doc ^Transaction tx (memoize #(WunderBoss/findOrCreateComponent Transaction)))

(def
^{:doc "The JTA TransactionManager"
:tag javax.transaction.TransactionManager}
manager (.manager tx))
(defn ^javax.transaction.TransactionManager manager
"The JTA TransactionManager"
[]
(.manager (tx)))

(defmacro transaction
"Execute body within current transaction, if any, otherwise start a
Expand All @@ -34,20 +34,20 @@
the [[immutant.transactions.scope/required]] transaction scope."
[& body]
(let [f `(fn [] ~@body)]
`(.required tx ~f)))
`(.required (tx) ~f)))

(defn set-rollback-only
"Modify the current transaction such that the only possible outcome
is a rollback; useful when rollback is desired but an exception is
not"
[]
(.setRollbackOnly manager))
(.setRollbackOnly (manager)))

(defn enlist
"Enlist a valid XAResource as a participant in the current
transaction. Not required for Immutant resources, i.e. messaging and
caching, as they will be enlisted automatically."
[^javax.transaction.xa.XAResource resource]
(-> manager
(-> (manager)
.getTransaction
(.enlistResource resource)))
12 changes: 6 additions & 6 deletions transactions/src/immutant/transactions/scope.clj
Expand Up @@ -22,39 +22,39 @@
otherwise run body in a new one"
[& body]
(let [f `(fn [] ~@body)]
`(.required tx ~f)))
`(.required (tx) ~f)))

(defmacro requires-new
"JEE RequiresNew - suspend current transaction, if any, and execute
body in a new one"
[& body]
(let [f `(fn [] ~@body)]
`(.requiresNew tx ~f)))
`(.requiresNew (tx) ~f)))

(defmacro not-supported
"JEE NotSupported - suspend current transaction, if any, and run
body without a transaction"
[& body]
(let [f `(fn [] ~@body)]
`(.notSupported tx ~f)))
`(.notSupported (tx) ~f)))

(defmacro supports
"JEE Supports - run body regardless of current transaction
state (unpredictable)"
[& body]
(let [f `(fn [] ~@body)]
`(.supports tx ~f)))
`(.supports (tx) ~f)))

(defmacro mandatory
"JEE Mandatory - throws an exception unless there's an active
transaction in which body will be run"
[& body]
(let [f `(fn [] ~@body)]
`(.mandatory tx ~f)))
`(.mandatory (tx) ~f)))

(defmacro never
"JEE Never - throws an exception if there's an active transaction,
otherwise runs body"
[& body]
(let [f `(fn [] ~@body)]
`(.never tx ~f)))
`(.never (tx) ~f)))

0 comments on commit 1b8b8f4

Please sign in to comment.