Package org.apache.camel.component.sql
Class DefaultSqlEndpoint
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.DefaultEndpoint
-
- org.apache.camel.support.ScheduledPollEndpoint
-
- org.apache.camel.support.DefaultPollingEndpoint
-
- org.apache.camel.component.sql.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.DefaultPollingEndpointBase class for SQL endpoints.
-
-
Constructor Summary
Constructors Constructor Description DefaultSqlEndpoint()DefaultSqlEndpoint(String endpointUri, org.apache.camel.Component component)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataSourcegetDataSource()intgetExpectedUpdateCount()org.springframework.jdbc.core.JdbcTemplategetJdbcTemplate()intgetMaxMessagesPerPoll()StringgetOnConsume()StringgetOnConsumeBatchComplete()StringgetOnConsumeFailed()StringgetOutputClass()StringgetOutputHeader()SqlOutputTypegetOutputType()intgetParametersCount()StringgetPlaceholder()SqlPrepareStatementStrategygetPrepareStatementStrategy()SqlProcessingStrategygetProcessingStrategy()chargetSeparator()Map<String,Object>getTemplateOptions()booleanisAllowNamedParameters()booleanisAlwaysPopulateStatement()booleanisBatch()booleanisBreakBatchOnConsumeFail()booleanisNoop()booleanisRouteEmptyResultSet()booleanisTransacted()booleanisUseIterator()booleanisUseMessageBodyForSql()booleanisUsePlaceholder()List<?>queryForList(ResultSet rs, boolean allowMapToClass)ObjectqueryForObject(ResultSet rs)ResultSetIteratorqueryForStreamList(Connection connection, Statement statement, ResultSet rs)voidsetAllowNamedParameters(boolean allowNamedParameters)Whether to allow using named parameters in the queries.voidsetAlwaysPopulateStatement(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.voidsetBatch(boolean batch)Enables or disables batch modevoidsetBreakBatchOnConsumeFail(boolean breakBatchOnConsumeFail)Sets whether to break batch if onConsume failed.voidsetDataSource(DataSource dataSource)Sets the DataSource to use to communicate with the database.voidsetExpectedUpdateCount(int expectedUpdateCount)Sets an expected update count to validate when using onConsume.voidsetJdbcTemplate(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)voidsetMaxMessagesPerPoll(int maxMessagesPerPoll)Sets the maximum number of messages to pollvoidsetNoop(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 processingvoidsetOnConsume(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.voidsetOnConsumeBatchComplete(String onConsumeBatchComplete)After processing the entire batch, this query can be executed to bulk update rows etc.voidsetOnConsumeFailed(String onConsumeFailed)After processing each row then this query can be executed, if the Exchange failed, for example to mark the row as failed.voidsetOutputClass(String outputClass)Specify the full package and class name to use as conversion when outputType=SelectOne.voidsetOutputHeader(String outputHeader)Store the query result in a header instead of the message body.voidsetOutputType(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.voidsetParametersCount(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.voidsetPlaceholder(String placeholder)Specifies a character that will be replaced to ? in SQL query.voidsetPrepareStatementStrategy(SqlPrepareStatementStrategy prepareStatementStrategy)Allows to plugin to use a custom org.apache.camel.component.sql.SqlPrepareStatementStrategy to control preparation of the query and prepared statement.voidsetProcessingStrategy(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.voidsetRouteEmptyResultSet(boolean routeEmptyResultSet)Sets whether empty resultset should be allowed to be sent to the next hop.voidsetSeparator(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.voidsetTemplateOptions(Map<String,Object> templateOptions)Configures the Spring JdbcTemplate with the key/values from the MapvoidsetTransacted(boolean transacted)Enables or disables transaction.voidsetUseIterator(boolean useIterator)Sets how resultset should be delivered to route.voidsetUseMessageBodyForSql(boolean useMessageBodyForSql)Whether to use the message body as the SQL and then headers for parameters.voidsetUsePlaceholder(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.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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.camel.Endpoint
createProducer, getEndpointBaseUri, isSingletonProducer
-
-
-
-
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
-
getProcessingStrategy
public SqlProcessingStrategy getProcessingStrategy()
-
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.
-
getPrepareStatementStrategy
public SqlPrepareStatementStrategy getPrepareStatementStrategy()
-
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.
-
getOutputType
public SqlOutputType getOutputType()
-
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
-
queryForList
public List<?> queryForList(ResultSet rs, boolean allowMapToClass) throws SQLException
- Throws:
SQLException
-
queryForObject
public Object queryForObject(ResultSet rs) throws SQLException
- Throws:
SQLException
-
queryForStreamList
public ResultSetIterator queryForStreamList(Connection connection, Statement statement, ResultSet rs) throws SQLException
- Throws:
SQLException
-
-