I'm trying to create my own Clojure bindings of the tinkerpop.blueprints library, and I've come across a snag with what appears to be a commit failure. Currently I'm using Neo4j as the graph implementation. Here is the specific function that doesn't work:
(defn remove-from-index!
([index-name elm key]
(remove-from-index!
index-name elm key (property elm key)))
([index-name elm key val]
(let [idx (index index-name)]
(tx
(-> idx
(.remove (name key) val elm)))
idx)))
to be used like this:
(remove-from-index! :users v1 :username)
(remove-from-index! :users v2 :username "foo")
It seems to be working properly, but when I query the index the vertex I tried to remove isn't removed. I tried to break it down piece by piece and determined that it actually was being removed, but as soon as .commit
is called it rolls everything back.
other functions/macros involved:
(defn property
[elm key]
(-> elm (.getProperty (name key))))
(defmacro tx
[& body]
`(try
(let [val# (do ~@body)]
(.commit *g*)
val#)
(catch Exception e#
(println (.getMessage e#))
(.rollback *g*))))
(defn index
([^String nomen]
(index (name nomen) "Vertex"))
([^String nomen ^String type]
(-> *g*
(.getIndex
(name nomen)
(Class/forName (str "com.tinkerpop.blueprints." type))))))