From 4dcae780057df32689e54aee80c87e3c6cb78199 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 29 Nov 2009 01:02:37 +0100 Subject: Add datastore transaction support. --- src/logikorr.clj | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/logikorr.clj b/src/logikorr.clj index d9dfbc6..a8f08e7 100644 --- a/src/logikorr.clj +++ b/src/logikorr.clj @@ -6,6 +6,23 @@ (:import [com.google.appengine.api.datastore DatastoreServiceFactory Entity Query Query$FilterOperator Query$SortDirection KeyFactory EntityNotFoundException Key] [com.google.appengine.api.users UserServiceFactory])) +(defmacro with-ds-transaction [& body] + `(call-with-ds-transaction (fn [] ~@body))) + +(defn call-with-ds-transaction [thunk] + (let [ds (DatastoreServiceFactory/getDatastoreService) + success (atom false) + transaction (.beginTransaction ds) + return-value (atom nil)] + (try (do + (swap! return-value (fn [_] (thunk))) + (.commit transaction) + (swap! success (fn [_] true))) + (finally + (when-not @success + (.rollback transaction)))) + @return-value)) + (defn ds-update "Update the corresponding entity from the supplied map in the data store." [map] -- cgit v1.2.3