I've also had the need for determining the state of a transaction. Previously, I'd defined a local WITH-TRANSACTION macro that bound a special variable *TRANSACTION* with the transaction in progress.
I have attached a patch that does just that. WITHIN-TRANSACTION-P
will return T if a transaction is open. I've not exported
*TRANSACTION* because I'm unsure whether this should be part of the
public interface. I'm yet to come up with a less hands-on approach to
nested transactions, but this allows options for experiments outside
of the postmodern proper.
For example, my ENSURE-TRANSACTION macro. Really, I should be using
savepoints, but this allows me some more flexibility in how I layer my
database access methods. I'm not sure if this is appropriate, but if
you think it is useful enough, I can prepare a patch to include this
as well.
(defmacro ensure-transaction ((&optional name) &body body)
`(flet ((exec-body ()
(let ,(if name `((,name postmodern::*transaction*)))
,@body)))
(if (within-transaction-p)
(exec-body)
(with-transaction (,name)
(exec-body)))))
--
Daniel White
add-function_-within_transaction_p_-to-determine-if-a-transaction-is-open.dpatch
Description: Binary data
_______________________________________________ postmodern-devel mailing list [email protected] http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
