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

Sneak Peek on Spring Data Kay

Sneak Peek on Spring Data Kay

Overview of current state and outlook on Spring Data release train Kay presented at Jax conference.

B0e9230af37f3a883c88d3f11c00e174?s=128

Christoph Strobl

May 10, 2017
Tweet

Transcript

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

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Christoph Strobl
 Pivotal Software Inc.
 @stroblchristoph Sneak Peek on Spring Data Kay
  2. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The next 60 Minutes 2 Core Themes Store Specifics Some Code
  3. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Where are we today? M1 Nov. 2016 M2 Apr. 2017 M3 May 2017 M4 Jun. 2017 RC1 Jun. 2017 GA Jul. 2017 2
  4. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ One word of caution 4 The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre- release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. We’re still working on it!
 Stuff I show you today might change tomorrow.
  5. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Core Themes 5 Java 8 Baseline Core Concept Revisit Reactive Data Access
  6. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Java 8 Baseline 6 Use of language level features. Get rid of the bloody hacks. Revisit some of the concepts.
  7. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ No more Serializable 7 public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> {
 Ingalls public interface CrudRepository<T, ID> extends Repository<T, ID> {
 Kay
  8. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ No more null 8 public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> {
 
 /**
 * Retrieves an entity by its id.
 * 
 * @param id must not be {@literal null}.
 * @return the entity with the given id or {@literal null} if none found.
 * @throws IllegalArgumentException if {@code id} is {@literal null}.
 */
 T findOne(ID id); Ingalls public interface CrudRepository<T, ID> extends Repository<T, ID> {
 
 /**
 * Retrieves an entity by its id.
 * 
 * @param id must not be {@literal null}.
 * @return the entity with the given id or {@literal Optional#empty()} if none found.
 * @throws IllegalArgumentException if {@code id} is {@literal null}.
 */
 Optional<T> findById(ID id); Kay
  9. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consistent naming 9 public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> {
 
 T findOne(ID id); ! <S extends T> S save(S entity); ! <S extends T> Iterable<S> save(Iterable<S> entities); ! Ingalls public interface CrudRepository<T, ID> extends Repository<T, ID> {
 
 findOne(…) -> findById(…) ! save(Iterable) -> saveAll(Iterable) ! findAll(Iterable<ID>) -> findAllById(…) ! delete(ID) -> deleteById(ID) Kay
  10. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Composable interfaces 10 interface FooRepository<T, ID extends Serializable> extends CRUDRepository<T, ID> {
 
 Ingalls interface FooRepository<T, ID> extends Insertable<T, ID>, Readable<T, ID> {
 
 Kay M4
  11. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Composable interfaces II - Custom implementations 11 interface FooRepo<T, ID extends Serializable> extends CRUDRepository<T, ID>, CustomRepo {
 ! interface CustomRepo { … }
 ! class FooRepositoryImpl implements CustomRepo { … } Ingalls interface FooRepo<T, ID> extends Insertable<T, ID>, Readable<T, ID>, CustomRepo { … }
 ! interface CustomRepo { … }
 ! class CustomRepoImpl implements CustomRepo { … } Kay M4
  12. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Builder style Template APIs 12 interface MongoOperations {
 ! <T> List<T> find(Query query, Class<T> entityClass); 
 <T> List<T> find(Query query, Class<T> entityClass, String collection); ! <S,T> List<T> find(Query query, Class<S> source, String collection, Class<T> target);
 ! ! template.find(query(where("name").is("luke")), Person.class, "star-wars", Jedi.class); Ingalls interface FindExecutionBuilder, MappingToBuilder, InCollectionBuilder,… ! ! template.query(Person.class) .inCollection("star-wars") .returning(Jedi.class) .findBy(query(where("name").is("luke")); M4 Kay
  13. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

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

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Store Specifics 14 Full switch to MongoDB Java Driver 3.x
 Reactive MongoTemplate & MongoRepository
 Enhanced Aggregation support
 Collation Support Upgrade to Cassandra 3.2
 Revised Template API
 Reactive CassandraTemplate & CassandraRepository
 Merge Spring CQL into Spring Data for Apache Cassandra SRP & JRedis support discontinued
 Upgrade to Lettuce 5
 Reactive RedisConnection & RedisTemplate
  15. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Store Specifics 15 Off-Heap, Redis Adapter and Security Annotation configuration
 Lucence index support Upgarde to Apache Solr 6
 Enhanced collection API CORS configuration mechanisms.
 Improved If-None-Match and If-Modified-Since header.
 Support for more media types.
  16. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Data Access 16 Spring Framework
 5 Project Reactor
 3 Spring Data
 Kay
  17. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Synchronous Data Access 17 {…} Thread: MAIN
  18. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Synchronous Data Access II 18 {…} Thread: MAIN Batching
  19. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous Data Access 19 {…} Dispatcher Thread: MAIN Thread: Worker A Thread: Worker B Thread: Worker C
  20. {…} {…} {…} Unless otherwise indicated, these slides are ©

    2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous Data Access II 20 {…} Dispatcher Thread: MAIN Thread: Worker A Thread: Worker B Thread: Worker C Scaling
  21. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Data Access 21 {…} Subscriber Publisher Stream
  22. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Data Access 22 {…} Stream Thread: MAIN Subscriber Publisher
  23. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Data Access 23 {…} Thread: Worker A Thread: Worker A Stream Subscriber Publisher
  24. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Data Access 24 {…} Subscriber Publisher Stream Thread: Worker A Thread: Worker B
  25. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25 Iterator.next() Future.get() Subscriber.onNext(t)
  26. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Repository 26 <S extends T> Mono<S> insert(S entity); <S extends T> Mono<S> insert(Mono<S> entity); <S extends T> Flux<S> insertAll(Iterable<S> entities); <S extends T> Flux<S> insertAll(Publisher<S> entities); Mono<Boolean> existsById(Mono<ID> id); Flux<T> findAll(); Mono<Long> count(); Mono<Void> deleteById(ID id); !!...
  27. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor & Reactive Streams 27 Publisher<T> (0…n) Flux<T> (0…n) Mono<T> (0…1) Reactive Streams
  28. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive 28 interface Repo extends ReactiveCrudRepository<Person, String> { ! ! ! ! ! } Flux<Person> findAllByLastname(String lastname); Flux<Person> findAllByLastname(Mono<String> lastname); Flux<Person> customQuery(String lastname); @Query("{lastname : ?0}"); Flux<Person> findAllByLastname(String ln, Pageable page);
  29. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ It’s Demo Time https://github.com/christophstrobl/spring-data-reactive-demo/tree/jax2017
  30. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - Repository 30 interface PersonRepository extends ReactiveCrudRepository<Person, String> { } Flux.interval(Duration.ofSeconds(1))
 .zipWith(starks)
 .map(Tuple2!::getT2)
 .flatMap(repository!::save)
 .subscribe(); String[] names = { "Eddard", "Catelyn", "Jon", "Rob", "Sansa", "Aria", "Bran", "Rickon" };
 Flux<Person> starks = Flux
 .fromStream(Stream.generate(() !-> 
 names[ramdom.nextInt(names.length-1)])
 .map(Person!::new));
  31. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - Repository 31 interface PersonRepository extends ReactiveCrudRepository<Person, String> { } Flux.interval(Duration.ofSeconds(1))
 .zipWith(starks)
 .map(Tuple2!::getT2)
 .flatMap(repository!::save)
 .subscribe(); String[] names = { "Eddard", "Catelyn", "Jon", "Rob", "Sansa", "Aria", "Bran", "Rickon" };
 Flux<Person> starks = Flux
 .fromStream(Stream.generate(() !-> 
 names[ramdom.nextInt(names.length-1)])
 .map(Person!::new)); > cstrobl $ ./bin/mongo --port 52291 ! > use test switched to db test ! { "_id" : ObjectId("591009c5ed68a820fb9956a5"), "name" : "Sansa", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009c6ed68a820fb9956a6"), "name" : "Rob", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009c7ed68a820fb9956a7"), "name" : "Sansa", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009c8ed68a820fb9956a8"), "name" : "Rob", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009c9ed68a820fb9956a9"), "name" : "Jon", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009caed68a820fb9956aa"), "name" : "Aria", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009cbed68a820fb9956ab"), "name" : "Rob", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009cced68a820fb9956ac"), "name" : "Jon", "_class" : "com.example.DemoApplication$Person" } { "_id" : ObjectId("591009cded68a820fb9956ad"), "name" : "Sansa", "_class" : "com.example.DemoApplication$Person" } > db.person.find();
  32. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - WebFlux 32 interface PersonRepository extends ReactiveCrudRepository<Person, String> { Flux<Person> findAllByName(String name); } @RestController
 static class PersonController {
 
 PersonRepository repository;
 
 
 
 
 
 
 } @GetMapping("/")
 Flux<Person> fluxPersons(String name) {
 return repository.findAllByName(name);
 }

  33. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - WebFlux 33 interface PersonRepository extends ReactiveCrudRepository<Person, String> { Flux<Person> findAllByName(String name); } @RestController
 static class PersonController {
 
 PersonRepository repository;
 
 
 
 
 
 
 } @GetMapping("/")
 Flux<Person> fluxPersons(String name) {
 return repository.findAllByName(name);
 }
 > cstrobl $ curl localhost:8080/?name=Eddard | jq ! [ { "name": "Eddard", "id": "591014f2756bac231a23f3a0" }, { "name": "Eddard", "id": "591014f7756bac231a23f3a5" } ] ! >
  34. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - RxJava types 34 interface PersonRepository extends ReactiveCrudRepository<Person, String> { Observable<Person> findByName(String name); } @RestController
 static class PersonController {
 
 PersonRepository repository;
 
 @GetMapping("/rx")
 Observable<Person> rxPersons(String name) {
 return repository.findByName(name);
 }
 }
  35. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - RxJava types 35 interface PersonRepository extends ReactiveCrudRepository<Person, String> { Observable<Person> findByName(String name); } @RestController
 static class PersonController {
 
 PersonRepository repository;
 
 @GetMapping("/rx")
 Observable<Person> rxPersons(String name) {
 return repository.findByName(name);
 }
 } > cstrobl $ curl localhost:8080/rx?name=Rob | jq ! [ { "name": "Rob", "id": "590f6e99756bac18a8d62bfe" }, { "name": "Rob", "id": "590f6e9d756bac18a8d62c02" } { "name": "Rob", "id": "590f6e9e756bac18a8d62c03" } ] ! >
  36. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - Event Stream 36 interface PersonRepository extends ReactiveCrudRepository<Person, String> { @Tailable Flux<Person> findBy(); } @RestController
 static class PersonController {
 
 PersonRepository repository;
 
 @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) Flux<Person> streamPersons() {
 return repository.findBy();
 }
 }
  37. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Reactive - Event Stream 37 interface PersonRepository extends ReactiveCrudRepository<Person, String> { @Tailable Flux<Person> findBy(); } @RestController
 static class PersonController {
 
 PersonRepository repository;
 
 @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) Flux<Person> streamPersons() {
 return repository.findBy();
 }
 } > cstrobl $ curl localhost:8080/stream ! data:{"name":"Sansa","id":"5910192e756bac26079dd623"} ! data:{"name":"Jon","id":"5910192f756bac26079dd624"} ! data:{"name":"Catelyn","id":"59101930756bac26079dd625"} ! data:{"name":"Eddard","id":"59101931756bac26079dd626"} ! data:{"name":"Jon","id":"59101932756bac26079dd627"} ! data:{"name":"Eddard","id":"59101933756bac26079dd628"}
  38. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 38 We need you! …give it a try!
 …tell us what you think!
 …contribute new ideas!
 …report issues! Spring 5 - RC1 Spring Boot 2 - M1 Spring Data Kay - M3
  39. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 39 More 15:00 - 16:00 Next Level Spring Boot Tooling
 Martin Lippert - Gutenberg Saal 2 ! 15:00 - 19:00 Microservices mit Spring Cloud und Spring Boot
 Eberhard Wolff - Zagreb ! 16:45 - 17:45 Spring Cloud Data Flow
 Nicolas Byl - Gutenberg Saal 2 ! 18:15 - 19:15 Sicher in die Cloud mit Angular 2 und Spring Boot
 Andreas Falk - Gutenberg Saal 2
  40. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 40 Learn More. Stay Connected. Twitter: twitter.com/springcentral YouTube: spring.io/video LinkedIn: spring.io/linkedin Google Plus: spring.io/gplus