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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA mutable builder for creating aDatabaseClient.static interfaceContract for specifying an SQL call along with options leading to the execution. -
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseClient.Builderbuilder()Obtain aDatabaseClientbuilder.static DatabaseClientcreate(ConnectionFactory factory) Create aDatabaseClientthat will use the providedConnectionFactory.Get theConnectionFactorythat this client uses.Specify a staticsqlstatement 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 theConnectionFactorythat this client uses.- Returns:
- the connection factory
-
sql
Specify a staticsqlstatement 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) whenNamedParameterExpanderis enabled.- Parameters:
sql- the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec - See Also:
-
NamedParameterExpanderDatabaseClient.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) whenNamedParameterExpanderis enabled.Accepts
PreparedOperationas SQL and bindingSupplier.DatabaseClientimplementations should defer the resolution of the SQL string as much as possible, ideally up to the point where aSubscriptionhappens. This is the case for the default implementation.- Parameters:
sqlSupplier- a supplier for the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec - See Also:
-
NamedParameterExpanderDatabaseClient.Builder.namedParameters(boolean)PreparedOperation
-
create
Create aDatabaseClientthat will use the providedConnectionFactory.- Parameters:
factory- theConnectionFactoryto use for obtaining connections- Returns:
- a new
DatabaseClient; nevernull
-
builder
Obtain aDatabaseClientbuilder.
-