Skip to content

Commit ce57b25

Browse files
committed
#413 - Refine reference documentation after Spring R2DBC migration.
1 parent b47da40 commit ce57b25

16 files changed

+537
-1017
lines changed

src/main/asciidoc/index.adoc

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ifdef::backend-epub3[:front-cover-image: image:epub-cover.png[Front Cover,1050,1
77
:spring-data-r2dbc-javadoc: https://docs.spring.io/spring-data/r2dbc/docs/{version}/api
88
:spring-framework-ref: https://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference
99
:reactiveStreamsJavadoc: https://www.reactive-streams.org/reactive-streams-{reactiveStreamsVersion}-javadoc
10+
:example-root: ../../../src/test/java/org/springframework/data/r2dbc/documentation
11+
:tabsize: 2
1012

1113
(C) 2018-2020 The original authors.
1214

@@ -38,10 +40,6 @@ include::{spring-data-commons-docs}/auditing.adoc[leveloffset=+1]
3840

3941
include::reference/r2dbc-auditing.adoc[leveloffset=+1]
4042

41-
include::reference/r2dbc-connections.adoc[leveloffset=+1]
42-
43-
include::reference/r2dbc-initialization.adoc[leveloffset=+1]
44-
4543
include::reference/mapping.adoc[leveloffset=+1]
4644

4745
include::reference/kotlin.adoc[leveloffset=+1]

src/main/asciidoc/reference/r2dbc-connections.adoc

-72
This file was deleted.

src/main/asciidoc/reference/r2dbc-core.adoc

+13-79
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
R2DBC contains a wide range of features:
22

33
* Spring configuration support with Java-based `@Configuration` classes for an R2DBC driver instance.
4-
* A `DatabaseClient` helper class that increases productivity when performing common R2DBC operations with integrated object mapping between rows and POJOs.
5-
* Exception translation into Spring's portable Data Access Exception hierarchy.
4+
* `R2dbcEntityTemplate` as central class for entity-bound operations that increases productivity when performing common R2DBC operations with integrated object mapping between rows and POJOs.
65
* Feature-rich object mapping integrated with Spring's Conversion Service.
76
* Annotation-based mapping metadata that is extensible to support other metadata formats.
87
* Automatic implementation of Repository interfaces, including support for custom query methods.
98
10-
For most tasks, you should use `DatabaseClient` or the repository support, which both use the rich mapping functionality.
11-
`DatabaseClient` is the place to look for accessing functionality such as ad-hoc CRUD operations.
9+
For most tasks, you should use `R2dbcEntityTemplate` or the repository support, which both use the rich mapping functionality.
10+
`R2dbcEntityTemplate` is the place to look for accessing functionality such as ad-hoc CRUD operations.
1211

1312
[[r2dbc.getting-started]]
1413
== Getting Started
@@ -92,37 +91,9 @@ logging.level.org.springframework.data.r2dbc=DEBUG
9291
Then you can, for example, create a `Person` class to persist, as follows:
9392

9493
====
95-
[source,java]
94+
[source,java,indent=0]
9695
----
97-
package org.spring.r2dbc.example;
98-
99-
public class Person {
100-
101-
private String id;
102-
private String name;
103-
private int age;
104-
105-
public Person(String id, String name, int age) {
106-
this.id = id;
107-
this.name = name;
108-
this.age = age;
109-
}
110-
111-
public String getId() {
112-
return id;
113-
}
114-
public String getName() {
115-
return name;
116-
}
117-
public int getAge() {
118-
return age;
119-
}
120-
121-
@Override
122-
public String toString() {
123-
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
124-
}
125-
}
96+
include::../{example-root}/Person.java[tags=class]
12697
----
12798
====
12899

@@ -140,48 +111,11 @@ CREATE TABLE person
140111

141112
You also need a main application to run, as follows:
142113

114+
143115
====
144-
[source,java]
116+
[source,java,indent=0]
145117
----
146-
package org.spring.r2dbc.example;
147-
148-
public class R2dbcApp {
149-
150-
private static final Log log = LogFactory.getLog(R2dbcApp.class);
151-
152-
public static void main(String[] args) throws Exception {
153-
154-
ConnectionFactory connectionFactory = ConnectionFactories.get("r2dbc:h2:mem:///test?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
155-
156-
DatabaseClient client = DatabaseClient.create(connectionFactory);
157-
158-
client.execute("CREATE TABLE person" +
159-
"(id VARCHAR(255) PRIMARY KEY," +
160-
"name VARCHAR(255)," +
161-
"age INT)")
162-
.fetch()
163-
.rowsUpdated()
164-
.as(StepVerifier::create)
165-
.expectNextCount(1)
166-
.verifyComplete();
167-
168-
client.insert()
169-
.into(Person.class)
170-
.using(new Person("joe", "Joe", 34))
171-
.then()
172-
.as(StepVerifier::create)
173-
.verifyComplete();
174-
175-
client.select()
176-
.from(Person.class)
177-
.fetch()
178-
.first()
179-
.doOnNext(it -> log.info(it))
180-
.as(StepVerifier::create)
181-
.expectNextCount(1)
182-
.verifyComplete();
183-
}
184-
}
118+
include::../{example-root}/R2dbcApp.java[tags=class]
185119
----
186120
====
187121

@@ -190,19 +124,19 @@ When you run the main program, the preceding examples produce output similar to
190124
====
191125
[source]
192126
----
193-
2018-11-28 10:47:03,893 DEBUG ata.r2dbc.function.DefaultDatabaseClient: 310 - Executing SQL statement [CREATE TABLE person
127+
2018-11-28 10:47:03,893 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 310 - Executing SQL statement [CREATE TABLE person
194128
(id VARCHAR(255) PRIMARY KEY,
195129
name VARCHAR(255),
196130
age INT)]
197-
2018-11-28 10:47:04,074 DEBUG ata.r2dbc.function.DefaultDatabaseClient: 908 - Executing SQL statement [INSERT INTO person (id, name, age) VALUES($1, $2, $3)]
198-
2018-11-28 10:47:04,092 DEBUG ata.r2dbc.function.DefaultDatabaseClient: 575 - Executing SQL statement [SELECT id, name, age FROM person]
131+
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)]
132+
2018-11-28 10:47:04,092 DEBUG amework.core.r2dbc.DefaultDatabaseClient: 575 - Executing SQL statement [SELECT id, name, age FROM person]
199133
2018-11-28 10:47:04,436 INFO org.spring.r2dbc.example.R2dbcApp: 43 - Person [id='joe', name='Joe', age=34]
200134
----
201135
====
202136

203137
Even in this simple example, there are few things to notice:
204138

205-
* You can create an instance of the central helper class in Spring Data R2DBC (<<r2dbc.datbaseclient,`DatabaseClient`>>) by using a standard `io.r2dbc.spi.ConnectionFactory` object.
139+
* You can create an instance of the central helper class in Spring Data R2DBC (`R2dbcEntityTemplate`) by using a standard `io.r2dbc.spi.ConnectionFactory` object.
206140
* The mapper works against standard POJO objects without the need for any additional metadata (though you can, optionally, provide that information -- see <<mapping,here>>.).
207141
* Mapping conventions can use field access. Notice that the `Person` class has only getters.
208142
* If the constructor argument names match the column names of the stored row, they are used to instantiate the object.
@@ -232,7 +166,7 @@ public class ApplicationConfiguration extends AbstractR2dbcConfiguration {
232166
@Override
233167
@Bean
234168
public ConnectionFactory connectionFactory() {
235-
return …;
169+
return …
236170
}
237171
}
238172
----

src/main/asciidoc/reference/r2dbc-databaseclient.adoc

-144
This file was deleted.

0 commit comments

Comments
 (0)