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.

Greg Turnquist

February 17, 2016
Tweet

More Decks by Greg Turnquist

Other Decks in Technology

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. It’s 2016 Why are we still writing… select * from

    EMPLOYEE where FIRST_NAME = %1 select e from Employee e where e.firstName = :name
  3. 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()
  4. 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
  5. Spring Data provides… relational non-relational Spring Data Elastic Solr Neo4j

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

    Cassandra MongoDB Gemfire Redis Couchbase abstraction JDBC JPA Reactive support coming soon!
  7. 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(...) }
  8. 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) }
  9. 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
  10. 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
  11. 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