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

Introduction to Spring Data @ SpringOne Platform 2016

Introduction to Spring Data @ SpringOne Platform 2016

It’s 2016. Are you still writing data queries by hand? Learn how Spring Data gives you the tools to leap over that hurdle and dive into solving problems. Feeling locked into your relational database due to having written gobs of SQL operations? In this live coding session, see how Spring Data provides the means to reduce that risk and give you the means to branch into other data stores. With a couple extra lines of code, you can even have a RESTful interface in no time flat.

Greg Turnquist

August 02, 2016
Tweet

More Decks by Greg Turnquist

Other Decks in Technology

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Introduction to Spring Data
    Greg Turnquist
    @gregturn

    View full-size slide

  2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Who am I?
    2
    GregLTurnquist.com/learning-spring-boot

    View full-size slide

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

    View full-size slide

  4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    It’s 2016
    4
    Why are we still writing…

    View full-size slide

  5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    It’s 2016
    4
    Why are we still writing…
    select * from EMPLOYEE
    where FIRST_NAME = %1

    View full-size slide

  6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    It’s 2016
    4
    Why are we still writing…
    select * from EMPLOYEE
    where FIRST_NAME = %1
    select e from Employee e
    where e.firstName = :name

    View full-size slide

  7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    It’s 2016
    4
    Why are we still writing…
    select * from EMPLOYEE
    where FIRST_NAME = %1
    select e from Employee e
    where e.firstName = :name
    create
    .select()
    .from(EMPLOYEE)
    .where(EMPLOYEE.FIRST_NAME
    .equal(name))
    .fetch()

    View full-size slide

  8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    It’s 2016
    4
    Why are we still writing…
    select * from EMPLOYEE
    where FIRST_NAME = %1
    select e from Employee e
    where e.firstName = :name
    create
    .select()
    .from(EMPLOYEE)
    .where(EMPLOYEE.FIRST_NAME
    .equal(name))
    .fetch()
    SQL
    JPA
    jOOQ

    View full-size slide

  9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    When we could write…
    5

    View full-size slide

  10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    When we could write…
    5

    View full-size slide

  11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data provides…
    6
    relational non-relational
    abstraction
    JDBC

    View full-size slide

  12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data provides…
    6
    relational non-relational
    Elastic
    Solr
    Neo4j
    Cassandra
    MongoDB Gemfire
    Redis
    Couchbase
    abstraction
    JDBC

    View full-size slide

  13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data provides…
    6
    relational non-relational
    Elastic
    Solr
    Neo4j
    Cassandra
    MongoDB Gemfire
    Redis
    Couchbase
    abstraction
    JDBC
    JPA

    View full-size slide

  14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data provides…
    6
    relational non-relational
    Spring Data
    Elastic
    Solr
    Neo4j
    Cassandra
    MongoDB Gemfire
    Redis
    Couchbase
    abstraction
    JDBC
    JPA

    View full-size slide

  15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Dialing it up
    7
    interface EmployeeRepository extends CrudRepository {
    List findByLastName(String f)
    List findByFirstNameAndLastName(String f, String l)
    List findByFirstNameAndManagerName(String f, String m)
    List findTop10ByFirstName(…) // or findFirst10ByFirstName
    List findDistinctEmployeesByFirstName(...)
    List findByFirstNameAndLastNameAllIgnoreCase(...)
    List findByFirstNameOrderByLastNameAsc(...)
    List findByLastNameIsNull(...)
    }

    View full-size slide

  16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Why stop there?
    8
    interface CoolRepo extends CrudRepository {
    Stream findByLastname(String lastname)
    @Async Future findByLastname(…)
    @Async CompletableFuture findByLastname(…)
    @Async ListenableFuture findByLastname(…)
    Page findAll(Pageable p)
    Page findByFirstName(String f, Pageable p)
    List findAll(Sort s)
    Page findByFirstName(String f, Pageable p, Sort s)
    }

    View full-size slide

  17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Coming soon…
    9
    interface ReactiveStreamsRepo extends CrudRepository {
    Mono findByLastname(String lastname)
    Flux findByLastname(…)
    }
    Integration with Spring 5 + Project Reactor

    View full-size slide

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

    View full-size slide

  19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Introduction to Spring Data
    Visit spring.io/guides, type “data”, and enjoy!
    See all talks by Oliver Gierke, Christoph Stroble, Mark Paluch, & John Blum
    and
    Spinnaker: Land of a 1000 Builds - later today @ 5pm
    @springcentral
    spring.io/blog
    @pivotal
    pivotal.io/blog
    @pivotalcf
    http://engineering.pivotal.io

    View full-size slide