Package org.springframework.r2dbc.core
Interface DatabaseClient
- All Superinterfaces:
ConnectionAccessor
A non-blocking, reactive client for performing database calls with Reactive Streams
back pressure. Provides a higher level, common API over R2DBC client libraries.
Propagates
DataAccessException
variants for errors.
Use the static factory method create(ConnectionFactory)
or obtain
a builder to create an instance.
Usage example:
ConnectionFactory factory = … DatabaseClient client = DatabaseClient.create(factory); Mono<Actor> actor = client.sql("select first_name, last_name from t_actor") .map(row -> new Actor(row.get("first_name", String.class), row.get("last_name", String.class))) .first();
- Since:
- 5.3
- Author:
- Mark Paluch, Juergen Hoeller
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A mutable builder for creating aDatabaseClient
.static interface
Contract for specifying an SQL call along with options leading to the execution. -
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseClient.Builder
builder()
Obtain aDatabaseClient
builder.static DatabaseClient
create
(ConnectionFactory factory) Create aDatabaseClient
that will use the providedConnectionFactory
.Get theConnectionFactory
that this client uses.Specify a staticsql
statement to run.Specify an SQL supplier that provides SQL to run.Methods inherited from interface org.springframework.r2dbc.core.ConnectionAccessor
inConnection, inConnectionMany
-
Method Details
-
getConnectionFactory
ConnectionFactory getConnectionFactory()Get theConnectionFactory
that this client uses.- Returns:
- the connection factory
-
sql
Specify a staticsql
statement to run. Contract for specifying an SQL call along with options leading to the execution. The SQL string can contain either native parameter bind markers or named parameters (e.g. :foo, :bar) whenNamedParameterExpander
is enabled.- Parameters:
sql
- the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec
- See Also:
-
NamedParameterExpander
DatabaseClient.Builder.namedParameters(boolean)
-
sql
Specify an SQL supplier that provides SQL to run. Contract for specifying an SQL call along with options leading to the execution. The SQL string can contain either native parameter bind markers or named parameters (e.g. :foo, :bar) whenNamedParameterExpander
is enabled.Accepts
PreparedOperation
as SQL and bindingSupplier
.DatabaseClient
implementations should defer the resolution of the SQL string as much as possible, ideally up to the point where aSubscription
happens. This is the case for the default implementation.- Parameters:
sqlSupplier
- a supplier for the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec
- See Also:
-
NamedParameterExpander
DatabaseClient.Builder.namedParameters(boolean)
PreparedOperation
-
create
Create aDatabaseClient
that will use the providedConnectionFactory
.- Parameters:
factory
- theConnectionFactory
to use for obtaining connections- Returns:
- a new
DatabaseClient
; nevernull
-
builder
Obtain aDatabaseClient
builder.
-