grails and neo4j
DESCRIPTION
Talk given at http://eu.gr8conf.org 2011 regarding integrating Neo4j as a full GORM compliant Datastore for Grails applications.TRANSCRIPT
![Page 1: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/1.jpg)
Grails and Neo4j
Stefan Armbruster
gr8conf CPH, 2011 May 19th
![Page 2: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/2.jpg)
About myself
●located in Munich/Germany●freelancer since 10 years ●cofounder of Netjay●Java +10 years, Groovy ~5 years, Grails 3+ years●author of some Grails plugins●cofounder of the usergroup in Munich●passionate volunteer firefighter●twitter: darthvader42●http://blog.armbruster-it.de
![Page 3: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/3.jpg)
What's wrong with SQL?
What's about the hype of NoSQL?
![Page 4: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/4.jpg)
![Page 5: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/5.jpg)
![Page 6: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/6.jpg)
4 trends
●much larger data sets: ● IDC comparison: 2010 to 2007 is 40 : 1
●data gets more connected●semi-structured data●horizontal scalability – distributed architecture
![Page 7: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/7.jpg)
One size fits all?
![Page 8: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/8.jpg)
exploring the nosql-landscape
Key-Value:Key-Value:➢RIAK *➢Redis *➢Membase
Bigtable:Bigtable:➢Hadoop / Hbase *➢SimpleDB➢Cassandra **
Graph:Graph:➢InfiniteGraph➢Neo4j *
DocumentDocument:➢CouchDB * ➢Mongo *
*: GORM compliant implementation, **: Grails support without GORM
![Page 9: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/9.jpg)
nosql is not the silver bullet
![Page 10: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/10.jpg)
neo4j basic building blocks
1) nodes
2) relationships
3) properties on both, nodes and relationship
that's it!
![Page 11: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/11.jpg)
neo4j
![Page 12: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/12.jpg)
querying neo4j
●simple way: navigate the relationships●more powerful: use a traverser with callbacks for
● decide where to end● decide if node should be part of the result
![Page 13: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/13.jpg)
SQL querying vs traversing
Node node = // retrieve the starting poing
def myFriendsAndFriends = node.traverse( BREADTH_FIRST, { it.depth()<3 } as StopEvaluator, { true } as RetrunableEvaluator, DynamicRelationshipType.withName('friend'), Direction.OUTGOING).allNodes
SQL challenge: SQL statement that retrieves friends up to n'th grade. Anyone?
Neo4j: using a traverser:
![Page 14: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/14.jpg)
query performance
some benchmark data:
– each Person has 50 friends in avg
Database # persons query time
Relational 1.000 2000 ms
Neo4j 1.000 2 ms
Neo4j 1.000.000 2 ms
![Page 15: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/15.jpg)
accessing the database
Choosing an implementation of GraphDatabase:
● EmbeddedGraphDatabase: just local to JVM
● RestGraphDatabase (https://github.com/jexp/neo4j-java-rest-binding)
● HighAvailableGraphDatabase: uses Zookeeper
![Page 16: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/16.jpg)
neo4j - Licensing
3 editions:
community: GPL or $
advanced: AGPL or $
enterprise: AGPL or $
![Page 17: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/17.jpg)
history of nosql & neo4j for Grails
end 2009: first version of neo4j plugin
during 2010: GORM for nosql– 'inconsequential' -> 'spring-data-mapping'
end 2010: 'spring-data-graph'– aspectj based injection of JPA like methods
– focussed at Roo an POWAs
– "not the right approach for Grails" (IMHO)
May 2011: Neo4j for Grails using spring-data-mapping
![Page 18: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/18.jpg)
GORM: spring-data-mapping
●provides abstraction layer●TCK ●various implementations:
● hibernate, jpa● gemfire, redis, riak ● mongo, jcr● neo4j <- the new child on the block
![Page 19: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/19.jpg)
dependencies
![Page 20: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/20.jpg)
interfaces/abstract base classes in GORM
●Datastore:● create sessions● manage connection to low-level storage
●MappingContext:● holds metainformation about mapping domain classes to the underlying
datastore (type conversion, list of EntityPersisters,...)
●EntityPersister:● does the dirty work: interact with low level datastore
●Session:● similar HibernateSession
●Query:● knows how to query the datastore by criteria (criterion, projections,...)
![Page 21: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/21.jpg)
mapping domain model to nodespace
domain class
association
domain classinstance
domain instanceproperty
reference node
subreference
subreference node
instance
properties
![Page 22: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/22.jpg)
praying to the demo god....
![Page 23: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/23.jpg)
currently working in neo4j plugin
●passing >90% of GORM TCK (hurray!)●accessing embedded, REST and [HA datasources]●property type conversion●access to native API●<DomainClass>.traverseStatic, <instance>.traverse
![Page 24: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/24.jpg)
currently not working in neo4j plugin
●nasty bug: some trouble if a domain class references itself -> StackOverflowException
●Transactions●Optimistic Locking●Query performance not as good as could be●Indexing
![Page 25: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/25.jpg)
roadmap
●Write docs & publish●Handle relationship to self (Neo4j 1.4?)●Support for arbitrary attributes●Support for indexing (and its usage in criteria queries)●Embed some controller/servlet to visually navigate
the nodespace (SVG?)●Support for migrations?●... your suggestions?
![Page 26: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/26.jpg)
Q & A
![Page 27: Grails and Neo4j](https://reader034.vdocuments.us/reader034/viewer/2022052307/554f8085b4c905435d8b4987/html5/thumbnails/27.jpg)
References
general overview of nosql:
– http://www.nosql-databases.org/
http://www.neo4j.org
neo4j grails plugin:
– source: https://github.com/sarmbruster/spring-data-mapping
– issues: http://jira.grails.org/browse/GPNEO4J
https://github.com/jexp/neo4j-java-rest-binding
site running grails w/ neo4j: http://www.fanorakel.de
my blog: http://blog.armbruster-it.de,
twitter: darthvader42