Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Gerrit Meier

January 23, 2019

More Decks by Gerrit Meier

Other Decks in Programming


  1. • About Neo4j • Connect to Neo4j • Neo4j Object

    Graph Mapper • Spring Data Neo4j • Import Data • Demo Application Agenda
  2. • 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
  3. 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
  4. The Whiteboard Model Is the Physical Model Hero PART_OF Team

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

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

    is for relational databases. Open Source http://www.opencypher.org/ and ready for other Graph Database technology.
  7. Transport modes Bolt - Binary protocol Embedded - Running Neo4j

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

    - connector written in C Community driver - R, Rust, Elixir…
  9. Neo4j-OGM Annotations - Describe your Graph Configuration - Driver, Domain

    packages,… Basic Data Access - CRUD operations built-in Mapping - Java Object Graph <> Graph Model
  10. @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
  11. @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
  12. Configuration Database Access - Transport mode, connection pooling, encryption… Packages

    to scan - NodeEntities and RelationshipEntities Auto Indexing - Auto-generate indexes (development)
  13. Basic Data Access Result result = session.query("MATCH (h:Hero) return h",

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

    h.name = ${name} return h",
 singletonMap("name", "John") );
  15. 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
  16. public interface HeroRepository extends Neo4jRepository<Hero, Long> {} Spring Data Neo4j

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

    Hero findByRealName(String realName); } MATCH (h:Hero) where h.realName=realName
  18. 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); }
  19. Import LOAD CSV - File, HTTP(S) and FTP APOC -

    Support for JSON, JDBC… ETL Tool - Import and map data from SQL source
  20. "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
  21. LOAD CSV LOAD CSV WITH HEADERS FROM “file:paradise.csv” AS row

    CREATE (:Officer {name: row.n.name, country: row.n.country,…});