Neo4J and Grails

Post on 10-May-2015

3.605 views 1 download

Transcript of Neo4J and Grails

Rapid development with Neo4J under Grails

About Myself

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

no:sql

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

Issues

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

brings to diversity of solutions

Data Model

Distribution Model

Disk Data Structure

types

Document storeGraph

Key-value storeMultivalue databases

Object databaseTabular

Tuple store

hard to integrate in industrialized companies

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

Graph DB implemetationsLanguage

DEX C++

FlockDB Scala

InfiniteGraph Java

HyperGraphDB Java

Neo4J Java

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

OrientDB Java

Sones GraphDB C#

Graph on(in) Grails

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

Data is connected

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.

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

Where Graph DB

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

• Bio

Why Neo4J?

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

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

Access & Implementation Types

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

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.

Groovy & Grails Architecture

Controller

View GSP

Plug-in

Service Domain

SpringSite Mesh

GORM

Hibernate

DB

Java EE Groovy

JVM

Gan

t

GORM

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

Integration testing via TCK

Neo4j plug-in

Plugin features

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

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

Jump into Neo4J

name:SplinterfullName:Hamato Yoshitype: rat

name:stafftype:weapon

name:ShredderfullName:Oroku Saki

type: interact

type:knows

Nodes

Relationships

Properties

name:SplinterfullName:Hamato Yoshitype: rat

name:stafftype:weapon

type: interact

type:knows

Mapping

Domain Class/Type

Reference Node

Subreference

SubreferenceNode

InstanceDomain Class Instance

Domain Class Properties

Instance Properties

Assocoation

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)

Getting Started

grails install-plugin neo4jgrails uninstall-plugin hibernate

Create Domain

grails create-domain-class Hero

Examples

hero.save()

Hero.findByWeightGreaterThan( 100 )Hero.findAllByFullNameNotNull()

hero.weapons.each {…

}

Combining Neo4j And Hibernate

static mapWith = "neo4j”

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

Advanced Configurationgrails-app/conf/DataSource.groovy

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

Via RESTtype = "rest”

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

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' ] }}

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

Questions

Q are guaranteed in life – answers aren’t.