Neo4 + Grails
-
Upload
stasimus -
Category
Technology
-
view
1.047 -
download
1
Transcript of Neo4 + Grails
![Page 1: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/1.jpg)
Rapid development with Neo4J under Grails
![Page 2: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/2.jpg)
About Myself
• Stanislav Shevchenko• Located in Riga/Latvia• Technical Architect in Accenture• Experience since 10 years• C#/Java/Groovy/Scala/Erlang
![Page 3: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/3.jpg)
no:sql
Market has significantly different challenges in dealing with data that the traditional RDBMS solutions could not cope with.
![Page 4: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/4.jpg)
Issues
• size data sets• data relations are connected• distributed processing• Data Model -> semi-structured approach
![Page 5: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/5.jpg)
brings to diversity of solutions
Data Model
Distribution Model
Disk Data Structure
![Page 6: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/6.jpg)
types
Document storeGraph
Key-value storeMultivalue databases
Object databaseTabular
Tuple store
![Page 7: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/7.jpg)
hard to integrate in industrialized companies
![Page 8: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/8.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/9.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/10.jpg)
Graph on(in) Grails
Neo4j is (as of now) the only graph database that fits nicely in a Grails application.
![Page 11: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/11.jpg)
Data is connected
![Page 12: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/12.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/13.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/14.jpg)
Where Graph DB
• Network Management• Master Data Management• Social• Finance• Spatial– Map Routing
• Bio
![Page 15: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/15.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/16.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/17.jpg)
Access & Implementation Types
1. EmbeddedGraphDatabase: just to local JVM2. RestGraphDatabase: rest-binding3. HighAvaibleGraphDatabase: uses Zookeeper
![Page 18: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/18.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/19.jpg)
Groovy & Grails Architecture
Controller
View GSP
Plug-in
Service Domain
SpringSite Mesh
GORM
Hibernate
DB
Java EE Groovy
JVM
Gan
t
![Page 20: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/20.jpg)
GORM
Abstraction on abstractions, wraps:– Hibernate– JPA– Gemfire, Redis, Riak– MongoDB, JCR– Neo4J
Integration testing via TCK
![Page 21: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/21.jpg)
Neo4j plug-in
![Page 22: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/22.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/23.jpg)
Jump into Neo4J
name:SplinterfullName:Hamato Yoshitype: rat
name:stafftype:weapon
name:ShredderfullName:Oroku Saki
type: interact
type:knows
![Page 24: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/24.jpg)
Nodes
![Page 25: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/25.jpg)
Relationships
![Page 26: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/26.jpg)
Properties
name:SplinterfullName:Hamato Yoshitype: rat
name:stafftype:weapon
type: interact
type:knows
![Page 27: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/27.jpg)
Mapping
Domain Class/Type
Reference Node
Subreference
SubreferenceNode
InstanceDomain Class Instance
Domain Class Properties
Instance Properties
Assocoation
![Page 28: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/28.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/29.jpg)
Getting Started
grails install-plugin neo4jgrails uninstall-plugin hibernate
![Page 30: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/30.jpg)
Create Domain
grails create-domain-class Hero
![Page 31: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/31.jpg)
Examples
hero.save()
Hero.findByWeightGreaterThan( 100 )Hero.findAllByFullNameNotNull()
hero.weapons.each {…
}
![Page 32: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/32.jpg)
Combining Neo4j And Hibernate
static mapWith = "neo4j”
def hibernateHero = Hero.get(1)hibernateHero.neo4j.save()def neo4jHero = Person.neo4j.get(1)
![Page 33: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/33.jpg)
Advanced Configurationgrails-app/conf/DataSource.groovy
grails { neo4j { type = "embedded" location = "/var/neo4j" params = [] }}
![Page 34: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/34.jpg)
Via RESTtype = "rest”
grails { neo4j { type = "rest" location = "http://localhost:7474/db/data/" }}
![Page 35: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/35.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/36.jpg)
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: Neo4 + Grails](https://reader035.fdocuments.us/reader035/viewer/2022081507/55587679d8b42a8d018b5312/html5/thumbnails/37.jpg)
Questions
Q are guaranteed in life – answers aren’t.