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

Pouring Coffee into the Matrix: Building Java Applications on Neo4j

Jennifer Reif
September 28, 2022

Pouring Coffee into the Matrix: Building Java Applications on Neo4j

Many of us have built applications for traditional data structures (like relational database tables), but is it different for graph data stores? Do developers need to retool and relearn? In this session, we will cover a brief intro to graphs and walk through writing a typical Java application with Spring and connect it to a graph database. We will walk through interacting with the graph data from the application, and show it in the cloud, as well. Come to this session to apply your business applications to graph data!

Jennifer Reif

September 28, 2022
Tweet

More Decks by Jennifer Reif

Other Decks in Technology

Transcript

  1. Jennifer Reif
    Email: [email protected]
    Twitter: @JMHReif
    LinkedIn: linkedin.com/in/jmhreif
    Github: GitHub.com/JMHReif
    Website: jmhreif.com
    Pouring Coffee into the Matrix
    Building Java applications on Neo4j

    View Slide

  2. Who Am I?
    • Developer + Advocate

    • Continuous learner

    • Technical content writer

    • Conference speaker

    • Other: geek
    Jennifer Reif
    Email: [email protected]
    Twitter: @JMHReif
    LinkedIn: linkedin.com/in/jmhreif
    Github: GitHub.com/JMHReif
    Website: jmhreif.com

    View Slide

  3. What is graph?

    View Slide

  4. What is graph?
    • Database - data storage

    • Way to store relationships with entities

    • Powerful when…

    • Queried - results based on the network structure

    • Visualized - depth comprehension of network

    • Utilized in algorithms/pipelines - factoring network into calculations

    View Slide

  5. Graph History
    • Graph much older than technology of the last decade…

    • Arose from solution need (then and now)
    Seven Bridges of Konigsberg problem. Leonhard Euler, 1735

    View Slide

  6. Graph Data Model

    View Slide

  7. Property Graph
    • Node (vertex)

    • Relationship (edge)

    View Slide

  8. Nodes
    • Represent objects or entities

    • Can be labeled
    JavaVersion
    VersionDiff
    JavaVersion

    View Slide

  9. Nodes
    • Represent objects or entities

    • Can be labeled

    • May have properties
    JavaVersion
    VersionDiff
    JavaVersion
    version: “17”


    gaDate: 2021-09-14
    fromVersion: “17.0.3+7-tem”


    toVersion: “1.6.0_45-oracle”
    version: “6”


    gaDate: 2006-12-12


    codeName: “Mustang”

    View Slide

  10. Relationships
    • Must have a type

    • Must have a direction
    JavaVersion
    VersionDiff
    JavaVersion
    version: “17”


    View Slide

  11. Relationships
    • Must have a type

    • Must have a direction

    • May have properties
    JavaVersion
    VersionDiff
    JavaVersion
    version: “17”


    View Slide

  12. Relationships
    • Must have a type

    • Must have a direction

    • May have properties

    • Nodes can share multiple relationships
    JavaVersion
    VersionDiff
    JavaVersion
    version: “17”


    View Slide

  13. Label
    • A group of nodes

    • Like a category

    • Domain class :)
    Person

    View Slide

  14. Label
    • A group of nodes

    • Like a category

    • Domain class :)

    • Inheritance :)
    Person
    Employee
    Customer

    View Slide

  15. Properties
    • Key-value pair

    • Associated with node or relationship

    • Like a variable name and value
    JavaVersion
    JavaVersion
    version: “17”
    version: “6”
    versionSteps: 3
    M
    IG
    RATES
    gaDate: 2021-09-14
    gaDate: 2006-12-12
    codeName: “Mustang”

    View Slide

  16. Modeling

    View Slide

  17. Whiteboard friendliness

    View Slide

  18. Graph data

    View Slide

  19. Developing applications

    View Slide

  20. Java App Data Store Options
    • Relational

    • Straight JDBC

    • JDBC Template

    • JOOQ

    • JPA or Hibernate

    • NoSQL - Document

    • MongoDB

    • Graph

    • Neo4j

    View Slide

  21. Java Dev: Why Graph?

    View Slide

  22. Answering data questions
    • Java Versions (i.e. 8, 11, 17)

    • Changes between versions over time

    • Di
    ff
    s

    • History for one speci
    fi
    c feature

    View Slide

  23. Domain/Application alignment
    • Class

    • Entity/Object

    • Represents domain type

    • General outline for objects of that type

    • Variables/Properties

    • Details for that entity

    • Values may not always exist

    • Constructor - instance of object

    • Each instance is unique object with varying info
    @Node
    @Data
    @RequiredArgsConstructor
    public class JavaVersion {
    @Id
    @Property("version")
    private
    fi
    nal String javaVersion;
    private String name, codeName, status, apiSpec;
    private LocalDate gaDate, eolDate;
    }

    View Slide

  24. Retaining Relationships
    • Adding relationships

    • Add variable as pointer to another object

    • Links entities together

    • Might have some annotations for mapping @Node
    @Data
    @RequiredArgsConstructor
    public class JavaVersion {
    @Relationship(“FROM_NEWER”)
    private List olderVersionDiffs;
    }

    View Slide

  25. • Set theory - rows and columns

    • Schema - rigid, enforced

    • Entities - table row

    • Metadata - columns

    • Relationships - crafted JOINs

    • Queries - JOINs at runtime

    • Indexes - Lookups scans
    Graphs for Java devs
    • Graph theory - entity network

    • Schema -
    fl
    exible, optional

    • Entities - node (object)

    • Metadata - properties

    • Relationships - stored joins

    • Queries - joins at write

    • Indexes - place to start
    Relational database Graph database

    View Slide

  26. • Links stored as primary/foreign keys

    • Traversal expressed as nested
    subqueries

    • Every subquery needs separate query
    plan
    Relational vs Graph
    • Links stored as pointers (IFA)

    • Traversal expressed as single pattern

    • One query plan for entire path

    View Slide

  27. Demo Background

    View Slide

  28. Neo4j AuraDB
    • Free tier instance

    • Java language version data loaded

    View Slide

  29. Language drivers
    • Neo4j Java driver (o
    ffi
    cial)

    • Spring Data Neo4j

    • Uses Neo4j Java driver at base

    • Other options:

    • O
    ffi
    cial drivers-> Python, JavaScript, Go, .NET

    • Java frameworks-> Quarkus, Helidon, Micronaut, etc

    View Slide

  30. Spring provisions
    • Spring Initializr

    • Spring Boot’s reduction of boilerplate

    • Annotation-based OGM for POJOs

    • Query derivation + DSL for custom (Cypher)

    • Spring Data’s easy connection to Neo4j

    • BOLT or HTTP

    View Slide

  31. Let’s see some code!
    Demo time!

    View Slide

  32. Resources
    • Source code: github.com/JMHReif/pouring-co
    ff
    ee-into-matrix-lombok

    • Spring Data Neo4j documentation: dev.neo4j.com/sdn-docs

    • Neo4j AuraDB: dev.neo4j.com/aura-java

    • Blog: bit.ly/jmhreif-blog

    • NODES: dev.neo4j.com/nodes
    Jennifer Reif
    Email: [email protected]
    Twitter: @JMHReif
    LinkedIn: linkedin.com/in/jmhreif
    Github: GitHub.com/JMHReif
    Website: jmhreif.com DON’T MISS!

    View Slide