summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-11-29 01:02:37 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-11-29 01:02:37 +0100
commit4dcae780057df32689e54aee80c87e3c6cb78199 (patch)
tree098379ad79f3c507969f062e3ae564e05ddb1d06 /src
parent268267c9e45351322ec61800f5b9900d83f40a24 (diff)
Add datastore transaction support.
Diffstat (limited to 'src')
-rw-r--r--src/logikorr.clj17
1 files changed, 17 insertions, 0 deletions
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]