$30 off During Our Annual Pro Sale. View Details »

Spring Data Repositories - A Deep Dive

Spring Data Repositories - A Deep Dive

Slides of my talk on Spring Data repositories at 33degree conference in Warszaw, Poland.

Oliver Drotbohm

March 14, 2013

More Decks by Oliver Drotbohm

Other Decks in Programming


  1. Spring Data Repositories A Deep Dive Oliver Gierke

  2. Oliver Gierke SpringSource Spring Data modules Core / JPA /

    Mongo ogierke@vmware.com www.olivergierke.de olivergierke
  3. Hands on

  4. Sample code https://github.com/olivergierke/ repositories-deepdive

  5. Step 0 Initial project setup

  6. Summary Use kickstart projects to ease setup

  7. Step 1 Basic JPA infrastructure setup

  8. "Persistence technology of choice is JPA. e application uses JavaConfig

    and sample data contained in data.sql.
  9. Summary Easy setup through JavaConfig XML-less JPA configuration

  10. Step 2 Quickstart

  11. "e implementation of the persistence layer will be based on

    the Spring Data repositories abstraction. Customers can be saved, looked up by their id, email address.
  12. Summary Interface-based programming model No implementation required Queries derived from

    method names
  13. Step 3 Extended CRUD methods

  14. " Customers can be deleted and obtained all at once.

  15. Summary Switched to CrudRepository Exposed CRUD methods Broad API exposed

  16. Step 4 Pagination

  17. "Customers can be accessed page by page.

  18. Summary Switched to PagingAndSortingRepository Exposed CRUD methods and paging ones

    Broad API exposed
  19. Step 5 Re-declaring existing CRUD methods

  20. "CustomerRepository.findAll() should rather return a List. e transaction timeout for

    save(…) should be customized to 10 seconds.
  21. Summary Re-declare methods to customize Return types Annotation config (Tx,

  22. Step 6 Introducing a read-only repository base interface

  23. "Products shall be accessible in read-only mode only.

  24. Summary Craft custom base interface Return types Annotation config (Tx,

  25. Step 7 Using manually defined queries

  26. "As a user, I want to look up products by

    their custom attributes.
  27. Summary @Query annotation JPA named queries Spring Data named queries

  28. Step 8 Flexible predicate execution

  29. "As a user, I want to search for customers by

    firstname, lastname, email address and any combination of them
  30. Summary Querydsl - type safe queries for Java QuerydslPredicateExecutor

  31. Side track: Repository proxies

  32. Proxy mechanism Using Spring's JDK proxy support Bootstrap through Factory

    Spring FactroyBean / CDI XML namespace / @EnableRepositories
  33. Proxy mechanism Query interface CRUD implementation class QueryDslPredicateExecutor Custom implementation

  34. Step 9 Custom implementations for repositories

  35. "As an admin user, I'd like to delete all products

    beyond a given price.
  36. Summary Provide custom implementation Base class support (Querydsl)

  37. Stuff on top Spring MVC integration Spring Data REST Spring

  38. Up and beyond

  39. Supported modules JPA MongoDB Neo4j Gemfire

  40. Community implementations Spring Data Solr Couchbase Elasticsearch FuzzyDB

  41. Summary

  42. Interface-based programming model

  43. Start simple, get more sophisticated

  44. Declarative query execution

  45. Flexible predicate execution

  46. Custom implementation

  47. CDI integration

  48. Spring Data Modern Data Access For Enterprise Java NoSQL JPA

    JDBC Redis Big Data Hadoop HBase MongoDB Neo4j REST exporter Roo Hive Pig Querydsl Repositories Gemfire Splunk Free JPA chapter - http://bit.ly/sd-book-chapter
  49. Spring Data Book http://bit.ly/sd-book

  50. Questions?

  51. Thank you!

  52. Code https://github.com/olivergierke/ repositories-deepdive https://github.com/olivergierke/ spring-restbucks