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?
> 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?
> 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?
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
> On Nov 30, 2010 6:19 PM, "edoloughlin" <ed.olough...@gmail.com> wrote:
> > 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?