introduction to spring data

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/ Introduction to Spring Data Greg Turnquist @gregturn

Upload: spring-by-pivotal

Post on 16-Apr-2017

632 views

Category:

Technology


0 download

TRANSCRIPT

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Introduction to Spring DataGreg Turnquist

@gregturn

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Who am I?

2

GregLTurnquist.com/learning-spring-boot

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

It’s 2016

3

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

It’s 2016

4

Why are we still writing…select * from EMPLOYEE where FIRST_NAME = %1select e from Employee e where e.firstName = :name create

.select()

.from(EMPLOYEE)

.where(EMPLOYEE.FIRST_NAME .equal(name))

.fetch()

SQL

JPA

jOOQ

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

When we could write…

5

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Data provides…

6relational non-relational

Spring Data

Elastic

Solr

Neo4jCassandra

MongoDB GemfireRedis

Couchbase

abst

ract

ion

JDBC

JPA

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /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(...) }

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /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) }

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /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

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Data Demo

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /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 Blumand

Spinnaker: Land of a 1000 Builds - later today @ 5pm

@springcentralspring.io/blog

@pivotalpivotal.io/blog

@pivotalcfhttp://engineering.pivotal.io