Transactions in c.c.sql functions

5 views
Skip to first unread message

Shantanu Kumar

unread,
Aug 13, 2010, 5:23:25 PM8/13/10
to Clojure
Hi,

While going through the clojure.contrib.sql sources I noticed at
several places that a new transaction is started to execute the
operation under. Case at hand: do-commands, do-prepared, update-or-
insert-values.

As far I understand, transactions belong to the user. The user should
decide what to execute under which transaction. By beginning
transaction inside these functions, is it assumed that the user can
wrap bigger constructs under her own transactions and that the JDBC
driver would support nested transactions?

Cheers,
Shantanu

Saul Hazledine

unread,
Aug 14, 2010, 12:47:55 PM8/14/10
to Clojure
On Aug 13, 11:23 pm, Shantanu Kumar <kumar.shant...@gmail.com> wrote:
>
> As far I understand, transactions belong to the user. The user should
> decide what to execute under which transaction. By beginning
> transaction inside these functions, is it assumed that the user can
> wrap bigger constructs under her own transactions and that the JDBC
> driver would support nested transactions?

I'm unsure of why clojure.contrib.sql does start transactions without
documenting them but it is a lot smarter than it first appears. My
understanding is that JDBC relies on the underlying database to
support nested transactions. However, clojure.contrib.sql supports
nested transactions on all databases by keeping a count of the level
of nesting and only executing a database transaction at the outer
level.

http://github.com/richhickey/clojure-contrib/blob/6a0483d9e216ca00fc648a4b3673996b76a2785a/src/main/clojure/clojure/contrib/sql/internal.clj#L144

I don't know if this is an ideal thing to do but my own modest, not
mission critical, use of it has not run into any problems.

Saul
Reply all
Reply to author
Forward
0 new messages