Grails and Neo4j
The document discusses using Neo4j, a graph database, with Grails. It covers trends in large, connected, semi-structured data driving NoSQL adoption. Neo4j uses nodes connected by relationships with properties to model data. Queries traverse relationships rather than using SQL. The neo4j Grails plugin uses Spring Data to provide a GORM-like interface to Neo4j, passing most tests while transactions and indexing require more work. The roadmap includes documentation, relationship handling, and visual navigation of the nodespace.
2. 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
6. 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
●
12. 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
13. SQL querying vs traversing
SQL challenge: SQL statement that retrieves friends
up to n'th grade. Anyone?
Neo4j: using a traverser:
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
14. 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
15. 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
16. neo4j - Licensing
3 editions:
community: GPL or $
advanced: AGPL or $
enterprise: AGPL or $
17. 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
20. 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,...)
21. mapping domain model to nodespace
reference node
domain class
subreference
subreference node
domain class instance
instance
domain instance
properties
property
association
23. 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
●
24. 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
●
25. 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?