Hi Sean,

I think there are two ways to do this;

1) Use an agent. You can "send-off" a fn to the agent with your
select/update logic and this will run within the agent thread -
guaranteed to be serial so you only need your select/update and no
retry logic. The state of the agent is not important - you could just
keep some useful info from each call, or maybe the db connection. Just
remember to return that as the last item of your fn. You also need to
have an appropriate error handler - see (doc agent). Note also that
the error handling for agents has changed for clojure 1.2.

2.) Use a traditional db transaction - select ... for update, commit
or roll-back and try again. You could use clojure.contrib.sql or there
are a few other clojure sql libraries available. I personally just use
java interop with jdbc directly.

Don't use refs or atoms as they are not suited to fn's that perform
side-effects - because they could and will be executed more than once
(even if the side-effect is the last step). They are for use with
shared access to in-memory immutable structures.

-Hth, Adrian.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to