Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1CFF618F30 for ; Sat, 21 Nov 2015 11:22:49 +0000 (UTC) Received: (qmail 29037 invoked by uid 500); 21 Nov 2015 11:22:48 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 28981 invoked by uid 500); 21 Nov 2015 11:22:48 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 28972 invoked by uid 99); 21 Nov 2015 11:22:48 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Nov 2015 11:22:48 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 42FFDC7D30 for ; Sat, 21 Nov 2015 11:22:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.215 X-Spam-Level: * X-Spam-Status: No, score=1.215 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.586, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Yuq3i0xRtNRP for ; Sat, 21 Nov 2015 11:22:41 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id 6B8B342AEE for ; Sat, 21 Nov 2015 11:22:41 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id C261FE0752 for ; Sat, 21 Nov 2015 11:22:40 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B61CE3A023D for ; Sat, 21 Nov 2015 11:22:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r973133 [3/3] - in /websites/production/camel/content: book-component-appendix.html book-in-one-page.html cache/main.pageCache camel-2170-release.html elsql.html mybatis.html sql-component.html Date: Sat, 21 Nov 2015 11:22:40 -0000 To: commits@camel.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151121112240.B61CE3A023D@svn01-us-west.apache.org> Modified: websites/production/camel/content/elsql.html ============================================================================== --- websites/production/camel/content/elsql.html (original) +++ websites/production/camel/content/elsql.html Sat Nov 21 11:22:39 2015 @@ -96,7 +96,7 @@

This component can be used as a Transactional Client.

The SQL component uses the following endpoint URI notation:

-

You can append query options to the URI in the following format, ?option=value&option=value&...

The parameters to the SQL queries are named parameters in the elsql mapping files, and maps to corresponding keys from the Camel message, in the given precedence:

1. Camel 2.16.1: from message body if Simple expression.

2. from message body if its a java.util.Map
3. from message headers

If a named parameter cannot be resolved, then an exception is thrown.

Options

Option

Type

Default

Description

resourceUriStringnullRequired The resource file which contains the elsql SQL statements to use. You can specify multiple resources separated by comma. The resources are loaded on the classpath by default, you can prefix with file: to load from file system. Notice you can set this option on the component and then you do not have to configure this on the endpoint.
elSqlConfig nullTo use a specific configured ElSqlConfig. It may be better to use the databaseVendor option instead.
databaseVendor DefaultTo use a vendor specific ElSqlConfig. The possible values are: Default, Postgres, HSql, MySql, Oracle, SqlServer2008, Veritca

batch

boolean

false

Execute SQL batch update statements. See notes below on how the treatment of the inbound message body changes if this is set to true.

dataSour ce

String

null

Reference to a DataSource to look up in the registry.

template.<xxx>

 

null

Sets additional options on the Spring NamedParameterJdbcTemplate that is used behind the scenes to execute the queries. For instance, template.maxRows=10. For detailed documentation, see the NamedParameterJdbcTemplate javadoc documentation.

consumer.delay

long

500

Delay in milliseconds between each poll.

consumer.initialDelay

long

1000

Milliseconds before polling starts.

consumer.useFixedDelay

boolean

false

Set to true to use fixed delay between polls, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.

maxMessagesPerPoll

int

0

An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set.

consumer.useIterator

boolean

true

If true each row returned when polling will be pro cessed individually. If false the entire java.util.List of data is set as the IN body.

consumer.routeEmptyResultSet

boolean

false

Whether to route a single empty Exchange if there was no data to poll.

consumer.onConsume

String

null

After processing each row then this query can be executed, if the Exchange was pr ocessed successfully, for example to mark the row as processed. The query can have parameter.

consumer.onConsumeFailed

String

null

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.

consumer.onConsumeBatchComplete

String

null

After processing the entire batch, this query can be executed to bulk update rows etc. The query cannot have parameters.

consumer.breakBatchOnConsumeFail

boolean

false

If using consumer.onConsume and it fails, then this option controls whether to break out of the batch or continue processing the next row from the batch.

outputType

String

SelectList

Make the output of consumer or producer to SelectList as List of Map, or SelectOne a s 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.

Tthe SelectList also supports mapping each row to a Java object as the SelectOne does (only step c).

outputClass

String

null

Specify the full package and class name to use as conversion when outputType=SelectOne.

outputHeader

Stringnull

To store the result as a header instead of the message body. This allows to preserve the existing message body as-is.

noop

boolean

false

If set, will ignore the results of the SQL query an d use the existing IN message as the OUT message for the continuation of processing

Result of the query

For select operations, the result is an instance of List<Map<String, Object>> type, as returned by the JdbcTemplate.queryForList() method. For update operations, the result is the number of updated rows, returned as an Integer.

By default, the result is placed in the message body.  If the outputHeader parameter is set, the result is placed in the header.  This is an alternative to using a full message enrichment pattern to add headers, it provides a concise syntax for querying a sequence or some other small value into a header.  It is convenient to use outputHeader and outputType together:

Header values

When performing update operations, the SQL Component stores the up date count in the following message headers:

Header

Description

CamelSqlUpdateCount

The number of rows updated for update operations, returned as an Integer object.

CamelSqlRowCount

The number of rows returned for select operations, returned as an Integer object.

Sample

In the given route below, we want to get all the projects from the projects table. Notice the SQL query has 2 named parameters, :#lic and :#min.

Camel will then lookup for these parameters from the message body or message headers. Notice in the example above we set two headers with constant value
for the named parameters:

+

You can append query options to the URI in the following format, ?option=value&option=value&...

The parameters to the SQL queries are named parameters in the elsql mapping files, and maps to corresponding keys from the Camel message, in the given precedence:

1. Camel 2.16.1: from message body if Simple expression.

2. from message body if its a java.util.Map
3. from message headers

If a named parameter cannot be resolved, then an exception is thrown.

Options

Option

Type

Default

Description

resourceUriStringnullRequired The resource file which contains the elsql SQL statements to use. You can specify multiple resources separated by comma. The resources are loaded on the classpath by default, you can prefix with file: to load from file system. Notice you can set this option on the component and then you do not have to configure this on the endpoint.
elSqlConfig nullTo use a specific configured ElSqlConfig. It may be better to use the databaseVendor option instead.
databaseVendor DefaultTo use a vendor specific ElSqlConfig. The possible values are: Default, Postgres, HSql, MySql, Oracle, SqlServer2008, Veritca

batch

boolean

false

Execute SQL batch update statements. See notes below on how the treatment of the inbound message body changes if this is set to true.

dataSour ce

String

null

Reference to a DataSource to look up in the registry.

template.<xxx>

 

null

Sets additional options on the Spring NamedParameterJdbcTemplate that is used behind the scenes to execute the queries. For instance, template.maxRows=10. For detailed documentation, see the NamedParameterJdbcTemplate javadoc documentation.

consumer.delay

long

500

Delay in milliseconds between each poll.

consumer.initialDelay

long

1000

Milliseconds before polling starts.

consumer.useFixedDelay

boolean

false

Set to true to use fixed delay between polls, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.

maxMessagesPerPoll

int

0

An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set.

consumer.useIterator

boolean

true

If true each row returned when polling will be pro cessed individually. If false the entire java.util.List of data is set as the IN body.

consumer.routeEmptyResultSet

boolean

false

Whether to route a single empty Exchange if there was no data to poll.

consumer.onConsume

String

null

After processing each row then this query can be executed, if the Exchange was pr ocessed successfully, for example to mark the row as processed. The query can have parameter.

consumer.onConsumeFailed

String

null

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.

consumer.onConsumeBatchComplete

String

null

After processing the entire batch, this query can be executed to bulk update rows etc. The query cannot have parameters.

consumer.breakBatchOnConsumeFail

boolean

false

If using consumer.onConsume and it fails, then this option controls whether to break out of the batch or continue processing the next row from the batch.

outputType

String

SelectList

Make the output of consumer or producer to SelectList as List of Map, or SelectOne a s 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.

Tthe SelectList also supports mapping each row to a Java object as the SelectOne does (only step c).

outputClass

String

null

Specify the full package and class name to use as conversion when outputType=SelectOne.

outputHeader

Stringnull

To store the result as a header instead of the message body. This allows to preserve the existing message body as-is.

noop

boolean

false

If set, will ignore the results of the SQL query an d use the existing IN message as the OUT message for the continuation of processing

transactedbooleanfalseCamel 2.16.2: SQL consumer only: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

Result of the query

For select operations, the result is an instance of List<Map<String, Object>> type, as returned by the JdbcTemplate.queryForList() method. For update operations, the result is the number of updated rows, returned as an Integer.

By default, the result is placed in the message body.  If the outputHeader parameter is set, the result is placed in the header.  This is an alternative to using a full message enrichment pattern to add headers, it provides a concise syntax for querying a sequence or some other small value into a header.  It is convenient to use outputHeader and outputType together:

Header values

When performing update operations, the SQL Component stores the update count in the following message headers:

Header

Description

CamelSqlUpdateCount

The number of rows updated for update operations, returne d as an Integer object.

CamelSqlRowCount

The number of rows returned for select operations, returned as an Integer object.

Sample

In the given route below, we want to get all the projects from the projects table. Notice the SQL query has 2 named parameters, :#lic and :#min.

Camel will then lookup for these parameters from the message body or message headers. Notice in the example above we set two headers with constant value
for the named parameters:

-

Where statementName is the statement name in the MyBatis XML mapping file which maps to the query, insert, update or delete operation you wish to evaluate.

You can append query options to the URI in the following format, ?option=value&option=value&...

This component will by default load the MyBatis SqlMapConfig file from the root of the classpath with the expected name of SqlMapConfig.xml.
If the file is located in another location, you will need to configure the configurationUri option on the MyBatisComponent component.

Options

Option

Type

Default

Description

consumer.onConsume

String

null

Statements to run after consuming. Can be used, for example, to update rows after they have been consumed and processed in Camel. See sample later. Multiple statements can be separated with commas.

consumer.useIterator

boolean

true

If true each row returned when polling will be processed individually. If false the entire List of data is set as the IN body.

consumer.routeEmptyResultSet

boolean

false

Sets whether empty result sets should be routed.

statementType

StatementType

null

Mandatory to specify for the producer to control which kind of operation to invoke. The enum values are: SelectOne, SelectList, Insert, InsertList, Update, Update List, Delete, and DeleteList. Notice: InsertList is available as of Camel 2.10, and UpdateList, DeleteList is available as of Camel 2.11.

maxMessagesPerPoll

int

0

This option is intended to split results returned by the database pool into the batches and deliver them in multiple exchanges. This integer defines the maximum messages to deliver in single exchange. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid when starting up the server that there are thousands of files. Set a value of 0 or negative to disable it.

executorType

String

null

Camel 2.11: The executor type to be used while executing statements. The supported values are: simple, reuse, batch. By default, the value is not specified and is equal to what MyBatis uses, i.e. simple.
simple executor does nothing special.
reuse executor reuses prepared statements.
batch executor reuses statements and batches updates.

outputHeader

StringnullCamel 2.15: To store the result as a header instead of the message body. This allows to preserve the existing message body as-is.
inputHeaderStringnullCamel 2.15:  "inputHeader" parameter to use a header value as input to the component instead of the body.

Message Headers

Camel will populate the result message, either IN or OUT with a header with the statement used:

Header

Type

Description

CamelMyBatisStatementName

String

The statementName used (for example: insertAccount).

CamelMyBatisResult

Object

The response returned from MtBatis in any of the operations. For instance an INSERT could return the auto-generated key, or number of rows etc.

Message Body

The response from MyBatis will only be set as the body if it's a SELECT statement. That means, for example, for INSERT statements Camel will not replace the body. This allows you to continue routing and keep the original body. The response from MyBatis is always stored in the header with the key CamelMyBatisResult.

Samples

For example if you wish to consume beans from a JMS queue and insert them into a database you could do the following:

+

Where statementName is the statement name in the MyBatis XML mapping file which maps to the query, insert, update or delete operation you wish to evaluate.

You can append query options to the URI in the following format, ?option=value&option=value&...

This component will by default load the MyBatis SqlMapConfig file from the root of the classpath with the expected name of SqlMapConfig.xml.
If the file is located in another location, you will need to configure the configurationUri option on the MyBatisComponent component.

Options

Option

Type

Default

Description

consumer.onConsume

String

null

Statements to run after consuming. Can be used, for example, to update rows after they have been consumed and processed in Camel. See sample later. Multiple statements can be separated with commas.

consumer.useIterator

boolean

true

If true each row returned when polling will be processed individually. If false the entire List of data is set as the IN body.

consumer.routeEmptyResultSet

boolean

false

Sets whether empty result sets should be routed.

statementType

StatementType

null

Mandatory to specify for the producer to control which kind of operation to invoke. The enum values are: SelectOne, SelectList, Insert, InsertList, Update, Update List, Delete, and DeleteList. Notice: InsertList is available as of Camel 2.10, and UpdateList, DeleteList is available as of Camel 2.11.

maxMessagesPerPoll

int

0

This option is intended to split results returned by the database pool into the batches and deliver them in multiple exchanges. This integer defines the maximum messages to deliver in single exchange. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid when starting up the server that there are thousands of files. Set a value of 0 or negative to disable it.

executorType

String

null

Camel 2.11: The executor type to be used while executing statements. The supported values are: simple, reuse, batch. By default, the value is not specified and is equal to what MyBatis uses, i.e. simple.
simple executor does nothing special.
reuse executor reuses prepared statements.
batch executor reuses statements and batches updates.

outputHeader

StringnullCamel 2.15: To store the result as a header instead of the message body. This allows to preserve the existing message body as-is.
inputHeaderStringnullCamel 2.15:  "inputHeader" parameter to use a header value as input to the component instead of the body.
transactedbooleanfalseCamel 2.16.2: SQL consumer only: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

Message Headers

Camel will populate the result message, either IN or OUT with a header with the statement used:

Header

Type

Description

CamelMyBatisStatementName

String

Th e statementName used (for example: insertAccount).

CamelMyBatisResult

Object

The response returned from MtBatis in any of the operations. For instance an INSERT could return the auto-generated key, or number of rows etc.

Message Body

The response from MyBatis will only be set as the body if it's a SELECT statement. That means, for example, for INSERT statements Camel will not replace the body. This allows you to continue routing and keep the original body. The response from MyBatis is always stored in the header with the key CamelMyBatisResult.

Samples

For example if you wish t o consume beans from a JMS queue and insert them into a database you could do the following:

@@ -121,13 +121,13 @@ from("direct:start") .to("mybatis:selectAccountById?statementType=SelectOne") .to("mock:result"); ]]> -

In the code above we can invoke the MyBatis statement selectAccountById and the IN body should contain the account id we want to retrieve, such as an Integer type.

We can do the same for some of the other operations, such as SelectList:

+
In the code above we can invoke the MyBatis statement selectAccountById and the IN body should contain the account id we want to retrieve, such as an Integer type.

We can do the same for some of the other operations, such as SelectList:

-

And the same for UPDATE, where we can send an Account object as the IN body to MyBatis:

+
And the same for UPDATE, where we can send an Account object as the IN body to MyBatis:
-

Then you can insert multiple rows, by sending a Camel message to the mybatis endpoint which uses the InsertList statement type, as shown below:

+
Then you can insert multiple rows, by sending a Camel message to the mybatis endpoint which uses the InsertList statement type, as shown below:
-

And the statements in the sqlmap file:

+
And the statements in the sqlmap file:

When using named parameters, Camel will lookup the names from, in the given precedence:
1. from message body if its a java.util.Map
2. from message headers

If a named parameter cannot be resolved, then an exception is thrown.

From Camel 2.14 onward you can use Simple expressions as parameters as shown:

-

Notice that the standard ? symbol that denotes the parameters to an SQL query is substituted with the # symbol, because the ? symbol is used to specify options for the endpoint. The ? symbol replacement can be configured on endpoint basis.

You can append query options to the URI in the following format, ?option=value&option=value&...

Options

Option

Type

Default

Description

batch

bool ean

false

Camel 2.7.5, 2.8.4 and 2.9: Execute SQL batch update statements. See notes below on how the treatment of the inbound message body changes if this is set to true.

dataSourceRef

String

null

Deprecated and will be removed in Camel 3.0: Reference to a DataSource to look up in the registry. Use dataSource=#theName instead.

dataSource

String< /code>

null

Camel 2.11: Reference to a DataSource to look up in the registry.

placeholder

String

#

Camel 2.4: 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). This replacement is only happening if the endpoint is created using the SqlComponent. If you manually create the endpoint, then use the expected ? sign instead.

< /td>

template.<xxx>

 

null

Sets additional options on the Spring JdbcTemplate that is used behind the scenes to execute the queries. For instance, template.maxRows=10. For detailed documentation, see the JdbcTemplate javadoc documentation.

allowNamedParameters

boolean

true

Camel 2.11: Whether to allow using named parameters in the queries.

processingStrategy

 

 

Camel 2.11: SQL consumer only: Allows to plugin to use a custom org.apache.camel.component.sql.SqlProcessingStrategy to execute queries when the consumer has processed the rows/batch.

prepareStatementStrategy

 

 

Camel 2.11: Allows to plugin to use a custom org.apache.camel.component.sql.SqlPrepareStatementStrategy to control preparation of the query and prepared statement.

consumer.delay

long

500

Camel 2.11: SQL consumer only: Delay in milliseconds between each poll.

consumer.initialDelay

long

1000

Camel 2.11: SQL consumer only: Milliseconds before polling starts.

consumer.useFixedDelay

boolean

false

Camel 2.11: SQL consumer only: Set to true to use fixed delay between polls, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.

maxMessagesPerPoll

int

0

Camel 2.11: SQL consumer only: An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set.

consumer.useIterator

boolean

true

Camel 2.11: SQL consumer only: If true each row returned when polling will be processed individually. If false the entire java.util.List of data is set as the IN body.

consumer.routeEmptyResultSet

boolean

false

Camel 2.11: SQL consumer only: Whether to route a single empty Exchange if there was no data to poll.

consumer.onConsume

String

null

Camel 2.11: SQL consumer only: 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.

consumer.onConsumeFailed

String

null

Camel 2.11: SQL consumer only: 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.

consumer.onConsumeBatchComplete

String

null

Camel 2.11: SQL consumer only: After processing the entire batch, this query can be executed to bulk update rows etc. The query cannot have parameters.

consumer.expectedUpdateCount

int

-1

Camel 2.11: SQL consumer only: If using consumer.onConsume then this option can be used to set an expected number of rows being updated. Typically you may set this to 1 to expect one row to be updated.

consumer.breakBatchOnConsumeFail

boolean

false

Camel 2.11: SQL consumer only: If using consumer.onConsume and it fails, then this optio n controls whether to break out of the batch or continue processing the next row from the batch.

alwaysPopulateStatement

boolean

false

Camel 2.11: SQL producer only: 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.

separator

char

,

Camel 2.11.1: 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.

outputType

String

SelectList

Camel 2.12.0: 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.

From Camel 2.14.1 onwards the SelectList also supports mapping each row to a Java object as the SelectOne does (only step c).

outputClass

String

null

Camel 2.12.0: Specify the full package and class name to use as conversion when outputType=SelectOne.

outputHeader

Stringnull

Camel 2.15: To store the result as a header instead of the message body. This allows to preserve the existing message body as-is.

parametersCount

int

0

Camel 2.11.2/2.12.0 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.

noop

boolean

false

Camel 2.12.0 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

useMessageBodyForSqlbooleanfalseCamel 2.16: 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. The SQL parameters must then be provided in a header with the key CamelSqlParameters. This option is only for the producer.

Treatment of the message body

The SQL component tries to convert the message body to an object of java.util.Iterator type and then uses this iterator to fill the query parameters (where each query parameter is represented by a # symbol (or configured placeholder) in the endpoint URI). If the message body is not an array or collection, the conversion results in an iterator that iterates over only one object, which is the body itself.

For example, if the message body is an instance of java.util.List, the first item in the list is substituted into the first occurrence of # in the SQL query, the second item in the list is substituted into the second occurrence of #, and so on.

If batch is set to true, then the interpretation of the inbound message body changes slightly – instead of an iterator of parameters, the component expects an iterator that contains the parameter iterators; the size of the outer iterator determines the batch size.

From Camel 2.16 onwards you can use the option useMessageBodyForSql that allows to use the message body as the SQL statement, and then the SQL parameters must be provided in a header with the key SqlConstants.SQL_PARAMETERS. This allows the SQL component to work more dynamic as the SQL query is from the message body.

Result of the query

For select operations, the result is an instance of List<Map<String, Object>> type, as returned by the JdbcTemplate.queryForList() method. For update operations, the result is the number of updated rows, returned as an Integer.

By default, the result is placed in the message body.  If the outputHeader parameter is set, the result is placed in the header.  This is an alternative to using a full message enrichment pattern to add headers, it provides a concise syntax for querying a sequence or some other small value into a header.  It is convenient to use outputHeader and outputType together:

+

Notice that the standard ? symbol that denotes the parameters to an SQL query is substituted with the # symbol, because the ? symbol is used to specify options for the endpoint. The ? symbol replacement can be configured on endpoint basis.

You can append query options to the URI in the following format, ?option=value&option=value&...

Options

Option

Type

Default

Description

batch

bool ean

false

Camel 2.7.5, 2.8.4 and 2.9: Execute SQL batch update statements. See notes below on how the treatment of the inbound message body changes if this is set to true.

dataSourceRef

String

null

Deprecated and will be removed in Camel 3.0: Reference to a DataSource to look up in the registry. Use dataSource=#theName instead.

dataSource

String< /code>

null

Camel 2.11: Reference to a DataSource to look up in the registry.

placeholder

String

#

Camel 2.4: 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). This replacement is only happening if the endpoint is created using the SqlComponent. If you manually create the endpoint, then use the expected ? sign instead.

< /td>

template.<xxx>

 

null

Sets additional options on the Spring JdbcTemplate that is used behind the scenes to execute the queries. For instance, template.maxRows=10. For detailed documentation, see the JdbcTemplate javadoc documentation.

allowNamedParameters

boolean

true

Camel 2.11: Whether to allow using named parameters in the queries.

processingStrategy

 

 

Camel 2.11: SQL consumer only: Allows to plugin to use a custom org.apache.camel.component.sql.SqlProcessingStrategy to execute queries when the consumer has processed the rows/batch.

prepareStatementStrategy

 

 

Camel 2.11: Allows to plugin to use a custom org.apache.camel.component.sql.SqlPrepareStatementStrategy to control preparation of the query and prepared statement.

consumer.delay

long

500

Camel 2.11: SQL consumer only: Delay in milliseconds between each poll.

consumer.initialDelay

long

1000

Camel 2.11: SQL consumer only: Milliseconds before polling starts.

consumer.useFixedDelay

boolean

false

Camel 2.11: SQL consumer only: Set to true to use fixed delay between polls, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.

maxMessagesPerPoll

int

0

Camel 2.11: SQL consumer only: An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set.

consumer.useIterator

boolean

true

Camel 2.11: SQL consumer only: If true each row returned when polling will be processed individually. If false the entire java.util.List of data is set as the IN body.

consumer.routeEmptyResultSet

boolean

false

Camel 2.11: SQL consumer only: Whether to route a single empty Exchange if there was no data to poll.

consumer.onConsume

String

null

Camel 2.11: SQL consumer only: 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.

consumer.onConsumeFailed

String

null

Camel 2.11: SQL consumer only: 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.

consumer.onConsumeBatchComplete

String

null

Camel 2.11: SQL consumer only: After processing the entire batch, this query can be executed to bulk update rows etc. The query cannot have parameters.

consumer.expectedUpdateCount

int

-1

Camel 2.11: SQL consumer only: If using consumer.onConsume then this option can be used to set an expected number of rows being updated. Typically you may set this to 1 to expect one row to be updated.

consumer.breakBatchOnConsumeFail

boolean

false

Camel 2.11: SQL consumer only: If using consumer.onConsume and it fails, then this optio n controls whether to break out of the batch or continue processing the next row from the batch.

alwaysPopulateStatement

boolean

false

Camel 2.11: SQL producer only: 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.

separator

char

,

Camel 2.11.1: 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.

outputType

String

SelectList

Camel 2.12.0: 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.

From Camel 2.14.1 onwards the SelectList also supports mapping each row to a Java object as the SelectOne does (only step c).

outputClass

String

null

Camel 2.12.0: Specify the full package and class name to use as conversion when outputType=SelectOne.

outputHeader

Stringnull

Camel 2.15: To store the result as a header instead of the message body. This allows to preserve the existing message body as-is.

parametersCount

int

0

Camel 2.11.2/2.12.0 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.

noop

boolean

false

Camel 2.12.0 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

useMessageBodyForSqlbooleanfalseCamel 2.16: 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. The SQL parameters must then be provided in a header with the key CamelSqlParameters. This option is only for the producer.
transactedbooleanfalseCamel 2.16.2: SQL consumer only: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

Treatment of the message body

The SQL component tries to convert the message body to an object of java.util.Iterator type and then uses this iterator to fill the query parameters (where each query parameter is represented by a # symbol (or configured placeholder) in the endpoint URI). If the message body is not an array or collection, the conversion results in an iterator that iterates over only one object, which is the body itself.

For example, if the message body is an instance of java.util.List, the first item in the list is substituted into the first occurrence of # in the SQL query, the second item in the list is substituted into the second occurrence of #, and so on.

If batch is set to true, then the interpretation of the inbound message body changes slightly – instead of an iterator of parameters, the component expects an iterator that contains the parameter iterators; the size of the outer it erator determines the batch size.

From Camel 2.16 onwards you can use the option useMessageBodyForSql that allows to use the message body as the SQL statement, and then the SQL parameters must be provided in a header with the key SqlConstants.SQL_PARAMETERS. This allows the SQL component to work more dynamic as the SQL query is from the message body.

Result of the query

For select operations, the result is an instance of List<Map<String, Object>> type, as returned by the JdbcTemplate.queryForList() method. For update operations, the result is the number of updated rows, returned as an Integer.

By default, the result is placed in the message body.  If the outputHeader parameter is set, the result is placed in the header.  This is an alternative to using a full message enrichment pattern to add headers, it provides a concise syntax for querying a sequence or some other small value into a header.  It is convenient to use outputHeader and outputType together: