Sunday, December 7, 2008

Groovy does Neo4J thanks to Maven Simplicity

Guillaume Laforge, Groovy Project Manager, kicked off a debate on the Neo4J mailing list with his post Groovy and Neo4J. He stated some examples of how Neo4J could be more Groovy. However, since most Neo4J developers aren't familiar with Groovy, the topic wasen't tested out further.

Therefore, with of my L337 skillz in Groovy, Neo4J and Maven, I saw it my destiny to create a simple Neo4J test in a Groovy environment to validate Guillaume's propositions. Along the way, I had to add some GMaven magic, embedded Neo4J, Mercurial version control and Maven Archetype for distribution. No wonder why I didn't get this out the door yesterday! ;)

The Proposition


firstNode.setProperty( "message", "Hello, " );
Groovy handles the setProperty/getProperty methods in a particular fashion, and without doing anything special, you should be able to directly use this nicer syntax in Groovy:
firstNode.message = "Hello"
...
Combining everything:
[
[name: "Neo"],
[KNOWS: [since: someDate],
[name: "Trinity"]
]

The Result


Setting up the demo takes less than 1 min!!! No unzip and stuff, and you get both a Java and Groovy version of the code. (You need Maven installed, and the time for automatically downloading from the toobs.) However, the proposed handling of properties did not work directly. Possibly due to not implementing the right interface (?) The more advanced example is a little harder to get around, so I just dropped it :)
The conclusion: Groovy just might have a nice syntax for writing the data-entries. However, I didn't get it up and running as proposed, and therefore I am quite happy with getting a demo up and running on Groovy, and am passing the task of making the proposition work to Guillaume and the Neo4J team.
More on Maven Archetype soon to come.

Instructions


Downloading and setting up the code


mvn archetype:generate -DgroupId=org.neo4j -DartifactId=neo4j-groovy-test -DarchetypeArtifactId=helloworld-test -DarchetypeGroupId=no.lau.neo4j -DarchetypeVersion=0.1 -DarchetypeRepository=http://ultimate-roundtrip.googlecode.com/svn/trunk/maven-repository
cd neo4j-groovy-test

Testing


mvn test
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
[Parser] Running:
Command line suiteRunning Groovy tests
Thomas Andersson's friends:
At depth 1 => Trinity
At depth 1 => Morpheus
At depth 2 => Cypher
At depth 3 => Agent Smith
Finding hackers
Hackers:
At depth 4 => The Architect
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.111 sec
gmaven-console1

Smacking up a quick IDE for running the code and testing


mvn groovy:console

3 comments:

  1. Nice Stig! You should cross-post this to the mailing list aswell! :)

    ReplyDelete
  2. Writing code demoes, blogs, twatters and mailing list responses takes a lot of time. But at last I feel updated and offloaded. Thanx for the interest in the subject!

    ReplyDelete
  3. Cool, great prototyping work, thanks for the effort!

    /peter

    ReplyDelete

Spam will be pruned