Rapid development with Neo4J
         under Grails
About Myself
•   Stanislav Shevchenko
•   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                Disk Data
           Model                    Structure
types

 Document store
        Graph
  Key-value store
Multivalue databases
 Object database
       Tabular
     Tuple store
hard to integrate in industrialized
            companies
Grails Support
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                             +
Graph DB implemetations
                      Language
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 JVM
2. RestGraphDatabase: rest-binding
3. 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        Service        Domain

                    Plug-in




                                              Gant
                                   GORM

   Site Mesh        Spring        Hibernate

                                     DB

         Java EE                Groovy

                     JVM
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:staff
                                     type:weapon
name:Splinter
fullName:Hamato Yoshi
type: rat


                                       type: interact




                        type:knows

                                     name:Shredder
                                     fullName:Oroku Saki
Nodes
Relationships
Properties
                                              name:staff
                                              type:weapon
name:Splinter
fullName:Hamato Yoshi
type: rat


                                                type: interact




                        type:knows
Mapping
                      Reference Node

                                  Subreference
Domain Class/Type
                                                 SubreferenceNode

  Domain Class        Instance
    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 neo4j
grails 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 Configuration
grails-app/conf/DataSource.groovy

       grails {
         neo4j {
            type = "embedded"
            location = "/var/neo4j"
            params = []
         }
       }
Via REST
type = "rest”

grails {
  neo4j {
     type = "rest"
     location = "http://localhost:7474/db/data/"
  }
}
High Availabile
type = "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:sql
   http://nosql-database.org/
neo4j
   http://neo4j.org
grails-neo4j plug-in
  http://jira.grails.org/browse/GPNEO4J
  http://springsource.github.com/grails-data-
  mapping/neo4j/manual/guide/index.html
Questions




Q are guaranteed in life – answers aren’t.

Neo4 + Grails

  • 1.
    Rapid development withNeo4J under Grails
  • 2.
    About Myself • Stanislav Shevchenko • Located in Riga/Latvia • Technical Architect in Accenture • Experience since 10 years • C#/Java/Groovy/Scala/Erlang
  • 3.
    no:sql Market has significantlydifferent challenges in dealing with data that the traditional RDBMS solutions could not cope with.
  • 4.
    Issues • size data sets • data relations are connected • distributed processing • Data Model -> semi-structured approach
  • 5.
    brings to diversityof solutions Data Model Distribution Disk Data Model Structure
  • 6.
    types Document store Graph Key-value store Multivalue databases Object database Tabular Tuple store
  • 7.
    hard to integratein industrialized companies
  • 8.
    Grails Support 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 +
  • 9.
    Graph DB implemetations Language DEX C++ FlockDB Scala InfiniteGraph Java HyperGraphDB Java Neo4J Java OpenLink Virtuoso C++, C#, Java, SPARQL OrientDB Java Sones GraphDB C#
  • 10.
    Graph on(in) Grails Neo4jis (as of now) the only graph database that fits nicely in a Grails application.
  • 11.
  • 12.
    Why Graph DB? InsufficientRDBMS 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.
  • 13.
    SQL addons Some DBshas 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
  • 14.
    Where Graph DB • Network Management • Master Data Management • Social • Finance • Spatial – Map Routing • Bio
  • 15.
    Why Neo4J? • true ACID transactions • high availability • scales to billions of nodes and relationships • high speed querying through traversals • well documented • Java • licenses
  • 16.
    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
  • 17.
    Access & ImplementationTypes 1. EmbeddedGraphDatabase: just to local JVM 2. RestGraphDatabase: rest-binding 3. HighAvaibleGraphDatabase: uses Zookeeper
  • 18.
    When Grails shines Rubyplatform isn’t a case, Java is too expensive, Scala is too smart. Startups & prototypes Model-driven architecture where GORM is fundament.
  • 19.
    Groovy & GrailsArchitecture Controller View GSP Service Domain Plug-in Gant GORM Site Mesh Spring Hibernate DB Java EE Groovy JVM
  • 20.
    GORM Abstraction on abstractions,wraps: – Hibernate – JPA – Gemfire, Redis, Riak – MongoDB, JCR – Neo4J Integration testing via TCK
  • 21.
  • 22.
    Plugin features • Neo4j-> Groovy/Java • GORM dynamic finders, criteria and named queries • Session-managed transactions • Bean Validation • Neo4j's traversal • Embedded, REST and HA
  • 23.
    Jump into Neo4J name:staff type:weapon name:Splinter fullName:Hamato Yoshi type: rat type: interact type:knows name:Shredder fullName:Oroku Saki
  • 24.
  • 25.
  • 26.
    Properties name:staff type:weapon name:Splinter fullName:Hamato Yoshi type: rat type: interact type:knows
  • 27.
    Mapping Reference Node Subreference Domain Class/Type SubreferenceNode Domain Class Instance Instance Domain Class Properties Instance Properties Assocoation
  • 28.
    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)
  • 29.
    Getting Started grails install-pluginneo4j grails uninstall-plugin hibernate
  • 30.
  • 31.
  • 32.
    Combining Neo4j AndHibernate static mapWith = "neo4j” def hibernateHero = Hero.get(1) hibernateHero.neo4j.save() def neo4jHero = Person.neo4j.get(1)
  • 33.
    Advanced Configuration grails-app/conf/DataSource.groovy grails { neo4j { type = "embedded" location = "/var/neo4j" params = [] } }
  • 34.
    Via REST type ="rest” grails { neo4j { type = "rest" location = "http://localhost:7474/db/data/" } }
  • 35.
    High Availabile type ="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' ] } }
  • 36.
    References no:sql http://nosql-database.org/ neo4j http://neo4j.org grails-neo4j plug-in http://jira.grails.org/browse/GPNEO4J http://springsource.github.com/grails-data- mapping/neo4j/manual/guide/index.html
  • 37.
    Questions Q are guaranteedin life – answers aren’t.