Re: support for nested transactions

Aleksandar Bakic <a_bakic-/[email protected]> Sat, 15 Apr 2006 09:55:57 -0700 (PDT)
Newsgroups gmane.lisp.clsql.devel
Message-ID <[email protected]>
Hi,

> I'll package the diff up, but I'm wondering how others are using CLSQL
> transactions.  What kinda patch you want?  Should I just set up a cvs
> working copy?

Here are two macros that I've been using, FWIW.

(defmacro with-nested-transaction (args &body body)
  (with-unique-names (%body)
    `(flet ((,%body () ,@body))
       (if (in-transaction-p ,@args) ; assuming no side-effects in args
           (,%body)
           (with-transaction ,args
             (,%body))))))

(defmacro with-transaction-status
    ((&key (database '*default-database*) status-var (max-retries 3))
     &rest body)
  (with-unique-names (attempt result)
    (if status-var
        `(loop initially (setf ,status-var nil)
            for ,attempt upto ,max-retries
            until ,status-var
            for ,result = (with-transaction (:database ,database) ; WARNING
                            (add-transaction-commit-hook
                             #'(lambda () (setf ,status-var t)))
                            (add-transaction-rollback-hook
                             #'(lambda () (setf ,status-var nil)))
                            ,@body)
            finally (return ,result))
        `(with-transaction (:database ,database) ,@body))))

Alex

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com