$30 off During Our Annual Pro Sale. View Details »

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

    View Slide

  2. GregLTurnquist.com/list

    View Slide

  3. GregLTurnquist.com/list

    View Slide

  4. View Slide

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

    View Slide

  6. It’s 2016

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  12. When we could write…

    View Slide

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

    View Slide

  14. 10+ years ago
    SQL

    View Slide

  15. Today
    SQL NoSQL

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  22. Dialing it up
    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 Slide

  23. Why stop there?
    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 Slide

  24. Why stop there?
    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)
    }
    Use @Query to write custom queries

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide