Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Spring Data Repositories
Best Practices
Oliver Gierke & Thomas Darimont

© 2013 SpringOne 2GX. All rights reserved. Do not...
Oliver Gierke
Spring Data Engineer
Project lead Core/JPA/MongoDB
ogierke@gopivotal.com
www.olivergierke.de
olivergierke

2...
Thomas Darimont
Spring Data Engineer
Core/JPA/MongoDB
tdarimont@gopivotal.com
www.tutorials.de
thomasdarimont

3
Wednesday...
Spring Data
Modern Data Access For Enterprise Java

JDBC

Hive

HBase Pig Splunk
JPA
Big Data Hadoop
NoSQL
Redis Roo Gemfir...
Get More Refcardz! Visit refcardz.com

#184

Core Spring Data

CONTENTS INCLUDE:
About the Spring Data Project
Configurati...
Hands on

6
Wednesday, September 11, 13
Sample code
https:/
/github.com/olivergierke/repositories-deepdive

7
Wednesday, September 11, 13
Step 0
Initial project setup

8
Wednesday, September 11, 13
"
9
Wednesday, September 11, 13

How to get a Spring Data JPA based project up and
running quickly?
Summary
Check out Spring Boot
Easily configure dependencies for your project
Defaults application config based on classpat...
Step 1
Basic JPA infrastructure setup

11
Wednesday, September 11, 13
"
12
Wednesday, September 11, 13

Persistence technology of choice is JPA. e application
uses JavaConfig and sample data c...
Summary
Easy setup through JavaConfig
XML-less JPA configuration

13
Wednesday, September 11, 13
Step 2
Quickstart

14
Wednesday, September 11, 13
"
15
Wednesday, September 11, 13

e implementation of the persistence layer will be
based on the Spring Data repositories...
Summary
Interface-based programming model
No implementation required
Queries derived from method names

16
Wednesday, Sept...
Step 3
Extended CRUD methods

17
Wednesday, September 11, 13
"
18
Wednesday, September 11, 13

Customers can be deleted and obtained all at once.
Summary
Switched to CrudRepository
Exposed CRUD methods
Broad API exposed

19
Wednesday, September 11, 13
Step 4
Pagination

20
Wednesday, September 11, 13
"
21
Wednesday, September 11, 13

Customers can be accessed page by page.
Summary
Switched to PagingAndSortingRepository
Exposed CRUD methods and paging ones
Broad API exposed

22
Wednesday, Septe...
Step 5
Re-declaring existing CRUD methods

23
Wednesday, September 11, 13
"
24
Wednesday, September 11, 13

CustomerRepository.findAll() should rather return a
List. e transaction timeout for save...
Summary
Re-declare methods to customize
Return types
Annotation config (Tx, Locking, Query, Hints)

25
Wednesday, Septembe...
Step 6
Introducing a read-only repository base interface

26
Wednesday, September 11, 13
"
27
Wednesday, September 11, 13

Products shall be accessible in read-only mode only.
Summary
Craft custom base interface
Return types
Narrow down the API to the necessary parts

28
Wednesday, September 11, 1...
Step 7
Using manually defined queries

29
Wednesday, September 11, 13
"
30
Wednesday, September 11, 13

As a user, I want to look up products by their custom
attributes.
Summary
@Query annotation
JPA named queries
Spring Data named queries

31
Wednesday, September 11, 13
Step 8
Flexible predicate execution

32
Wednesday, September 11, 13
"
33
Wednesday, September 11, 13

As a user, I want to search for customers by first name,
last name, email address and any...
Summary
Querydsl - type safe queries for Java
QuerydslPredicateExecutor

34
Wednesday, September 11, 13
Side track:
Repository proxies

35
Wednesday, September 11, 13
Proxy mechanism
Using Spring's JDK proxy support
Bootstrap through Factory
Spring FactroyBean / CDI
XML namespace / @Enabl...
Proxy mechanism
Query interface
CRUD implementation class
QueryDslPredicateExecutor
Custom implementation extension

37
We...
Step 9
Custom implementations for repositories

38
Wednesday, September 11, 13
"
39
Wednesday, September 11, 13

As an admin user, I'd like to use custom code to delete
all products beyond a given pric...
Summary
Provide custom implementation
Base class support (Querydsl)

40
Wednesday, September 11, 13
Stuff on top
Spring MVC integration
Spring Data REST
Spring Boot

41
Wednesday, September 11, 13
Up and beyond

42
Wednesday, September 11, 13
Supported modules
JPA
MongoDB
Neo4j
Gemfire

43
Wednesday, September 11, 13
Community modules
Solr
Elasticsearch
Couchbase
FuzzyDB
(Cassandra)
44
Wednesday, September 11, 13
Further sessions
Tackling Big Data Complexity with Spring - Wed, 2:30pm
Your Data, Your Search, Elasticsearch - Wed, 2:30p...
Summary

46
Wednesday, September 11, 13
Interface-based
programming model

47
Wednesday, September 11, 13
Start simple, get
more sophisticated

48
Wednesday, September 11, 13
Declarative
query execution

49
Wednesday, September 11, 13
Flexible predicate
execution

50
Wednesday, September 11, 13
Custom
implementation

51
Wednesday, September 11, 13
CDI integration

52
Wednesday, September 11, 13
Nächste SlideShare
Wird geladen in …5
×

Spring Data Repositories - Best Practices

12.499 Aufrufe

Veröffentlicht am

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.

Veröffentlicht in: Software
  • Did u try to use external powers for studying? Like ⇒ www.HelpWriting.net ⇐ ? They helped me a lot once.
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Sex in your area is here: ❶❶❶ http://bit.ly/39mQKz3 ❶❶❶
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39mQKz3 ❶❶❶
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier

Spring Data Repositories - Best Practices

  1. 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. 2. Oliver Gierke Spring Data Engineer Project lead Core/JPA/MongoDB ogierke@gopivotal.com www.olivergierke.de olivergierke 2 Wednesday, September 11, 13
  3. 3. Thomas Darimont Spring Data Engineer Core/JPA/MongoDB tdarimont@gopivotal.com www.tutorials.de thomasdarimont 3 Wednesday, September 11, 13
  4. 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. 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. 6. Hands on 6 Wednesday, September 11, 13
  7. 7. Sample code https:/ /github.com/olivergierke/repositories-deepdive 7 Wednesday, September 11, 13
  8. 8. Step 0 Initial project setup 8 Wednesday, September 11, 13
  9. 9. " 9 Wednesday, September 11, 13 How to get a Spring Data JPA based project up and running quickly?
  10. 10. Summary Check out Spring Boot Easily configure dependencies for your project Defaults application config based on classpath 10 Wednesday, September 11, 13
  11. 11. Step 1 Basic JPA infrastructure setup 11 Wednesday, September 11, 13
  12. 12. " 12 Wednesday, September 11, 13 Persistence technology of choice is JPA. e application uses JavaConfig and sample data contained in data.sql.
  13. 13. Summary Easy setup through JavaConfig XML-less JPA configuration 13 Wednesday, September 11, 13
  14. 14. Step 2 Quickstart 14 Wednesday, September 11, 13
  15. 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. 16. Summary Interface-based programming model No implementation required Queries derived from method names 16 Wednesday, September 11, 13
  17. 17. Step 3 Extended CRUD methods 17 Wednesday, September 11, 13
  18. 18. " 18 Wednesday, September 11, 13 Customers can be deleted and obtained all at once.
  19. 19. Summary Switched to CrudRepository Exposed CRUD methods Broad API exposed 19 Wednesday, September 11, 13
  20. 20. Step 4 Pagination 20 Wednesday, September 11, 13
  21. 21. " 21 Wednesday, September 11, 13 Customers can be accessed page by page.
  22. 22. Summary Switched to PagingAndSortingRepository Exposed CRUD methods and paging ones Broad API exposed 22 Wednesday, September 11, 13
  23. 23. Step 5 Re-declaring existing CRUD methods 23 Wednesday, September 11, 13
  24. 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. 25. Summary Re-declare methods to customize Return types Annotation config (Tx, Locking, Query, Hints) 25 Wednesday, September 11, 13
  26. 26. Step 6 Introducing a read-only repository base interface 26 Wednesday, September 11, 13
  27. 27. " 27 Wednesday, September 11, 13 Products shall be accessible in read-only mode only.
  28. 28. Summary Craft custom base interface Return types Narrow down the API to the necessary parts 28 Wednesday, September 11, 13
  29. 29. Step 7 Using manually defined queries 29 Wednesday, September 11, 13
  30. 30. " 30 Wednesday, September 11, 13 As a user, I want to look up products by their custom attributes.
  31. 31. Summary @Query annotation JPA named queries Spring Data named queries 31 Wednesday, September 11, 13
  32. 32. Step 8 Flexible predicate execution 32 Wednesday, September 11, 13
  33. 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. 34. Summary Querydsl - type safe queries for Java QuerydslPredicateExecutor 34 Wednesday, September 11, 13
  35. 35. Side track: Repository proxies 35 Wednesday, September 11, 13
  36. 36. Proxy mechanism Using Spring's JDK proxy support Bootstrap through Factory Spring FactroyBean / CDI XML namespace / @EnableRepositories 36 Wednesday, September 11, 13
  37. 37. Proxy mechanism Query interface CRUD implementation class QueryDslPredicateExecutor Custom implementation extension 37 Wednesday, September 11, 13
  38. 38. Step 9 Custom implementations for repositories 38 Wednesday, September 11, 13
  39. 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. 40. Summary Provide custom implementation Base class support (Querydsl) 40 Wednesday, September 11, 13
  41. 41. Stuff on top Spring MVC integration Spring Data REST Spring Boot 41 Wednesday, September 11, 13
  42. 42. Up and beyond 42 Wednesday, September 11, 13
  43. 43. Supported modules JPA MongoDB Neo4j Gemfire 43 Wednesday, September 11, 13
  44. 44. Community modules Solr Elasticsearch Couchbase FuzzyDB (Cassandra) 44 Wednesday, September 11, 13
  45. 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. 46. Summary 46 Wednesday, September 11, 13
  47. 47. Interface-based programming model 47 Wednesday, September 11, 13
  48. 48. Start simple, get more sophisticated 48 Wednesday, September 11, 13
  49. 49. Declarative query execution 49 Wednesday, September 11, 13
  50. 50. Flexible predicate execution 50 Wednesday, September 11, 13
  51. 51. Custom implementation 51 Wednesday, September 11, 13
  52. 52. CDI integration 52 Wednesday, September 11, 13

×