@@ -32,49 +32,49 @@ Here is a quick teaser of an application using Spring Data JDBC Repositories in
32
32
----
33
33
interface PersonRepository extends CrudRepository<Person, Long> {
34
34
35
- @Query("SELECT * FROM person WHERE lastname = :lastname")
36
- List<Person> findByLastname(String lastname);
35
+ @Query("SELECT * FROM person WHERE lastname = :lastname")
36
+ List<Person> findByLastname(String lastname);
37
37
38
- @Query("SELECT * FROM person WHERE firstname LIKE :firstname")
39
- List<Person> findByFirstnameLike(String firstname);
38
+ @Query("SELECT * FROM person WHERE firstname LIKE :firstname")
39
+ List<Person> findByFirstnameLike(String firstname);
40
40
}
41
41
42
42
@Service
43
43
class MyService {
44
44
45
- private final PersonRepository repository;
45
+ private final PersonRepository repository;
46
46
47
- public MyService(PersonRepository repository) {
48
- this.repository = repository;
49
- }
47
+ public MyService(PersonRepository repository) {
48
+ this.repository = repository;
49
+ }
50
50
51
- public void doWork() {
51
+ public void doWork() {
52
52
53
- repository.deleteAll();
53
+ repository.deleteAll();
54
54
55
- Person person = new Person();
56
- person.setFirstname("Jens");
57
- person.setLastname("Schauder");
58
- repository.save(person);
55
+ Person person = new Person();
56
+ person.setFirstname("Jens");
57
+ person.setLastname("Schauder");
58
+ repository.save(person);
59
59
60
- List<Person> lastNameResults = repository.findByLastname("Schauder");
61
- List<Person> firstNameResults = repository.findByFirstnameLike("Je%");
62
- }
60
+ List<Person> lastNameResults = repository.findByLastname("Schauder");
61
+ List<Person> firstNameResults = repository.findByFirstnameLike("Je%");
62
+ }
63
63
}
64
64
65
65
@Configuration
66
66
@EnableJdbcRepositories
67
67
class ApplicationConfig extends AbstractJdbcConfiguration {
68
68
69
- @Bean
70
- public DataSource dataSource() {
71
- return …;
72
- }
69
+ @Bean
70
+ public DataSource dataSource() {
71
+ return …;
72
+ }
73
73
74
- @Bean
75
- public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) {
76
- return new NamedParameterJdbcTemplate(dataSource);
77
- }
74
+ @Bean
75
+ public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) {
76
+ return new NamedParameterJdbcTemplate(dataSource);
77
+ }
78
78
}
79
79
----
80
80
@@ -85,9 +85,9 @@ Add the Maven dependency:
85
85
[source,xml]
86
86
----
87
87
<dependency>
88
- <groupId>org.springframework.data</groupId>
89
- <artifactId>spring-data-jdbc</artifactId>
90
- <version>${version}</version>
88
+ <groupId>org.springframework.data</groupId>
89
+ <artifactId>spring-data-jdbc</artifactId>
90
+ <version>${version}</version>
91
91
</dependency>
92
92
----
93
93
@@ -96,15 +96,15 @@ If you'd rather like the latest snapshots of the upcoming major version, use our
96
96
[source,xml]
97
97
----
98
98
<dependency>
99
- <groupId>org.springframework.data</groupId>
100
- <artifactId>spring-data-jdbc</artifactId>
101
- <version>${version}-SNAPSHOT</version>
99
+ <groupId>org.springframework.data</groupId>
100
+ <artifactId>spring-data-jdbc</artifactId>
101
+ <version>${version}-SNAPSHOT</version>
102
102
</dependency>
103
103
104
104
<repository>
105
- <id>spring-snapshot</id>
106
- <name>Spring Snapshot Repository</name>
107
- <url>https://repo.spring.io/snapshot</url>
105
+ <id>spring-snapshot</id>
106
+ <name>Spring Snapshot Repository</name>
107
+ <url>https://repo.spring.io/snapshot</url>
108
108
</repository>
109
109
----
110
110
@@ -116,46 +116,46 @@ Here is a quick teaser of an application using Spring Data R2DBC Repositories in
116
116
----
117
117
interface PersonRepository extends ReactiveCrudRepository<Person, Long> {
118
118
119
- @Query("SELECT * FROM person WHERE lastname = :lastname")
120
- Flux<Person> findByLastname(String lastname);
119
+ @Query("SELECT * FROM person WHERE lastname = :lastname")
120
+ Flux<Person> findByLastname(String lastname);
121
121
122
- @Query("SELECT * FROM person WHERE firstname LIKE :firstname")
123
- Flux<Person> findByFirstnameLike(String firstname);
122
+ @Query("SELECT * FROM person WHERE firstname LIKE :firstname")
123
+ Flux<Person> findByFirstnameLike(String firstname);
124
124
}
125
125
126
126
@Service
127
127
class MyService {
128
128
129
- private final PersonRepository repository;
129
+ private final PersonRepository repository;
130
130
131
- public MyService(PersonRepository repository) {
132
- this.repository = repository;
133
- }
131
+ public MyService(PersonRepository repository) {
132
+ this.repository = repository;
133
+ }
134
134
135
- public Flux<Person> doWork() {
135
+ public Flux<Person> doWork() {
136
136
137
- Person person = new Person();
138
- person.setFirstname("Jens");
139
- person.setLastname("Schauder");
140
- repository.save(person);
137
+ Person person = new Person();
138
+ person.setFirstname("Jens");
139
+ person.setLastname("Schauder");
140
+ repository.save(person);
141
141
142
- Mono<Void> deleteAll = repository.deleteAll();
142
+ Mono<Void> deleteAll = repository.deleteAll();
143
143
144
- Flux<Person> lastNameResults = repository.findByLastname("Schauder");
145
- Flux<Person> firstNameResults = repository.findByFirstnameLike("Je%");
144
+ Flux<Person> lastNameResults = repository.findByLastname("Schauder");
145
+ Flux<Person> firstNameResults = repository.findByFirstnameLike("Je%");
146
146
147
- return deleteAll.thenMany(lastNameResults.concatWith(firstNameResults));
148
- }
147
+ return deleteAll.thenMany(lastNameResults.concatWith(firstNameResults));
148
+ }
149
149
}
150
150
151
151
@Configuration
152
152
@EnableR2dbcRepositories
153
153
class ApplicationConfig extends AbstractR2dbcConfiguration {
154
154
155
- @Bean
156
- public ConnectionFactory connectionFactory() {
157
- return ConnectionFactories.get("r2dbc:<driver>://<host>:<port>/<database>");
158
- }
155
+ @Bean
156
+ public ConnectionFactory connectionFactory() {
157
+ return ConnectionFactories.get("r2dbc:<driver>://<host>:<port>/<database>");
158
+ }
159
159
160
160
}
161
161
----
@@ -167,9 +167,9 @@ Add the Maven dependency:
167
167
[source,xml]
168
168
----
169
169
<dependency>
170
- <groupId>org.springframework.data</groupId>
171
- <artifactId>spring-data-r2dbc</artifactId>
172
- <version>${version}</version>
170
+ <groupId>org.springframework.data</groupId>
171
+ <artifactId>spring-data-r2dbc</artifactId>
172
+ <version>${version}</version>
173
173
</dependency>
174
174
----
175
175
@@ -178,15 +178,15 @@ If you'd rather like the latest snapshots of the upcoming major version, use our
178
178
[source,xml]
179
179
----
180
180
<dependency>
181
- <groupId>org.springframework.data</groupId>
182
- <artifactId>spring-data-r2dbc</artifactId>
183
- <version>${version}-SNAPSHOT</version>
181
+ <groupId>org.springframework.data</groupId>
182
+ <artifactId>spring-data-r2dbc</artifactId>
183
+ <version>${version}-SNAPSHOT</version>
184
184
</dependency>
185
185
186
186
<repository>
187
- <id>spring-libs-snapshot</id>
188
- <name>Spring Snapshot Repository</name>
189
- <url>https://repo.spring.io/snapshot</url>
187
+ <id>spring-libs-snapshot</id>
188
+ <name>Spring Snapshot Repository</name>
189
+ <url>https://repo.spring.io/snapshot</url>
190
190
</repository>
191
191
----
192
192
0 commit comments