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.

Christoph Strobl

May 10, 2017
Tweet

More Decks by Christoph Strobl

Other Decks in Programming

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

    View Slide

  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

    View Slide

  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

    View Slide

  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.

    View Slide

  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

    View Slide

  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.

    View Slide

  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 extends Repository {

    Ingalls
    public interface CrudRepository extends Repository {

    Kay

    View Slide

  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 extends Repository {


    /**

    * 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 extends Repository {


    /**

    * 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 findById(ID id);
    Kay

    View Slide

  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 extends Repository {


    T findOne(ID id);
    !
    S save(S entity);
    !
    Iterable save(Iterable entities);
    !
    Ingalls
    public interface CrudRepository extends Repository {


    findOne(…) -> findById(…)
    !
    save(Iterable) -> saveAll(Iterable)
    !
    findAll(Iterable) -> findAllById(…)
    !
    delete(ID) -> deleteById(ID)
    Kay

    View Slide

  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 extends CRUDRepository {


    Ingalls
    interface FooRepository extends Insertable, Readable {


    Kay
    M4

    View Slide

  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 extends CRUDRepository, CustomRepo {

    !
    interface CustomRepo { … }

    !
    class FooRepositoryImpl implements CustomRepo { … }
    Ingalls
    interface FooRepo extends Insertable, Readable, CustomRepo { … }

    !
    interface CustomRepo { … }

    !
    class CustomRepoImpl implements CustomRepo { … }
    Kay
    M4

    View Slide

  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 {

    !
    List find(Query query, Class entityClass);

    List find(Query query, Class entityClass, String collection);
    !
    List find(Query query, Class source, String collection, Class 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

    View Slide

  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

    View Slide

  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

    View Slide

  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.

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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)

    View Slide

  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
    Mono insert(S entity);
    Mono insert(Mono entity);
    Flux insertAll(Iterable entities);
    Flux insertAll(Publisher entities);
    Mono existsById(Mono id);
    Flux findAll();
    Mono count();
    Mono deleteById(ID id);
    !!...

    View Slide

  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 (0…n)
    Flux (0…n) Mono (0…1)
    Reactive Streams

    View Slide

  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 {
    !
    !
    !
    !
    !
    }
    Flux findAllByLastname(String lastname);
    Flux findAllByLastname(Mono lastname);
    Flux customQuery(String lastname);
    @Query("{lastname : ?0}");
    Flux findAllByLastname(String ln, Pageable page);

    View Slide

  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

    View Slide

  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 {
    }
    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 starks = Flux

    .fromStream(Stream.generate(() !-> 

    names[ramdom.nextInt(names.length-1)])

    .map(Person!::new));

    View Slide

  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 {
    }
    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 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();

    View Slide

  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 {
    Flux findAllByName(String name);
    }
    @RestController

    static class PersonController {


    PersonRepository repository;







    }
    @GetMapping("/")

    Flux fluxPersons(String name) {

    return repository.findAllByName(name);

    }


    View Slide

  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 {
    Flux findAllByName(String name);
    }
    @RestController

    static class PersonController {


    PersonRepository repository;







    }
    @GetMapping("/")

    Flux fluxPersons(String name) {

    return repository.findAllByName(name);

    }

    > cstrobl $ curl localhost:8080/?name=Eddard | jq
    !
    [
    {
    "name": "Eddard",
    "id": "591014f2756bac231a23f3a0"
    },
    {
    "name": "Eddard",
    "id": "591014f7756bac231a23f3a5"
    }
    ]
    !
    >

    View Slide

  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 {
    Observable findByName(String name);
    }
    @RestController

    static class PersonController {


    PersonRepository repository;


    @GetMapping("/rx")

    Observable rxPersons(String name) {

    return repository.findByName(name);

    }

    }

    View Slide

  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 {
    Observable findByName(String name);
    }
    @RestController

    static class PersonController {


    PersonRepository repository;


    @GetMapping("/rx")

    Observable 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"
    }
    ]
    !
    >

    View Slide

  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 {
    @Tailable Flux findBy();
    }
    @RestController

    static class PersonController {


    PersonRepository repository;


    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    Flux streamPersons() {

    return repository.findBy();

    }

    }

    View Slide

  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 {
    @Tailable Flux findBy();
    }
    @RestController

    static class PersonController {


    PersonRepository repository;


    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    Flux 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"}

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide