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

Introduction to Spring Data

Introduction to Spring Data

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? See how Spring Data provides the means to reduce that risk and give you the means to branch into other data stores. In this talk, you’ll see how to rapidly get off the ground with data persistence, how Spring Data supports lots of platforms, and also how you can take your solution and turn it into a REST service with just a few extra lines.

43e9a9d63f7f4f9891c9fcd592b89cfa?s=128

Greg Turnquist

February 17, 2016
Tweet

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2014 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 github.com/gregturn
  2. GregLTurnquist.com/list

  3. GregLTurnquist.com/list

  4. None
  5. We’re hiring! (Atlanta + the world) http://pivotal.io/careers

  6. It’s 2016

  7. It’s 2016 Why are we still writing…

  8. It’s 2016 Why are we still writing… select * from

    EMPLOYEE where FIRST_NAME = %1
  9. It’s 2016 Why are we still writing… select * from

    EMPLOYEE where FIRST_NAME = %1 select e from Employee e where e.firstName = :name
  10. It’s 2016 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()
  11. It’s 2016 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
  12. When we could write…

  13. When we could write… save(), findOne(), findAll() exists(), delete(), and

    count() …includes
  14. 10+ years ago SQL

  15. Today SQL NoSQL

  16. Today SQL NoSQL Cypher MongoDB CLI CQL OQL EJBQL HQL

    N1QL
  17. Spring Data provides… relational non-relational abstraction JDBC

  18. Spring Data provides… relational non-relational Elastic Solr Neo4j Cassandra MongoDB

    Gemfire Redis Couchbase abstraction JDBC
  19. Spring Data provides… relational non-relational Elastic Solr Neo4j Cassandra MongoDB

    Gemfire Redis Couchbase abstraction JDBC JPA
  20. Spring Data provides… relational non-relational Spring Data Elastic Solr Neo4j

    Cassandra MongoDB Gemfire Redis Couchbase abstraction JDBC JPA
  21. Spring Data provides… relational non-relational Spring Data Elastic Solr Neo4j

    Cassandra MongoDB Gemfire Redis Couchbase abstraction JDBC JPA Reactive support coming soon!
  22. Dialing it up 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(...) }
  23. Why stop there? 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) }
  24. Why stop there? 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) } Use @Query to write custom queries
  25. Demo Unless otherwise indicated, these slides are 
 © 2013-2014

    Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http:// creativecommons.org/licenses/by-nc/3.0/ Spring Data
  26. Links • http://projects.spring.io/spring-data • https://github.com/spring-projects/spring-data- examples • https://spring.io/guides/tutorials/react-and-spring- data-rest/ •

    https://spring.io/guides?filter=spring%20data
  27. Unless otherwise indicated, these slides are © 2013-2014 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 github.com/gregturn