@@ -11,11 +11,13 @@ specification effort to standardize access to SQL databases using reactive patte
1111The Spring Framework's R2DBC abstraction framework consists of two different packages:
1212
1313* `core`: The `org.springframework.r2dbc.core` package contains the `DatabaseClient`
14- class plus a variety of related classes. See xref:data-access/r2dbc.adoc#r2dbc-core[Using the R2DBC Core Classes to Control Basic R2DBC Processing and Error Handling].
14+ class plus a variety of related classes. See
15+ xref:data-access/r2dbc.adoc#r2dbc-core[Using the R2DBC Core Classes to Control Basic R2DBC Processing and Error Handling].
1516
1617* `connection`: The `org.springframework.r2dbc.connection` package contains a utility class
1718for easy `ConnectionFactory` access and various simple `ConnectionFactory` implementations
18- that you can use for testing and running unmodified R2DBC. See xref:data-access/r2dbc.adoc#r2dbc-connections[Controlling Database Connections].
19+ that you can use for testing and running unmodified R2DBC. See
20+ xref:data-access/r2dbc.adoc#r2dbc-connections[Controlling Database Connections].
1921
2022
2123[[r2dbc-core]]
@@ -31,6 +33,7 @@ including error handling. It includes the following topics:
3133* xref:data-access/r2dbc.adoc#r2dbc-DatabaseClient-filter[Statement Filters]
3234* xref:data-access/r2dbc.adoc#r2dbc-auto-generated-keys[Retrieving Auto-generated Keys]
3335
36+
3437[[r2dbc-DatabaseClient]]
3538=== Using `DatabaseClient`
3639
@@ -43,8 +46,9 @@ SQL and extract results. The `DatabaseClient` class:
4346* Runs SQL queries
4447* Update statements and stored procedure calls
4548* Performs iteration over `Result` instances
46- * Catches R2DBC exceptions and translates them to the generic, more informative, exception
47- hierarchy defined in the `org.springframework.dao` package. (See xref:data-access/dao.adoc#dao-exceptions[Consistent Exception Hierarchy].)
49+ * Catches R2DBC exceptions and translates them to the generic, more informative,
50+ exception hierarchy defined in the `org.springframework.dao` package.
51+ (See xref:data-access/dao.adoc#dao-exceptions[Consistent Exception Hierarchy].)
4852
4953The client has a functional, fluent API using reactive types for declarative composition.
5054
@@ -250,7 +254,6 @@ Kotlin::
250254----
251255======
252256
253-
254257[[r2dbc-DatabaseClient-mapping-null]]
255258.What about `null`?
256259****
@@ -315,10 +318,10 @@ The following example shows parameter binding for a query:
315318
316319[source,java]
317320----
318- db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
319- .bind("id", "joe")
320- .bind("name", "Joe")
321- .bind("age", 34);
321+ db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
322+ .bind("id", "joe")
323+ .bind("name", "Joe")
324+ .bind("age", 34);
322325----
323326
324327.R2DBC Native Bind Markers
@@ -327,7 +330,7 @@ R2DBC uses database-native bind markers that depend on the actual database vendo
327330As an example, Postgres uses indexed markers, such as `$1`, `$2`, `$n`.
328331Another example is SQL Server, which uses named bind markers prefixed with `@`.
329332
330- This is different from JDBC, which requires `?` as bind markers.
333+ This is different from JDBC which requires `?` as bind markers.
331334In JDBC, the actual drivers translate `?` bind markers to database-native
332335markers as part of their statement execution.
333336
@@ -363,7 +366,7 @@ Java::
363366 tuples.add(new Object[] {"Ann", 50});
364367
365368 client.sql("SELECT id, name, state FROM table WHERE (name, age) IN (:tuples)")
366- .bind("tuples", tuples);
369+ .bind("tuples", tuples);
367370----
368371
369372Kotlin::
@@ -375,7 +378,7 @@ Kotlin::
375378 tuples.add(arrayOf("Ann", 50))
376379
377380 client.sql("SELECT id, name, state FROM table WHERE (name, age) IN (:tuples)")
378- .bind("tuples", tuples)
381+ .bind("tuples", tuples)
379382----
380383======
381384
@@ -390,7 +393,7 @@ Java::
390393[source,java,indent=0,subs="verbatim,quotes",role="primary"]
391394----
392395 client.sql("SELECT id, name, state FROM table WHERE age IN (:ages)")
393- .bind("ages", Arrays.asList(35, 50));
396+ .bind("ages", Arrays.asList(35, 50));
394397----
395398
396399Kotlin::
@@ -402,7 +405,7 @@ Kotlin::
402405 tuples.add(arrayOf("Ann", 50))
403406
404407 client.sql("SELECT id, name, state FROM table WHERE age IN (:ages)")
405- .bind("tuples", arrayOf(35, 50))
408+ .bind("tuples", arrayOf(35, 50))
406409----
407410======
408411
@@ -429,19 +432,19 @@ Java::
429432[source,java,indent=0,subs="verbatim,quotes",role="primary"]
430433----
431434 client.sql("INSERT INTO table (name, state) VALUES(:name, :state)")
432- .filter((s, next) -> next.execute(s.returnGeneratedValues("id")))
433- .bind("name", …)
434- .bind("state", …);
435+ .filter((s, next) -> next.execute(s.returnGeneratedValues("id")))
436+ .bind("name", …)
437+ .bind("state", …);
435438----
436439
437440Kotlin::
438441+
439442[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
440443----
441444 client.sql("INSERT INTO table (name, state) VALUES(:name, :state)")
442- .filter { s: Statement, next: ExecuteFunction -> next.execute(s.returnGeneratedValues("id")) }
443- .bind("name", …)
444- .bind("state", …)
445+ .filter { s: Statement, next: ExecuteFunction -> next.execute(s.returnGeneratedValues("id")) }
446+ .bind("name", …)
447+ .bind("state", …)
445448----
446449======
447450
@@ -455,21 +458,21 @@ Java::
455458[source,java,indent=0,subs="verbatim,quotes",role="primary"]
456459----
457460 client.sql("INSERT INTO table (name, state) VALUES(:name, :state)")
458- .filter(statement -> s.returnGeneratedValues("id"));
461+ .filter(statement -> s.returnGeneratedValues("id"));
459462
460463 client.sql("SELECT id, name, state FROM table")
461- .filter(statement -> s.fetchSize(25));
464+ .filter(statement -> s.fetchSize(25));
462465----
463466
464467Kotlin::
465468+
466469[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
467470----
468471 client.sql("INSERT INTO table (name, state) VALUES(:name, :state)")
469- .filter { statement -> s.returnGeneratedValues("id") }
472+ .filter { statement -> s.returnGeneratedValues("id") }
470473
471474 client.sql("SELECT id, name, state FROM table")
472- .filter { statement -> s.fetchSize(25) }
475+ .filter { statement -> s.fetchSize(25) }
473476----
474477======
475478
@@ -593,7 +596,7 @@ Java::
593596[source,java,indent=0,subs="verbatim,quotes",role="primary"]
594597----
595598 Mono<Integer> generatedId = client.sql("INSERT INTO table (name, state) VALUES(:name, :state)")
596- .filter(statement -> s.returnGeneratedValues("id"))
599+ .filter(statement -> s.returnGeneratedValues("id"))
597600 .map(row -> row.get("id", Integer.class))
598601 .first();
599602
@@ -605,7 +608,7 @@ Kotlin::
605608[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
606609----
607610 val generatedId = client.sql("INSERT INTO table (name, state) VALUES(:name, :state)")
608- .filter { statement -> s.returnGeneratedValues("id") }
611+ .filter { statement -> s.returnGeneratedValues("id") }
609612 .map { row -> row.get("id", Integer.class) }
610613 .awaitOne()
611614
@@ -672,7 +675,6 @@ Kotlin::
672675[[r2dbc-ConnectionFactoryUtils]]
673676=== Using `ConnectionFactoryUtils`
674677
675-
676678The `ConnectionFactoryUtils` class is a convenient and powerful helper class
677679that provides `static` methods to obtain connections from `ConnectionFactory`
678680and close connections (if necessary).
0 commit comments