Your SlideShare is downloading. ×
0
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Spring Data Repositories - Best Practices
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Spring Data Repositories - Best Practices

4,688

Published on

Speakers: Thomas Darimont and Oliver Gierke …

Speakers: Thomas Darimont and Oliver Gierke
The repository abstraction layer is one of the core pieces of the Spring Data projects. It provides a consistent, interface-based programming model to allow implementing data access layers easily for relational and NoSQL databases. We will have a look at the lessons learned from the application of it in various customer projects and summarize best practices for you to apply in your projects. The session will also discuss advanced features like the Querydsl integration, the integration of custom implementation code as well as hooks into Spring MVC and Spring HATEOAS.

Published in: Software
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,688
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
92
Comments
0
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Spring Data Repositories Best Practices Oliver Gierke & Thomas Darimont © 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Wednesday, September 11, 13
  • 2. Oliver Gierke Spring Data Engineer Project lead Core/JPA/MongoDB ogierke@gopivotal.com www.olivergierke.de olivergierke 2 Wednesday, September 11, 13
  • 3. Thomas Darimont Spring Data Engineer Core/JPA/MongoDB tdarimont@gopivotal.com www.tutorials.de thomasdarimont 3 Wednesday, September 11, 13
  • 4. Spring Data Modern Data Access For Enterprise Java JDBC Hive HBase Pig Splunk JPA Big Data Hadoop NoSQL Redis Roo Gemfire MongoDB Neo4j REST exporter Querydsl Repositories 1 free copy per attendee! 4 Wednesday, September 11, 13
  • 5. Get More Refcardz! Visit refcardz.com #184 Core Spring Data CONTENTS INCLUDE: About the Spring Data Project Configuration Support Object Mapping Template APIs Repositories By: Oliver Gierke Advanced Features... and more! ABOUT THE SPRING DATA PROJECT The Spring Data project is part of the ecosystem surrounding the Spring Framework and constitutes an umbrella project for advanced data access related topics. It contains modules to support traditional relational data stores (based on plain JDBC or JPA), NoSQL ones (like MongoDB, Neo4j or Redis), and big data technologies like Apache Hadoop. The core mission of the project is to provide a familiar and consistent Spring-based programming model for various data access technologies while retaining JPA XML element Description <jpa:repositories /> Enables Spring Data repositories support for repository interfaces underneath the package configured in the base-package attribute. JavaConfig equivalent is @EnableJpaRepositories. <jpa:auditing /> Enables transparent auditing of JPA managed entities. Note that this requires the AuditingEntityListener applied to the entity (either globally through a declaration in orm.xml or through @EntityListener on the entity class). General Themes MongoDB resources to access the underlying technology. This support is implemented using XML namespaces and support classes for Spring 5 Wednesday, September 11, 13 embedded Neo4j instance, and the like. Also, integration with core Spring functionality like JMX is provided, meaning that some stores will expose statistics through their native API, which will be exposed to JMX via Spring Data. Most of the NoSQL Java APIs do not provide support to map domain For Spring Data MongoDB XML namespace elements not mentioning a annotated method and use the plain Java APIs of the classes that would have otherwise been set up by the XML element. Alternatively, you can use MongoDB ships for convenience. XML element Description <mongo:db-factory /> One stop shop to set up a Mongo
  • 6. Hands on 6 Wednesday, September 11, 13
  • 7. Sample code https:/ /github.com/olivergierke/repositories-deepdive 7 Wednesday, September 11, 13
  • 8. Step 0 Initial project setup 8 Wednesday, September 11, 13
  • 9. " 9 Wednesday, September 11, 13 How to get a Spring Data JPA based project up and running quickly?
  • 10. Summary Check out Spring Boot Easily configure dependencies for your project Defaults application config based on classpath 10 Wednesday, September 11, 13
  • 11. Step 1 Basic JPA infrastructure setup 11 Wednesday, September 11, 13
  • 12. " 12 Wednesday, September 11, 13 Persistence technology of choice is JPA. e application uses JavaConfig and sample data contained in data.sql.
  • 13. Summary Easy setup through JavaConfig XML-less JPA configuration 13 Wednesday, September 11, 13
  • 14. Step 2 Quickstart 14 Wednesday, September 11, 13
  • 15. " 15 Wednesday, September 11, 13 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.
  • 16. Summary Interface-based programming model No implementation required Queries derived from method names 16 Wednesday, September 11, 13
  • 17. Step 3 Extended CRUD methods 17 Wednesday, September 11, 13
  • 18. " 18 Wednesday, September 11, 13 Customers can be deleted and obtained all at once.
  • 19. Summary Switched to CrudRepository Exposed CRUD methods Broad API exposed 19 Wednesday, September 11, 13
  • 20. Step 4 Pagination 20 Wednesday, September 11, 13
  • 21. " 21 Wednesday, September 11, 13 Customers can be accessed page by page.
  • 22. Summary Switched to PagingAndSortingRepository Exposed CRUD methods and paging ones Broad API exposed 22 Wednesday, September 11, 13
  • 23. Step 5 Re-declaring existing CRUD methods 23 Wednesday, September 11, 13
  • 24. " 24 Wednesday, September 11, 13 CustomerRepository.findAll() should rather return a List. e transaction timeout for save(…) should be customized to 10 seconds.
  • 25. Summary Re-declare methods to customize Return types Annotation config (Tx, Locking, Query, Hints) 25 Wednesday, September 11, 13
  • 26. Step 6 Introducing a read-only repository base interface 26 Wednesday, September 11, 13
  • 27. " 27 Wednesday, September 11, 13 Products shall be accessible in read-only mode only.
  • 28. Summary Craft custom base interface Return types Narrow down the API to the necessary parts 28 Wednesday, September 11, 13
  • 29. Step 7 Using manually defined queries 29 Wednesday, September 11, 13
  • 30. " 30 Wednesday, September 11, 13 As a user, I want to look up products by their custom attributes.
  • 31. Summary @Query annotation JPA named queries Spring Data named queries 31 Wednesday, September 11, 13
  • 32. Step 8 Flexible predicate execution 32 Wednesday, September 11, 13
  • 33. " 33 Wednesday, September 11, 13 As a user, I want to search for customers by first name, last name, email address and any combination of them
  • 34. Summary Querydsl - type safe queries for Java QuerydslPredicateExecutor 34 Wednesday, September 11, 13
  • 35. Side track: Repository proxies 35 Wednesday, September 11, 13
  • 36. Proxy mechanism Using Spring's JDK proxy support Bootstrap through Factory Spring FactroyBean / CDI XML namespace / @EnableRepositories 36 Wednesday, September 11, 13
  • 37. Proxy mechanism Query interface CRUD implementation class QueryDslPredicateExecutor Custom implementation extension 37 Wednesday, September 11, 13
  • 38. Step 9 Custom implementations for repositories 38 Wednesday, September 11, 13
  • 39. " 39 Wednesday, September 11, 13 As an admin user, I'd like to use custom code to delete all products beyond a given price.
  • 40. Summary Provide custom implementation Base class support (Querydsl) 40 Wednesday, September 11, 13
  • 41. Stuff on top Spring MVC integration Spring Data REST Spring Boot 41 Wednesday, September 11, 13
  • 42. Up and beyond 42 Wednesday, September 11, 13
  • 43. Supported modules JPA MongoDB Neo4j Gemfire 43 Wednesday, September 11, 13
  • 44. Community modules Solr Elasticsearch Couchbase FuzzyDB (Cassandra) 44 Wednesday, September 11, 13
  • 45. Further sessions Tackling Big Data Complexity with Spring - Wed, 2:30pm Your Data, Your Search, Elasticsearch - Wed, 2:30pm Spring Data Community Lightning Talks - Thu, 8:30am Researching Cancer in the Cloud with Spring - Thu, 12:45pm 45 Wednesday, September 11, 13
  • 46. Summary 46 Wednesday, September 11, 13
  • 47. Interface-based programming model 47 Wednesday, September 11, 13
  • 48. Start simple, get more sophisticated 48 Wednesday, September 11, 13
  • 49. Declarative query execution 49 Wednesday, September 11, 13
  • 50. Flexible predicate execution 50 Wednesday, September 11, 13
  • 51. Custom implementation 51 Wednesday, September 11, 13
  • 52. CDI integration 52 Wednesday, September 11, 13

×