Author: buildbot
Date: Fri Aug 25 14:20:21 2017
New Revision: 1017284
Log:
Production update by buildbot for camel
Modified:
websites/production/camel/content/book-in-one-page.html
websites/production/camel/content/cache/main.pageCache
websites/production/camel/content/sql-component.html
websites/production/camel/content/type-converter.html
websites/production/camel/content/websocket.html
Modified: websites/production/camel/content/book-in-one-page.html
==============================================================================
--- websites/production/camel/content/book-in-one-page.html (original)
+++ websites/production/camel/content/book-in-one-page.html Fri Aug 25 14:20:21
2017
@@ -4368,11 +4368,11 @@ So we completed the last piece in the pi
<p>This example has been removed from <strong>Camel 2.9</strong> onwards.
Apache Axis 1.4 is a very old and unsupported framework. We encourage users to
use <a shape="rect" href="cxf.html">CXF</a> instead of Axis.</p></div></div>
<style type="text/css">/*<![CDATA[*/
-div.rbtoc1503659924819 {padding: 0px;}
-div.rbtoc1503659924819 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1503659924819 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1503670734831 {padding: 0px;}
+div.rbtoc1503670734831 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1503670734831 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style><div class="toc-macro rbtoc1503659924819">
+/*]]>*/</style><div class="toc-macro rbtoc1503670734831">
<ul class="toc-indentation"><li><a shape="rect"
href="#BookInOnePage-TutorialusingAxis1.4withApacheCamel">Tutorial using Axis
1.4 with Apache Camel</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#BookInOnePage-Prerequisites">Prerequisites</a></li><li><a shape="rect"
href="#BookInOnePage-Distribution">Distribution</a></li><li><a shape="rect"
href="#BookInOnePage-Introduction">Introduction</a></li><li><a shape="rect"
href="#BookInOnePage-SettinguptheprojecttorunAxis">Setting up the project to
run Axis</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#BookInOnePage-Maven2">Maven 2</a></li><li><a shape="rect"
href="#BookInOnePage-wsdl">wsdl</a></li><li><a shape="rect"
href="#BookInOnePage-ConfiguringAxis">Configuring Axis</a></li><li><a
shape="rect" href="#BookInOnePage-RunningtheExample">Running the
Example</a></li></ul>
Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/camel/content/sql-component.html
==============================================================================
--- websites/production/camel/content/sql-component.html (original)
+++ websites/production/camel/content/sql-component.html Fri Aug 25 14:20:21
2017
@@ -36,18 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushSql.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: SQL Component
@@ -87,173 +75,74 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="SQLComponent-SQLComponent">SQL
Component</h2><p>The <strong>sql:</strong> component allows you to work with
databases using JDBC queries. The difference between this component and <a
shape="rect" href="jdbc.html">JDBC</a> component is that in case of SQL the
query is a property of the endpoint and it uses message payload as parameters
passed to the query.</p><p>This component uses
<code><strong>spring-jdbc</strong></code> behind the scenes for the actual SQL
handling.</p><p>Maven users will need to add the following dependency to their
<code>pom.xml</code> for this component:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+<div class="wiki-content maincontent"><h2 id="SQLComponent-SQLComponent">SQL
Component</h2><p>The <strong>sql:</strong> component allows you to work with
databases using JDBC queries. The difference between this component and <a
shape="rect" href="jdbc.html">JDBC</a> component is that in case of SQL the
query is a property of the endpoint and it uses message payload as parameters
passed to the query.</p><p>This component uses
<code><strong>spring-jdbc</strong></code> behind the scenes for the actual SQL
handling.</p><p>Maven users will need to add the following dependency to their
<code>pom.xml</code> for this component:</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-sql</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div><p>The SQL component also supports:</p><ul class="alternate"><li>a
JDBC based repository for the <a shape="rect"
href="idempotent-consumer.html">Idempotent Consumer</a> EIP pattern. See
further below.</li><li>a JDBC based repository for the <a shape="rect"
href="aggregator2.html">Aggregator</a> EIP pattern. See further
below.</li></ul><h3 id="SQLComponent-URIformat">URI format</h3><div
class="confluence-information-macro confluence-information-macro-warning"><span
class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From Camel 2.11 onwards this
component can create both consumer (e.g. <code>from()</code>) and producer
endpoints (e.g. <code>to()</code>).</p><p>In previous versions, it could only
act as a producer.</p></div></div><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-informati
on-macro-icon"></span><div class="confluence-information-macro-body"><p>This
component can be used as a <a shape="rect" class="external-link"
href="http://camel.apache.org/transactional-client.html">Transactional
Client</a>.</p></div></div><p>The SQL component uses the following endpoint URI
notation:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[sql:select * from table where id=# order by
name[?options]
-]]></script>
-</div></div><p>From Camel 2.11 onwards you can use named parameters by using
:<code>#name_of_the_parameter</code> style as shown:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[sql:select * from table where id=:#myId order
by name[?options]
-]]></script>
-</div></div><p>When using named parameters, Camel will lookup the names from,
in the given precedence:<br clear="none"> 1. from message body if its a
<code>java.util.Map</code><br clear="none"> 2. from message headers</p><p>If a
named parameter cannot be resolved, then an exception is thrown.</p><p>From
<strong>Camel 2.14</strong> onward you can use Simple expressions as parameters
as shown:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[sql:select * from table where
id=:#${property.myId} order by name[?options]]]></script>
-</div></div><p>Notice that the standard <code>?</code> symbol that denotes the
parameters to an SQL query is substituted with the <code>#</code> symbol,
because the <code>?</code> symbol is used to specify options for the endpoint.
The <code>?</code> symbol replacement can be configured on endpoint
basis.</p><p>From <strong>Camel 2.17</strong> onwards you can externalize your
SQL queries to files in the classpath or file system as shown:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[sql:classpath:sql/myquery.sql[?options]]]></script>
-</div></div><p>And the myquery.sql file is in the classpath and is just a
plain text</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[-- this is a comment
+</plain-text-body><p>The SQL component also supports:</p><ul
class="alternate"><li>a JDBC based repository for the <a shape="rect"
href="idempotent-consumer.html">Idempotent Consumer</a> EIP pattern. See
further below.</li><li>a JDBC based repository for the <a shape="rect"
href="aggregator2.html">Aggregator</a> EIP pattern. See further
below.</li></ul><h3 id="SQLComponent-URIformat">URI
format</h3><rich-text-body><p>From Camel 2.11 onwards this component can create
both consumer (e.g. <code>from()</code>) and producer endpoints (e.g.
<code>to()</code>).</p><p>In previous versions, it could only act as a
producer.</p></rich-text-body><rich-text-body><p>This component can be used as
a <a shape="rect" class="external-link"
href="http://camel.apache.org/transactional-client.html">Transactional
Client</a>.</p></rich-text-body><p>The SQL component uses the following
endpoint URI notation:</p><plain-text-body>sql:select * from table where id=#
order by name[?options]
+</plain-text-body><p>From Camel 2.11 onwards you can use named parameters by
using :<code>#name_of_the_parameter</code> style as
shown:</p><plain-text-body>sql:select * from table where id=:#myId order by
name[?options]
+</plain-text-body><p>When using named parameters, Camel will lookup the names
from, in the given precedence:<br clear="none"> 1. from message body if its a
<code>java.util.Map</code><br clear="none"> 2. from message headers</p><p>If a
named parameter cannot be resolved, then an exception is thrown.</p><p>From
<strong>Camel 2.14</strong> onward you can use Simple expressions as parameters
as shown:</p><plain-text-body>sql:select * from table where
id=:#${property.myId} order by name[?options]</plain-text-body><p>Notice that
the standard <code>?</code> symbol that denotes the parameters to an SQL query
is substituted with the <code>#</code> symbol, because the <code>?</code>
symbol is used to specify options for the endpoint. The <code>?</code> symbol
replacement can be configured on endpoint basis.</p><p>From <strong>Camel
2.17</strong> onwards you can externalize your SQL queries to files in the
classpath or file system as
shown:</p><plain-text-body>sql:classpath:sql/myquery.sql[?op
tions]</plain-text-body><p>And the myquery.sql file is in the classpath and is
just a plain text</p><plain-text-body>-- this is a comment
select *
from table
where
id = :#${property.myId}
order by
- name]]></script>
-</div></div><p>In the file you can use multilines and format the SQL as you
wish. And also use comments such as the – dash line.</p><p>You can
append query options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="SQLComponent-Options">Options</h3><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>batch</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.7
.5, 2.8.4 and 2.9:</strong> Execute SQL batch update statements. See notes
below on how the treatment of the inbound message body changes if this is set
to <code>true</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>dataSourceRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Deprecated and will be removed in
Camel 3.0:</strong> Reference to a <code>DataSource</code> to look up in the
registry. Use <code>dataSource=#theName</code> instead.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>dataSource</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</s
trong> Reference to a <code>DataSource</code> to look up in the
registry.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>placeholder</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>#</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.4:</strong> Specifies a
character that will be replaced to <code>?</code> in SQL query. Notice, that it
is simple <code>String.replaceAll()</code> operation and no SQL parsing is
involved (quoted strings will also change). This replacement is
<strong>only</strong> happening if the endpoint is created using the
<code>SqlComponent</code>. If you manually create the endpoint, then use the
expected <code>?</code> sign instead.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><code>usePlaceholder</code></td><td
colspan="1" rowspan="1" class="confluenceTd"><code>boolean</code></td
><td colspan="1" rowspan="1" class="confluenceTd"><code>true</code></td><td
>colspan="1" rowspan="1" class="confluenceTd"><strong>Camel 2.17:</strong>
>Sets whether to use placeholder and replace all placeholder characters with ?
>sign in the SQL queries.</td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>template.<xxx></code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>Sets additional options on
>the Spring <code>JdbcTemplate</code> that is used behind the scenes to
>execute the queries. For instance, <code>template.maxRows=10</code>. For
>detailed documentation, see the <a shape="rect" class="external-link"
>href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html"
> rel="nofollow">JdbcTemplate javadoc</a> documentation.</p></td></tr><tr><td
>colspan="1"
rowspan="1"
class="confluenceTd"><p><code>allowNamedParameters</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> Whether to
allow using named parameters in the queries.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>processingStrategy</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
only:</strong> Allows to plugin to use a custom
<code>org.apache.camel.component.sql.SqlProcessingStrategy</code> to execute
queries when the consumer has processed the rows/batch.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>prepareStatementStrate
gy</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.11:</strong> Allows to plugin to use a
custom <code>org.apache.camel.component.sql.SqlPrepareStatementStrategy</code>
to control preparation of the query and prepared
statement.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.delay</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>long</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>500</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Delay in milliseconds between each
poll.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.initialDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>long</code>
</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>1000</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
only:</strong> Milliseconds before polling starts.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.useFixedDelay</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Set to <code>true</code> to use fixed delay between
polls, otherwise fixed rate is used. See <a shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code
>maxMessagesPerPoll</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>int</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
>only:</strong> An integer value to define the maximum number of messages to
>gather per poll. By default, no maximum is set.</p></td></tr><tr><td
>colspan="1" rowspan="1"
>class="confluenceTd"><p><code>useIterator</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
><strong>SQL consumer only:</strong> If <code>true</code> each row returned
>when polling will be processed individually. If <code>false</code> the entire
><code>java.util.List</code> of data is set as the IN body.<span> Notice in
>Camel 2.15.x o
r older you need to prefix this option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>routeEmptyResultSet</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Whether to route a single empty <a shape="rect"
href="exchange.html">Exchange</a> if there was no data to poll.<span> Notice in
Camel 2.15.x or older you need to prefix this option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>onConsume</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1
" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
only:</strong> After processing each row then this query can be executed, if
the <a shape="rect" href="exchange.html">Exchange</a> was processed
successfully, for example to mark the row as processed. The query can have
parameter.<span> Notice in Camel 2.15.x or older you need to prefix this option
with consumer., eg consumer.useIterator=true.</span></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>onConsumeFailed</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> After processing each row then this query can be
executed, if the <a shape="rect" href="exchange.html">Exchange</a> failed, for
example to mark the row as failed. The query can have param
eter.<span> Notice in Camel 2.15.x or older you need to prefix this option
with consumer., eg consumer.useIterator=true.</span></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>onConsumeBatchComplete</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
<strong>SQL consumer only:</strong> After processing the entire batch, this
query can be executed to bulk update rows etc. The query cannot have
parameters.<span> Notice in Camel 2.15.x or older you need to prefix this
option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>expectedUpdateCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p
><code>-1</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
>only:</strong> If using <code>consumer.onConsume</code> then this option can
>be used to set an expected number of rows being updated. Typically you may
>set this to <code>1</code> to expect one row to be updated.<span> Notice in
>Camel 2.15.x or older you need to prefix this option with consumer., eg
>consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1"
>rowspan="1"
>class="confluenceTd"><p><code>breakBatchOnConsumeFail</code></p></td><td
>colspan="1" rowspan="1"
>class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
><strong>SQL consumer only:</strong> If using <code>consumer.onConsume</code>
>and it fails, then this option controls whether to break out of the batch or
>continue processing the nex
t row from the batch. Notice in Camel 2.15.x or older you need to prefix this
option with consumer., eg consumer.useIterator=true.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>alwaysPopulateStatement</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
producer only:</strong> If enabled then the <code>populateStatement</code>
method from
<code>org.apache.camel.component.sql.SqlPrepareStatementStrategy</code> is
always invoked, also if there is no expected parameters to be prepared. When
this is <code>false</code> then the <code>populateStatement</code> 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.</p></td></tr><tr><td colspan="1
" rowspan="1" class="confluenceTd"><p><code>separator</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>char</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>,</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11.1:</strong>
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 <code>Map</code> type is used
instead.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outputType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>SelectList</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.0:</strong>
<span>outputType='SelectList', for consumer or producer, w</span><span>ill
output a List of Map</span>. <code>SelectOne</code>
will output single Java object in the following way:<br clear="none"> a) If
the query has only single column, then that JDBC Column object is returned.
(such as <code>SELECT COUNT( * ) FROM PROJECT</code> will return a Long
object.<br clear="none"> b) If the query has more than one column, then it will
return a Map of that result.<br clear="none"> c) If the
<code>outputClass</code> 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.<br
clear="none"> d) If the query resulted in more than one rows, it throws an
non-unique result exception.</p><p>From <strong>Camel 2.14.1</strong> onwards
the SelectList also supports mapping each row to a Java object as the SelectOne
does <span>(only step c)</span>.</p><p>From <strong>Camel 2.18</strong> onwards
there is a new StreamList outputType that streams the result of the query using
an Iterator
. It can be used with the <a shape="rect" href="splitter.html">Splitter</a>
EIP in streaming mode to process the ResultSet in streaming fashion. This
StreamList do not support batch mode, but you can use outputClass to map each
row to a class.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outputClass</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.0:</strong> Specify the
full package and class name to use as conversion when
<code>outputType=SelectOne</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outputHeader</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>String</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>null</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Ca
mel 2.15:</strong> To store the result as a header instead of the message
body. This allows to preserve the existing message body
as-is.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>parametersCount</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11.2/2.12.0</strong> 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.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>noop</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
ro
wspan="1" class="confluenceTd"><p><strong>Camel 2.12.0</strong> 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</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><code>useMessageBodyForSql</code></td><td
colspan="1" rowspan="1" class="confluenceTd"><code>boolean</code></td><td
colspan="1" rowspan="1" class="confluenceTd"><code>false</code></td><td
colspan="1" rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong>
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 <code>CamelSqlParameters</code>.
This option is only for the producer.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>transacted</code></td><td colspan="1" rowspan="1"
class="confluenceTd"><code>boolean</code></td><td colspan="1" rowspan="1" cl
ass="confluenceTd"><code>false</code></td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16.2:</strong> <strong>SQL consumer
only:</strong>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</td></tr></tbody></table></div></div>
-
-
-<h3 id="SQLComponent-Treatmentofthemessagebody">Treatment of the message
body</h3><p>The SQL component tries to convert the message body to an object of
<code>java.util.Iterator</code> type and then uses this iterator to fill the
query parameters (where each query parameter is represented by a <code>#</code>
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.</p><p>For example, if the
message body is an instance of <code>java.util.List</code>, the first item in
the list is substituted into the first occurrence of <code>#</code> in the SQL
query, the second item in the list is substituted into the second occurrence of
<code>#</code>, and so on.</p><p>If <code>batch</code> is set to
<code>true</code>, then the interpretation of the inbound message body changes
slightly – instead of an iterator of parameters, the component exp
ects an iterator that contains the parameter iterators; the size of the outer
iterator determines the batch size.</p><p>From Camel 2.16 onwards you can use
the option <span>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.</span></p><h3
id="SQLComponent-Resultofthequery">Result of the query</h3><p>For
<code>select</code> operations, the result is an instance of
<code>List<Map<String, Object>></code> type, as returned by the <a
shape="rect" class="external-link"
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html#queryForList(java.lang.String,%20java.lang.Object%91%93)"
rel="nofollow">JdbcTemplate.queryForList()</a> method. For <code>update</code>
operations, the result is the number of
updated rows, returned as an <code>Integer</code>.</p><p>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:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("jms:order.inbox")
- .to("sql:select order_seq.nextval from
dual?outputHeader=OrderId&outputType=SelectOne")
- .to("jms:order.booking");]]></script>
-</div></div><h3 id="SQLComponent-UsingStreamList">Using
StreamList</h3><p>From<strong> Camel 2.18</strong> onwards the producer
supports outputType=StreamList that uses an iterator to stream the output of
the query. This allows to process the data in a streaming fashion which for
example can be used by the <a shape="rect"
href="splitter.html">Splitter</a> EIP to process each row one at a time, and
load data from the database as needed.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:withSplitModel")
- .to("sql:select * from projects order by
id?outputType=StreamList&outputClass=org.apache.camel.component.sql.ProjectModel")
- .to("log:stream")
+ name</plain-text-body><p>In the file you can use multilines and format the
SQL as you wish. And also use comments such as the – dash
line.</p><p>You can append query options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="SQLComponent-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>batch</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.7.5, 2.8.4 and
2.9:</strong> Execute SQL batch update statements. See notes below on how the
treatment of the inbound message body changes if this is set to
<code>true</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>dataSourceRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Deprecated and will be removed in
Camel 3.0:</strong> Reference to a <code>DataSource</code> to look up in the
registry. Use <code>dataSource=#theName</code> instead.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>dataSource</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowsp
an="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> Reference to a
<code>DataSource</code> to look up in the registry.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>placeholder</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>#</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.4:</strong> Specifies a
character that will be replaced to <code>?</code> in SQL query. Notice, that it
is simple <code>String.replaceAll()</code> operation and no SQL parsing is
involved (quoted strings will also change). This replacement is
<strong>only</strong> happening if the endpoint is created using the
<code>SqlComponent</code>. If you manually create the endpoint, then use the
expected <code>?</code> sign instead.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><code>usePlaceholder</code></td><td
colspan="1" rows
pan="1" class="confluenceTd"><code>boolean</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>true</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.17:</strong> Sets whether to
use placeholder and replace all placeholder characters with ? sign in the SQL
queries.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>template.<xxx></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Sets additional options on the Spring
<code>JdbcTemplate</code> that is used behind the scenes to execute the
queries. For instance, <code>template.maxRows=10</code>. For detailed
documentation, see the <a shape="rect" class="external-link"
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html"
rel="nofollow">JdbcTemplate javadoc
</a> documentation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>allowNamedParameters</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> Whether to
allow using named parameters in the queries.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>processingStrategy</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
only:</strong> Allows to plugin to use a custom
<code>org.apache.camel.component.sql.SqlProcessingStrategy</code> to execute
queries when the consumer has processed the rows/batch.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>prepareStatementStrategy</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.11:</strong> Allows to plugin to use a
custom <code>org.apache.camel.component.sql.SqlPrepareStatementStrategy</code>
to control preparation of the query and prepared
statement.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.delay</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>long</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>500</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Delay in milliseconds between each
poll.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.initialDelay</code></p></td><td
colspan="1"
rowspan="1" class="confluenceTd"><p><code>long</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Milliseconds before polling
starts.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.useFixedDelay</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Set to <code>true</code> to use fixed delay between
polls, otherwise fixed rate is used. See <a shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for
details.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>maxMessagesPerPoll</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> An integer value to define the maximum number of
messages to gather per poll. By default, no maximum is
set.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useIterator</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
<strong>SQL consumer only:</strong> If <code>true</code> each row returned when
polling will be processed individually. If <code>false</code> the entire
<code>java.util.List</code> of data
is set as the IN body.<span> Notice in Camel 2.15.x or older you need to
prefix this option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>routeEmptyResultSet</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> Whether to route a single empty <a shape="rect"
href="exchange.html">Exchange</a> if there was no data to poll.<span> Notice in
Camel 2.15.x or older you need to prefix this option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>onConsume</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p
><code>null</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
>only:</strong> After processing each row then this query can be executed, if
>the <a shape="rect" href="exchange.html">Exchange</a> was processed
>successfully, for example to mark the row as processed. The query can have
>parameter.<span> Notice in Camel 2.15.x or older you need to prefix this
>option with consumer., eg
>consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>onConsumeFailed</code></p></td><td
>colspan="1" rowspan="1"
>class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
>consumer only:</strong> After processing each row then this query can be
>executed, if the <a shape="rect" href="exchange.html">Exchange</a> failed,
>for exampl
e to mark the row as failed. The query can have parameter.<span> Notice in
Camel 2.15.x or older you need to prefix this option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>onConsumeBatchComplete</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
<strong>SQL consumer only:</strong> After processing the entire batch, this
query can be executed to bulk update rows etc. The query cannot have
parameters.<span> Notice in Camel 2.15.x or older you need to prefix this
option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>expectedUpdateCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>int</code></p></t
d><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>-1</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL consumer
only:</strong> If using <code>consumer.onConsume</code> then this option can be
used to set an expected number of rows being updated. Typically you may set
this to <code>1</code> to expect one row to be updated.<span> Notice in Camel
2.15.x or older you need to prefix this option with consumer., eg
consumer.useIterator=true.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>breakBatchOnConsumeFail</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
consumer only:</strong> If using <code>consumer.onConsume</code> and it fails,
then this option controls whether to
break out of the batch or continue processing the next row from the batch.
Notice in Camel 2.15.x or older you need to prefix this option with consumer.,
eg consumer.useIterator=true.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>alwaysPopulateStatement</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> <strong>SQL
producer only:</strong> If enabled then the <code>populateStatement</code>
method from
<code>org.apache.camel.component.sql.SqlPrepareStatementStrategy</code> is
always invoked, also if there is no expected parameters to be prepared. When
this is <code>false</code> then the <code>populateStatement</code> 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 querie
s with no parameters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>separator</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>char</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>,</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.11.1:</strong> 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 <code>Map</code> type is used instead.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>outputType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>SelectList</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.0:</strong>
<span>outputType='SelectList', for consumer or producer, w</span><span>il
l output a List of Map</span>. <code>SelectOne</code> will output single Java
object in the following way:<br clear="none"> a) If the query has only single
column, then that JDBC Column object is returned. (such as <code>SELECT COUNT(
* ) FROM PROJECT</code> will return a Long object.<br clear="none"> b) If the
query has more than one column, then it will return a Map of that result.<br
clear="none"> c) If the <code>outputClass</code> 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.<br clear="none"> d) If the query resulted in more than one rows,
it throws an non-unique result exception.</p><p>From <strong>Camel
2.14.1</strong> onwards the SelectList also supports mapping each row to a Java
object as the SelectOne does <span>(only step c)</span>.</p><p>From
<strong>Camel 2.18</strong> onwards there is a new StreamList outputType t
hat streams the result of the query using an Iterator. It can be used with the
<a shape="rect" href="splitter.html">Splitter</a> EIP in streaming mode to
process the ResultSet in streaming fashion. This StreamList do not support
batch mode, but you can use outputClass to map each row to a
class.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outputClass</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.0:</strong> Specify the
full package and class name to use as conversion when
<code>outputType=SelectOne</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outputHeader</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>String</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>null</code></td><td colsp
an="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.15:</strong> To
store the result as a header instead of the message body. This allows to
preserve the existing message body as-is.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>parametersCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.11.2/2.12.0</strong> 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.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>noop</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1"
rowspan="1" class="confluenc
eTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.12.0</strong> 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</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>useMessageBodyForSql</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>boolean</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><code>false</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong> 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 <code>CamelSqlParameters</code>. This option
is only for the producer.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>transacted</code></td><td colspan="1" rowspan="1"
class="confluenceTd"><c
ode>boolean</code></td><td colspan="1" rowspan="1"
class="confluenceTd"><code>false</code></td><td colspan="1" rowspan="1"
class="confluenceTd"><strong>Camel 2.16.2:</strong> <strong>SQL consumer
only:</strong>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</td></tr></tbody></table></div></rich-text-body><h3
id="SQLComponent-Treatmentofthemessagebody">Treatment of the message
body</h3><p>The SQL component tries to convert the message body to an object of
<code>java.util.Iterator</code> type and then uses this iterator to fill the
query parameters (where each query parameter is represented by a <code>#</code>
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.</p><p>For example, if the
message body is an instanc
e of <code>java.util.List</code>, the first item in the list is substituted
into the first occurrence of <code>#</code> in the SQL query, the second item
in the list is substituted into the second occurrence of <code>#</code>, and so
on.</p><p>If <code>batch</code> is set to <code>true</code>, 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.</p><p>From Camel 2.16 onwards you can use the
option <span>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.</span></p><h3
id="SQLComponent-Resultofthequery">Result of the query</h3><p>For
<code>select</code> operations, the
result is an instance of <code>List<Map<String, Object>></code>
type, as returned by the <a shape="rect" class="external-link"
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html#queryForList(java.lang.String,%20java.lang.Object%91%93)"
rel="nofollow">JdbcTemplate.queryForList()</a> method. For <code>update</code>
operations, the result is the number of updated rows, returned as an
<code>Integer</code>.</p><p>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:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("jms:order.inbox")
+ .to("sql:select order_seq.nextval from
dual?outputHeader=OrderId&outputType=SelectOne")
+ .to("jms:order.booking");</plain-text-body><h3
id="SQLComponent-UsingStreamList">Using StreamList</h3><p>From<strong> Camel
2.18</strong> onwards the producer supports outputType=StreamList that uses an
iterator to stream the output of the query. This allows to process the data in
a streaming fashion which for example can be used by the <a shape="rect"
href="splitter.html">Splitter</a> EIP to process each row one at a time, and
load data from the database as needed.</p><parameter
ac:name="">java</parameter><plain-text-body>from("direct:withSplitModel")
+ .to("sql:select * from projects order by
id?outputType=StreamList&outputClass=org.apache.camel.component.sql.ProjectModel")
+ .to("log:stream")
.split(body()).streaming()
- .to("log:row")
- .to("mock:result")
- .end();]]></script>
-</div></div><p> </p><h3 id="SQLComponent-Headervalues">Header
values</h3><p>When performing <code>update</code> operations, the SQL Component
stores the update count in the following message headers:</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelSqlUpdateCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The number of rows updated for
<code>update</code> operations, returned as an <code>Integer</code> object.
<span>T</span><span>his header is not provided when using
outputType=StreamList.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelSqlRowCount</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The number of rows returned for
<code>select</code> operations, returne
d as an <code>Integer</code> object. This header is not provided when
using outputType=StreamList.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelSqlQuery</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> Query to
execute. This query takes precedence over the query specified in the endpoint
URI. Note that query parameters in the header <em>are</em> represented by a
<code>?</code> instead of a <code>#</code>
symbol</p></td></tr></tbody></table></div><p>When
performing <code>insert</code> operations, the SQL Component stores the
rows with the generated keys and number of these rown in the following message
headers (<strong>Available as of Camel 2.12.4, 2.13.1</strong>):</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><pre>CamelSqlGeneratedKeysRowCount</pre></td><td
colspan="1" rowspan="1" class="confluenceTd">The number of rows in the header
that contains generated keys.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><pre>CamelSqlGeneratedKeyRows</pre></td><td colspan="1"
rowspan="1" class="confluenceTd"> Rows that contains the generated keys (a
list of maps of keys).</td></tr></tbody></table></div><h3
id="SQLComponent-Generatedkeys">Generated keys</h3><p><strong>Available as of
Camel 2.12.4, 2.13.1 and 2.14<br clear="none"></strong></p><p>If you insert
data using SQL INSERT, then the RDBMS may support auto generated keys. You can
instruct the SQL producer to return the generated keys in headers.<br
clear="none"> To do that set the header
<code>CamelSqlRetrieveGeneratedKeys=true</code>. Then the generated keys will
be provided as headers with the keys listed in the table above.</p><p>You can
see more details in this <a shape="rect" class="ext
ernal-link"
href="https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob_plain;f=components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java;hb=3962b23f94bb4bc23011b931add08c3f6833c82e">unit
test</a>.</p><h3 id="SQLComponent-Configuration">Configuration</h3><p>You can
now set a reference to a <code>DataSource</code> in the URI directly:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[sql:select * from table where id=# order by
name?dataSource=myDS
-]]></script>
-</div></div><h3 id="SQLComponent-Sample">Sample</h3><p>In the sample below we
execute a query and retrieve the result as a <code>List</code> of rows, where
each row is a <code>Map<String, Object</code> and the key is the column
name.</p><p>First, we set up a table to use for our sample. As this is based on
an unit test, we do it in java:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-// this is the database we create with some initial data for our unit test
-db = new EmbeddedDatabaseBuilder()
-
.setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase.sql").build();
-]]></script>
-</div></div>The SQL script <code>createAndPopulateDatabase.sql</code> we
execute looks like as described below:<div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: sql; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-create table projects (id integer primary key, project varchar(10), license
varchar(5));
-insert into projects values (1, 'Camel', 'ASF');
-insert into projects values (2, 'AMQ', 'ASF');
-insert into projects values (3, 'Linux', 'XXX');
-]]></script>
-</div></div>Then we configure our route and our <code>sql</code> component.
Notice that we use a <code>direct</code> endpoint in front of the
<code>sql</code> endpoint. This allows us to send an exchange to the
<code>direct</code> endpoint with the URI, <code>direct:simple</code>, which is
much easier for the client to use than the long <code>sql:</code> URI. Note
that the <code>DataSource</code> is looked up up in the registry, so we can use
standard Spring XML to configure our <code>DataSource</code>.<div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:simple")
- .to("sql:select * from projects where license = # order by
id?dataSource=#jdbc/myDataSource")
- .to("mock:result");
-]]></script>
-</div></div>And then we fire the message into the <code>direct</code> endpoint
that will route it to our <code>sql</code> component that queries the
database.<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-MockEndpoint mock = getMockEndpoint("mock:result");
-mock.expectedMessageCount(1);
-
-// send the query to direct that will route it to the sql where we will
execute the query
-// and bind the parameters with the data from the body. The body only contains
one value
-// in this case (XXX) but if we should use multi values then the body will be
iterated
-// so we could supply a List<String> instead containing each binding
value.
-template.sendBody("direct:simple", "XXX");
-
-mock.assertIsSatisfied();
-
-// the result is a List
-List<?> received = assertIsInstanceOf(List.class,
mock.getReceivedExchanges().get(0).getIn().getBody());
-
-// and each row in the list is a Map
-Map<?, ?> row = assertIsInstanceOf(Map.class, received.get(0));
-
-// and we should be able the get the project from the map that should be Linux
-assertEquals("Linux", row.get("PROJECT"));
-]]></script>
-</div></div>We could configure the <code>DataSource</code> in Spring XML as
follows:<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <jee:jndi-lookup id="myDS"
jndi-name="jdbc/myDataSource"/>
-]]></script>
-</div></div><h4 id="SQLComponent-Usingnamedparameters">Using named
parameters</h4><p><strong>Available as of Camel 2.11</strong></p><p>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.<br clear="none">
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<br
clear="none"> for the named parameters:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ from("direct:projects")
- .setHeader("lic", constant("ASF"))
- .setHeader("min", constant(123))
- .to("sql:select * from projects where license = :#lic and id >
:#min order by id")
-]]></script>
-</div></div><p>Though if the message body is a <code>java.util.Map</code> then
the named parameters will be taken from the body.</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ from("direct:projects")
- .to("sql:select * from projects where license = :#lic and id >
:#min order by id")
-]]></script>
-</div></div><h4 id="SQLComponent-Usingexpressionparameters">Using expression
parameters</h4><p><strong>Available as of Camel 2.14</strong></p><p>In the
given route below, we want to get all the project from the database. It uses
the body of the exchange for defining the license and uses the value of a
property as the second parameter.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:projects")
- .setBody(constant("ASF"))
- .setProperty("min", constant(123))
- .to("sql:select * from projects where license = :#${body} and id >
:#${property.min} order by id")]]></script>
-</div></div><h4 id="SQLComponent-UsingINquerieswithdynamicvalues">Using IN
queries with dynamic values</h4><p><strong>Available as of Camel
2.17</strong></p><p>From Camel 2.17 onwards the SQL producer allows to use SQL
queries with IN statements where the IN values is dynamic computed. For example
from the message body or a header etc.</p><p>To use IN you need
to:</p><ul><li><span style="line-height: 1.42857;">prefix the parameter name
with <code>in:</code></span></li><li><span style="line-height:
1.42857;">add <code>( )</code> around the
parameter</span></li></ul><p><span style="line-height: 1.42857;">An example
explains this better. The following query is used:</span></p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[-- this is a comment
+ .to("log:row")
+ .to("mock:result")
+ .end();</plain-text-body><p> </p><h3
id="SQLComponent-Headervalues">Header values</h3><p>When performing
<code>update</code> operations, the SQL Component stores the update count in
the following message headers:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelSqlUpdateCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The number of rows updated for
<code>update</code> operations, returned as an <code>Integer</code> object.
<span>T</span><span>his header is not provided when using
outputType=StreamList.</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelSqlRowCount</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The number of rows returned for
<code>select</code
> operations, returned as an <code>Integer</code> object. This header is
> not provided when using outputType=StreamList.</p></td></tr><tr><td
> colspan="1" rowspan="1"
> class="confluenceTd"><p><code>CamelSqlQuery</code></p></td><td colspan="1"
> rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> Query to
> execute. This query takes precedence over the query specified in the
> endpoint URI. Note that query parameters in the header <em>are</em>
> represented by a <code>?</code> instead of a <code>#</code>
> symbol</p></td></tr></tbody></table></div><p>When
> performing <code>insert</code> operations, the SQL Component stores the
> rows with the generated keys and number of these rown in the following
> message headers (<strong>Available as of Camel 2.12.4,
> 2.13.1</strong>):</p><div class="table-wrap"><table
> class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
> class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
> class="confluenceTh"><p>Description</p></th></t
r><tr><td colspan="1" rowspan="1"
class="confluenceTd"><pre>CamelSqlGeneratedKeysRowCount</pre></td><td
colspan="1" rowspan="1" class="confluenceTd">The number of rows in the header
that contains generated keys.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><pre>CamelSqlGeneratedKeyRows</pre></td><td colspan="1"
rowspan="1" class="confluenceTd"> Rows that contains the generated keys (a
list of maps of keys).</td></tr></tbody></table></div><h3
id="SQLComponent-Generatedkeys">Generated keys</h3><p><strong>Available as of
Camel 2.12.4, 2.13.1 and 2.14<br clear="none"></strong></p><p>If you insert
data using SQL INSERT, then the RDBMS may support auto generated keys. You can
instruct the SQL producer to return the generated keys in headers.<br
clear="none"> To do that set the header
<code>CamelSqlRetrieveGeneratedKeys=true</code>. Then the generated keys will
be provided as headers with the keys listed in the table above.</p><p>You can
see more details in this <a sh
ape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob_plain;f=components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java;hb=3962b23f94bb4bc23011b931add08c3f6833c82e">unit
test</a>.</p><h3 id="SQLComponent-Configuration">Configuration</h3><p>You can
now set a reference to a <code>DataSource</code> in the URI
directly:</p><plain-text-body>sql:select * from table where id=# order by
name?dataSource=myDS
+</plain-text-body><h3 id="SQLComponent-Sample">Sample</h3><p>In the sample
below we execute a query and retrieve the result as a <code>List</code> of
rows, where each row is a <code>Map<String, Object</code> and the key is the
column name.</p><p>First, we set up a table to use for our sample. As this is
based on an unit test, we do it in
java:<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java}</plain-text-body>The
SQL script <code>createAndPopulateDatabase.sql</code> we execute looks like as
described
below:<plain-text-body>{snippet:id=e1|lang=sql|url=camel/trunk/components/camel-sql/src/test/resources/sql/createAndPopulateDatabase.sql}</plain-text-body>Then
we configure our route and our <code>sql</code> component. Notice that we use
a <code>direct</code> endpoint in front of the <code>sql</code> endpoint. This
allows us to send an exchange to the <code>direct</code> endpoint with
the URI, <code>direct:simple</code>, which is much easier for the client to
use than the long <code>sql:</code> URI. Note that the <code>DataSource</code>
is looked up up in the registry, so we can use standard Spring XML to configure
our
<code>DataSource</code>.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java}</plain-text-body>And
then we fire the message into the <code>direct</code> endpoint that will route
it to our <code>sql</code> component that queries the
database.<plain-text-body>{snippet:id=e3|lang=java|url=camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java}</plain-text-body>We
could configure the <code>DataSource</code> in Spring XML as
follows:</p><parameter ac:name="">xml</parameter><plain-text-body>
<jee:jndi-lookup id="myDS" jndi-name="jdbc/myDataSource"/>
+</plain-text-body><h4 id="SQLComponent-Usingnamedparameters">Using named
parameters</h4><p><strong>Available as of Camel 2.11</strong></p><p>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.<br clear="none">
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<br
clear="none"> for the named parameters:</p><parameter
ac:name="language">java</parameter><plain-text-body> from("direct:projects")
+ .setHeader("lic", constant("ASF"))
+ .setHeader("min", constant(123))
+ .to("sql:select * from projects where license = :#lic and id > :#min
order by id")
+</plain-text-body><p>Though if the message body is a
<code>java.util.Map</code> then the named parameters will be taken from the
body.</p><parameter ac:name="language">java</parameter><plain-text-body>
from("direct:projects")
+ .to("sql:select * from projects where license = :#lic and id > :#min
order by id")
+</plain-text-body><h4 id="SQLComponent-Usingexpressionparameters">Using
expression parameters</h4><p><strong>Available as of Camel
2.14</strong></p><p>In the given route below, we want to get all the project
from the database. It uses the body of the exchange for defining the license
and uses the value of a property as the second parameter.</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:projects")
+ .setBody(constant("ASF"))
+ .setProperty("min", constant(123))
+ .to("sql:select * from projects where license = :#${body} and id >
:#${property.min} order by id")</plain-text-body><h4
id="SQLComponent-UsingINquerieswithdynamicvalues">Using IN queries with dynamic
values</h4><p><strong>Available as of Camel 2.17</strong></p><p>From Camel 2.17
onwards the SQL producer allows to use SQL queries with IN statements where the
IN values is dynamic computed. For example from the message body or a header
etc.</p><p>To use IN you need to:</p><ul><li><span style="line-height:
1.42857;">prefix the parameter name
with <code>in:</code></span></li><li><span style="line-height:
1.42857;">add <code>( )</code> around the
parameter</span></li></ul><p><span style="line-height: 1.42857;">An example
explains this better. The following query is
used:</span></p><plain-text-body>-- this is a comment
select *
from projects
where project in (:#in:names)
-order by id]]></script>
-</div></div><p><span style="line-height: 1.42857;">In the following
route:</span></p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:query")
- .to("sql:classpath:sql/selectProjectsIn.sql")
- .to("log:query")
- .to("mock:query");]]></script>
-</div></div><p><span style="line-height: 1.42857;">Then the IN query can use a
header with the key names with the dynamic values such as:</span></p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// use an array
-template.requestBodyAndHeader("direct:query", "Hi there!",
"names", new String[]{"Camel", "AMQ"});
+order by id</plain-text-body><p><span style="line-height: 1.42857;">In the
following route:</span></p><plain-text-body>from("direct:query")
+ .to("sql:classpath:sql/selectProjectsIn.sql")
+ .to("log:query")
+ .to("mock:query");</plain-text-body><p><span style="line-height:
1.42857;">Then the IN query can use a header with the key names with the
dynamic values such as:</span></p><plain-text-body>// use an array
+template.requestBodyAndHeader("direct:query", "Hi there!", "names", new
String[]{"Camel", "AMQ"});
// use a list
List<String> names = new ArrayList<String>();
-names.add("Camel");
-names.add("AMQ");
+names.add("Camel");
+names.add("AMQ");
-template.requestBodyAndHeader("direct:query", "Hi there!",
"names", names);
+template.requestBodyAndHeader("direct:query", "Hi there!", "names", names);
// use a string separated values with comma
-template.requestBodyAndHeader("direct:query", "Hi there!",
"names", "Camel,AMQ");]]></script>
-</div></div><p>The query can also be specified in the endpoint instead of
being externalized (notice that externalizing makes maintaining the SQL queries
easier)</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:query")
- .to("sql:select * from projects where project in (:#in:names) order
by id")
- .to("log:query")
- .to("mock:query");]]></script>
-</div></div><p> </p><h2
id="SQLComponent-UsingtheJDBCbasedidempotentrepository">Using the JDBC based
idempotent repository</h2><p><strong>Available as of Camel 2.7</strong>: In
this section we will use the JDBC based idempotent repository.</p><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Abstract class</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"> From Camel 2.9 onwards there is
an abstract
class <code>org.apache.camel.processor.idempotent.jdbc.AbstractJdbcMessageIdRepository</code> you
can extend to build custom JDBC idempotent repository.</div></div><p>First we
have to create the database table which will be used by the idempotent
repository. For <strong>Camel 2.7</strong>, we use the following
schema:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: sql; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[CREATE TABLE CAMEL_MESSAGEPROCESSED (
processorName VARCHAR(255), messageId VARCHAR(100) )Â ]]></script>
-</div></div><p>In <strong>Camel 2.8</strong>, we added the createdAt
column:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: sql; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[CREATE TABLE CAMEL_MESSAGEPROCESSED (
processorName VARCHAR(255), messageId VARCHAR(100), createdAt TIMESTAMP )Â
]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-warning"><span class="aui-icon aui-icon-small
aui-iconfont-error confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"> The SQL
Server <strong>TIMESTAMP</strong> type is a fixed-length
binary-string type. It does not map to any of the JDBC time
types: <strong>DATE</strong>, <strong>TIME</strong>,
or <strong>TIMESTAMP</strong>.</div></div><p> </p><p>We recommend to
have a unique constraint on the columns processorName and messageId. Because
the syntax for this constraint differs for database to database, we do not show
it here.</p><p>Second we need to setup a <code>javax.sql.DataSource</code> in
the spring XML file:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<jdbc:embedded-database
id="dataSource" type="DERBY" />Â ]]></script>
-</div></div><p><br clear="none">And finally we can create our JDBC idempotent
repository in the spring XML file as well:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <bean
id="messageIdRepository"
class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository">
- <constructor-arg ref="dataSource" />
- <constructor-arg value="myProcessorName" />
- </bean>Â ]]></script>
-</div></div><p><br clear="none">Customize the
JdbcMessageIdRepository</p><p>Starting with <strong>Camel 2.9.1</strong> you
have a few options to tune the
<code>org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository</code>
for your needs:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh">Parameter</th><th colspan="1" rowspan="1"
class="confluenceTh">Default Value</th><th colspan="1" rowspan="1"
class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">createTableIfNotExists</td><td colspan="1" rowspan="1"
class="confluenceTd">true</td><td colspan="1" rowspan="1"
class="confluenceTd">Defines whether or not Camel should try to create the
table if it doesn't exist.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">tableExistsString</td><td colspan="1" rowspan="1"
class="confluenceTd">SELECT 1 FROM CAMEL_MESSAGEPROCESSED WHERE 1 = 0</td><td
colspan="1" rowspan=
"1" class="confluenceTd">This query is used to figure out whether the table
already exists or not. It must throw an exception to indicate the table doesn't
exist.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>createString</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>CREATE TABLE CAMEL_MESSAGEPROCESSED (processorName
VARCHAR(255), messageId VARCHAR(100), createdAt TIMESTAMP)</p></td><td
colspan="1" rowspan="1" class="confluenceTd">The statement which is used to
create the table.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">queryString</td><td colspan="1" rowspan="1"
class="confluenceTd">SELECT COUNT(*) FROM CAMEL_MESSAGEPROCESSED WHERE
processorName = ? AND messageId = ?</td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The query which is used to figure out whether the
message already exists in the repository (the result is not equals to '0'). It
takes two parameters. This first one is the processor name
(<code>String</code>) a
nd the second one is the message id
(<code>String</code>).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">insertString</td><td colspan="1" rowspan="1"
class="confluenceTd">INSERT INTO CAMEL_MESSAGEPROCESSED (processorName,
messageId, createdAt) VALUES (?, ?, ?)</td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The statement which is used to add the entry into the
table. It takes three parameter. The first one is the processor name
(<code>String</code>), the second one is the message id (<code>String</code>)
and the third one is the timestamp (<code>java.sql.Timestamp</code>) when this
entry was added to the repository.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">deleteString</td><td colspan="1" rowspan="1"
class="confluenceTd">DELETE FROM CAMEL_MESSAGEPROCESSED WHERE processorName = ?
AND messageId = ?</td><td colspan="1" rowspan="1" class="confluenceTd"><p>The
statement which is used to delete the entry from the database. It takes two
parameter. This first one is the processor name (<code>String</code>) and the
second one is the message id
(<code>String</code>).</p></td></tr></tbody></table></div><p> </p><p>A
customized
<code>org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository</code>
could look like:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <bean
id="messageIdRepository"
class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository">
- <constructor-arg ref="dataSource" />
- <constructor-arg value="myProcessorName" />
- <property name="tableExistsString" value="SELECT 1
FROM CUSTOMIZED_MESSAGE_REPOSITORY WHERE 1 = 0" />
- <property name="createString" value="CREATE TABLE
CUSTOMIZED_MESSAGE_REPOSITORY (processorName VARCHAR(255), messageId
VARCHAR(100), createdAt TIMESTAMP)" />
- <property name="queryString" value="SELECT COUNT(*)
FROM CUSTOMIZED_MESSAGE_REPOSITORY WHERE processorName = ? AND messageId =
?" />
- <property name="insertString" value="INSERT INTO
CUSTOMIZED_MESSAGE_REPOSITORY (processorName, messageId, createdAt) VALUES (?,
?, ?)" />
- <property name="deleteString" value="DELETE FROM
CUSTOMIZED_MESSAGE_REPOSITORY WHERE processorName = ? AND messageId = ?"
/>
- </bean>]]></script>
[... 31 lines stripped ...]