Neo4J and Grails

37
Rapid development with Neo4J under Grails

Transcript of Neo4J and Grails

Page 1: Neo4J and Grails

Rapid development with Neo4J under Grails

Page 2: Neo4J and Grails

About Myself

• Located in Riga/Latvia• Technical Architect in Accenture• Experience since 10 years• C#/Java/Groovy/Scala/Erlang

Page 3: Neo4J and Grails

no:sql

Market has significantly different challenges in dealing with data that the traditional RDBMS solutions could not cope with.

Page 4: Neo4J and Grails

Issues

• size data sets• data relations are connected• distributed processing• Data Model -> semi-structured approach

Page 5: Neo4J and Grails

brings to diversity of solutions

Data Model

Distribution Model

Disk Data Structure

Page 6: Neo4J and Grails

types

Document storeGraph

Key-value storeMultivalue databases

Object databaseTabular

Tuple store

Page 7: Neo4J and Grails

hard to integrate in industrialized companies

Page 8: Neo4J and Grails

Name Type

RIAK Eventually consistent key value‐ ‐ +

REDIS Key-value cache in RAM +

MemcacheDB Ordered key-value stores +-

Apache CouchDB Document store +

MongoDB Document store +

Apache Hadoop Tabular/Big Table +

Apache Cassandra Eventually consistent key value‐ ‐ +

Neo4J Graph +

Grails Support

Page 9: Neo4J and Grails

Graph DB implemetationsLanguage

DEX C++

FlockDB Scala

InfiniteGraph Java

HyperGraphDB Java

Neo4J Java

OpenLink Virtuoso C++, C#, Java, SPARQL

OrientDB Java

Sones GraphDB C#

Page 10: Neo4J and Grails

Graph on(in) Grails

Neo4j is (as of now) the only graph database that fits nicely in a Grails application.

Page 11: Neo4J and Grails

Data is connected

Page 12: Neo4J and Grails

Why Graph DB?

Insufficient RDBMS performance in hierarchical structures. The graph database storage shines when storing richly-connected data. Querying is performed through traversals, which can perform millions of traversal steps per second. A traversal step resembles a join in a RDBMS.

Page 13: Neo4J and Grails

SQL addons

Some DBs has even special DSL:SELECT empno, ename, job, mgr, hiredate, LEVEL FROM emp WHERE LEVEL <= 2 START WITH mgr IS NULL CONNECT BY PRIOR empno = mgr

Page 14: Neo4J and Grails

Where Graph DB

• Network Management• Master Data Management• Social• Finance• Spatial– Map Routing

• Bio

Page 15: Neo4J and Grails

Why Neo4J?

• true ACID transactions• high availability• scales to billions of nodes and relationships• high speed querying through traversals• well documented• Java• licenses

Page 16: Neo4J and Grails

Why neo4j - details

• Disk ready– Native graph storage engine with custom (SSD-

ready) binary on-disk format• Transactional– JTA/JTS, XA, 2PC, Tx Recovery, deadlock detection

…• Scalable– Billions of nodes on single JVM

Page 17: Neo4J and Grails

Access & Implementation Types

1. EmbeddedGraphDatabase: just to local JVM2. RestGraphDatabase: rest-binding3. HighAvaibleGraphDatabase: uses Zookeeper

Page 18: Neo4J and Grails

When Grails shines

Ruby platform isn’t a case, Java is too expensive, Scala is too smart.

Startups & prototypes

Model-driven architecture where GORM is fundament.

Page 19: Neo4J and Grails

Groovy & Grails Architecture

Controller

View GSP

Plug-in

Service Domain

SpringSite Mesh

GORM

Hibernate

DB

Java EE Groovy

JVM

Gan

t

Page 20: Neo4J and Grails

GORM

Abstraction on abstractions, wraps:– Hibernate– JPA– Gemfire, Redis, Riak– MongoDB, JCR– Neo4J

Integration testing via TCK

Page 21: Neo4J and Grails

Neo4j plug-in

Page 22: Neo4J and Grails

Plugin features

• Neo4j -> Groovy/Java• GORM dynamic finders, criteria and named

queries• Session-managed transactions• Bean Validation• Neo4j's traversal• Embedded, REST and HA

Page 23: Neo4J and Grails

Jump into Neo4J

name:SplinterfullName:Hamato Yoshitype: rat

name:stafftype:weapon

name:ShredderfullName:Oroku Saki

type: interact

type:knows

Page 24: Neo4J and Grails

Nodes

Page 25: Neo4J and Grails

Relationships

Page 26: Neo4J and Grails

Properties

name:SplinterfullName:Hamato Yoshitype: rat

name:stafftype:weapon

type: interact

type:knows

Page 27: Neo4J and Grails

Mapping

Domain Class/Type

Reference Node

Subreference

SubreferenceNode

InstanceDomain Class Instance

Domain Class Properties

Instance Properties

Assocoation

Page 28: Neo4J and Grails

Compatibility with GORM✔ ✗

Simple persistence methods HQL queries

Dynamic finders Dirty checking methods

Criteria queries Composite primary keys

Named queries Any direct interaction with the Hibernate API

Inheritance Custom Hibernate user types

Embedded types

Query by example

Many-to-many associations (these can be modelled with a mapping class)

Page 29: Neo4J and Grails

Getting Started

grails install-plugin neo4jgrails uninstall-plugin hibernate

Page 30: Neo4J and Grails

Create Domain

grails create-domain-class Hero

Page 31: Neo4J and Grails

Examples

hero.save()

Hero.findByWeightGreaterThan( 100 )Hero.findAllByFullNameNotNull()

hero.weapons.each {…

}

Page 32: Neo4J and Grails

Combining Neo4j And Hibernate

static mapWith = "neo4j”

def hibernateHero = Hero.get(1)hibernateHero.neo4j.save()def neo4jHero = Person.neo4j.get(1)

Page 33: Neo4J and Grails

Advanced Configurationgrails-app/conf/DataSource.groovy

grails { neo4j { type = "embedded" location = "/var/neo4j" params = [] }}

Page 34: Neo4J and Grails

Via RESTtype = "rest”

grails { neo4j { type = "rest" location = "http://localhost:7474/db/data/" }}

Page 35: Neo4J and Grails

High Availabiletype = "ha”

grails { neo4j { type = "ha" location = "/var/neo4j" params = [ // see http://docs.neo4j.org/chunked/stable/ha-configuration.html

'ha.server_id': 1, 'ha.coordinators': 'localhost:2181,localhost:2182,localhost:2183' ] }}

Page 36: Neo4J and Grails

References

no:sqlhttp://nosql-database.org/

neo4jhttp://neo4j.org

grails-neo4j plug-inhttp://jira.grails.org/browse/GPNEO4Jhttp://springsource.github.com/grails-data-mapping/neo4j/manual/guide/index.html

Page 37: Neo4J and Grails

Questions

Q are guaranteed in life – answers aren’t.