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

Spring Data Cookbook

Spring Data Cookbook

No matter if you have just discovered your passion for cooking or are already an advanced chef, in this session we discover ways to bake applications that deliver everything from persistence to web using your favourite ingredients. Let us explore classic data repository recipes and introduce fresh compositions leveraging latest Spring functionality along with JPA and a touch of NoSQL, mixing in result limits and keyset scrolling, rounding things off with an icing made of observability & metrics.

Christoph Strobl

May 31, 2024
Tweet

More Decks by Christoph Strobl

Other Decks in Programming

Transcript

  1. Spring Data Cookbook Delicious Recipes for Fast, Secure Data INGREDIENTS

    - 8 c Innovation - 2 tsp DDD - 5 Repository Interfaces - 12 Store Modules - a pinch of devs 2024 Edition - Christoph Strobl Image by: private photo
  2. Image by: private photo The ambition of every good cook


    must be to make something 
 very good
 with the fewest possible 
 ingredients. Urbain Dubois
 French chef (1818-1901) Preface
  3. The SD Domain Image source: Microsoft Stock Photos A type

    holding user de fi ned information within a given scope / problem space. Domain Type An extension to a repository that provides additional domain speci fi c functionality. Custom Implementation An isolated view based on an aggregate root. Projection Low level API managing resources and transaction boundaries. Template Interface to access persistent collections of aggregate roots. Repository A cluster of domain types that can be treated as a single unit. Aggregate Root
  4. Equalicense CC0 Image source: Microsoft Stock Photos Pancakes INGREDIENTS -

    Packages & Visibility - Domain Types - Repository Interface Topping: - Executor Addons - Custom Implementations
  5. Order Order, LineItem, … OrderRepository OrderManagement Repository PagingAndSortingRepository CrudRepository ListCrudRepository

    ListPagingAndSortingRepository JpaRepository (Try to) Avoid leaking store speci fi cs like entityManager. fl ush() into your repository.
  6. Annotation Sauce JPA Flavoured Try store speci fi c fl

    avours. Each one o ff ers a unique taste.
  7. Image source: Microsoft Stock Photos BBQ Skewers INGREDIENTS - Packages

    & Visibility - Domain Types - Repository Interface Topping: - Prede fi ned Layout - Executor Addons - Custom Implementations Image source: Microsoft Stock Photos INGREDIENTS - Collections - Streams - Slice & Pages - Windows Variations: - Reactive - Async
  8. Window Skewer selected DB fl avours only o ff set

    skip limit keyset position limit hasNext
  9. Iterable List Stream Slice Page Window Flux size total next

    data
 loaded count
 query scroll
 strategy n n n+1 n+1 n driver request o ff set o ff set o ff set o ff set o ff set o ff set keyset / o ff set n n n n n n y
  10. Red Beans Burger INGREDIENTS - Projections - Entity Converters -

    Property Converters Image source: Microsoft Stock Photos
  11. Open Projection Closed Projections are backed by Maps holding only

    the required subset of fi elds required to render the view. Open Projections are backed by the entire target domain type loaded into memory.
  12. Custom Conversion selected DB fl avours only Property Converter You

    can also register converter as beans
 to leverage the full application context.
  13. null -> EmptyResultDataAccessException null Order#34 Nullability Annotations leverage 
 JSR-305

    meta-annotations 
 to indicate nullability to tools 
 and Kotlin. jsr 305 placeholder
  14. Runtimes Considerations GraalVM CRaC CDS Closed World Compatibility Built Time

    Fixed Bean Conditions
 No dynamic class loading Additional Metadata for
 re fl ection, proxies,… Checkpoint
 startup Need to start 
 the App ahead
 Lifecycle
 management Need to close/reopen
 sockets, fi les, … Secret
 management Sensitive information 
 may be leaked System
 Integration Linux only Training
 run Need to start 
 the App ahead
 Lifecycle
 management Lazy resource 
 connect takes longer