Beziehungsmanagement mit Spring Data Neo4j

Beziehungsmanagement mit Spring Data Neo4j

Overview of Spring Data Neo4j and the Neo4j Object Graph Mapper (Neo4j-OGM) with an introduction to Neo4j and how to import data from csv, json or jdbc.
Note: Everything but the title (slide) is in English.

34ecacd077244d141a23c46ea094df5c?s=128

Gerrit Meier

January 23, 2019
Tweet

Transcript

  1. Beziehungsmanagement mit Spring Data Neo4j Gerrit Meier @meistermeier

  2. • About Neo4j • Connect to Neo4j • Neo4j Object

    Graph Mapper • Spring Data Neo4j • Import Data • Demo Application Agenda
  3. About Neo4j

  4. • Neo4j is the #1 platform for connected data. •

    Neo4j powers the next generation of applications and analytics • Prominent use cases are found in areas like machine learning, personalized recommendations, fraud detection, data governance and more. Neo4j: The #1 Platform for Connected Data
  5. Ecosystem Neo4j Professional Services 300+ partners 47,000 group members 61,000

    trained engineers 3.5M downloads Mindset “Graph Thinking” is all about considering connections in data as important as the data itself. Native Graph Platform Neo4j is an internet-scale, native graph database which executes connected workloads faster than any other database management system. Neo4j
  6. None
  7. The Whiteboard Model Is the Physical Model Hero PART_OF Team

    FIGHTS Bad Person
  8. The Whiteboard Model Is the Physical Model Hero PART_OF Team

    FIGHTS Bad Person {realName: “Anthony Stark”} {event: “Infinity War”}
  9. The Whiteboard Model Is the Physical Model Iron Man :PART_OF

    Avengers :FIGHTS Thanos Groot :PART_OF Guardians of the Galaxy :FIGHTS
  10. Cypher Cypher Query Language is to Neo4j what 
 SQL

    is for relational databases. Open Source http://www.opencypher.org/ and ready for other Graph Database technology.
  11. MATCH 
 (t:Team)<-[p:PART_OF]-(h:Hero)-[f:FIGHTS]->(b:Bad_Person) WHERE b.name=“Thanos” RETURN t,p,h,f,b Cypher

  12. Cypher

  13. Connect to Neo4j

  14. Transport modes Bolt - Binary protocol Embedded - Running Neo4j

    in the same JVM HTTP - First remote access, no library needed
  15. Bolt drivers Languages - Python, Java, JavaScript, C#, Go Seabolt

    - connector written in C Community driver - R, Rust, Elixir…
  16. Neo4j Object Graph Mapper
 (Neo4j-OGM)

  17. Spring Data Neo4j

  18. {name: “Emil Eifrem”} Spring Data Neo4j

  19. {name: “Emil Eifrem”} {name: “Rod Johnson”} Spring Data Neo4j

  20. {name: “Emil Eifrem”} {name: “Rod Johnson”} Spring Data Neo4j

  21. Spring Data Neo4j / Neo4j-OGM

  22. Spring Data Neo4j / Neo4j-OGM

  23. Neo4j Object Graph Mapper
 (Neo4j-OGM)

  24. Java Driver Neo4j-OGM

  25. Java Driver Neo4j-OGM TransactionManger SessionFactory

  26. Java Driver Neo4j-OGM Embedded Bolt HTTP

  27. Neo4j-OGM Annotations - Describe your Graph Configuration - Driver, Domain

    packages,… Basic Data Access - CRUD operations built-in Mapping - Java Object Graph <> Graph Model
  28. Annotations :Hero :PART_OF :Team

  29. @NodeEntity(label = "Hero") public class Hero { @Id @GeneratedValue private

    Long id; @Property(name = "name") private String superheroName; private String realName; @Relationship(type = "PART_OF", direction = Relationship.OUTGOING) private PartOf team; } :PART_OF :Team
  30. @RelationshipEntity(type = "PART_OF") public class PartOf { @Id @GeneratedValue private

    Long id; @StartNode private Hero hero; @EndNode private Team team; private String role; } :Hero :Team
  31. @NodeEntity public class Team { @Id @GeneratedValue private Long id;

    private String name; } :PART_OF :Hero
  32. Configuration Database Access - Transport mode, connection pooling, encryption… Packages

    to scan - NodeEntities and RelationshipEntities Auto Indexing - Auto-generate indexes (development)
  33. Basic Data Access Session session = sessionFactory.openSession(); Hero hero =

    new Hero(); session.save(hero);
  34. Basic Data Access Hero hero = session.load(Hero.class, heroId); Collection<Hero> heroes

    = session.loadAll(Hero.class);
  35. Basic Data Access session.delete(hero); session.deleteAll(Hero.class);

  36. Basic Data Access Result result = session.query("MATCH (h:Hero) return h",

    emptyMap());
 Hero hero = session.queryForObject(Hero.class,
 “MATCH (h:Hero) return h", emptyMap());
  37. Basic Data Access Hero hero = session.queryForObject(Hero.class,
 "MATCH (h:Hero) where

    h.name = ${name} return h",
 singletonMap("name", "John") );
  38. Spring Data Neo4j

  39. Spring Data Neo4j Convenient Data Access - Spring Data way

    Derived Finder Methods - no Cypher needed Abstraction from Cypher - if wanted Specialisation for Graph Operations - graph-ish way to work with data
  40. public interface HeroRepository extends Neo4jRepository<Hero, Long> {} Spring Data Neo4j

    CRUD Methods - save, findById, delete, count… Graph specific - depth “second” parameter
  41. Spring Data Neo4j public interface HeroRepository extends Neo4jRepository<Hero, Long> {

    Hero findByRealName(String realName); }
  42. Spring Data Neo4j public interface HeroRepository extends Neo4jRepository<Hero, Long> {

    Hero findByRealName(String realName); } MATCH (h:Hero) where h.realName=realName
  43. Spring Data Neo4j public interface HeroRepository extends Neo4jRepository<Hero, Long> {

    @Query("MATCH (h:Hero)-[:FIGHTS]->(b:Bad_Person) WHERE b.name={0} return h”) List<Hero> findAllies(String opponent); }
  44. Spring Data Neo4j 5.x (Lovelace/Moore) Spring Boot 2.x (only) Schema-based

    Loading Persistence Constructor
  45. The Don’ts Complex Custom Cypher Batch Operations Domain Model does

    not represent the Graph
  46. Import Data

  47. Import LOAD CSV - File, HTTP(S) and FTP APOC -

    Support for JSON, JDBC… ETL Tool - Import and map data from SQL source
  48. "labels(n)","n.valid_until","n.country_codes","n.countries","n.node_id","n.sourceID","n.address","n.name","n.jurisdiction_description","n.service_provider","n.jurisdiction","n.closed_date"," n.incorporation_date","n.ibcRUC","n.type","n.status","n.company_type","n.note" "[""Officer""]","Appleby","MUS","Mauritius","80113134","Paradise Papers - Appleby","","Lee Mo Lin - Noel

    Patrick L.C.K - Mauritius","","","","","","","","","","" "[""Officer""]","Appleby","SGP;USA","Singapore;United States","80113142","Paradise Papers - Appleby","","Pleshko - Daniel","","","","","","","","","","" "[""Officer""]","Appleby","BMU;GBR","Bermuda;United Kingdom","80113143","Paradise Papers - Appleby","","Plested - John","","","","","","","","","","" "[""Officer""]","Appleby","AUS;SGP","Australia;Singapore","80113145","Paradise Papers - Appleby","","Plewright - Peter John","","","","","","","","","","" "[""Officer""]","Appleby","CYM","Cayman Islands","80113146","Paradise Papers - Appleby","","Plexman - Eric Anthony","","","","","","","","","","" "[""Officer""]","Appleby","BMU;FRA","Bermuda;France","80113149","Paradise Papers - Appleby","","Plianthos - Nicolas Lawrence","","","","","","","","","","" "[""Officer""]","Appleby","USA","United States","80113152","Paradise Papers - Appleby","","Plimpton - Tara","","","","","","","","","","" "[""Officer""]","Appleby","USA","United States","80113153","Paradise Papers - Appleby","","Pliska - Bernard F.","","","","","","","","","","" "[""Officer""]","Appleby","USA","United States","80113157","Paradise Papers - Appleby","","Plotkin - Roger B.","","","","","","","","","","" "[""Officer""]","Appleby","","","80113158","Paradise Papers - Appleby","","Plott - Jeffrey","","","","","","","","","","" "[""Officer""]","Appleby","USA","United States","80113159","Paradise Papers - Appleby","","Plotz - Michael A.","","","","","","","","","","" "[""Officer""]","Appleby","","","80113160","Paradise Papers - Appleby","","Plouin - Graciela","","","","","","","","","","" "[""Officer""]","Appleby","GRC;GBR","Greece;United Kingdom","80113161","Paradise Papers - Appleby","","PLOUGHMAN - Dale","","","","","","","","","","" LOAD CSV
  49. LOAD CSV LOAD CSV WITH HEADERS FROM “file:paradise.csv” AS row

    CREATE (:Officer {name: row.n.name, country: row.n.country,…});
  50. APOC WITH “https://webservice/json” AS url CALL apoc.load.json(url) YIELD value UNWIND

    value.items AS item MERGE (:Item {title=item.title}
  51. APOC WITH “jdbc:mysql://database” AS url CALL apoc.load.jdbc(url) YIELD value UNWIND

    value.items AS item MERGE (:Item {title=item.title}
  52. ETL Tool

  53. Demo

  54. None
  55. None
  56. None
  57. Bloom

  58. More Neo4j

  59. None
  60. Thank you!

  61. Neo4j Desktop - https://neo4j.com/download/ Neo4j Sandbox - https://neo4j.com/sandbox-v2/ ICIJ Leaks

    Database - https://offshoreleaks.icij.org/pages/database Links