Class DefaultSqlEndpoint

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.Endpoint, org.apache.camel.IsSingleton, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasId, org.apache.camel.StatefulService, org.apache.camel.SuspendableService
    Direct Known Subclasses:
    SqlEndpoint

    public abstract class DefaultSqlEndpoint
    extends org.apache.camel.support.DefaultPollingEndpoint
    Base class for SQL endpoints.
    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DataSource getDataSource()  
      int getExpectedUpdateCount()  
      org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()  
      int getMaxMessagesPerPoll()  
      String getOnConsume()  
      String getOnConsumeBatchComplete()  
      String getOnConsumeFailed()  
      String getOutputClass()  
      String getOutputHeader()  
      SqlOutputType getOutputType()  
      int getParametersCount()  
      String getPlaceholder()  
      SqlPrepareStatementStrategy getPrepareStatementStrategy()  
      SqlProcessingStrategy getProcessingStrategy()  
      char getSeparator()  
      Map<String,​Object> getTemplateOptions()  
      boolean isAllowNamedParameters()  
      boolean isAlwaysPopulateStatement()  
      boolean isBatch()  
      boolean isBreakBatchOnConsumeFail()  
      boolean isNoop()  
      boolean isRouteEmptyResultSet()  
      boolean isTransacted()  
      boolean isUseIterator()  
      boolean isUseMessageBodyForSql()  
      boolean isUsePlaceholder()  
      List<?> queryForList​(ResultSet rs, boolean allowMapToClass)  
      Object queryForObject​(ResultSet rs)  
      ResultSetIterator queryForStreamList​(Connection connection, Statement statement, ResultSet rs)  
      void setAllowNamedParameters​(boolean allowNamedParameters)
      Whether to allow using named parameters in the queries.
      void setAlwaysPopulateStatement​(boolean alwaysPopulateStatement)
      If enabled then the populateStatement method from org.apache.camel.component.sql.SqlPrepareStatementStrategy is always invoked, also if there is no expected parameters to be prepared.
      void setBatch​(boolean batch)
      Enables or disables batch mode
      void setBreakBatchOnConsumeFail​(boolean breakBatchOnConsumeFail)
      Sets whether to break batch if onConsume failed.
      void setDataSource​(DataSource dataSource)
      Sets the DataSource to use to communicate with the database.
      void setExpectedUpdateCount​(int expectedUpdateCount)
      Sets an expected update count to validate when using onConsume.
      void setJdbcTemplate​(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)  
      void setMaxMessagesPerPoll​(int maxMessagesPerPoll)
      Sets the maximum number of messages to poll
      void setNoop​(boolean noop)
      If set, will ignore the results of the SQL query and use the existing IN message as the OUT message for the continuation of processing
      void setOnConsume​(String onConsume)
      After processing each row then this query can be executed, if the Exchange was processed successfully, for example to mark the row as processed.
      void setOnConsumeBatchComplete​(String onConsumeBatchComplete)
      After processing the entire batch, this query can be executed to bulk update rows etc.
      void setOnConsumeFailed​(String onConsumeFailed)
      After processing each row then this query can be executed, if the Exchange failed, for example to mark the row as failed.
      void setOutputClass​(String outputClass)
      Specify the full package and class name to use as conversion when outputType=SelectOne.
      void setOutputHeader​(String outputHeader)
      Store the query result in a header instead of the message body.
      void setOutputType​(SqlOutputType outputType)
      Make the output of consumer or producer to SelectList as List of Map, or SelectOne as single Java object in the following way: a) If the query has only single column, then that JDBC Column object is returned.
      void setParametersCount​(int parametersCount)
      If set greater than zero, then Camel will use this count value of parameters to replace instead of querying via JDBC metadata API.
      void setPlaceholder​(String placeholder)
      Specifies a character that will be replaced to ? in SQL query.
      void setPrepareStatementStrategy​(SqlPrepareStatementStrategy prepareStatementStrategy)
      Allows to plugin to use a custom org.apache.camel.component.sql.SqlPrepareStatementStrategy to control preparation of the query and prepared statement.
      void setProcessingStrategy​(SqlProcessingStrategy processingStrategy)
      Allows to plugin to use a custom org.apache.camel.component.sql.SqlProcessingStrategy to execute queries when the consumer has processed the rows/batch.
      void setRouteEmptyResultSet​(boolean routeEmptyResultSet)
      Sets whether empty resultset should be allowed to be sent to the next hop.
      void setSeparator​(char separator)
      The separator to use when parameter values is taken from message body (if the body is a String type), to be inserted at # placeholders.
      void setTemplateOptions​(Map<String,​Object> templateOptions)
      Configures the Spring JdbcTemplate with the key/values from the Map
      void setTransacted​(boolean transacted)
      Enables or disables transaction.
      void setUseIterator​(boolean useIterator)
      Sets how resultset should be delivered to route.
      void setUseMessageBodyForSql​(boolean useMessageBodyForSql)
      Whether to use the message body as the SQL and then headers for parameters.
      void setUsePlaceholder​(boolean usePlaceholder)
      Sets whether to use placeholder and replace all placeholder characters with ? sign in the SQL queries.
      • Methods inherited from class org.apache.camel.support.DefaultPollingEndpoint

        createConsumer
      • Methods inherited from class org.apache.camel.support.ScheduledPollEndpoint

        configureConsumer, configureProperties, configureScheduledPollConsumerProperties, doConfigureConsumer, doStart, doStop, getBackoffErrorThreshold, getBackoffIdleThreshold, getBackoffMultiplier, getDefaultDelay, getDelay, getInitialDelay, getPollStrategy, getRepeatCount, getRunLoggingLevel, getScheduledExecutorService, getScheduler, getSchedulerProperties, getTimeUnit, isGreedy, isSendEmptyMessageWhenIdle, isStartScheduler, isUseFixedDelay, setBackoffErrorThreshold, setBackoffIdleThreshold, setBackoffMultiplier, setDelay, setGreedy, setInitialDelay, setPollStrategy, setRepeatCount, setRunLoggingLevel, setScheduledExecutorService, setScheduler, setSchedulerProperties, setSendEmptyMessageWhenIdle, setStartScheduler, setTimeUnit, setUseFixedDelay
      • Methods inherited from class org.apache.camel.support.DefaultEndpoint

        configureExchange, configurePollingConsumer, createAsyncProducer, createEndpointUri, createExchange, createExchange, createPollingConsumer, doInit, equals, getCamelContext, getComponent, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, isLenientProperties, isPollingConsumerBlockWhenFull, isPollingConsumerCopy, isSingleton, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerCopy, setPollingConsumerQueueSize, setProperties, toString
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Endpoint

        createProducer, getEndpointBaseUri, isSingletonProducer
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • DefaultSqlEndpoint

        public DefaultSqlEndpoint()
      • DefaultSqlEndpoint

        public DefaultSqlEndpoint​(String endpointUri,
                                  org.apache.camel.Component component)
    • Method Detail

      • getJdbcTemplate

        public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
      • setJdbcTemplate

        public void setJdbcTemplate​(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
      • isTransacted

        public boolean isTransacted()
      • setTransacted

        public void setTransacted​(boolean transacted)
        Enables or disables transaction. If enabled then if processing an exchange failed then the consumer + break out processing any further exchanges to cause a rollback eager
      • isBatch

        public boolean isBatch()
      • setBatch

        public void setBatch​(boolean batch)
        Enables or disables batch mode
      • getMaxMessagesPerPoll

        public int getMaxMessagesPerPoll()
      • setMaxMessagesPerPoll

        public void setMaxMessagesPerPoll​(int maxMessagesPerPoll)
        Sets the maximum number of messages to poll
      • setProcessingStrategy

        public void setProcessingStrategy​(SqlProcessingStrategy processingStrategy)
        Allows to plugin to use a custom org.apache.camel.component.sql.SqlProcessingStrategy to execute queries when the consumer has processed the rows/batch.
      • setPrepareStatementStrategy

        public void setPrepareStatementStrategy​(SqlPrepareStatementStrategy prepareStatementStrategy)
        Allows to plugin to use a custom org.apache.camel.component.sql.SqlPrepareStatementStrategy to control preparation of the query and prepared statement.
      • getOnConsume

        public String getOnConsume()
      • setOnConsume

        public void setOnConsume​(String onConsume)
        After processing each row then this query can be executed, if the Exchange was processed successfully, for example to mark the row as processed. The query can have parameter.
      • getOnConsumeFailed

        public String getOnConsumeFailed()
      • setOnConsumeFailed

        public void setOnConsumeFailed​(String onConsumeFailed)
        After processing each row then this query can be executed, if the Exchange failed, for example to mark the row as failed. The query can have parameter.
      • getOnConsumeBatchComplete

        public String getOnConsumeBatchComplete()
      • setOnConsumeBatchComplete

        public void setOnConsumeBatchComplete​(String onConsumeBatchComplete)
        After processing the entire batch, this query can be executed to bulk update rows etc. The query cannot have parameters.
      • isAllowNamedParameters

        public boolean isAllowNamedParameters()
      • setAllowNamedParameters

        public void setAllowNamedParameters​(boolean allowNamedParameters)
        Whether to allow using named parameters in the queries.
      • isAlwaysPopulateStatement

        public boolean isAlwaysPopulateStatement()
      • setAlwaysPopulateStatement

        public void setAlwaysPopulateStatement​(boolean alwaysPopulateStatement)
        If enabled then the populateStatement method from org.apache.camel.component.sql.SqlPrepareStatementStrategy is always invoked, also if there is no expected parameters to be prepared. When this is false then the populateStatement is only invoked if there is 1 or more expected parameters to be set; for example this avoids reading the message body/headers for SQL queries with no parameters.
      • getSeparator

        public char getSeparator()
      • setSeparator

        public void setSeparator​(char separator)
        The separator to use when parameter values is taken from message body (if the body is a String type), to be inserted at # placeholders. Notice if you use named parameters, then a Map type is used instead.

        The default value is comma.

      • setOutputType

        public void setOutputType​(SqlOutputType outputType)
        Make the output of consumer or producer to SelectList as List of Map, or SelectOne as single Java object in the following way: a) If the query has only single column, then that JDBC Column object is returned. (such as SELECT COUNT( * ) FROM PROJECT will return a Long object. b) If the query has more than one column, then it will return a Map of that result. c) If the outputClass is set, then it will convert the query result into an Java bean object by calling all the setters that match the column names. It will assume your class has a default constructor to create instance with. d) If the query resulted in more than one rows, it throws an non-unique result exception.
      • getOutputClass

        public String getOutputClass()
      • setOutputClass

        public void setOutputClass​(String outputClass)
        Specify the full package and class name to use as conversion when outputType=SelectOne.
      • getParametersCount

        public int getParametersCount()
      • setParametersCount

        public void setParametersCount​(int parametersCount)
        If set greater than zero, then Camel will use this count value of parameters to replace instead of querying via JDBC metadata API. This is useful if the JDBC vendor could not return correct parameters count, then user may override instead.
      • isNoop

        public boolean isNoop()
      • setNoop

        public void setNoop​(boolean noop)
        If set, will ignore the results of the SQL query and use the existing IN message as the OUT message for the continuation of processing
      • getOutputHeader

        public String getOutputHeader()
      • setOutputHeader

        public void setOutputHeader​(String outputHeader)
        Store the query result in a header instead of the message body. By default, outputHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If outputHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved.
      • isUseMessageBodyForSql

        public boolean isUseMessageBodyForSql()
      • setUseMessageBodyForSql

        public void setUseMessageBodyForSql​(boolean useMessageBodyForSql)
        Whether to use the message body as the SQL and then headers for parameters.

        If this option is enabled then the SQL in the uri is not used.

      • getDataSource

        public DataSource getDataSource()
      • setDataSource

        public void setDataSource​(DataSource dataSource)
        Sets the DataSource to use to communicate with the database.
      • isUseIterator

        public boolean isUseIterator()
      • setUseIterator

        public void setUseIterator​(boolean useIterator)
        Sets how resultset should be delivered to route. Indicates delivery as either a list or individual object. defaults to true.
      • isRouteEmptyResultSet

        public boolean isRouteEmptyResultSet()
      • setRouteEmptyResultSet

        public void setRouteEmptyResultSet​(boolean routeEmptyResultSet)
        Sets whether empty resultset should be allowed to be sent to the next hop. Defaults to false. So the empty resultset will be filtered out.
      • getExpectedUpdateCount

        public int getExpectedUpdateCount()
      • setExpectedUpdateCount

        public void setExpectedUpdateCount​(int expectedUpdateCount)
        Sets an expected update count to validate when using onConsume.
      • isBreakBatchOnConsumeFail

        public boolean isBreakBatchOnConsumeFail()
      • setBreakBatchOnConsumeFail

        public void setBreakBatchOnConsumeFail​(boolean breakBatchOnConsumeFail)
        Sets whether to break batch if onConsume failed.
      • getPlaceholder

        public String getPlaceholder()
      • setPlaceholder

        public void setPlaceholder​(String placeholder)
        Specifies a character that will be replaced to ? in SQL query. Notice, that it is simple String.replaceAll() operation and no SQL parsing is involved (quoted strings will also change).
      • isUsePlaceholder

        public boolean isUsePlaceholder()
      • setUsePlaceholder

        public void setUsePlaceholder​(boolean usePlaceholder)
        Sets whether to use placeholder and replace all placeholder characters with ? sign in the SQL queries.

        This option is default true

      • setTemplateOptions

        public void setTemplateOptions​(Map<String,​Object> templateOptions)
        Configures the Spring JdbcTemplate with the key/values from the Map