I needed to create an Unmanaged Extension in Neo4j but the prospect of using Java gave me shudders.
I have been programming in Clojure for a little while now. Given that Clojure is a JVM language, I decided to try to write the extension in that. Neo4j uses the JAX-RS API for supporting user supplied code. Luckily O’Reilly’s excellent book on Clojure, Clojure Programming had an example of a JAX-RS class. I love it when a plan comes together.
I modified that code to get what I needed. I hit across two issues:
Neo4j 2.0 documentation stated that a transaction is required only when the graph is being written to. Nope. I’ve highlighted it to them and as ever they’ve quickly fixed it. I was trying to get a node by its ID and I was getting a
NotInTransactionException. Anyway its not needed for this exercise.
Here is my working code (I’ve tried to stay close to the Neo4j provided example; my only deviation being calling another function from the function which directly handles the
So now I have Java, Scala (for Cypher) and Clojure (for my extension) all running in the same JVM.
JVM ftw! Woot!!