Slide 1

Slide 1 text

Object  Graph  Mapping   Spring  Data  Neo4j  3.0   Nicki  Wa(  @  opencredo     Michael  Hunger  @  neotechnology  

Slide 2

Slide 2 text

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  

Slide 3

Slide 3 text

1.  Why     Object-­‐Graph-­‐Mapping?  

Slide 4

Slide 4 text

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  

Slide 5

Slide 5 text

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  

Slide 6

Slide 6 text

2.  What  is     Spring  Data  Neo4j?  

Slide 7

Slide 7 text

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  

Slide 8

Slide 8 text

With  and  without  SDN  ...  

Slide 9

Slide 9 text

With  and  without  SDN  ...  

Slide 10

Slide 10 text

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)  

Slide 11

Slide 11 text

Example  Domain:     “Conference  Management”  

Slide 12

Slide 12 text

Sample  graph  

Slide 13

Slide 13 text

High  Level  Object  Model  

Slide 14

Slide 14 text

DePining  Your  Entities  

Slide 15

Slide 15 text

SDN  Domain  Entities   @NodeEntity   @TypeAlias(value  =  "Conference")   public  class  Conference    {        @GraphId  Long  graphId;        @Indexed  String  name;        Date  date;          @RelatedTo(type="ATTENDEE")        Set  attendees;        @RelatedTo(type="TALK")        Set  talks;   //  .  .  .   }  

Slide 16

Slide 16 text

SDN  Domain  Entities   @NodeEntity   @TypeAlias(value  =  "Person")   public  class  Person  {        @GraphId  Long  graphId;        @Indexed(unique  =  true)  String  name;        @RelatedToVia        Iterable  talksAttended;        //    .  .  .   }  

Slide 17

Slide 17 text

SDN  Domain  Entities  (Relationship)   @RelationshipEntity(type  =  "LISTENED_TO")   public  class  Attended  {        @GraphId  Long  graphId;          @StartNode  Person  attendee;        @EndNode  Talk  talk;          Integer  rating;          //  .  .  .   }  

Slide 18

Slide 18 text

SDN  Domain  Entities   @NodeEntity   @TypeAlias(value  =  "Talk")   public  class  Talk  {        @GraphId  Long  graphId;        @Indexed  String  name;        String  description;          @RelatedTo(type="SPEAKER")        Set  speakers;        @RelatedToVia(direction  =  INCOMING)        Set  attendees;        //  .  .  .   }  

Slide 19

Slide 19 text

SDN  Domain  Entities   @TypeAlias(value  =  "Speaker")   public  class  Speaker  extends  Person  {        String  bio;        @RelatedTo(type="SPEAKER",  direction  =  INCOMING)        Iterable  talks;        //  .  .  .   }  

Slide 20

Slide 20 text

SDN  Repository  Support  -­‐   Derived  Finder  Methods  

Slide 21

Slide 21 text

SDN  Repository  Support   import  org....data.neo4j.repository.GraphRepository;   import  java.util.Set;   public  interface  TalkRepository  extends                                                                    GraphRepository  {          Set  findTalksBySpeakersName(String  name);   }  

Slide 22

Slide 22 text

@NodeEntity   @TypeAlias(value  =  "Talk")   public  class  Talk  {        @GraphId  Long  graphId;        @Indexed  String  name;        String  description;          @RelatedTo(type="SPEAKER")        Set  speakers;        @RelatedToVia(direction  =  INCOMING)        Set  attendees;        //  .  .  .   }   SDN  Repository  Support   findTalksBySpeakersName  

Slide 23

Slide 23 text

SDN  Repository  Support   findTalksBySpeakersName   @TypeAlias(value  =  "Speaker")   public  class  Speaker  extends  Person  {          String  bio;        @RelatedTo(type="SPEAKER",  direction  =  INCOMING)        Iterable  talks;        //  .  .  .   }   @NodeEntity   @TypeAlias(value  =  "Person")   public  class  Person  {        @GraphId  Long  graphId;        @Indexed(unique  =  true)  String  name;        @RelatedToVia(type="ATTENDED")        Iterable  talksAttended;        //    .  .  .   }  

Slide 24

Slide 24 text

SDN  Repository  Support   import  org....data.neo4j.repository.GraphRepository;   import  java.util.Set;   public  interface  TalkRepository  extends                                                                    GraphRepository  {          Set  findTalksBySpeakersName(String  name);   }    START  `talk_speakers`=node:`Person`(`name`={0})    MATCH  (`talk`)-­‐[:`SPEAKER`]-­‐>(`talk_speakers`)    RETURN  `talk`  

Slide 25

Slide 25 text

SDN  Repository  Support  -­‐   Dynamic  Queries  

Slide 26

Slide 26 text

SDN  Repository  Support   import  org....data.neo4j.repository.GraphRepository;   import  java.util.Set;   public  interface  TalkRepository  extends                                                                    GraphRepository  {        //  Repository  Query  Method        @Query(value  =          "MATCH  (talk:Talk)-­‐[:SPEAKER]-­‐>(speaker:Speaker)  "  +          "WHERE  speaker.name={0}  RETURN  talk")        Set  findTalksBySpeakersNameQuery(String  name);            //  .  .  .   }  

Slide 27

Slide 27 text

3.  Current     State  Of  Affairs  

Slide 28

Slide 28 text

Current  State  Of  Affairs   -­‐  Current  ProducVon  Version:  2.3.2.RELEASE   -­‐  Neo4j  1.9.3  support  

Slide 29

Slide 29 text

4.  SDN  3.0  

Slide 30

Slide 30 text

Disclaimer  !!  

Slide 31

Slide 31 text

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  

Slide 32

Slide 32 text

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  

Slide 33

Slide 33 text

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)  

Slide 34

Slide 34 text

Label  Type  Representation  Strategy  

Slide 35

Slide 35 text

@NodeEntity   @TypeAlias(value  =  "Person")   public  class  Person  {    @Query("MATCH  (person)<-­‐[:ATTENDEE]-­‐(gathering:Conference)"  +                  "  WHERE    id(person)  =  {self}  "  +                  "  RETURN  gathering")    public  Iterable  findAllConferencesAttended;    //    .  .  .   }       @NodeEntity   @TypeAlias(value  =  "Conference")   public  class  Conference    {    //  .  .  .   }  

Slide 36

Slide 36 text

@TypeAlias(value  =  "Speaker")   public  class  Speaker  extends  Person  {          String  bio;        @RelatedTo(type="SPEAKER",  direction  =  INCOMING)        Iterable  talks;        //  .  .  .   }   @NodeEntity   @TypeAlias(value  =  "Person")   public  class  Person  {        @GraphId  Long  graphId;        @Indexed(unique  =  true)  String  name;        @RelatedToVia(type="ATTENDED")        Iterable  talksAttended;        //    .  .  .   }  

Slide 37

Slide 37 text

Index  vs  Label  TRS   public  interface  ConferenceRepository  extends                                                                    GraphRepository  {    /*              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  findAllByDate(Date  date);   }    

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

-­‐  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)   Label  Type  Representation  Strategy  

Slide 40

Slide 40 text

5.  The  Future  

Slide 41

Slide 41 text

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  

Slide 42

Slide 42 text

Future  Plans  -­‐  OGM   •  PotenVally  extract  or  use  standalone,   cypher-­‐based  Java-­‐Neo4j-­‐OGM   •  Also  useable  without  Spring  (Data)  

Slide 43

Slide 43 text

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  

Slide 44

Slide 44 text

Future  Plans  -­‐  Support   •  Be(er  support  for   •  Spring  Boot   •  Spring  Data  Rest   •  Remote  transacVonal  integraVon   •  JDBC-­‐Driver  in  Spring  

Slide 45

Slide 45 text

Future  Plans  -­‐  Migration   •  Migrate  Type  RepresentaVon   •  Index-­‐based  -­‐>  Label  based   •  Refactor/Rename  EnVVes,  Fields,  References   •  Rename  Indexes   •  @TypeAlias  

Slide 46

Slide 46 text

6.  Some  Use  Cases  

Slide 47

Slide 47 text

WhyOwnIt:  Ownership  Sharing  Service  

Slide 48

Slide 48 text

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  

Slide 49

Slide 49 text

WhyOwnIt:  Ownership  Sharing  Service  

Slide 50

Slide 50 text

WhyOwnIt:  Ownership  Sharing  Service  

Slide 51

Slide 51 text

WhyOwnIt:  Ownership  Sharing  Service  

Slide 52

Slide 52 text

Music  Sharing/Discovery/Recommendation   Service  

Slide 53

Slide 53 text

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  

Slide 54

Slide 54 text

Music  Sharing/Discovery/Recommendation   Service  

Slide 55

Slide 55 text

Music  Sharing/Discovery/Recommendation   Service  

Slide 56

Slide 56 text

Other  Use-­‐Cases  

Slide 57

Slide 57 text

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  

Slide 58

Slide 58 text

•  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   SAN/NAS  Provider  -­‐  Lifetime  device   tracking  

Slide 59

Slide 59 text

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  

Slide 60

Slide 60 text

Does  it  love  me  or  does  it   not?  

Slide 61

Slide 61 text

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   To  SDN  or  Not  to  SDN  ...  

Slide 62

Slide 62 text

Data-­‐Centric   •  high  volume  database  interacVons   •  reads  and  writes  (inserts)   •  thin  domain  view  on  top  of  graph  queries   •  remote  Client  to  Neo4j  Server   To  SDN  or  Not  to  SDN  ...  

Slide 63

Slide 63 text

Want  More  Info  ?  

Slide 64

Slide 64 text

•  Spring  Data  Book     •  Spring  Data  Neo4j  Guidebook   •  Spring  Data  Neo4j  on  Spring.io   •  Chapter  in  Neo4j  in  AcVon   •  Cineasts.net  Tutorial   Resources  

Slide 65

Slide 65 text

Thanks   ☺   Questions  ?   @techiewa(     @mesirii