Browse Source

Fix indentation in code examples.

Fixes the indentation to 4 characters in all code examples in *.adoc files.

Original pull request #1948
pull/1954/head
Jens Schauder 1 year ago
parent
commit
e651a565a1
No known key found for this signature in database
GPG Key ID: 74F6C554AE971567
  1. 130
      README.adoc
  2. 8
      src/main/antora/modules/ROOT/pages/jdbc/auditing.adoc
  3. 22
      src/main/antora/modules/ROOT/pages/jdbc/getting-started.adoc
  4. 8
      src/main/antora/modules/ROOT/pages/jdbc/mybatis.adoc
  5. 34
      src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc
  6. 10
      src/main/antora/modules/ROOT/pages/jdbc/schema-support.adoc
  7. 49
      src/main/antora/modules/ROOT/pages/jdbc/transactions.adoc
  8. 8
      src/main/antora/modules/ROOT/pages/r2dbc/auditing.adoc
  9. 8
      src/main/antora/modules/ROOT/pages/r2dbc/entity-persistence.adoc
  10. 62
      src/main/antora/modules/ROOT/pages/r2dbc/getting-started.adoc
  11. 52
      src/main/antora/modules/ROOT/pages/r2dbc/mapping.adoc
  12. 28
      src/main/antora/modules/ROOT/pages/r2dbc/query-methods.adoc
  13. 20
      src/main/antora/modules/ROOT/pages/r2dbc/repositories.adoc

130
README.adoc

@ -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>
---- ----

8
src/main/antora/modules/ROOT/pages/jdbc/auditing.adoc

@ -11,10 +11,10 @@ In order to activate auditing, add `@EnableJdbcAuditing` to your configuration,
@EnableJdbcAuditing @EnableJdbcAuditing
class Config { class Config {
@Bean @Bean
AuditorAware<AuditableUser> auditorProvider() { AuditorAware<AuditableUser> auditorProvider() {
return new AuditorAwareImpl(); return new AuditorAwareImpl();
} }
} }
---- ----

22
src/main/antora/modules/ROOT/pages/jdbc/getting-started.adoc

@ -39,13 +39,13 @@ Then enter a project and a package name, such as `org.spring.jdbc.example`.
---- ----
<dependencies> <dependencies>
<!-- other dependency elements omitted --> <!-- other dependency elements omitted -->
<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>
</dependencies> </dependencies>
---- ----
@ -62,11 +62,11 @@ Then enter a project and a package name, such as `org.spring.jdbc.example`.
[source,xml] [source,xml]
---- ----
<repositories> <repositories>
<repository> <repository>
<id>spring-milestone</id> <id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name> <name>Spring Maven MILESTONE Repository</name>
<url>https://repo.spring.io/milestone</url> <url>https://repo.spring.io/milestone</url>
</repository> </repository>
</repositories> </repositories>
---- ----

8
src/main/antora/modules/ROOT/pages/jdbc/mybatis.adoc

@ -16,10 +16,10 @@ The easiest way to properly plug MyBatis into Spring Data JDBC is by importing `
@Import(MyBatisJdbcConfiguration.class) @Import(MyBatisJdbcConfiguration.class)
class Application { class Application {
@Bean @Bean
SqlSessionFactoryBean sqlSessionFactoryBean() { SqlSessionFactoryBean sqlSessionFactoryBean() {
// Configure MyBatis here // Configure MyBatis here
} }
} }
---- ----

34
src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc

@ -11,25 +11,25 @@ Defining such a query is a matter of declaring a method on the repository interf
---- ----
interface PersonRepository extends PagingAndSortingRepository<Person, String> { interface PersonRepository extends PagingAndSortingRepository<Person, String> {
List<Person> findByFirstname(String firstname); <1> List<Person> findByFirstname(String firstname); <1>
List<Person> findByFirstnameOrderByLastname(String firstname, Pageable pageable); <2> List<Person> findByFirstnameOrderByLastname(String firstname, Pageable pageable); <2>
Slice<Person> findByLastname(String lastname, Pageable pageable); <3> Slice<Person> findByLastname(String lastname, Pageable pageable); <3>
Page<Person> findByLastname(String lastname, Pageable pageable); <4> Page<Person> findByLastname(String lastname, Pageable pageable); <4>
Person findByFirstnameAndLastname(String firstname, String lastname); <5> Person findByFirstnameAndLastname(String firstname, String lastname); <5>
Person findFirstByLastname(String lastname); <6> Person findFirstByLastname(String lastname); <6>
@Query("SELECT * FROM person WHERE lastname = :lastname") @Query("SELECT * FROM person WHERE lastname = :lastname")
List<Person> findByLastname(String lastname); <7> List<Person> findByLastname(String lastname); <7>
@Query("SELECT * FROM person WHERE lastname = :lastname") @Query("SELECT * FROM person WHERE lastname = :lastname")
Stream<Person> streamByLastname(String lastname); <8> Stream<Person> streamByLastname(String lastname); <8>
@Query("SELECT * FROM person WHERE username = :#{ principal?.username }") @Query("SELECT * FROM person WHERE username = :#{ principal?.username }")
Person findActiveUser(); <9> Person findActiveUser(); <9>
} }
---- ----
<1> The method shows a query for all people with the given `firstname`. <1> The method shows a query for all people with the given `firstname`.
@ -156,8 +156,8 @@ The following example shows how to use `@Query` to declare a query method:
---- ----
interface UserRepository extends CrudRepository<User, Long> { interface UserRepository extends CrudRepository<User, Long> {
@Query("select firstName, lastName from User u where u.emailAddress = :email") @Query("select firstName, lastName from User u where u.emailAddress = :email")
User findByEmailAddress(@Param("email") String email); User findByEmailAddress(@Param("email") String email);
} }
---- ----
@ -252,9 +252,9 @@ The following example shows how to register `DefaultQueryMappingConfiguration`:
---- ----
@Bean @Bean
QueryMappingConfiguration rowMappers() { QueryMappingConfiguration rowMappers() {
return new DefaultQueryMappingConfiguration() return new DefaultQueryMappingConfiguration()
.register(Person.class, new PersonRowMapper()) .register(Person.class, new PersonRowMapper())
.register(Address.class, new AddressRowMapper()); .register(Address.class, new AddressRowMapper());
} }
---- ----

10
src/main/antora/modules/ROOT/pages/jdbc/schema-support.adoc

@ -11,11 +11,11 @@ Consider the following domain entity:
---- ----
@Table @Table
class Person { class Person {
@Id long id; @Id long id;
String firstName; String firstName;
String lastName; String lastName;
LocalDate birthday; LocalDate birthday;
boolean active; boolean active;
} }
---- ----

49
src/main/antora/modules/ROOT/pages/jdbc/transactions.adoc

@ -12,11 +12,11 @@ If you need to tweak transaction configuration for one of the methods declared i
---- ----
interface UserRepository extends CrudRepository<User, Long> { interface UserRepository extends CrudRepository<User, Long> {
@Override @Override
@Transactional(timeout = 10) @Transactional(timeout = 10)
List<User> findAll(); List<User> findAll();
// Further query method declarations // Further query method declarations
} }
---- ----
@ -32,23 +32,24 @@ The following example shows how to create such a facade:
@Service @Service
public class UserManagementImpl implements UserManagement { public class UserManagementImpl implements UserManagement {
private final UserRepository userRepository; private final UserRepository userRepository;
private final RoleRepository roleRepository; private final RoleRepository roleRepository;
UserManagementImpl(UserRepository userRepository, UserManagementImpl(UserRepository userRepository,
RoleRepository roleRepository) { RoleRepository roleRepository) {
this.userRepository = userRepository; this.userRepository = userRepository;
this.roleRepository = roleRepository; this.roleRepository = roleRepository;
} }
@Transactional @Transactional
public void addRoleToAllUsers(String roleName) { public void addRoleToAllUsers(String roleName) {
Role role = roleRepository.findByName(roleName); Role role = roleRepository.findByName(roleName);
for (User user : userRepository.findAll()) { for (User user : userRepository.findAll()) {
user.addRole(role); user.addRole(role);
userRepository.save(user); userRepository.save(user);
}
} }
} }
---- ----
@ -69,12 +70,12 @@ To let your query methods be transactional, use `@Transactional` at the reposito
@Transactional(readOnly = true) @Transactional(readOnly = true)
interface UserRepository extends CrudRepository<User, Long> { interface UserRepository extends CrudRepository<User, Long> {
List<User> findByLastname(String lastname); List<User> findByLastname(String lastname);
@Modifying @Modifying
@Transactional @Transactional
@Query("delete from User u where u.active = false") @Query("delete from User u where u.active = false")
void deleteInactiveUsers(); void deleteInactiveUsers();
} }
---- ----
@ -105,8 +106,8 @@ In that cases both modes are equivalent of `PESSIMISTIC_WRITE`.
---- ----
interface UserRepository extends CrudRepository<User, Long> { interface UserRepository extends CrudRepository<User, Long> {
@Lock(LockMode.PESSIMISTIC_READ) @Lock(LockMode.PESSIMISTIC_READ)
List<User> findByLastname(String lastname); List<User> findByLastname(String lastname);
} }
---- ----

8
src/main/antora/modules/ROOT/pages/r2dbc/auditing.adoc

@ -10,10 +10,10 @@ Since Spring Data R2DBC 1.2, auditing can be enabled by annotating a configurati
@EnableR2dbcAuditing @EnableR2dbcAuditing
class Config { class Config {
@Bean @Bean
public ReactiveAuditorAware<AuditableUser> myAuditorProvider() { public ReactiveAuditorAware<AuditableUser> myAuditorProvider() {
return new AuditorAwareImpl(); return new AuditorAwareImpl();
} }
} }
---- ----

8
src/main/antora/modules/ROOT/pages/r2dbc/entity-persistence.adoc

@ -189,10 +189,10 @@ include::partial$optimistic-locking.adoc[]
@Table @Table
class Person { class Person {
@Id Long id; @Id Long id;
String firstname; String firstname;
String lastname; String lastname;
@Version Long version; @Version Long version;
} }
R2dbcEntityTemplate template = …; R2dbcEntityTemplate template = …;

62
src/main/antora/modules/ROOT/pages/r2dbc/getting-started.adoc

@ -41,20 +41,20 @@ Then enter a project and a package name, such as `org.spring.r2dbc.example`.
---- ----
<dependencies> <dependencies>
<!-- other dependency elements omitted --> <!-- other dependency elements omitted -->
<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>
<!-- a R2DBC driver --> <!-- a R2DBC driver -->
<dependency> <dependency>
<groupId>io.r2dbc</groupId> <groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId> <artifactId>r2dbc-h2</artifactId>
<version>x.y.z</version> <version>x.y.z</version>
</dependency> </dependency>
</dependencies> </dependencies>
---- ----
@ -71,11 +71,11 @@ Then enter a project and a package name, such as `org.spring.r2dbc.example`.
[source,xml] [source,xml]
---- ----
<repositories> <repositories>
<repository> <repository>
<id>spring-milestone</id> <id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name> <name>Spring Maven MILESTONE Repository</name>
<url>https://repo.spring.io/milestone</url> <url>https://repo.spring.io/milestone</url>
</repository> </repository>
</repositories> </repositories>
---- ----
@ -100,10 +100,11 @@ Next, you need to create a table structure in your database, as follows:
[source,sql] [source,sql]
---- ----
CREATE TABLE person CREATE TABLE person(
(id VARCHAR(255) PRIMARY KEY, id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255), name VARCHAR(255),
age INT); age INT
);
---- ----
You also need a main application to run, as follows: You also need a main application to run, as follows:
@ -117,10 +118,11 @@ When you run the main program, the preceding examples produce output similar to
[source] [source]
---- ----
2018-11-28 10:47:03,893 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 310 - Executing SQL statement [CREATE TABLE person 2018-11-28 10:47:03,893 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 310 - Executing SQL statement [CREATE TABLE person(
(id VARCHAR(255) PRIMARY KEY, id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255), name VARCHAR(255),
age INT)] age INT
)]
2018-11-28 10:47:04,074 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 908 - Executing SQL statement [INSERT INTO person (id, name, age) VALUES($1, $2, $3)] 2018-11-28 10:47:04,074 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 908 - Executing SQL statement [INSERT INTO person (id, name, age) VALUES($1, $2, $3)]
2018-11-28 10:47:04,092 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 575 - Executing SQL statement [SELECT id, name, age FROM person] 2018-11-28 10:47:04,092 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 575 - Executing SQL statement [SELECT id, name, age FROM person]
2018-11-28 10:47:04,436 INFO org.spring.r2dbc.example.R2dbcApp: 43 - Person [id='joe', name='Joe', age=34] 2018-11-28 10:47:04,436 INFO org.spring.r2dbc.example.R2dbcApp: 43 - Person [id='joe', name='Joe', age=34]
@ -155,11 +157,11 @@ The following example shows an example of using Java-based bean metadata to regi
@Configuration @Configuration
public class ApplicationConfiguration extends AbstractR2dbcConfiguration { public class ApplicationConfiguration extends AbstractR2dbcConfiguration {
@Override @Override
@Bean @Bean
public ConnectionFactory connectionFactory() { public ConnectionFactory connectionFactory() {
return … return …
} }
} }
---- ----

52
src/main/antora/modules/ROOT/pages/r2dbc/mapping.adoc

@ -62,16 +62,16 @@ See xref:r2dbc/getting-started.adoc#r2dbc.dialects[R2DBC Drivers] for how to con
@Configuration @Configuration
public class MyAppConfig extends AbstractR2dbcConfiguration { public class MyAppConfig extends AbstractR2dbcConfiguration {
public ConnectionFactory connectionFactory() { public ConnectionFactory connectionFactory() {
return ConnectionFactories.get("r2dbc:…"); return ConnectionFactories.get("r2dbc:…");
} }
// the following are optional // the following are optional
@Override @Override
protected List<Object> getCustomConverters() { protected List<Object> getCustomConverters() {
return List.of(new PersonReadConverter(), new PersonWriteConverter()); return List.of(new PersonReadConverter(), new PersonWriteConverter());
} }
} }
---- ----
@ -100,14 +100,14 @@ package com.mycompany.domain;
@Table @Table
public class Person { public class Person {
@Id @Id
private Long id; private Long id;
private Integer ssn; private Integer ssn;
private String firstName; private String firstName;
private String lastName; private String lastName;
} }
---- ----
@ -199,13 +199,13 @@ The following example of a Spring Converter implementation converts from a `Row`
[source,java] [source,java]
---- ----
@ReadingConverter @ReadingConverter
public class PersonReadConverter implements Converter<Row, Person> { public class PersonReadConverter implements Converter<Row, Person> {
public Person convert(Row source) { public Person convert(Row source) {
Person p = new Person(source.get("id", String.class),source.get("name", String.class)); Person p = new Person(source.get("id", String.class),source.get("name", String.class));
p.setAge(source.get("age", Integer.class)); p.setAge(source.get("age", Integer.class));
return p; return p;
} }
} }
---- ----
@ -222,13 +222,13 @@ The following example converts from a `Person` to a `OutboundRow`:
@WritingConverter @WritingConverter
public class PersonWriteConverter implements Converter<Person, OutboundRow> { public class PersonWriteConverter implements Converter<Person, OutboundRow> {
public OutboundRow convert(Person source) { public OutboundRow convert(Person source) {
OutboundRow row = new OutboundRow(); OutboundRow row = new OutboundRow();
row.put("id", Parameter.from(source.getId())); row.put("id", Parameter.from(source.getId()));
row.put("name", Parameter.from(source.getFirstName())); row.put("name", Parameter.from(source.getFirstName()));
row.put("age", Parameter.from(source.getAge())); row.put("age", Parameter.from(source.getAge()));
return row; return row;
} }
} }
---- ----

28
src/main/antora/modules/ROOT/pages/r2dbc/query-methods.adoc

@ -10,21 +10,21 @@ Defining such a query is a matter of declaring a method on the repository interf
---- ----
interface ReactivePersonRepository extends ReactiveSortingRepository<Person, Long> { interface ReactivePersonRepository extends ReactiveSortingRepository<Person, Long> {
Flux<Person> findByFirstname(String firstname); <1> Flux<Person> findByFirstname(String firstname); <1>
Flux<Person> findByFirstname(Publisher<String> firstname); <2> Flux<Person> findByFirstname(Publisher<String> firstname); <2>
Flux<Person> findByFirstnameOrderByLastname(String firstname, Pageable pageable); <3> Flux<Person> findByFirstnameOrderByLastname(String firstname, Pageable pageable); <3>
Mono<Person> findByFirstnameAndLastname(String firstname, String lastname); <4> Mono<Person> findByFirstnameAndLastname(String firstname, String lastname); <4>
Mono<Person> findFirstByLastname(String lastname); <5> Mono<Person> findFirstByLastname(String lastname); <5>
@Query("SELECT * FROM person WHERE lastname = :lastname") @Query("SELECT * FROM person WHERE lastname = :lastname")
Flux<Person> findByLastname(String lastname); <6> Flux<Person> findByLastname(String lastname); <6>
@Query("SELECT firstname, lastname FROM person WHERE lastname = $1") @Query("SELECT firstname, lastname FROM person WHERE lastname = $1")
Mono<Person> findFirstByLastname(String lastname); <7> Mono<Person> findFirstByLastname(String lastname); <7>
} }
---- ----
@ -147,11 +147,11 @@ Using keywords from the preceding table can be used in conjunction with `delete
---- ----
interface ReactivePersonRepository extends ReactiveSortingRepository<Person, String> { interface ReactivePersonRepository extends ReactiveSortingRepository<Person, String> {
Mono<Integer> deleteByLastname(String lastname); <1> Mono<Integer> deleteByLastname(String lastname); <1>
Mono<Void> deletePersonByLastname(String lastname); <2> Mono<Void> deletePersonByLastname(String lastname); <2>
Mono<Boolean> deletePersonByLastname(String lastname); <3> Mono<Boolean> deletePersonByLastname(String lastname); <3>
} }
---- ----
@ -192,8 +192,8 @@ The following example shows how to use `@Query` to declare a query method:
---- ----
interface UserRepository extends ReactiveCrudRepository<User, Long> { interface UserRepository extends ReactiveCrudRepository<User, Long> {
@Query("select firstName, lastName from User u where u.emailAddress = :email") @Query("select firstName, lastName from User u where u.emailAddress = :email")
Flux<User> findByEmailAddress(@Param("email") String email); Flux<User> findByEmailAddress(@Param("email") String email);
} }
---- ----

20
src/main/antora/modules/ROOT/pages/r2dbc/repositories.adoc

@ -18,12 +18,12 @@ Consider the following `Person` class:
---- ----
public class Person { public class Person {
@Id @Id
private Long id; private Long id;
private String firstname; private String firstname;
private String lastname; private String lastname;
// … getters and setters omitted // … getters and setters omitted
} }
---- ----
@ -34,7 +34,7 @@ The following example shows a repository interface for the preceding `Person` cl
---- ----
public interface PersonRepository extends ReactiveCrudRepository<Person, Long> { public interface PersonRepository extends ReactiveCrudRepository<Person, Long> {
// additional custom query methods go here // additional custom query methods go here
} }
---- ----
@ -49,10 +49,10 @@ The following example shows how to use Java configuration for a repository:
@EnableR2dbcRepositories @EnableR2dbcRepositories
class ApplicationConfig extends AbstractR2dbcConfiguration { class ApplicationConfig extends AbstractR2dbcConfiguration {
@Override @Override
public ConnectionFactory connectionFactory() { public ConnectionFactory connectionFactory() {
return … return …
} }
} }
---- ----

Loading…
Cancel
Save