Slide 1

Slide 1 text

Persistence made easy with Jakarta Data & NoSQL Otávio Santana Distinguished Engineer [email protected] Karina Varela Principal Technical Marketing Manager [email protected]

Slide 2

Slide 2 text

It's now time to upgrade your persistence skills

Slide 3

Slide 3 text

A persistence drama ○ Which persistence framework? ○ Use spec capabilities only or… explore framework capabilities? ○ Performance or development speed? Once upon a time…

Slide 4

Slide 4 text

A persistence drama Once upon a time… ○ Which design pattern? ○ Decoupled code… ○ SQL or NoSQL? ○ Which database flavor?

Slide 5

Slide 5 text

@otaviojava || @kvarel4 Architectural design demands knowledge How much information is available? App design Persistence design

Slide 6

Slide 6 text

@otaviojava || @kvarel4 Broad knowledge set The application landscape Documentation Pattern Architecture Refactoring

Slide 7

Slide 7 text

@otaviojava || @kvarel4 Maturity Model State of affairs Persistence landscape Database flavors Paradigms Source: https://survey.stackoverflow.co/2022/#most-popular-technologies-language-prof 2022 Stackoverflow developer survey

Slide 8

Slide 8 text

@otaviojava || @kvarel4 It's the first thing we do Change is hard and expensive Maintaining evolutionary data Challenges in a database land

Slide 9

Slide 9 text

@otaviojava || @kvarel4 SQL Database key value key key key value value value Column Family Graph Document Key Value NoSQL Database Challenges in a database land Over 400 database options ! SQL NoSQL NewSQL x x

Slide 10

Slide 10 text

@otaviojava || @kvarel4 Challenges in a database land Different paradigms: Apps x DBMS Application (Object Oriented Language) Mismatch Database (Relational) Object Tables src: https://en.wikipedia.org/wiki/Directed_graph

Slide 11

Slide 11 text

@otaviojava || @kvarel4 Challenges in a database land Different paradigms: Apps x DBMS Application Mismatch Database Heritage Polymorphism Encapsulation Types Normalization Denormalization Structure

Slide 12

Slide 12 text

@otaviojava || @kvarel4 Objectives and priorities we seek Business Isolation Performance

Slide 13

Slide 13 text

@otaviojava || @kvarel4 After exploring the database land, it's time to discuss about applications. How do you handle persistence in Java?

Slide 14

Slide 14 text

@otaviojava || @kvarel4 After exploring the database land, it's time to discuss about applications. How do you handle persistence in Java? How much effort would it take to change: ❏ Change the database vendor? (e.g. DB2 to PostgreSQL) ❏ Change the database paradigm? (e.g. SQL to NoSQL) ❏ Change the utilized framework? (e.g. Spring Data to Hibernate)

Slide 15

Slide 15 text

@otaviojava || @kvarel4 Developer experience, improved efficiency Java + Database Integration needs DB server data config. management; Connection handling (open, track, close); Mapping classes to tables; Mapping of classes relations; Transaction management; Out-of-the-box querying capabilities; Custom query capability; Fetching strategies for enhanced performance; In-memory caching; Code generation for traditional operations; Decouple business logic from technical details; How do you handle persistence in Java? Database abstraction

Slide 16

Slide 16 text

@otaviojava || @kvarel4 Developer experience, improved efficiency Java + Database Integration needs DB server data config. management; Connection handling (open, track, close); Mapping classes to tables; Mapping of classes relations; Transaction management; Out-of-the-box querying capabilities; Custom query capability; Fetching strategies for enhanced performance; In-memory caching; Code generation for traditional operations; Decouple business logic from technical details; How do you handle persistence in Java? Database abstraction

Slide 17

Slide 17 text

@otaviojava || @kvarel4 try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(QUERY);) { // Extract data from result set while (rs.next()) { // Retrieve by column name System.out.print("ID: " + rs.getInt("id")); System.out.print(", name: " + rs.getInt("name")); System.out.print(", birthday: " + rs.getString("birthday")); System.out.println(", city: " + rs.getString("city")); System.out.println(", city: " + rs.getString("street")); … } Challenges: Driver Java + Database Integration Code flexibility ++ Complex relation with business logic

Slide 18

Slide 18 text

@otaviojava || @kvarel4 Challenges: Data Mapper Java + Database Integration @Entity public class Person { @Id @GeneratedValue(strategy = AUTO) Long id; String name; LocalDate birthday; @ManyToOne List
address; … } Business ++ Too far away from database's aspects

Slide 19

Slide 19 text

@otaviojava || @kvarel4 Challenges: Active Record Java + Database Integration Increased domain's responsibility Increased code coupling @Entity public class Person extends PanacheEntity { public String name; public LocalDate birthday; public List
addresses; } Person person =...; // persist it person.persist(); List people = Person.listAll(); // finding a specific person by ID person = Person.findById(personId);

Slide 20

Slide 20 text

@otaviojava || @kvarel4 Challenges: Repository Java + Database Integration Single domain's responsibility Increased code complexity @Entity public class Person { private @Id Long id; private @Column String name; private @Column LocalDate birthday; private @ManyToOne List
addresses; } public interface PersonRepository extends { } Person person =...; // persist it repository.save(person); List people = Person.listAll(); // finding a specific person by ID person = repository.findById(personId);

Slide 21

Slide 21 text

JPA Mature stack Active Record Repository Data Mapper … Design Patterns Quarkus Spring Data Micronaut … Technologies supports influences

Slide 22

Slide 22 text

@otaviojava || @kvarel4 Architect Developer Jakarta EE A Java persistence drama

Slide 23

Slide 23 text

@otaviojava || @kvarel4 To the rescue! ✓ Common Annotation ✓ Multiple APIs ✓ Extensions ✓ Graph (Apache Tinkerpop) Jakarta NoSQL App. layers Out-of-the-box integration APIs: ✓ Column Family ✓ Graph ✓ Document ✓ Key Value

Slide 24

Slide 24 text

@otaviojava || @kvarel4 App. layers Out-of-the-box integration APIs: ✓ Column Family ✓ Graph ✓ Document ✓ Key Value To the rescue! ✓ Common Annotation ✓ Multiple APIs ✓ Extensions ✓ Graph (Apache Tinkerpop) Jakarta NoSQL

Slide 25

Slide 25 text

@otaviojava || @kvarel4 Motivation BaseDocument baseDocument = new BaseDocument(); baseDocument.addAttribute(name, value); Document document = new Document(); document.append(name, value); JsonObject jsonObject = JsonObject.create(); jsonObject.put(name, value); ODocument document = new ODocument(“collection”); document.field(name, value); Jakarta NoSQL

Slide 26

Slide 26 text

@otaviojava || @kvarel4 Makes it easy DocumentEntity entity = DocumentEntity.of("collection"); entity.add(name, value); Jakarta NoSQL

Slide 27

Slide 27 text

@otaviojava || @kvarel4 Developer Architect Architect A Java persistence drama Upcoming chapters:

Slide 28

Slide 28 text

@otaviojava || @kvarel4 Jakarta Data The second Jakarta EE spec Data agnostic Approved, initial phases https://projects.eclipse.org/proposals/jakarta-data

Slide 29

Slide 29 text

Jakarta Data

Slide 30

Slide 30 text

@otaviojava || @kvarel4 Repository Jakarta Data NoSQL JPA Rest Client

Slide 31

Slide 31 text

@otaviojava || @kvarel4 ● Repository/DDD ● CQRS ● Event-Driven Design ● DTO Supported design patterns Jakarta Data

Slide 32

Slide 32 text

@otaviojava || @kvarel4 Jakarta NoSQL Simplified data design for Java Jakarta Data JPA Jakarta NoSQL

Slide 33

Slide 33 text

Thank you! Otávio Santana Software Engineer & Architect [email protected] @otaviojava osarchitech.com Karina Varela Principal Technical Marketing Manager [email protected] @kvarel4