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

Persistence made easy with Jakarta Data & NoSQL

Persistence made easy with Jakarta Data & NoSQL

https://thedevconf.com/tdc/2022/business/trilha-arquitetura-java

Persistence is the soul of modern architecture. It is a way to have a state in the stateless application, mainly in distributed systems such as microservices and cloud age app style.

We handle various persistence sources such as SQL, NoSQL, or even web services. With a considerable amount of options or flavors, how can we have a business away from these details or have a loose couple between the application and the persistence engine?

This presentation will discuss the new trends in the modern persistence model around enterprise architecture.

By Otavio Santana e Karina Varela
TDC Business São Paulo, 2022

Karina Macedo Varela

August 24, 2022
Tweet

More Decks by Karina Macedo Varela

Other Decks in Technology

Transcript

  1. Persistence made easy with Jakarta Data & NoSQL Otávio Santana

    Distinguished Engineer [email protected] Karina Varela Principal Technical Marketing Manager [email protected]
  2. A persistence drama ◦ Which persistence framework? ◦ Use spec

    capabilities only or… explore framework capabilities? ◦ Performance or development speed? Once upon a time…
  3. A persistence drama Once upon a time… ◦ Which design

    pattern? ◦ Decoupled code… ◦ SQL or NoSQL? ◦ Which database flavor?
  4. @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
  5. @otaviojava || @kvarel4 It's the first thing we do Change

    is hard and expensive Maintaining evolutionary data Challenges in a database land
  6. @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
  7. @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
  8. @otaviojava || @kvarel4 Challenges in a database land Different paradigms:

    Apps x DBMS Application Mismatch Database Heritage Polymorphism Encapsulation Types Normalization Denormalization Structure
  9. @otaviojava || @kvarel4 After exploring the database land, it's time

    to discuss about applications. How do you handle persistence in Java?
  10. @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)
  11. @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
  12. @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
  13. @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
  14. @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> address; … } Business ++ Too far away from database's aspects
  15. @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<Address> addresses; } Person person =...; // persist it person.persist(); List<Person> people = Person.listAll(); // finding a specific person by ID person = Person.findById(personId);
  16. @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<Address> addresses; } public interface PersonRepository extends <Person, String> { } Person person =...; // persist it repository.save(person); List<Person> people = Person.listAll(); // finding a specific person by ID person = repository.findById(personId);
  17. JPA Mature stack Active Record Repository Data Mapper … Design

    Patterns Quarkus Spring Data Micronaut … Technologies supports influences
  18. @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
  19. @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
  20. @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
  21. @otaviojava || @kvarel4 Jakarta Data The second Jakarta EE spec

    Data agnostic Approved, initial phases https://projects.eclipse.org/proposals/jakarta-data
  22. Thank you! Otávio Santana Software Engineer & Architect [email protected] @otaviojava

    osarchitech.com Karina Varela Principal Technical Marketing Manager [email protected] @kvarel4