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
  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
  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
  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…
  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
  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
  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()
  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
  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
  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
  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
  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
  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
  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
  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<Employee, Long> { List<Employee> findByLastName(String f) List<Employee> findByFirstNameAndLastName(String f, String l) List<Employee> findByFirstNameAndManagerName(String f, String m) List<Employee> findTop10ByFirstName(…) // or findFirst10ByFirstName List<Employee> findDistinctEmployeesByFirstName(...) List<Employee> findByFirstNameAndLastNameAllIgnoreCase(...) List<Employee> findByFirstNameOrderByLastNameAsc(...) List<Employee> findByLastNameIsNull(...) }
  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<Employee, Long> { Stream<Employee> findByLastname(String lastname) @Async Future<Employee> findByLastname(…) @Async CompletableFuture<Employee> findByLastname(…) @Async ListenableFuture<Employee> findByLastname(…) Page<Employee> findAll(Pageable p) Page<Employee> findByFirstName(String f, Pageable p) List<Employee> findAll(Sort s) Page<Employee> findByFirstName(String f, Pageable p, Sort s) }
  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<Employee, Long> { Mono<Employee> findByLastname(String lastname) Flux<Employee> findByLastname(…) } Integration with Spring 5 + Project Reactor
  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
  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