Today I released the first version of the Neo4j Grails plugin. The plugin’s goal is to provide an alternative approach for storing Grails domain classes: in the Neo4j database.
Neo4j is a relative new and very interesting approach for persitence in a non-SQLish way. Neo4j is a graph database and uses the concept of
A node is the basic building block. It normally represents a “something”, a entity.
Relationsships are associations between nodes. Each relationship connects exactly two nodes. Relationsships have a direction: incoming, outgoing or both.
Each node or relationship might contain a set of properties. A property has a name (String) and a value (primitive datatype). Complex value are not allowed for properties.
This is completely different from the SQL approach. There are no tables, columns, indexes, and other stuff we’ve dealt with for years. Somewhat crucial is the way how to organize the node space. Neo4j gives some advice here.
How the plugin works
Using Groovy’s metaprogramming capabilities, the basic CRUD-methods list, save, get and delete are added transparently to each domain class. In addition, each domain instance gets a ‘node’ property referencing the associated Neo4j Node.
For each domain class a subreference node is created related to the reference aka root node. Each domain instance holds a relation to it’s subreference node. For non-primitive properties, either relations to other domain nodes are used or they are converted to strings using the Spring’s PropertyEditor approach.
Aside from this, the plugin starts up and closes the Neo4j database. The database’s path is configured using the grails.neo4j.storeDir property in Config.groovy.
Howto use the plugin
The plugin can be used transparently in a Grails application. The only thing you have to do is to remove the hibernate plugin and install the neo4j plugin:
grails uninstall-plugin hibernate grails install-plugin neo4j
Add some domain classes and controllers with scaffolding – they should work.
What currently works
- basic CRUD operations on domain classes
- one-to-one, one-to-many, many-to-one and many-to-many relations of domain classes
- the current implementation supports scaffolding
- Together with the acegi plugin, you can store your user, role and requestmap information in neo4j. Since the default UserDetailsService relies on Hibernate’s SessionFactory you have to use a custom UserDetailsService to get this working.
What’s still missing (and hopefully will be added in upcoming releases)
- currently all constraints are ignored
- only a subset of the domain methods are implemented
- dynamic finders have only a very basic support: just DomainClass.findBy[Property](value) works so far
New planned features
- SVG controller/views to display the complete object graph, just like Neoclipse does.
- Gant scripts for automatically snapshotting and restoring the database
- Criteria queries implemented using Neo4j traversers
Any feedback is appreciated.