|
|
|
@ -32,49 +32,49 @@ Here is a quick teaser of an application using Spring Data JDBC Repositories in |
|
|
|
---- |
|
|
|
---- |
|
|
|
interface PersonRepository extends CrudRepository<Person, Long> { |
|
|
|
interface PersonRepository extends CrudRepository<Person, Long> { |
|
|
|
|
|
|
|
|
|
|
|
@Query("SELECT * FROM person WHERE lastname = :lastname") |
|
|
|
@Query("SELECT * FROM person WHERE lastname = :lastname") |
|
|
|
List<Person> findByLastname(String lastname); |
|
|
|
List<Person> findByLastname(String lastname); |
|
|
|
|
|
|
|
|
|
|
|
@Query("SELECT * FROM person WHERE firstname LIKE :firstname") |
|
|
|
@Query("SELECT * FROM person WHERE firstname LIKE :firstname") |
|
|
|
List<Person> findByFirstnameLike(String firstname); |
|
|
|
List<Person> findByFirstnameLike(String firstname); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
class MyService { |
|
|
|
class MyService { |
|
|
|
|
|
|
|
|
|
|
|
private final PersonRepository repository; |
|
|
|
private final PersonRepository repository; |
|
|
|
|
|
|
|
|
|
|
|
public MyService(PersonRepository repository) { |
|
|
|
public MyService(PersonRepository repository) { |
|
|
|
this.repository = repository; |
|
|
|
this.repository = repository; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void doWork() { |
|
|
|
public void doWork() { |
|
|
|
|
|
|
|
|
|
|
|
repository.deleteAll(); |
|
|
|
repository.deleteAll(); |
|
|
|
|
|
|
|
|
|
|
|
Person person = new Person(); |
|
|
|
Person person = new Person(); |
|
|
|
person.setFirstname("Jens"); |
|
|
|
person.setFirstname("Jens"); |
|
|
|
person.setLastname("Schauder"); |
|
|
|
person.setLastname("Schauder"); |
|
|
|
repository.save(person); |
|
|
|
repository.save(person); |
|
|
|
|
|
|
|
|
|
|
|
List<Person> lastNameResults = repository.findByLastname("Schauder"); |
|
|
|
List<Person> lastNameResults = repository.findByLastname("Schauder"); |
|
|
|
List<Person> firstNameResults = repository.findByFirstnameLike("Je%"); |
|
|
|
List<Person> firstNameResults = repository.findByFirstnameLike("Je%"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableJdbcRepositories |
|
|
|
@EnableJdbcRepositories |
|
|
|
class ApplicationConfig extends AbstractJdbcConfiguration { |
|
|
|
class ApplicationConfig extends AbstractJdbcConfiguration { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public DataSource dataSource() { |
|
|
|
public DataSource dataSource() { |
|
|
|
return …; |
|
|
|
return …; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) { |
|
|
|
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) { |
|
|
|
return new NamedParameterJdbcTemplate(dataSource); |
|
|
|
return new NamedParameterJdbcTemplate(dataSource); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
@ -85,9 +85,9 @@ Add the Maven dependency: |
|
|
|
[source,xml] |
|
|
|
[source,xml] |
|
|
|
---- |
|
|
|
---- |
|
|
|
<dependency> |
|
|
|
<dependency> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<artifactId>spring-data-jdbc</artifactId> |
|
|
|
<artifactId>spring-data-jdbc</artifactId> |
|
|
|
<version>${version}</version> |
|
|
|
<version>${version}</version> |
|
|
|
</dependency> |
|
|
|
</dependency> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
@ -96,15 +96,15 @@ If you'd rather like the latest snapshots of the upcoming major version, use our |
|
|
|
[source,xml] |
|
|
|
[source,xml] |
|
|
|
---- |
|
|
|
---- |
|
|
|
<dependency> |
|
|
|
<dependency> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<artifactId>spring-data-jdbc</artifactId> |
|
|
|
<artifactId>spring-data-jdbc</artifactId> |
|
|
|
<version>${version}-SNAPSHOT</version> |
|
|
|
<version>${version}-SNAPSHOT</version> |
|
|
|
</dependency> |
|
|
|
</dependency> |
|
|
|
|
|
|
|
|
|
|
|
<repository> |
|
|
|
<repository> |
|
|
|
<id>spring-snapshot</id> |
|
|
|
<id>spring-snapshot</id> |
|
|
|
<name>Spring Snapshot Repository</name> |
|
|
|
<name>Spring Snapshot Repository</name> |
|
|
|
<url>https://repo.spring.io/snapshot</url> |
|
|
|
<url>https://repo.spring.io/snapshot</url> |
|
|
|
</repository> |
|
|
|
</repository> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
@ -116,46 +116,46 @@ Here is a quick teaser of an application using Spring Data R2DBC Repositories in |
|
|
|
---- |
|
|
|
---- |
|
|
|
interface PersonRepository extends ReactiveCrudRepository<Person, Long> { |
|
|
|
interface PersonRepository extends ReactiveCrudRepository<Person, Long> { |
|
|
|
|
|
|
|
|
|
|
|
@Query("SELECT * FROM person WHERE lastname = :lastname") |
|
|
|
@Query("SELECT * FROM person WHERE lastname = :lastname") |
|
|
|
Flux<Person> findByLastname(String lastname); |
|
|
|
Flux<Person> findByLastname(String lastname); |
|
|
|
|
|
|
|
|
|
|
|
@Query("SELECT * FROM person WHERE firstname LIKE :firstname") |
|
|
|
@Query("SELECT * FROM person WHERE firstname LIKE :firstname") |
|
|
|
Flux<Person> findByFirstnameLike(String firstname); |
|
|
|
Flux<Person> findByFirstnameLike(String firstname); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
class MyService { |
|
|
|
class MyService { |
|
|
|
|
|
|
|
|
|
|
|
private final PersonRepository repository; |
|
|
|
private final PersonRepository repository; |
|
|
|
|
|
|
|
|
|
|
|
public MyService(PersonRepository repository) { |
|
|
|
public MyService(PersonRepository repository) { |
|
|
|
this.repository = repository; |
|
|
|
this.repository = repository; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Flux<Person> doWork() { |
|
|
|
public Flux<Person> doWork() { |
|
|
|
|
|
|
|
|
|
|
|
Person person = new Person(); |
|
|
|
Person person = new Person(); |
|
|
|
person.setFirstname("Jens"); |
|
|
|
person.setFirstname("Jens"); |
|
|
|
person.setLastname("Schauder"); |
|
|
|
person.setLastname("Schauder"); |
|
|
|
repository.save(person); |
|
|
|
repository.save(person); |
|
|
|
|
|
|
|
|
|
|
|
Mono<Void> deleteAll = repository.deleteAll(); |
|
|
|
Mono<Void> deleteAll = repository.deleteAll(); |
|
|
|
|
|
|
|
|
|
|
|
Flux<Person> lastNameResults = repository.findByLastname("Schauder"); |
|
|
|
Flux<Person> lastNameResults = repository.findByLastname("Schauder"); |
|
|
|
Flux<Person> firstNameResults = repository.findByFirstnameLike("Je%"); |
|
|
|
Flux<Person> firstNameResults = repository.findByFirstnameLike("Je%"); |
|
|
|
|
|
|
|
|
|
|
|
return deleteAll.thenMany(lastNameResults.concatWith(firstNameResults)); |
|
|
|
return deleteAll.thenMany(lastNameResults.concatWith(firstNameResults)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableR2dbcRepositories |
|
|
|
@EnableR2dbcRepositories |
|
|
|
class ApplicationConfig extends AbstractR2dbcConfiguration { |
|
|
|
class ApplicationConfig extends AbstractR2dbcConfiguration { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public ConnectionFactory connectionFactory() { |
|
|
|
public ConnectionFactory connectionFactory() { |
|
|
|
return ConnectionFactories.get("r2dbc:<driver>://<host>:<port>/<database>"); |
|
|
|
return ConnectionFactories.get("r2dbc:<driver>://<host>:<port>/<database>"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
---- |
|
|
|
---- |
|
|
|
@ -167,9 +167,9 @@ Add the Maven dependency: |
|
|
|
[source,xml] |
|
|
|
[source,xml] |
|
|
|
---- |
|
|
|
---- |
|
|
|
<dependency> |
|
|
|
<dependency> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<artifactId>spring-data-r2dbc</artifactId> |
|
|
|
<artifactId>spring-data-r2dbc</artifactId> |
|
|
|
<version>${version}</version> |
|
|
|
<version>${version}</version> |
|
|
|
</dependency> |
|
|
|
</dependency> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
@ -178,15 +178,15 @@ If you'd rather like the latest snapshots of the upcoming major version, use our |
|
|
|
[source,xml] |
|
|
|
[source,xml] |
|
|
|
---- |
|
|
|
---- |
|
|
|
<dependency> |
|
|
|
<dependency> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<groupId>org.springframework.data</groupId> |
|
|
|
<artifactId>spring-data-r2dbc</artifactId> |
|
|
|
<artifactId>spring-data-r2dbc</artifactId> |
|
|
|
<version>${version}-SNAPSHOT</version> |
|
|
|
<version>${version}-SNAPSHOT</version> |
|
|
|
</dependency> |
|
|
|
</dependency> |
|
|
|
|
|
|
|
|
|
|
|
<repository> |
|
|
|
<repository> |
|
|
|
<id>spring-libs-snapshot</id> |
|
|
|
<id>spring-libs-snapshot</id> |
|
|
|
<name>Spring Snapshot Repository</name> |
|
|
|
<name>Spring Snapshot Repository</name> |
|
|
|
<url>https://repo.spring.io/snapshot</url> |
|
|
|
<url>https://repo.spring.io/snapshot</url> |
|
|
|
</repository> |
|
|
|
</repository> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|