Slide 1

Slide 1 text

Beziehungsmanagement mit Spring Data Neo4j Gerrit Meier @meistermeier

Slide 2

Slide 2 text

• About Neo4j • Connect to Neo4j • Neo4j Object Graph Mapper • Spring Data Neo4j • Import Data • Demo Application Agenda

Slide 3

Slide 3 text

About Neo4j

Slide 4

Slide 4 text

• 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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

The Whiteboard Model Is the Physical Model Hero PART_OF Team FIGHTS Bad Person {realName: “Anthony Stark”} {event: “Infinity War”}

Slide 9

Slide 9 text

The Whiteboard Model Is the Physical Model Iron Man :PART_OF Avengers :FIGHTS Thanos Groot :PART_OF Guardians of the Galaxy :FIGHTS

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

MATCH 
 (t:Team)<-[p:PART_OF]-(h:Hero)-[f:FIGHTS]->(b:Bad_Person) WHERE b.name=“Thanos” RETURN t,p,h,f,b Cypher

Slide 12

Slide 12 text

Cypher

Slide 13

Slide 13 text

Connect to Neo4j

Slide 14

Slide 14 text

Transport modes Bolt - Binary protocol Embedded - Running Neo4j in the same JVM HTTP - First remote access, no library needed

Slide 15

Slide 15 text

Bolt drivers Languages - Python, Java, JavaScript, C#, Go Seabolt - connector written in C Community driver - R, Rust, Elixir…

Slide 16

Slide 16 text

Neo4j Object Graph Mapper
 (Neo4j-OGM)

Slide 17

Slide 17 text

Spring Data Neo4j

Slide 18

Slide 18 text

{name: “Emil Eifrem”} Spring Data Neo4j

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Spring Data Neo4j / Neo4j-OGM

Slide 22

Slide 22 text

Spring Data Neo4j / Neo4j-OGM

Slide 23

Slide 23 text

Neo4j Object Graph Mapper
 (Neo4j-OGM)

Slide 24

Slide 24 text

Java Driver Neo4j-OGM

Slide 25

Slide 25 text

Java Driver Neo4j-OGM TransactionManger SessionFactory

Slide 26

Slide 26 text

Java Driver Neo4j-OGM Embedded Bolt HTTP

Slide 27

Slide 27 text

Neo4j-OGM Annotations - Describe your Graph Configuration - Driver, Domain packages,… Basic Data Access - CRUD operations built-in Mapping - Java Object Graph <> Graph Model

Slide 28

Slide 28 text

Annotations :Hero :PART_OF :Team

Slide 29

Slide 29 text

@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

Slide 30

Slide 30 text

@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

Slide 31

Slide 31 text

@NodeEntity public class Team { @Id @GeneratedValue private Long id; private String name; } :PART_OF :Hero

Slide 32

Slide 32 text

Configuration Database Access - Transport mode, connection pooling, encryption… Packages to scan - NodeEntities and RelationshipEntities Auto Indexing - Auto-generate indexes (development)

Slide 33

Slide 33 text

Basic Data Access Session session = sessionFactory.openSession(); Hero hero = new Hero(); session.save(hero);

Slide 34

Slide 34 text

Basic Data Access Hero hero = session.load(Hero.class, heroId); Collection heroes = session.loadAll(Hero.class);

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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());

Slide 37

Slide 37 text

Basic Data Access Hero hero = session.queryForObject(Hero.class,
 "MATCH (h:Hero) where h.name = ${name} return h",
 singletonMap("name", "John") );

Slide 38

Slide 38 text

Spring Data Neo4j

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

public interface HeroRepository extends Neo4jRepository {} Spring Data Neo4j CRUD Methods - save, findById, delete, count… Graph specific - depth “second” parameter

Slide 41

Slide 41 text

Spring Data Neo4j public interface HeroRepository extends Neo4jRepository { Hero findByRealName(String realName); }

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Spring Data Neo4j public interface HeroRepository extends Neo4jRepository { @Query("MATCH (h:Hero)-[:FIGHTS]->(b:Bad_Person) WHERE b.name={0} return h”) List findAllies(String opponent); }

Slide 44

Slide 44 text

Spring Data Neo4j 5.x (Lovelace/Moore) Spring Boot 2.x (only) Schema-based Loading Persistence Constructor

Slide 45

Slide 45 text

The Don’ts Complex Custom Cypher Batch Operations Domain Model does not represent the Graph

Slide 46

Slide 46 text

Import Data

Slide 47

Slide 47 text

Import LOAD CSV - File, HTTP(S) and FTP APOC - Support for JSON, JDBC… ETL Tool - Import and map data from SQL source

Slide 48

Slide 48 text

"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

Slide 49

Slide 49 text

LOAD CSV LOAD CSV WITH HEADERS FROM “file:paradise.csv” AS row CREATE (:Officer {name: row.n.name, country: row.n.country,…});

Slide 50

Slide 50 text

APOC WITH “https://webservice/json” AS url CALL apoc.load.json(url) YIELD value UNWIND value.items AS item MERGE (:Item {title=item.title}

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

ETL Tool

Slide 53

Slide 53 text

Demo

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Bloom

Slide 58

Slide 58 text

More Neo4j

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Thank you!

Slide 61

Slide 61 text

Neo4j Desktop - https://neo4j.com/download/ Neo4j Sandbox - https://neo4j.com/sandbox-v2/ ICIJ Leaks Database - https://offshoreleaks.icij.org/pages/database Links