Skip to content

Commit

Permalink
Initial transaction support
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Klishin committed Feb 12, 2013
1 parent cc2cfa1 commit 9670317
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Changes between Titanium 1.0.0-alpha1 and 1.0.0-alpha2

### Transaction Control Functions

`clojurewerkz.titanium.graph/commit-tx!` and `clojurewerkz.titanium.graph/rollback-tx!`
commit and roll back current transaction, respectively. Note that closing a
graph will automatically commit current transaction. Every operation
that modifies the graph will automatically start a transaction if needed.


### clojurewerkz.titanium.graph/get-vertices Now Accepts Keywords For Keys

`clojurewerkz.titanium.graph/get-vertices` now accepts keywords for keys,
Expand Down
19 changes: 18 additions & 1 deletion src/clojure/clojurewerkz/titanium/graph.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(ns clojurewerkz.titanium.graph
(:require [clojurewerkz.titanium.elements :as te])
(:import [com.thinkaurelius.titan.core TitanFactory TitanGraph]
[com.tinkerpop.blueprints Graph KeyIndexableGraph Vertex Edge]))
[com.tinkerpop.blueprints Vertex Edge
Graph KeyIndexableGraph
TransactionalGraph TransactionalGraph$Conclusion]))


;;
Expand Down Expand Up @@ -139,3 +141,18 @@
(defn deindex-edges-by-key!
[^KeyIndexableGraph g ^String k]
(.dropKeyIndex g k com.tinkerpop.blueprints.Edge))


;;
;; Transactions
;;

(defn commit-tx!
"Commits current transaction"
[^TransactionalGraph g]
(.stopTransaction g TransactionalGraph$Conclusion/SUCCESS))

(defn rollback-tx!
"Rolls back current transaction"
[^TransactionalGraph g]
(.stopTransaction g TransactionalGraph$Conclusion/FAILURE))
19 changes: 19 additions & 0 deletions test/clojurewerkz/titanium/graph_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,22 @@
m2 {"station" "Northfields" "lines" #{"Piccadilly"}}]
(tg/populate g
(m1 -links-> m2))))


;;
;; Transactions
;;

(deftest test-very-basic-transaction-that-is-committed
(let [g (tg/open-in-memory-graph)
v1 (tg/add-vertex g {})
v2 (tg/add-vertex g {})]
(tg/commit-tx! g)
(tg/close g)))

(deftest test-very-basic-transaction-that-is-rolled-back
(let [g (tg/open (System/getProperty "java.io.tmpdir"))
v1 (tg/add-vertex g {})
v2 (tg/add-vertex g {})]
(tg/rollback-tx! g)
(tg/close g)))

0 comments on commit 9670317

Please sign in to comment.