Rolling back transactions

13 views
Skip to first unread message

edoloughlin

unread,
Nov 30, 2010, 6:19:53 PM11/30/10
to clj-record-dev
Hi all,

I'm trying to use clj-record.core/transaction to rollback based on
some logic.

I don't want to throw exceptions directly, as I'm using ring and it
works nicely with clojure.contrib.condition/raise. However, a clj-
record transaction seems to ignore this and my transacitons don't get
rolled back. If I use (clojure.contrib.sql/set-rollback-only) then my
transaction does get rolled back but I get an ugly exception thrown:

java.lang.Exception: transaction rolled back: null
at clojure.contrib.sql.internal$throw_rollback.invoke(internal.clj:
142)
at clojure.contrib.sql.internal$transaction_STAR_.invoke(internal.clj:
169)
[... my code]

Any advice as to how I might cleanly roll back without mixing Java
exceptions and clojure.contrib.condition's?

Thanks,
Ed O'Loughlin

Shantanu Kumar

unread,
Dec 1, 2010, 9:43:51 AM12/1/10
to clj-record-dev

John D. Hume

unread,
Dec 1, 2010, 11:07:11 AM12/1/10
to clj-rec...@googlegroups.com

I don't have any suggestions off-hand, but do let the list know if you see a change that could be made to clj-record that would make this cleaner.

-- typed with my thumbs

edoloughlin

unread,
Dec 30, 2010, 4:05:58 PM12/30/10
to clj-record-dev
I implemented something similar to contrib.sql/transaction and
contrib.sql/set-rollback to cause a condition to be raised. The code's
at https://gist.github.com/760295

Call rollback-with-raise within a transaction body to cause a
condition to be raised with a specific error code. I haven't included
my.util.error/raise-with-message as it does some error text lookup
specific to my app but it's simple to implement.

On Dec 1, 4:07 pm, "John D. Hume" <duelin.mark...@gmail.com> wrote:
> I don't have any suggestions off-hand, but do let the list know if you see a
> change that could be made to clj-record that would make this cleaner.
>
> -- typed with my thumbs
Reply all
Reply to author
Forward
0 new messages