public class R2dbcMessageSource extends AbstractMessageSource<org.reactivestreams.Publisher<?>>
MessageSource
which returns
a Message
with a payload which is the result of
execution of query. When expectSingleResult
is false (default), the R2DBC
query is executed returning a Flux
.
The returned Flux
will be used as the payload of the
Message
returned by the AbstractMessageSource.receive()
method.
When expectSingleResult
is true, the query is executed returning a Mono
for the single object returned from the query.
Modifier and Type | Class and Description |
---|---|
class |
R2dbcMessageSource.SelectCreator
An instance of this class is used as a root object for query expression
to give a limited access only to the
StatementMapper.createSelect(java.lang.String) fluent API. |
IntegrationManagement.ManagementOverrides
EXPRESSION_PARSER, logger
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Constructor and Description |
---|
R2dbcMessageSource(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations,
Expression queryExpression)
Create an instance with the provided
R2dbcEntityOperations and SpEL expression
which should resolve to a query string or StatementMapper.SelectSpec instance. |
R2dbcMessageSource(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations,
String query)
Create an instance with the provided
R2dbcEntityOperations and SpEL expression
which should resolve to a Relational 'query' string. |
Modifier and Type | Method and Description |
---|---|
protected Object |
doReceive()
Execute a query returning its results as the Message payload.
|
String |
getComponentType() |
protected void |
onInit() |
void |
setBindFunction(java.util.function.BiFunction<DatabaseClient.GenericExecuteSpec,?,DatabaseClient.GenericExecuteSpec> bindFunction)
Set a
BiFunction which is used to bind parameters into the update query. |
void |
setExpectSingleResult(boolean expectSingleResult)
The flag to manage which find* method to invoke on
R2dbcEntityOperations . |
void |
setPayloadType(Class<?> payloadType)
Set the type of the entityClass which is used for the
EntityRowMapper . |
void |
setUpdateSql(String updateSql)
Set an update query that will be passed to the
DatabaseClient.sql(String) method. |
buildMessage, destroy, getBeanName, getComponentName, getManagedName, getManagedType, getOverrides, isLoggingEnabled, receive, registerMetricsCaptor, setBeanName, setHeaderExpressions, setLoggingEnabled, setManagedName, setManagedType
afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionService
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getIntegrationPatternType
getThisAs
public R2dbcMessageSource(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations, String query)
R2dbcEntityOperations
and SpEL expression
which should resolve to a Relational 'query' string.
It assumes that the R2dbcEntityOperations
is fully initialized and ready to be used.
The 'query' will be evaluated on every call to the AbstractMessageSource.receive()
method.r2dbcEntityOperations
- The reactive database client for performing database calls.query
- The query String.public R2dbcMessageSource(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations, Expression queryExpression)
R2dbcEntityOperations
and SpEL expression
which should resolve to a query string or StatementMapper.SelectSpec
instance.
It assumes that the R2dbcEntityOperations
is fully initialized and ready to be used.
The 'queryExpression' will be evaluated on every call to the AbstractMessageSource.receive()
method.r2dbcEntityOperations
- The reactive for performing database calls.queryExpression
- The query expression. The root object for evaluation context is a R2dbcMessageSource.SelectCreator
for delegation int the StatementMapper.createSelect(java.lang.String)
fluent API.public void setPayloadType(Class<?> payloadType)
EntityRowMapper
.payloadType
- The class to use.public void setUpdateSql(String updateSql)
DatabaseClient.sql(String)
method.updateSql
- the update query string.public void setBindFunction(java.util.function.BiFunction<DatabaseClient.GenericExecuteSpec,?,DatabaseClient.GenericExecuteSpec> bindFunction)
BiFunction
which is used to bind parameters into the update query.bindFunction
- the BiFunction
to use.public void setExpectSingleResult(boolean expectSingleResult)
R2dbcEntityOperations
.
Default is 'false', which means the AbstractMessageSource.receive()
method will use
the DatabaseClient.sql(String)
method and will fetch all. If set
to 'true'AbstractMessageSource.receive()
will use DatabaseClient.sql(String)
and will fetch one and the payload of the returned Message
will be the returned target Object of type
identified by payloadType
instead of a List.expectSingleResult
- true if a single result is expected.public String getComponentType()
protected void onInit()
onInit
in class AbstractExpressionEvaluator
protected Object doReceive()
Flux
or
Mono
of objects of type identified by payloadType
,
or a single element of type identified by payloadType
based on the value of expectSingleResult
attribute which defaults to 'false' resulting
Message
with payload of type
Flux
.doReceive
in class AbstractMessageSource<org.reactivestreams.Publisher<?>>