Nicki and Michael have recently been working together on the project to develop/upgrade the Spring Data Neo4j 3 (SDN) library to take advantage of some of the latest Neo4j 2.0 features. This talk takes a look at what can be expected of the new framework, and how it can be used to help model various different use cases with a simple Java domain model backed by a Neo4j database.
Decarbonising Buildings: Making a net-zero built environment a reality
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @ GraphConnect London 2013
1. Object
Graph
Mapping
Spring
Data
Neo4j
3.0
Nicki
Wa(
@
opencredo
Michael
Hunger
@
neotechnology
2. Agenda
1.
Why
Object-‐Graph-‐Mapping?
2.
What
is
Spring
Data
(Neo4j)?
3.
Current
State
of
affairs
4.
SDN
3.0
5.
The
Future
6.
Some
Spring
Data
Neoj
Use-‐Cases
4. Why
OGM
?
-‐
Convenience
-‐
Simplify
interac2on
with
underlying
data
source:
Framework/Library
handles
basic
CRUD
type
funcVonality
for
you
-‐
Provides
ability
to
work
with
na2ve
domain
language
constructs:
eg
domain
classes/objects
(POJOs
in
Java)
in
your
applicaVon
-‐
Use
Cases:
examples
at
end
of
talk
5. Why
OGM
?
But
…
-‐ IndirecVon,
addiVonal
abstracVon
layer
adds
performance,
overhead
-‐ Encourages
users
to
pull
larger
parts
of
the
database
into
memory
to
process
instead
of
le_ng
the
db
do
its
job
7. Spring
Data
Neo4j
-‐
OGM
aimed
at
Java
world
&
uses
Spring
-‐
Neo4j
Implementa2on
of
the
Spring
Data
project:
SpringSource/VMWare/Pivotal
iniVaVve
to
give
Spring
developers
easy
access
to
the
emerging
world
of
NOSQL.
Was
the
iniVal
and
first
Spring
Data
project
by
Rod
and
Emil
-‐
Simple
programming
model:
annotaVon-‐based
programming
for
applicaVons
with
rich
domains
10. Spring
Data
Neo4j
-‐
features
-‐
Two
mapping
modes:
Simple
&
Advanced
-‐
Provides
Spring
Data
Repository
Support
-‐
Ability
to
drop
down
to
Neo4j
Core
API
if
required
-‐
(Neo4j
Server
Support)
31. Disclaimer
SDN
3.0
s)ll
in
progress
...
• Subject
to
change
• Primary
changes
are
Neo4j
2.0
compliance
-‐
not
finalised
yet
• follow
progress
on
githubh"p://
spring.neo4j.org/source
32. SDN
3.0
-‐
Base
Neo4j
2.0
support
-‐
Spring
3.2.5
(eventually
4
as
well)
support
-‐
New
Type
Representa2on
Strategy
-‐
Labels
-‐
Migra2on
towards
more
Cypher
driven
founda2on
-‐
Various
bug
fixes
and
enhancements
33. Neo4j
2.0
Support
-‐
Will
be
able
to
run
against
a
Neo4j
2.X
DB
-‐
Query
using
Labels
-‐
Ability
to
use
new
Cypher
Syntax
-‐
Schema
Indexes
(Work
in
Progress)
35. @NodeEntity
@TypeAlias(value
=
"Person")
public
class
Person
{
@Query("MATCH
(person)<-‐[:ATTENDEE]-‐(gathering:Conference)"
+
"
WHERE
id(person)
=
{self}
"
+
"
RETURN
gathering")
public
Iterable<Conference>
findAllConferencesAttended;
//
.
.
.
}
@NodeEntity
@TypeAlias(value
=
"Conference")
public
class
Conference
{
//
.
.
.
}
36. @NodeEntity
@TypeAlias(value
=
"Person")
public
class
Person
{
@GraphId
Long
graphId;
@Indexed(unique
=
true)
String
name;
@RelatedToVia(type="ATTENDED")
Iterable<Attended>
talksAttended;
//
.
.
.
}
@TypeAlias(value
=
"Speaker")
public
class
Speaker
extends
Person
{
String
bio;
@RelatedTo(type="SPEAKER",
direction
=
INCOMING)
Iterable<Talk>
talks;
//
.
.
.
}
37. Index
vs
Label
TRS
public
interface
ConferenceRepository
extends
GraphRepository<Conference>
{
/*
Query
generated
when
using
Index
Based
TRS
START
`conference`=node:__types__(className="Conference")
WHERE
`conference`.`date`
=
{0}
RETURN
`conference`
Query
generated
when
using
Label
Based
TRS
MATCH
(`conference`:`Conference`)
WHERE
`conference`.`date`
=
{0}
RETURN
`conference`
*/
Set<Conference>
findAllByDate(Date
date);
}
38.
39. Label
Type
Representation
Strategy
-‐
Will
allow
for
schema
indexes**
to
be
used
-‐
Will
add
addiVonal
__TYPE__XX
labels
to
nodes
-‐
No
addiVonal
properVes
need
to
be
stored
on
nodes
to
represent
hierarchy
(If
Index
Based
TRS
used)
-‐
No
addiVonal
nodes
need
to
be
created
to
represent
hierarchy
(If
Sub
Reference
based
TRS
used)
41. Future
Plans
-‐
Cypher
based
•
•
•
•
•
Use
all
Cypher
for
the
mapping
layer
Align
embedded
and
remote
use
Benefit
from
Cypher
enhancements
Leverage
complex
query
mechanisms
Support
more
OGM
type
funcVonality
• Client
side
caching
• Lazy
loading
42. Future
Plans
-‐
OGM
• PotenVally
extract
or
use
standalone,
cypher-‐based
Java-‐Neo4j-‐OGM
• Also
useable
without
Spring
(Data)
43. Future
Plans
-‐
Query
Results
• Project
query
results
into
object
trees/graphs
• Useful
for
direct
view-‐layer
integraVon
• Less
overhead
by
an
intermediate
domain
model
that
has
to
be
converted
44. Future
Plans
-‐
Support
• Be(er
support
for
•
•
•
•
Spring
Boot
Spring
Data
Rest
Remote
transacVonal
integraVon
JDBC-‐Driver
in
Spring
48. WhyOwnIt:
Ownership
Sharing
Service
• Sharing
Culture
• You
own
things
you
only
seldomly
need
• You
need
things
you
don‘t
own
• Match
needs
and
available
devices/tools
• add
raVngs,
trust,
recommendaVons
• locaVon
based,
close
to
you
for
pick-‐up
• Startup
53. Music
Sharing/Discovery/Recommendation
Service
• Recommend
new
arVsts
and
songs
to
your
users
• take
their
previous
listen-‐history
into
account
• look
at
what‘s
hot
amongst
their
friends
• infer
broader
selecVon
via
bands
and
genres
•
Detect
duplicates
using
media-‐fingerprints
• copyright
infringements
57. Other
Use-‐Cases
• Financial
Services
-‐
Asset
/
Account
Management
• Bank
-‐
Permission
Management
and
AuthorizaVon
• EnVtlement
• Data
Sopware
Provider
-‐
Impact
analysis
of
changes
• ImplicaVon
of
changes
on
the
company
core
asset:
DATA
• Change
tracking
• Root
Cause
Analysis
58. SAN/NAS
Provider
-‐
Lifetime
device
tracking
• Networked
Storage
Boxes
• many
components,
disks,
controllers,
power
supply,
sensors
• Tracking
of
measurement
data
• Impact
analyVcs
• Early
detecVon
of
anomalies
• Intelligent
fail
over
• Huge
number
of
domain
enVVes
(~450)
• generaVng
domain
classes
and
repositories
59. Game
Retailer
• Buy
and
Download
&
Game
on
Demand
• Fraud
detecVon
• delayed
payments,
charge
backs,
fradulent
keys
are
invalid
• Convert
rules
to
traversals
• co-‐occurrance
of
sudden
large
sales
• fradulent
e-‐mail
pa(erns
• CombinaVon
with
Oracle
Infrastructure
• Cross-‐Store
61. To
SDN
or
Not
to
SDN
...
Domain-‐Centric
• Integrate
in
a
Springframework
Context
• ExisVng
ApplicaVons
with
POJO
Domains
• Move
a
manageable
amount
of
data
in
and
out
of
the
database
into
Domain
Objects
• Rich,
connected
domain
• MulVple
projecVons
62. To
SDN
or
Not
to
SDN
...
Data-‐Centric
• high
volume
database
interacVons
• reads
and
writes
(inserts)
• thin
domain
view
on
top
of
graph
queries
• remote
Client
to
Neo4j
Server