Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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…

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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()

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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(...) }

Slide 16

Slide 16 text

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) }

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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