Modified: websites/production/camel/content/sql-component.html
==============================================================================
--- websites/production/camel/content/sql-component.html (original)
+++ websites/production/camel/content/sql-component.html Tue May 15 08:19:00 
2018
@@ -36,6 +36,17 @@
     <![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 type="text/javascript">
+  SyntaxHighlighter.defaults['toolbar'] = false;
+  SyntaxHighlighter.all();
+  </script>
 
     <title>
     Apache Camel: SQL Component
@@ -78,74 +89,207 @@
        <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><parameter 
ac:name="">xml</parameter><plain-text-body>&lt;dependency&gt;
+<div class="wiki-content maincontent"><h2 id="SQLComponent-SQLComponent">SQL 
Component</h2><p>The&#160;<strong>sql:</strong>&#160;component allows you to 
work with databases using JDBC queries. The difference between this component 
and&#160;<a shape="rect" href="jdbc.html">JDBC</a>&#160;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&#160;<code><strong>spring-jdbc</strong></code>&#160;behind the scenes for 
the actual SQL handling.</p><p>Maven users will need to add the following 
dependency to their&#160;<code>pom.xml</code>&#160;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[&lt;dependency&gt; 
     &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
     &lt;artifactId&gt;camel-sql&lt;/artifactId&gt;
     &lt;version&gt;x.x.x&lt;/version&gt;
     &lt;!-- use the same version as your Camel core version --&gt;
-&lt;/dependency&gt;
-</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</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&#160;&#8211; dash 
line.</p><p>You can append query options to the URI in the following format, 
<code>?option=value&amp;option=value&amp;...</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.&lt;xxx&gt;</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p>&#160;</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>&#160;</p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>&#160;</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>&#160;</p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>&#160;</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 &#8211; 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&#160;<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&#160;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&lt;Map&lt;String, Object&gt;&gt;</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.&#160; If the outputHeader parameter is set, the result is placed in the 
header.&#160; 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.&#160; 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&amp;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&#160;<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&amp;outputClass=org.apache.camel.component.sql.ProjectModel")
-        .to("log:stream")
-        .split(body()).streaming()
-            .to("log:row")
-            .to("mock:result")
-        .end();</plain-text-body><p>&#160;</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&#160;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&#160;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&#160;<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">&#160;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&lt;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> 
&lt;jee:jndi-lookup id="myDS" jndi-name="jdbc/myDataSource"/&gt;
-</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 &gt; :#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 &gt; :#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 &gt; 
:#${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&#160;<code>in:</code></span></li><li><span style="line-height: 
1.42857;">add <code>( )</code>&#160;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</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"});
+&lt;/dependency&gt;]]></script>
+</div></div><p>The SQL component also supports:</p><ul class="alternate"><li>a 
JDBC based repository for the&#160;<a shape="rect" 
href="idempotent-consumer.html">Idempotent Consumer</a>&#160;EIP pattern. See 
further below.</li><li>a JDBC based repository for the&#160;<a shape="rect" 
href="aggregator2.html">Aggregator</a>&#160;EIP pattern. See further 
below.</li></ul><h3 id="SQLComponent-URIformat">URI format</h3><p>From Camel 
2.11 onwards this component can create both consumer 
(e.g.&#160;<code>from()</code>) and producer endpoints 
(e.g.&#160;<code>to()</code>).</p><p>In previous versions, it could only act as 
a producer.</p><p>This component can be used as a&#160;<a shape="rect" 
class="external-link" 
href="http://camel.apache.org/transactional-client.html";>Transactional 
Client</a>.</p><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>&#160;</p><p>From Camel 2.11 onwards you can use named 
parameters by using :<code>#name_of_the_parameter</code>&#160;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&#160;<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&#160;<strong>Camel 2.14</strong>&#160;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&#160;<code>?</code>&#160;symbol that 
denotes the parameters to an SQL query is substituted with 
the&#160;<code>#</code>&#160;symbol, because 
the&#160;<code>?</code>&#160;symbol is used to specify options for the 
endpoint. The&#160;<code>?</code>&#160;symbol replacement can be configured on 
endpoint basis.</p><p>From&#160;<strong>Camel 2.17</strong>&#160;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: sql; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[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&#160;&#8211; dash line.</p><p>You can 
append query options to the URI in the following 
format,&#160;<code>?option=value&amp;option=value&amp;...</code></p><h3 
id="SQLComponent-Options">Options</h3><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> E
 xecute 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:</strong> Reference to a 
<code>D
 ataSource</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.&lt;xxx&gt;</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p>&#160;</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="confluence
 Td"><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>&#160;</p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>&#160;</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>&#160;</p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>&#160;</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" rows
 pan="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. Notice in Camel 
 >2.15.x or older you need to prefix this opt
 ion with consumer., eg consumer.useIterator=true.</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. 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>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. 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>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 parameter. 
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>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. 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>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.1
 1:</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. 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>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 con
 sumer.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="con
 fluenceTd"><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> 
outputType='SelectList', for consumer or producer, will output a List of Map. 
<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 (only step c).</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. T
 his 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>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="confluenceTd"><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 a
 s 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" 
class="confluenceTd"><code>false</code></td><td colspan="1" rowspan="1" 
class="confluenceTd"><strong>Camel 2.16.2:</strong> <strong>SQL consumer onl
 y:</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><h3 
id="SQLComponent-Treatmentofthemessagebody">Treatment of the message 
body</h3><p>The SQL component tries to convert the message body to an object 
of&#160;<code>java.util.Iterator</code>&#160;type and then uses this iterator 
to fill the query parameters (where each query parameter is represented by 
a&#160;<code>#</code>&#160;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&#160;<code>java.util.List</code>, the first item in the list is substituted 
into the first occurrence of&#160;<code>#</code>&#160;in the SQL query, the 
second item in the list is substituted 
 into the second occurrence of&#160;<code>#</code>, and so 
on.</p><p>If&#160;<code>batch</code>&#160;is set to&#160;<code>true</code>, 
then the interpretation of the inbound message body changes slightly &#8211; 
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&#160;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&#160;SqlConstants.SQL_PARAMETERS. This allows the SQL component to work 
more dynamic as the SQL query is from the message body.</p><h3 
id="SQLComponent-Resultofthequery">Result of the 
query</h3><p>For&#160;<code>select</code>&#160;operations, the result is an 
instance of&#160;<code>List&lt;Map&lt;String, Object&gt;&gt;</code>&#160;type, 
as returned by the&#160;<a shape="rect" class="external-link" href="htt
 
p://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>&#160;method. 
For&#160;<code>update</code>&#160;operations, the result is the number of 
updated rows, returned as an&#160;<code>Integer</code>.</p><p>By default, the 
result is placed in the message body.&#160; If the outputHeader parameter is 
set, the result is placed in the header.&#160; 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.&#160; 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(&quot;jms:order.inbox&quot;)
+    .to(&quot;sql:select order_seq.nextval from 
dual?outputHeader=OrderId&amp;outputType=SelectOne&quot;)
+    .to(&quot;jms:order.booking&quot;);]]></script>
+</div></div><h3 id="SQLComponent-UsingStreamList">Using 
StreamList</h3><p>From<strong>&#160;Camel 2.18</strong>&#160;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&#160;<a shape="rect" 
href="splitter.html">Splitter</a>&#160;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(&quot;direct:withSplitModel&quot;)
+   .to(&quot;sql:select * from projects order by 
id?outputType=StreamList&amp;outputClass=org.apache.camel.component.sql.ProjectModel&quot;)
+   .to(&quot;log:stream&quot;)
+   .split(body()).streaming()
+       .to(&quot;log:row&quot;)
+       .to(&quot;mock:result&quot;)
+   .end();]]></script>
+</div></div><h3 id="SQLComponent-Headervalues">Header values</h3><p>When 
performing&#160;<code>update</code>&#160;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. 
This header&#160;is not provided when using 
outputType=StreamList.</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&#160;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&#160;<code>insert</code>&#160;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="conf
 luenceTd"><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">&#160;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&#160;<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&#160;<a shape="rect" 
class="external-link" hre
 
f="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&#160;<code>DataSource</code>&#160;in the URI 
directly:</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[ 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&#160;<code>List</code>&#160;of 
rows, where each row is a&#160;<code>Map&lt;String, Object&gt;</code>&#160;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[db = new EmbeddedDatabaseBuilder()
+    
.setType(EmbeddedDatabaseType.DERBY).addScript(&quot;sql/createAndPopulateDatabase.sql&quot;).build();]]></script>
+</div></div><p><br clear="none">The SQL 
script&#160;<code>createAndPopulateDatabase.sql</code>&#160;we execute looks 
like as described below:</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 projects (id integer primary 
key, project varchar(10), license varchar(5));
+insert into projects values (1, &#39;Camel&#39;, &#39;ASF&#39;);
+insert into projects values (2, &#39;AMQ&#39;, &#39;ASF&#39;);
+insert into projects values (3, &#39;Linux&#39;, &#39;XXX&#39;);]]></script>
+</div></div><p>Then we configure our route and 
our&#160;<code>sql</code>&#160;component. Notice that we use 
a&#160;<code>direct</code>&#160;endpoint in front of 
the&#160;<code>sql</code>&#160;endpoint. This allows us to send an exchange to 
the&#160;<code>direct</code>&#160;endpoint with the 
URI,&#160;<code>direct:simple</code>, which is much easier for the client to 
use than the long&#160;<code>sql:</code>&#160;URI. Note that 
the&#160;<code>DataSource</code>&#160;is looked up up in the registry, so we 
can use standard Spring XML to configure 
our&#160;<code>DataSource</code>.</p><p>&#160;</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(&quot;direct:simple&quot;)
+    .to(&quot;sql:select * from projects where license = # order by 
id?dataSource=#jdbc/myDataSource&quot;)
+    .to(&quot;mock:result&quot;);]]></script>
+</div></div><p>And then we fire the message into 
the&#160;<code>direct</code>&#160;endpoint that will route it to 
our&#160;<code>sql</code>&#160;component that queries the 
database.</p><p>&#160;</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[MockEndpoint mock = 
getMockEndpoint(&quot;mock:result&quot;);
+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&lt;String&gt; instead containing each binding 
value.
+template.sendBody(&quot;direct:simple&quot;, &quot;XXX&quot;);
 
-// use a list
-List&lt;String&gt; names = new ArrayList&lt;String&gt;();
-names.add("Camel");
-names.add("AMQ");
+mock.assertIsSatisfied();
 
-template.requestBodyAndHeader("direct:query", "Hi there!", "names", names);
+// the result is a List
+List&lt;?&gt; received = assertIsInstanceOf(List.class, 
mock.getReceivedExchanges().get(0).getIn().getBody());
 
+// and each row in the list is a Map
+Map&lt;?, ?&gt; row = assertIsInstanceOf(Map.class, received.get(0));
 
-// use a string separated values with comma
-template.requestBodyAndHeader("direct:query", "Hi there!", "names", 
"Camel,AMQ");</plain-text-body><p>The query can also be specified in the 
endpoint instead of being externalized (notice that externalizing makes 
maintaining the SQL queries easier)</p><plain-text-body>from("direct:query")
-    .to("sql:select * from projects where project in (:#in:names) order by id")
-    .to("log:query")
-    .to("mock:query");</plain-text-body><p>&#160;</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><parameter 
ac:name="title">Abstract class</parameter><rich-text-body>&#160;From Camel 2.9 
onwards there is an abstract 
class&#160;<code>org.apache.camel.processor.idempotent.jdbc.AbstractJdbcMessageIdRepository</code>&#160;you
 can extend to build custom JDBC idempotent 
repository.</rich-text-body><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><parameter 
ac:name="language">sql</parameter><plain-text-body>CREATE TABLE 
CAMEL_MESSAGEPROCESSED ( processorName VARCHAR(255), messageId VARCHAR(100) 
)&#160;</plain-text-body><p>In <strong>Camel 2.8</strong>, we added the 
createdAt column:</p><parameter ac:name="
 language">sql</parameter><plain-text-body>CREATE TABLE CAMEL_MESSAGEPROCESSED 
( processorName VARCHAR(255), messageId VARCHAR(100), createdAt TIMESTAMP 
)&#160;</plain-text-body><rich-text-body>&#160;The SQL 
Server&#160;<strong>TIMESTAMP</strong>&#160;type is a fixed-length 
binary-string type. It does not map to any of the JDBC time 
types:&#160;<strong>DATE</strong>,&#160;<strong>TIME</strong>, 
or&#160;<strong>TIMESTAMP</strong>.</rich-text-body><p>&#160;</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><parameter 
ac:name="language">xml</parameter><plain-text-body>&lt;jdbc:embedded-database 
id="dataSource" type="DERBY" /&gt;&#160;</plain-text-body><p><br 
clear="none">And finally we can create our JDBC idempotent repository in the 
spring XML file as well:</
 p><parameter ac:name="language">xml</parameter><plain-text-body>   &lt;bean 
id="messageIdRepository" 
class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository"&gt;
-       &lt;constructor-arg ref="dataSource" /&gt;
-       &lt;constructor-arg value="myProcessorName" /&gt;
-    &lt;/bean&gt;&#160;</plain-text-body><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>) and 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 fro
 m 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>&#160;</p><p>A 
customized 
<code>org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository</code> 
could look like:</p><parameter 
ac:name="language">xml</parameter><plain-text-body>    &lt;bean 
id="messageIdRepository" 
class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository"&gt;
-       &lt;constructor-arg ref="dataSource" /&gt;
-       &lt;constructor-arg value="myProcessorName" /&gt;
-       &lt;property name="tableExistsString" value="SELECT 1 FROM 
CUSTOMIZED_MESSAGE_REPOSITORY WHERE 1 = 0" /&gt;
-       &lt;property name="createString" value="CREATE TABLE 
CUSTOMIZED_MESSAGE_REPOSITORY (processorName VARCHAR(255), messageId 
VARCHAR(100), createdAt TIMESTAMP)" /&gt;
-       &lt;property name="queryString" value="SELECT COUNT(*) FROM 
CUSTOMIZED_MESSAGE_REPOSITORY WHERE processorName = ? AND messageId = ?" /&gt;
-       &lt;property name="insertString" value="INSERT INTO 
CUSTOMIZED_MESSAGE_REPOSITORY (processorName, messageId, createdAt) VALUES (?, 
?, ?)" /&gt;
-       &lt;property name="deleteString" value="DELETE FROM 
CUSTOMIZED_MESSAGE_REPOSITORY WHERE processorName = ? AND messageId = ?" /&gt;

[... 145 lines stripped ...]

Reply via email to