Class R2dbcMessageSource

java.lang.Object
org.springframework.integration.util.AbstractExpressionEvaluator
org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>
org.springframework.integration.r2dbc.inbound.R2dbcMessageSource
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.integration.core.MessageSource<org.reactivestreams.Publisher<?>>, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationInboundManagement, org.springframework.integration.support.management.IntegrationManagement

public class R2dbcMessageSource
extends org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>
An instance of 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.

Since:
5.4
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class 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.

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields inherited from class org.springframework.integration.util.AbstractExpressionEvaluator

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
  • Constructor Summary

    Constructors 
    Constructor Description
    R2dbcMessageSource​(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations, java.lang.String query)
    Create an instance with the provided R2dbcEntityOperations and SpEL expression which should resolve to a Relational 'query' string.
    R2dbcMessageSource​(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations, org.springframework.expression.Expression queryExpression)
    Create an instance with the provided R2dbcEntityOperations and SpEL expression which should resolve to a query string or StatementMapper.SelectSpec instance.
  • Method Summary

    Modifier and Type Method Description
    protected java.lang.Object doReceive()
    Execute a query returning its results as the Message payload.
    java.lang.String getComponentType()  
    protected void onInit()  
    void setBindFunction​(java.util.function.BiFunction<org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec,​?,​org.springframework.r2dbc.core.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​(java.lang.Class<?> payloadType)
    Set the type of the entityClass which is used for the EntityRowMapper.
    void setUpdateSql​(java.lang.String updateSql)
    Set an update query that will be passed to the DatabaseClient.sql(String) method.

    Methods inherited from class org.springframework.integration.endpoint.AbstractMessageSource

    buildMessage, destroy, getBeanName, getComponentName, getManagedName, getManagedType, getOverrides, isLoggingEnabled, receive, registerMetricsCaptor, setBeanName, setHeaderExpressions, setLoggingEnabled, setManagedName, setManagedType

    Methods inherited from class org.springframework.integration.util.AbstractExpressionEvaluator

    afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionService

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.integration.core.MessageSource

    getIntegrationPatternType
  • Constructor Details

    • R2dbcMessageSource

      public R2dbcMessageSource​(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations, java.lang.String query)
      Create an instance with the provided 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.
      Parameters:
      r2dbcEntityOperations - The reactive database client for performing database calls.
      query - The query String.
    • R2dbcMessageSource

      public R2dbcMessageSource​(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations, org.springframework.expression.Expression queryExpression)
      Create an instance with the provided 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.
      Parameters:
      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.
  • Method Details

    • setPayloadType

      public void setPayloadType​(java.lang.Class<?> payloadType)
      Set the type of the entityClass which is used for the EntityRowMapper.
      Parameters:
      payloadType - The class to use.
    • setUpdateSql

      public void setUpdateSql​(java.lang.String updateSql)
      Set an update query that will be passed to the DatabaseClient.sql(String) method.
      Parameters:
      updateSql - the update query string.
    • setBindFunction

      public void setBindFunction​(java.util.function.BiFunction<org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec,​?,​org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec> bindFunction)
      Set a BiFunction which is used to bind parameters into the update query.
      Parameters:
      bindFunction - the BiFunction to use.
    • setExpectSingleResult

      public void setExpectSingleResult​(boolean expectSingleResult)
      The flag to manage which find* method to invoke on 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.
      Parameters:
      expectSingleResult - true if a single result is expected.
    • getComponentType

      public java.lang.String getComponentType()
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.util.AbstractExpressionEvaluator
    • doReceive

      protected java.lang.Object doReceive()
      Execute a query returning its results as the Message payload. The payload can be either 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.
      Specified by:
      doReceive in class org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>