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

What's new in Spring Data Evans

What's new in Spring Data Evans

Presentation of What's new in Spring Data releast Train Evans at Voxxed Days Vienna 2015.

B0e9230af37f3a883c88d3f11c00e174?s=128

Christoph Strobl

February 06, 2015
Tweet

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s new in Spring Data? Christoph Strobl, Software Engineer, Pivotal Software Inc. @stroblchristoph
  2. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Agenda 2 Overview Core Themes Store Specifics Outlook / Q&A
  3. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Overview 3
  4. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11+ Modules 4
  5. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Modules 5 Commons Neo4j Gemfire JPA Solr ElasticSearch REST Cassandra Couchbase Redis MongoDB Community
 modules Core
 modules
  6. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Versions? 6
  7. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Release train ! Similar to the eclipse release model ! Modules still versioned independently ! Single canonical name —> Evans ! Communicate compatibility between modules ! Helps to avoid confusion with versions ! Now used by Spring Boot 7
  8. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Release train BOM <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-releasetrain</artifactId> <version>Evans-SR2</version> <scope>import</scope> <type>pom</type> </dependency> ! 8
  9. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Release train 9 03/2013 Arora 09/2013 Babbage 02/2014 Codd 05/2014 Dijkstra 09/2014 Evans 03/2015 Fowler*
  10. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Working with Spring Data 10
  11. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Goal… “Spring Data Repositories abstraction provides a uniform interface to access data from various data stores.” 11
  12. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interface based programming model 12 interface PersonRepository extends Repository<Person, Long> {}
  13. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interface based programming model 12 interface PersonRepository extends CrudRepository<Person, Long> {}
  14. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interface based programming model 12 interface PersonRepository extends PagingAndSortingRepository<Person, Long> {}
  15. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query Derivation 13 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } List<Person> findByFirstnameAndLastname(String firstname, String lastname);
  16. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query Derivation 13 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } List<Person> findByFirstnameAndLastname(String firstname, String lastname); @Query("select u from User u where u.firstname = ?0 and u.lastname = ?1")
  17. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query Derivation 13 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Page<Person> findByFirstname(String firstname, Pageable page); List<Person> findByFirstnameAndLastname(String firstname, String lastname); @Query("select u from User u where u.firstname = ?0 and u.lastname = ?1")
  18. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ QueryDSL Integration* 14 
 ! ! ! } Page<Person> findByFirstname(String firstname, Pageable page); List<Person> findByFirstnameAndLastname(String firstname, String lastname); , QueryDslPredicateExecutor { interface PersonRepository extends CrudRepository<Person, Long> @Query("select u from User u where u.firstname = ?0 and u.lastname = ?1")
  19. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Custom Implementations 15 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Page<Person> findByFirstname(String firstname, Pageable page); List<Person> findByFirstnameAndLastname(String firstname, String lastname); @Query("select u from Person p where p.firstname = ?0 and p.lastname = ?1") interface PersonRepositoryCustom { void springify(Person person) } 1 class PersonRepositoryImpl implements PersonRepositoryCustom { void springify(Person person) { ... } 2 ,PersonRepositoryCustom { 3
  20. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Core Themes
 Evans 16
  21. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Slices 17 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Page<Person> findByFirstname(String firstname, Pageable page); Paging without the overhead! Slice<Person> findByLastnameLike(String lastname, Pageable page);
  22. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Optional<T> 18 For both Java 8 and Google Guava! interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Optional<Person> findByLastname(String lastname); // ...
 personRepository.findByLastname("targaryen").orElse(johnDoe);
  23. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Default Methods 19 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Optional<Person> findByLastname(String lastname); default Optional<Customer> findByLastname(Customer cust) { return findByLastname(cust == null ? null : cust.lastname); }
  24. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Future<T> 20 use the async task execution infrastructure - @EnableAsync interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } @Async Future<Person> findByLastname(String lastname); // ...
 personRepository.findByLastname("lennister").get(5, SECONDS);
  25. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Repository Level Caching 21 use the cache infrastructure - @EnableCaching interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Person findByLastname(String lastname); @CacheConfig("persons") @CachePut(key="#person.lastname") <S extends Person> S save(S person); @Cacheable
  26. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Derived DeleteBy 22 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } Long deleteByLastname(String lastname); @Modifying @Transactional @Query("delete from Person p where p.lastname = ?1")
 void removeByLastname(String lastname); the simple alternative to @Modifying @Query
  27. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Limiting Results 23 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } List<Person> findTop5ByLastnameLike(String lastname); List<Person> findTop5By(Sort sort);
  28. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generic Query creation with SpEL 24 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! } @Modifying @Query("update #{#entityName} p set p.active= :activeState") void updateActiveState(@Param("activeState") boolean state); use the power of Spring Expression Language
  29. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi-Store configuration enhancements 25 … DEBUG … - Multiple Spring Data modules found, entering strict repository configuration mode! ! … DEBUG … - Spring Data JPA - Could not safely identify store assignment for repository candidate interface ….OrderRepository. ! … DEBUG … - Spring Data JPA - Registering repository:
 Interface: ….CustomerRepository Factory: ….JpaRepositoryFactoryBean
  30. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ And more…. ! Type safe Sort with QueryDSL ! CDI Improvements ! Common GeoSpatial Types ! Null Handling for Sort 26
  31. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hidden Gems 27
  32. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Repositories.class 28
  33. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RepositoryPopulator 29
  34. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Store Specifics
 Evans 30
  35. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data JPA 31
  36. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JPA 2.1 32 interface PersonRepository extends CrudRepository<Person, Long> { ! ! ! ! ! ! ! ! ! } Stored Procedures @Procedure("plus1inout") Integer explicitlyNamedPlus1inout(Integer arg); @Procedure Integer plus1inout(Integer arg); @Procedure(name = "Person.plus1IO") Integer entityAnnotatedCustomNamedProcedurePlus1IO(@Param("arg") Integer arg);
  37. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JPA 2.1 33 interface PersonRepository extends CrudRepository<Person, Long> { ! ! } Fetch Graphs @EntityGraph(type = EntityGraphType.LOAD, value = "Person.address") List<Person> findAll();
  38. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Security Integration 34 interface PersonRepository extends CrudRepository<Person, Long> { ! ! } @Query("..where o.email like ?#{hasRole('ROLE_ADMIN') ? '%' : principal.em...") List<BusinessObject> findBusinessObjectsForCurrentUser();
  39. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data MongoDB 35
  40. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Lazy Loading DBRefs 36 class Person { ! ! } @DBRef(lazy = true) User coworker;
  41. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Query Data 37 Set timeouts, comments and more! interface PersonRepository extends CrudRepository<Person, Long> { ! ! } @Meta(comment="voxxed-days-vienna15") List<Person> findByLastnameLike(String lastname);
  42. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Text Search 38 Simple and powerful full text search! interface PersonRepository extends CrudRepository<Person, Long> { ! ! } ! Page<Person> findAllBy(TextCriteria fullText, Pageable page);
  43. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Redis 39
  44. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SCAN Support 40 ! ScanOptions options = ScanOptions.scanOptions().count(99).build(); Cursor<String> cursor = setOperations.scan(key, options); ! while(cursor.hasNext()){ process(cursor.next()); } The non blocking alternative!
  45. Replication Unless otherwise indicated, these slides are © 2013-2015 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Redis Sentinel 41 Redis Master Redis Slave1 Redis Slave2 Sentinel Node1 Sentinel Node2 Sentinel Node3 for high availability systems!
  46. Replication Unless otherwise indicated, these slides are © 2013-2015 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Redis Sentinel 41 Redis Master Redis Slave1 Redis Slave2 Sentinel Node1 Sentinel Node2 Sentinel Node3 Redis Master for high availability systems!
  47. Replication Unless otherwise indicated, these slides are © 2013-2015 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Redis Sentinel 41 Redis Master Redis Slave1 Redis Slave2 Sentinel Node1 Sentinel Node2 Sentinel Node3 Redis Master Redis Master* for high availability systems!
  48. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Solr 42
  49. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Schema Support ! Usage of Schema Solr REST API ! Add new fields to existing schema. 43 @Configuration @EnableSolrRepositories(schemaCreationSupport = true) class SolrConfiguration { ! //...
  50. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Rest 44
  51. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ALPS Metadata 45 Describe Rest Resources, content-type, links, supported operations. ! { "version" : "1.0", "descriptors" : [ { "id" : "order-representation", "descriptors" : [ { "name" : "id", "type" : "SEMANTIC" }, { "name" : "items", "type" : "SEMANTIC", "descriptors" : [ { "name" : "price", ………
  52. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Excerpt Projections 46 { "_embedded" : { "orders" : [ { "items" : [ { "description" : "Lakewood guitar","price" : 1299.00 } ], "_embedded" : { "customer" : { "address" : "4711 Some Place, 54321 Charlottesville, VA", "firstname" : "Dave", "lastname" : "Matthews" } }, "_links" : { "self" : { "href" : “http://localhost:8080/orders/1" } } } ] }
  53. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JSON Patch Support 47 PATCH /my/data HTTP/1.1 Host: example.org Content-Length: 326 Content-Type: application/json-patch+json If-Match: "abc123" ! [ { "op": "test", "path": "/a/b/c", "value": "foo" }, { "op": "remove", "path": "/a/b/c" }, { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, { "op": "replace", "path": "/a/b/c", "value": 42 }, { "op": "move", "from": "/a/b/c", "path": "/a/b/d" }, { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" } ]
  54. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Where’s the code? 48
  55. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook Core Themes for Fowler 49
  56. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What will Fowler be all about… 50 GemFire 8 Performance REST Projections JSR-310 Improvements MongoDB Script Execution GeoJson Support Redis HyperLogLog Solr Stats Solr Realtime Get JPA Access Type Map Backed Interfaces CDI Support for SD Cassandra GemFire AsyncEventQueues RedisCache improvements @Version support for REST