Modified: websites/production/camel/content/freemarker.html
==============================================================================
--- websites/production/camel/content/freemarker.html (original)
+++ websites/production/camel/content/freemarker.html Fri Aug 25 10:20:13 2017
@@ -36,17 +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/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: FreeMarker
@@ -86,111 +75,45 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="FreeMarker-FreeMarker">FreeMarker</h2><p>The <strong>freemarker:</strong>
component allows for processing a message using a <a shape="rect"
class="external-link" href="http://freemarker.org/"
rel="nofollow">FreeMarker</a> template. This can be ideal when using <a
shape="rect" href="templating.html">Templating</a> to generate responses for
requests.</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="FreeMarker-FreeMarker">FreeMarker</h2><p>The <strong>freemarker:</strong>
component allows for processing a message using a <a shape="rect"
class="external-link" href="http://freemarker.org/"
rel="nofollow">FreeMarker</a> template. This can be ideal when using <a
shape="rect" href="templating.html">Templating</a> to generate responses for
requests.</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-freemarker</artifactId>
<version>x.x.x</version> <!-- use the same version as your
Camel core version -->
</dependency>
-]]></script>
-</div></div><h3 id="FreeMarker-URIformat">URI format</h3><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[freemarker:templateName[?options]
-]]></script>
-</div></div><p>Where <strong>templateName</strong> is the classpath-local URI
of the template to invoke; or the complete URL of the remote template (eg: <a
shape="rect" class="external-link" href="file://folder/myfile.ftl"
rel="nofollow">file://folder/myfile.ftl</a>).</p><p>You can append query
options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="FreeMarker-Options">Options</h3><div class="confluenceTableSmall">
+</plain-text-body><h3 id="FreeMarker-URIformat">URI
format</h3><plain-text-body>freemarker:templateName[?options]
+</plain-text-body><p>Where <strong>templateName</strong> is the
classpath-local URI of the template to invoke; or the complete URL of the
remote template (eg: <a shape="rect" class="external-link"
href="file://folder/myfile.ftl"
rel="nofollow">file://folder/myfile.ftl</a>).</p><p>You can append query
options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="FreeMarker-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> 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>contentCache</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>true</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Cache for the resource content when it's loaded. <br
clear="none" class="atl-forced-newline"> Note: as of <strong>Camel 2.9</strong>
cached resource content can be cleared via JMX using the endpoint's
<code>clearContentCache</code> operation. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>encoding</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>null</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> Character
encoding of the resource content. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>templateUpdateDelay</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>5</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <strong>Camel
2.9:</strong> Number of seconds the loaded template resource will remain in the
cache. </p></td></tr></tbody></table></div>
-</div>
-
-
-<h3 id="FreeMarker-Headers">Headers</h3><p>Headers set during the FreeMarker
evaluation are returned to the message and added as headers. This provides a
mechanism for the FreeMarker component to return values to the
Message.</p><p>An example: Set the header value of <code>fruit</code> in the
FreeMarker template:</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[${request.setHeader('fruit',
'Apple')}
-]]></script>
-</div></div><p>The header, <code>fruit</code>, is now accessible from the
<code>message.out.headers</code>.</p><h3
id="FreeMarker-FreeMarkerContext">FreeMarker Context</h3><p>Camel will provide
exchange information in the FreeMarker context (just a <code>Map</code>). The
<code>Exchange</code> is transferred as:</p><div class="confluenceTableSmall">
+</rich-text-body><h3 id="FreeMarker-Headers">Headers</h3><p>Headers set during
the FreeMarker evaluation are returned to the message and added as headers.
This provides a mechanism for the FreeMarker component to return values to the
Message.</p><p>An example: Set the header value of <code>fruit</code> in the
FreeMarker template:</p><plain-text-body>${request.setHeader('fruit', 'Apple')}
+</plain-text-body><p>The header, <code>fruit</code>, is now accessible from
the <code>message.out.headers</code>.</p><h3
id="FreeMarker-FreeMarkerContext">FreeMarker Context</h3><p>Camel will provide
exchange information in the FreeMarker context (just a <code>Map</code>). The
<code>Exchange</code> is transferred as:</p><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> key </p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p> value </p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>exchange</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> The <code>Exchange</code>
itself. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>exchange.properties</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The <code>Exchange</code> properties.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>headers</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The headers of the In message. </p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>camelContext</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The Camel
Context. </p></td></tr><tr><td colspan="1" rowspan="1" clas
s="confluenceTd"><p> <code>request</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> The In message. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>body</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> The In message body. </p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>response</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The Out message
(only for InOut message exchange pattern). </p></td></tr></tbody></table></div>
-</div>
-
-
-<p>From Camel 2.14, you can setup your custom FreeMarker context in the
message header with the key "<strong>CamelFreemarkerDataModel</strong>" just
like this</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[Map<String, Object> variableMap = new
HashMap<String, Object>();
-variableMap.put("headers", headersMap);
-variableMap.put("body", "Monday");
-variableMap.put("exchange", exchange);
-exchange.getIn().setHeader("CamelFreemarkerDataModel", variableMap);
-]]></script>
-</div></div><h3 id="FreeMarker-Hotreloading">Hot reloading</h3><p>The
FreeMarker template resource is by default <strong>not</strong> hot reloadable
for both file and classpath resources (expanded jar). If you set
<code>contentCache=false</code>, then Camel will not cache the resource and hot
reloading is thus enabled. This scenario can be used in development.</p><h3
id="FreeMarker-Dynamictemplates">Dynamic templates</h3><p>Camel provides two
headers by which you can define a different resource location for a template or
the template content itself. If any of these headers is set then Camel uses
this over the endpoint configured resource. This allows you to provide a
dynamic template at runtime.</p><div class="confluenceTableSmall">
+</rich-text-body><p>From Camel 2.14, you can setup your custom FreeMarker
context in the message header with the key
"<strong>CamelFreemarkerDataModel</strong>" just like
this</p><plain-text-body>Map<String, Object> variableMap = new
HashMap<String, Object>();
+variableMap.put("headers", headersMap);
+variableMap.put("body", "Monday");
+variableMap.put("exchange", exchange);
+exchange.getIn().setHeader("CamelFreemarkerDataModel", variableMap);
+</plain-text-body><h3 id="FreeMarker-Hotreloading">Hot reloading</h3><p>The
FreeMarker template resource is by default <strong>not</strong> hot reloadable
for both file and classpath resources (expanded jar). If you set
<code>contentCache=false</code>, then Camel will not cache the resource and hot
reloading is thus enabled. This scenario can be used in development.</p><h3
id="FreeMarker-Dynamictemplates">Dynamic templates</h3><p>Camel provides two
headers by which you can define a different resource location for a template or
the template content itself. If any of these headers is set then Camel uses
this over the endpoint configured resource. This allows you to provide a
dynamic template at runtime.</p><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> Header </p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p> Type </p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p> Description </p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p> Support Version </p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>
FreemarkerConstants.FREEMARKER_RESOURCE </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> org.springframework.core.io.Resource </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> The template resource
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <= 2.1
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
FreemarkerConstants.FREEMARKER_RESOURCE_URI </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> String </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> A URI for the template resource to use i
nstead of the endpoint configured. </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> >= 2.1 </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> FreemarkerConstants.FREEMARKER_TEMPLATE
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> String
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The template to
use instead of the endpoint configured. </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> >= 2.1 </p></td></tr></tbody></table></div>
-</div>
-
-
-<h3 id="FreeMarker-Samples">Samples</h3><p>For example you could use something
like:</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("activemq:My.Queue").
- to("freemarker:com/acme/MyResponse.ftl");
-]]></script>
-</div></div><p>To use a FreeMarker template to formulate a response for a
message for InOut message exchanges (where there is a <code>JMSReplyTo</code>
header).</p><p>If you want to use InOnly and consume the message and send it to
another destination you could use:</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("activemq:My.Queue").
- to("freemarker:com/acme/MyResponse.ftl").
- to("activemq:Another.Queue");
-]]></script>
-</div></div><p>And to disable the content cache, e.g. for development usage
where the <code>.ftl</code> template should be hot reloaded:</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("activemq:My.Queue").
- to("freemarker:com/acme/MyResponse.ftl?contentCache=false").
- to("activemq:Another.Queue");
-]]></script>
-</div></div><p>And a file-based resource:</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("activemq:My.Queue").
- to("freemarker:file://myfolder/MyResponse.ftl?contentCache=false").
- to("activemq:Another.Queue");
-]]></script>
-</div></div><p>In <strong>Camel 2.1</strong> it's possible to specify what
template the component should use dynamically via a header, so for
example:</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:in").
-
setHeader(FreemarkerConstants.FREEMARKER_RESOURCE_URI).constant("path/to/my/template.ftl").
- to("freemarker:dummy");
-]]></script>
-</div></div><h3 id="FreeMarker-TheEmailSample">The Email Sample</h3><p>In this
sample we want to use FreeMarker templating for an order confirmation email.
The email template is laid out in FreeMarker as:</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[Dear ${headers.lastName}, ${headers.firstName}
+</rich-text-body><h3 id="FreeMarker-Samples">Samples</h3><p>For example you
could use something like:</p><plain-text-body>from("activemq:My.Queue").
+ to("freemarker:com/acme/MyResponse.ftl");
+</plain-text-body><p>To use a FreeMarker template to formulate a response for
a message for InOut message exchanges (where there is a <code>JMSReplyTo</code>
header).</p><p>If you want to use InOnly and consume the message and send it to
another destination you could
use:</p><plain-text-body>from("activemq:My.Queue").
+ to("freemarker:com/acme/MyResponse.ftl").
+ to("activemq:Another.Queue");
+</plain-text-body><p>And to disable the content cache, e.g. for development
usage where the <code>.ftl</code> template should be hot
reloaded:</p><plain-text-body>from("activemq:My.Queue").
+ to("freemarker:com/acme/MyResponse.ftl?contentCache=false").
+ to("activemq:Another.Queue");
+</plain-text-body><p>And a file-based
resource:</p><plain-text-body>from("activemq:My.Queue").
+ to("freemarker:file://myfolder/MyResponse.ftl?contentCache=false").
+ to("activemq:Another.Queue");
+</plain-text-body><p>In <strong>Camel 2.1</strong> it's possible to specify
what template the component should use dynamically via a header, so for
example:</p><plain-text-body>from("direct:in").
+
setHeader(FreemarkerConstants.FREEMARKER_RESOURCE_URI).constant("path/to/my/template.ftl").
+ to("freemarker:dummy");
+</plain-text-body><h3 id="FreeMarker-TheEmailSample">The Email
Sample</h3><p>In this sample we want to use FreeMarker templating for an order
confirmation email. The email template is laid out in FreeMarker
as:</p><plain-text-body>Dear ${headers.lastName}, ${headers.firstName}
Thanks for the order of ${headers.item}.
Regards Camel Riders Bookstore
${body}
-]]></script>
-</div></div><p>And the java code:</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[
-private Exchange createLetter() {
- Exchange exchange =
context.getEndpoint("direct:a").createExchange();
-
- Message msg = exchange.getIn();
- msg.setHeader("firstName", "Claus");
- msg.setHeader("lastName", "Ibsen");
- msg.setHeader("item", "Camel in Action");
- msg.setBody("PS: Next beer is on me, James");
-
- return exchange;
-}
-
-@Test
-public void testFreemarkerLetter() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMessageCount(1);
- mock.message(0).body().contains("Dear Ibsen, Claus");
- mock.message(0).body().contains("Thanks for the order of Camel in
Action.");
-
- template.send("direct:a", createLetter());
-
- mock.assertIsSatisfied();
-}
-
-protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
- from("direct:a")
-
.to("freemarker:org/apache/camel/component/freemarker/letter.ftl")
- .to("mock:result");
- }
- };
-}
-]]></script>
-</div></div><p></p><h3 id="FreeMarker-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul></div>
+</plain-text-body><p>And the java
code:</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerLetterTest.java}</plain-text-body><p><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/ibatis.html
==============================================================================
--- websites/production/camel/content/ibatis.html (original)
+++ websites/production/camel/content/ibatis.html Fri Aug 25 10:20:13 2017
@@ -36,17 +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/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: iBATIS
@@ -86,30 +75,17 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="iBATIS-iBATIS">iBATIS</h2><p>The
<strong>ibatis:</strong> component allows you to query, poll, insert, update
and delete data in a relational database using <a shape="rect"
class="external-link" href="http://ibatis.apache.org/">Apache
iBATIS</a>.</p><div class="confluence-information-macro
confluence-information-macro-warning"><p class="title">Prefer MyBatis</p><span
class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The Apache iBatis project is no
longer active. The project is moved outside Apache and is now know as the
MyBatis project.<br clear="none">Therefore we encourage users to use <a
shape="rect" href="mybatis.html">MyBatis</a> instead. This camel-ibatis
component will be removed in Camel 3.0.</p><p>iBatis do not support Spring 4.x.
So you can only use Spring 3.x or older with iBatis.</p></div></div><p>Maven
users will need to add the follo
wing 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="iBATIS-iBATIS">iBATIS</h2><p>The
<strong>ibatis:</strong> component allows you to query, poll, insert, update
and delete data in a relational database using <a shape="rect"
class="external-link" href="http://ibatis.apache.org/">Apache
iBATIS</a>.</p><parameter ac:name="title">Prefer
MyBatis</parameter><rich-text-body><p>The Apache iBatis project is no longer
active. The project is moved outside Apache and is now know as the MyBatis
project.<br clear="none">Therefore we encourage users to use <a shape="rect"
href="mybatis.html">MyBatis</a> instead. This camel-ibatis component will be
removed in Camel 3.0.</p><p>iBatis do not support Spring 4.x. So you can only
use Spring 3.x or older with iBatis.</p></rich-text-body><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-ibatis</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div><h3 id="iBATIS-URIformat">URI format</h3><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[ibatis:statementName[?options]
-]]></script>
-</div></div><p>Where <strong>statementName</strong> is the name in the iBATIS
XML configuration file which maps to the query, insert, update or delete
operation you wish to evaluate.</p><p>You can append query options to the URI
in the following format,
<code>?option=value&option=value&...</code></p><p>This component will
by default load the iBatis SqlMapConfig file from the root of the classpath and
expected named as <code>SqlMapConfig.xml</code>.<br clear="none"> It uses
Spring resource loading so you can define it using <code>classpath</code>,
<code>file</code> or <code>http</code> as prefix to load resources with those
schemes.<br clear="none"> In Camel 2.2 you can configure this on the
iBatisComponent with the <code>setSqlMapConfig(String)</code> method.</p><h3
id="iBATIS-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>consumer.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>Statements to run after
consuming. Can be used, for example, to update rows after they have been
consumed and processed in Camel. See sample later. Multiple statements can be
separated with comma.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.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>If <code>true</code> each row returned when polling
will be processed individually. If <code>false</code> the entire
<code>List</code> of data is set as the IN body.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.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>Sets whether empty result set should be
routed or not. By default, empty result sets are not
routed.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>statementType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>StatementType</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Mandatory to specify for
IbatisProducer to control wh
ich iBatis <code>SqlMapClient</code> method to invoke. The enum values are:
<code>QueryForObject</code>, <code>QueryForList</code>, <code>Insert</code>,
<code>Update</code>, <code>Delete</code>.</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>An integer to define a maximum
messages to gather per poll. By default, no maximum is set. Can be used to set
a limit of e.g. 1000 to avoid when starting up the server that there are
thousands of files. Set a value of 0 or negative to disabled
it.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>isolation</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>TRA
NSACTION_REPEATABLE_READ</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.9:</strong> A String the defines the
transaction isolation level of the will be used. Allowed values are
TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED,
TRANSACTION_REPEATABLE_READ,
TRANSACTION_SERIALIZABLE</p></td></tr></tbody></table></div><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>isolation</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>TRANSACTION_REPEATABLE_READ</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> A
String the defines the transaction isolation level of the will be used. Allowed
values are TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED,
TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION
_SERIALIZABLE</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="iBATIS-MessageHeaders">Message Headers</h3><p>Camel will populate the
result message, either IN or OUT with a header with the operationName
used:</p><div class="confluenceTableSmall"><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>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelIBatisStatementName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The
<strong>statementName</strong> used (for example:
insertAccount).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelIBatisResult</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>Object</code></p></td><td colspan="1"
rowspan="1" class="conf
luenceTd"><p>The <strong>response</strong> returned from iBatis in any of the
operations. For instance an <code>INSERT</code> could return the auto-generated
key, or number of rows etc.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="iBATIS-MessageBody">Message Body</h3><p>The response from iBatis will
only be set as body if it's a <code>SELECT</code> statement. That means, for
example, for <code>INSERT</code> statements Camel will not replace the body.
This allows you to continue routing and keep the original body. The response
from iBatis is always stored in the header with the key
<code>CamelIBatisResult</code>.</p><h3 id="iBATIS-Samples">Samples</h3><p>For
example if you wish to consume beans from a JMS queue and insert them into a
database you could do the following:</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("activemq:queue:newAccount").
- to("ibatis:insertAccount?statementType=Insert");
-]]></script>
-</div></div><p>Notice we have to specify the <code>statementType</code>, as we
need to instruct Camel which <code>SqlMapClient</code> operation to
invoke.</p><p>Where <strong>insertAccount</strong> is the iBatis ID in the SQL
map 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[ <!-- Insert example, using the Account
parameter class -->
- <insert id="insertAccount"
parameterClass="Account">
+</plain-text-body><h3 id="iBATIS-URIformat">URI
format</h3><plain-text-body>ibatis:statementName[?options]
+</plain-text-body><p>Where <strong>statementName</strong> is the name in the
iBATIS XML configuration file which maps to the query, insert, update or delete
operation you wish to evaluate.</p><p>You can append query options to the URI
in the following format,
<code>?option=value&option=value&...</code></p><p>This component will
by default load the iBatis SqlMapConfig file from the root of the classpath and
expected named as <code>SqlMapConfig.xml</code>.<br clear="none"> It uses
Spring resource loading so you can define it using <code>classpath</code>,
<code>file</code> or <code>http</code> as prefix to load resources with those
schemes.<br clear="none"> In Camel 2.2 you can configure this on the
iBatisComponent with the <code>setSqlMapConfig(String)</code> method.</p><h3
id="iBATIS-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>consumer.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>Statements to run after
consuming. Can be used, for example, to update rows after they have been
consumed and processed in Camel. See sample later. Multiple statements can be
separated with comma.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.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>If
<code>true</code> each row returned when polling will be processed
individually. If <code>false</code> the entire <code>List</code> of data is set
as the IN body.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>consumer.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>Sets whether empty result set should be
routed or not. By default, empty result sets are not
routed.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>statementType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>StatementType</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Mandat
ory to specify for IbatisProducer to control which iBatis
<code>SqlMapClient</code> method to invoke. The enum values are:
<code>QueryForObject</code>, <code>QueryForList</code>, <code>Insert</code>,
<code>Update</code>, <code>Delete</code>.</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>An integer to define a maximum
messages to gather per poll. By default, no maximum is set. Can be used to set
a limit of e.g. 1000 to avoid when starting up the server that there are
thousands of files. Set a value of 0 or negative to disabled
it.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>isolation</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>TRANSACTION_REPEATABLE_READ</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> A
String the defines the transaction isolation level of the will be used. Allowed
values are TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED,
TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ,
TRANSACTION_SERIALIZABLE</p></td></tr></tbody></table></div><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>isolation</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>TRANSACTION_REPEATABLE_READ</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> A
String the defines the transaction isolation level of the will be used. Allowed
values are TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMM
ITTED, TRANSACTION_REPEATABLE_READ,
TRANSACTION_SERIALIZABLE</p></td></tr></tbody></table></div></rich-text-body><h3
id="iBATIS-MessageHeaders">Message Headers</h3><p>Camel will populate the
result message, either IN or OUT with a header with the operationName
used:</p><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>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelIBatisStatementName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The
<strong>statementName</strong> used (for example:
insertAccount).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><cod
e>CamelIBatisResult</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>Object</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong>response</strong> returned from iBatis in
any of the operations. For instance an <code>INSERT</code> could return the
auto-generated key, or number of rows
etc.</p></td></tr></tbody></table></div></rich-text-body><h3
id="iBATIS-MessageBody">Message Body</h3><p>The response from iBatis will only
be set as body if it's a <code>SELECT</code> statement. That means, for
example, for <code>INSERT</code> statements Camel will not replace the body.
This allows you to continue routing and keep the original body. The response
from iBatis is always stored in the header with the key
<code>CamelIBatisResult</code>.</p><h3 id="iBATIS-Samples">Samples</h3><p>For
example if you wish to consume beans from a JMS queue and insert them into a
database you could do the
following:</p><plain-text-body>from("activemq:queue:newAcco
unt").
+ to("ibatis:insertAccount?statementType=Insert");
+</plain-text-body><p>Notice we have to specify the <code>statementType</code>,
as we need to instruct Camel which <code>SqlMapClient</code> operation to
invoke.</p><p>Where <strong>insertAccount</strong> is the iBatis ID in the SQL
map file:</p><parameter ac:name="">xml</parameter><plain-text-body> <!--
Insert example, using the Account parameter class -->
+ <insert id="insertAccount" parameterClass="Account">
insert into ACCOUNT (
ACC_ID,
ACC_FIRST_NAME,
@@ -120,52 +96,12 @@
#id#, #firstName#, #lastName#, #emailAddress#
)
</insert>
-]]></script>
-</div></div><h3 id="iBATIS-UsingStatementTypeforbettercontrolofIBatis">Using
StatementType for better control of IBatis</h3><p>When routing to an iBatis
endpoint you want more fine grained control so you can control whether the SQL
statement to be executed is a <code>SELEECT</code>, <code>UPDATE</code>,
<code>DELETE</code> or <code>INSERT</code> etc. So for instance if we want to
route to an iBatis endpoint in which the IN body contains parameters to a
<code>SELECT</code> statement we can do:</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:start")
- .to("ibatis:selectAccountById?statementType=QueryForObject")
- .to("mock:result");
-]]></script>
-</div></div><p>In the code above we can invoke the iBatis statement
<code>selectAccountById</code> and the IN body should contain the account id we
want to retrieve, such as an <code>Integer</code> type.</p><p>We can do the
same for some of the other operations, such as
<code>QueryForList</code>:</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:start")
- .to("ibatis:selectAllAccounts?statementType=QueryForList")
- .to("mock:result");
-]]></script>
-</div></div><p>And the same for <code>UPDATE</code>, where we can send an
<code>Account</code> object as IN body to iBatis:</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:start")
- .to("ibatis:updateAccount?statementType=Update")
- .to("mock:result");
-]]></script>
-</div></div><h4 id="iBATIS-Scheduledpollingexample">Scheduled polling
example</h4><p>Since this component does not support scheduled polling, you
need to use another mechanism for triggering the scheduled polls, such as the
<a shape="rect" href="timer.html">Timer</a> or <a shape="rect"
href="quartz.html">Quartz</a> components.</p><p>In the sample below we poll the
database, every 30 seconds using the <a shape="rect"
href="timer.html">Timer</a> component and send the data to the JMS
queue:</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("timer://pollTheDatabase?delay=30000").to("ibatis:selectAllAccounts?statementType=QueryForList").to("activemq:queue:allAccounts");
-]]></script>
-</div></div><p>And the iBatis SQL map file used:</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[ <!-- Select with no parameters using the
result map for Account class. -->
- <select id="selectAllAccounts"
resultMap="AccountResult">
+</plain-text-body><h3
id="iBATIS-UsingStatementTypeforbettercontrolofIBatis">Using StatementType for
better control of IBatis</h3><p>When routing to an iBatis endpoint you want
more fine grained control so you can control whether the SQL statement to be
executed is a <code>SELEECT</code>, <code>UPDATE</code>, <code>DELETE</code> or
<code>INSERT</code> etc. So for instance if we want to route to an iBatis
endpoint in which the IN body contains parameters to a <code>SELECT</code>
statement we can
do:</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java}</plain-text-body><p>In
the code above we can invoke the iBatis statement
<code>selectAccountById</code> and the IN body should contain the account id we
want to retrieve, such as an <code>Integer</code> type.</p><p>We can do the
same for some of the other operations, such as
<code>QueryForList</code>:</p><plain-text-body>{snipp
et:id=e1|lang=java|url=camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java}</plain-text-body><p>And
the same for <code>UPDATE</code>, where we can send an <code>Account</code>
object as IN body to
iBatis:</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java}</plain-text-body><h4
id="iBATIS-Scheduledpollingexample">Scheduled polling example</h4><p>Since
this component does not support scheduled polling, you need to use another
mechanism for triggering the scheduled polls, such as the <a shape="rect"
href="timer.html">Timer</a> or <a shape="rect" href="quartz.html">Quartz</a>
components.</p><p>In the sample below we poll the database, every 30 seconds
using the <a shape="rect" href="timer.html">Timer</a> component and send the
data to the JMS queue:</p><parameter
ac:name="">java</parameter><plain-text-body>from("timer
://pollTheDatabase?delay=30000").to("ibatis:selectAllAccounts?statementType=QueryForList").to("activemq:queue:allAccounts");
+</plain-text-body><p>And the iBatis SQL map file used:</p><parameter
ac:name="">xml</parameter><plain-text-body> <!-- Select with no parameters
using the result map for Account class. -->
+ <select id="selectAllAccounts" resultMap="AccountResult">
select * from ACCOUNT
</select>
-]]></script>
-</div></div><h4 id="iBATIS-UsingonConsume">Using onConsume</h4><p>This
component supports executing statements <strong>after</strong> data have been
consumed and processed by Camel. This allows you to do post updates in the
database. Notice all statements must be <code>UPDATE</code> statements. Camel
supports executing multiple statements whose name should be separated by
comma.</p><p>The route below illustrates we execute the
<strong>consumeAccount</strong> statement data is processed. This allows us to
change the status of the row in the database to processed, so we avoid
consuming it twice or more.</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("ibatis:selectUnprocessedAccounts?consumer.onConsume=consumeAccount").to("mock:results");
-]]></script>
-</div></div><p>And the statements in the sqlmap 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[
-<select id="selectUnprocessedAccounts"
resultMap="AccountResult">
- select * from ACCOUNT where PROCESSED = false
-</select>
-]]></script>
-</div></div><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[
-<update id="consumeAccount" parameterClass="Account">
- update ACCOUNT set PROCESSED = true where ACC_ID = #id#
-</update>
-]]></script>
-</div></div><p></p><h3 id="iBATIS-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul><ul
class="alternate"><li><a shape="rect"
href="mybatis.html">MyBatis</a></li></ul></div>
+</plain-text-body><h4 id="iBATIS-UsingonConsume">Using onConsume</h4><p>This
component supports executing statements <strong>after</strong> data have been
consumed and processed by Camel. This allows you to do post updates in the
database. Notice all statements must be <code>UPDATE</code> statements. Camel
supports executing multiple statements whose name should be separated by
comma.</p><p>The route below illustrates we execute the
<strong>consumeAccount</strong> statement data is processed. This allows us to
change the status of the row in the database to processed, so we avoid
consuming it twice or
more.</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueueTest.java}</plain-text-body><p>And
the statements in the sqlmap
file:</p><plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml}</plain-text-body><
plain-text-body>{snippet:id=e2|lang=xml|url=camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml}</plain-text-body><p><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p><ul class="alternate"><li><a shape="rect"
href="mybatis.html">MyBatis</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/jdbc.html
==============================================================================
--- websites/production/camel/content/jdbc.html (original)
+++ websites/production/camel/content/jdbc.html Fri Aug 25 10:20:13 2017
@@ -36,17 +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/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: JDBC
@@ -86,114 +75,34 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="JDBC-JDBCComponent">JDBC
Component</h2><p>The <strong>jdbc</strong> component enables you to access
databases through JDBC, where SQL queries (SELECT) and operations (INSERT,
UPDATE, etc) are sent in the message body. This component uses the standard
JDBC API, unlike the <a shape="rect" href="sql-component.html">SQL
Component</a> component, which uses spring-jdbc.</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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+<div class="wiki-content maincontent"><h2 id="JDBC-JDBCComponent">JDBC
Component</h2><p>The <strong>jdbc</strong> component enables you to access
databases through JDBC, where SQL queries (SELECT) and operations (INSERT,
UPDATE, etc) are sent in the message body. This component uses the standard
JDBC API, unlike the <a shape="rect" href="sql-component.html">SQL
Component</a> component, which uses spring-jdbc.</p><p>Maven users will need to
add the following dependency to their <code>pom.xml</code> for this
component:</p><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></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"><p>This component can only be used to
define producer endpoints, which means that you cannot use the JDBC component
in a <code>from()</code> statement.</p></div></div><h3 id="JDBC-URIformat">URI
format</h3><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[jdbc:dataSourceName[?options]
-]]></script>
-</div></div><p>This component only supports producer endpoints.</p><p>You can
append query options to the URI in the following format,
<code>?option=value&option=value&...</code></p><h3
id="JDBC-Options">Options</h3><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>readSize</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The default maximum number of
rows that can be read by a polling query. The default value is
0.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>statement.<xxx></code></p></td><td
colspan="1" rowspan="1" class="c
onfluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.1:</strong> Sets additional options on
the <code>java.sql.Statement</code> that is used behind the scenes to execute
the queries. For instance, <code>statement.maxRows=10</code>. For detailed
documentation, see the <a shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html"
rel="nofollow"><code>java.sql.Statement</code> javadoc</a>
documentation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useJDBC4ColumnNameAndLabelSemantics</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.2:</strong>
Sets whether to use JDBC 4/3 column label/name semantics. You can use this
option to turn it <code>false</code> in case you have issues with your JDBC
driver to select data. This only applies when using <c
ode>SQL SELECT</code> using aliases (e.g. <code>SQL SELECT id as identifier,
name as given_name from persons</code>).</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>resetAutoCommit</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.9:</strong> If
true, Camel will set the autoCommit on the JDBC connection to be false, commit
the change after executing the statement and reset the autoCommit flag of the
connection at the end. If the JDBC connection does not support resetting the
autoCommit flag, set this to false. <br clear="none">When used with XA
transactions you most likely need to set it to false so that the transaction
manager is in charge of committing this tx.</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>true</code></p></
td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.12:</strong> Whether to allow using named parameters in the
queries.</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><strong>Camel 2.12:</strong> Allows to
plugin to use a custom
<code>org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy</code> to
control preparation of the query and prepared statement.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>useHeadersAsParameters</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:</strong>
Set this option to <code>true</code> to use the
<code>prepareStatementStrategy</code> with named parameters. This allows to
define queries with named plac
eholders, and use headers with the dynamic values for the query
placeholders.</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>SelectList</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.1:</strong>
<span>outputType='SelectList', for consumer or producer, w</span><span>ill
output a List of Map. </span><code>SelectOne</code><span> will output single
Java object in the following way</span>:<br clear="none"> a) If the query has
only single column, then that JDBC Column object is returned. (such as SELECT
COUNT( * ) FROM PROJECT will return a Long object.<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 outputClass is set, then it will convert the query
result into an Java bean object by calling all the setters that match the
column names. It will assume your class
has a default constructor to create instance with. From <strong>Camel
2.14</strong> onwards then SelectList is also supported. <br clear="none"> d)
If the query resulted in more than one rows, it throws an non-unique result
exception.<br clear="none"> <strong>Camel 2.14.0:</strong> New
<code>StreamList</code> output type value that streams the result of the query
using an <code>Iterator<Map<String, Object>></code>, it can be used
along with the <a shape="rect" href="splitter.html">Splitter</a>
EIP.</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>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.1:</strong> Specify the
full package and class name to use as conversion when outputType=SelectOne.
From <strong>Camel 2.14</strong> onwards then SelectList is also
supported.</p></td></tr><tr><td colspan="1" rowspan="1" class="c
onfluenceTd"><p><code>beanRowMapper</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.12.1:</strong> To use a custom
<code>org.apache.camel.component.jdbc.BeanRowMapper</code> when using
<code>outputClass</code>. The default implementation will lower case the row
names and skip underscores, and dashes. For example <code>"CUST_ID"</code> is
mapped as <code>"custId"</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>useGetBytesForBlob</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> To read BLOB
columns as bytes instead of string data. This may be needed for certain
databases such as Oracle where you must read BLOB columns as
bytes.</td></tr></tbody></table></div></div>
-
-
-<h3 id="JDBC-Result">Result</h3><p>By default the result is returned in the
OUT body as an <code>ArrayList<HashMap<String, Object>></code>. The
<code>List</code> object contains the list of rows and the <code>Map</code>
objects contain each row with the <code>String</code> key as the column name.
You can use the option <code>outputType</code> to control the
result.</p><p><strong>Note:</strong> This component fetches
<code>ResultSetMetaData</code> to be able to return the column name as the key
in the <code>Map</code>.</p><h4 id="JDBC-MessageHeaders">Message
Headers</h4><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>CamelJdbcRowCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the query is a
<code>SELECT</code>, query the row
count is returned in this OUT header.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelJdbcUpdateCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the query is an
<code>UPDATE</code>, query the update count is returned in this OUT
header.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelGeneratedKeysRows</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Rows that contains the generated keys.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelGeneratedKeysRowCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
The number of rows in the header that contains generated
keys.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelJdbcColumnNames</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11.1:</strong>
The column n
ames from the ResultSet as a <code>java.util.Set</code>
type.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelJdbcParameters</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> A
<code>java.util.Map</code> which has the headers to be used if
<code>useHeadersAsParameters</code> has been
enabled.</p></td></tr></tbody></table></div><h3
id="JDBC-Generatedkeys">Generated keys</h3><p><strong>Available as of Camel
2.10</strong></p><p>If you insert data using SQL INSERT, then the RDBMS may
support auto generated keys. You can instruct the <a shape="rect"
href="jdbc.html">JDBC</a> producer to return the generated keys in headers.<br
clear="none"> To do that set the header
<code>CamelRetrieveGeneratedKeys=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="external-link"
href="https://svn.apache.org/repo
s/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcGeneratedKeysTest.java">unit
test</a>.</p><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Using generated keys does not work
with together with named parameters.</p></div></div><h3
id="JDBC-Usingnamedparameters">Using named parameters</h3><p><strong>Available
as of Camel 2.12</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 these
parameters from the 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))
- .setBody("select * from projects where license = :?lic and id >
:?min order by id")
- .to("jdbc:myDataSource?useHeadersAsParameters=true")
-]]></script>
-</div></div><p>You can also store the header values in a
<code>java.util.Map</code> and store the map on the headers with the key
<code>CamelJdbcParameters</code>.</p><h3 id="JDBC-Samples">Samples</h3><p>In
the following example, we fetch the rows from the customer table.</p><p>First
we register our datasource in the Camel registry as
<code>testdb</code>:</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[
-JndiRegistry reg = super.createRegistry();
-reg.bind("testdb", db);
-return reg;
-]]></script>
-</div></div>Then we configure a route that routes to the JDBC component, so
the SQL will be executed. Note how we refer to the <code>testdb</code>
datasource that was bound in the previous step:<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[
-// lets add simple route
-public void configure() throws Exception {
- from("direct:hello").to("jdbc:testdb?readSize=100");
-}
-]]></script>
-</div></div>Or you can create a <code>DataSource</code> in Spring like
this:<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[
-<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <!-- trigger every second -->
- <from uri="timer://kickoff?period=1s"/>
- <setBody>
- <constant>select * from customer</constant>
- </setBody>
- <to uri="jdbc:testdb"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-
-<!-- Just add a demo to show how to bind a data source for camel in
Spring-->
-<jdbc:embedded-database id="testdb" type="DERBY">
- <jdbc:script location="classpath:sql/init.sql"/>
-</jdbc:embedded-database>
-]]></script>
-</div></div>We create an endpoint, add the SQL query to the body of the IN
message, and then send the exchange. The result of the query is returned in the
OUT body:<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[
-// first we create our exchange using the endpoint
-Endpoint endpoint = context.getEndpoint("direct:hello");
-Exchange exchange = endpoint.createExchange();
-// then we set the SQL on the in body
-exchange.getIn().setBody("select * from customer order by ID");
-
-// now we send the exchange to the endpoint, and receives the response from
Camel
-Exchange out = template.send(endpoint, exchange);
-
-// assertions of the response
-assertNotNull(out);
-assertNotNull(out.getOut());
-List<Map<String, Object>> data = out.getOut().getBody(List.class);
-assertNotNull(data);
-assertEquals(3, data.size());
-Map<String, Object> row = data.get(0);
-assertEquals("cust1", row.get("ID"));
-assertEquals("jstrachan", row.get("NAME"));
-row = data.get(1);
-assertEquals("cust2", row.get("ID"));
-assertEquals("nsandhu", row.get("NAME"));
-]]></script>
-</div></div>If you want to work on the rows one by one instead of the entire
ResultSet at once you need to use the <a shape="rect"
href="splitter.html">Splitter</a> EIP such as:<p>In Camel 2.13.x or
older</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:hello")
- // here we split the data from the testdb into new messages one by one
- // so the mock endpoint will receive a message per row in the table
- .to("jdbc:testdb").split(body()).to("mock:result");
-
-]]></script>
-</div></div>In Camel 2.14.x or newer<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:hello")
+</plain-text-body><rich-text-body><p>This component can only be used to define
producer endpoints, which means that you cannot use the JDBC component in a
<code>from()</code> statement.</p></rich-text-body><h3 id="JDBC-URIformat">URI
format</h3><plain-text-body>jdbc:dataSourceName[?options]
+</plain-text-body><p>This component only supports producer
endpoints.</p><p>You can append query options to the URI in the following
format, <code>?option=value&option=value&...</code></p><h3
id="JDBC-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>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>readSize</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The default maximum number of
rows that can be read by a polling query. The default value is
0.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>statement.<xxx></cod
e></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.1:</strong> Sets additional options on
the <code>java.sql.Statement</code> that is used behind the scenes to execute
the queries. For instance, <code>statement.maxRows=10</code>. For detailed
documentation, see the <a shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html"
rel="nofollow"><code>java.sql.Statement</code> javadoc</a>
documentation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useJDBC4ColumnNameAndLabelSemantics</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.2:</strong>
Sets whether to use JDBC 4/3 column label/name semantics. You can use this
option to turn it <code>false</code> in case you have issues with your JDBC
driver
to select data. This only applies when using <code>SQL SELECT</code> using
aliases (e.g. <code>SQL SELECT id as identifier, name as given_name from
persons</code>).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>resetAutoCommit</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.9:</strong> If true, Camel
will set the autoCommit on the JDBC connection to be false, commit the change
after executing the statement and reset the autoCommit flag of the connection
at the end. If the JDBC connection does not support resetting the autoCommit
flag, set this to false. <br clear="none">When used with XA transactions you
most likely need to set it to false so that the transaction manager is in
charge of committing this tx.</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>true</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.12:</strong> Whether to allow using
named parameters in the queries.</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><strong>Camel 2.12:</strong> Allows to
plugin to use a custom
<code>org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy</code> to
control preparation of the query and prepared statement.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>useHeadersAsParameters</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:</strong>
Set this option to <code>true</code> to use the
<code>prepareStatementStrategy</code> with named parameters
. This allows to define queries with named placeholders, and use headers with
the dynamic values for the query placeholders.</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>SelectList</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.1:</strong>
<span>outputType='SelectList', for consumer or producer, w</span><span>ill
output a List of Map. </span><code>SelectOne</code><span> will output single
Java object in the following way</span>:<br clear="none"> a) If the query has
only single column, then that JDBC Column object is returned. (such as SELECT
COUNT( * ) FROM PROJECT will return a Long object.<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 outputClass is set, then it will convert the query
result into an Java bean object by calling all the setters that ma
tch the column names. It will assume your class has a default constructor to
create instance with. From <strong>Camel 2.14</strong> onwards then SelectList
is also supported. <br clear="none"> d) If the query resulted in more than one
rows, it throws an non-unique result exception.<br clear="none"> <strong>Camel
2.14.0:</strong> New <code>StreamList</code> output type value that streams the
result of the query using an <code>Iterator<Map<String,
Object>></code>, it can be used along with the <a shape="rect"
href="splitter.html">Splitter</a> EIP.</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>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12.1:</strong>
Specify the full package and class name to use as conversion when
outputType=SelectOne. From <strong>Camel 2.14</strong> onwards then SelectList
is also supported.</p></t
d></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>beanRowMapper</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.12.1:</strong> To use a custom
<code>org.apache.camel.component.jdbc.BeanRowMapper</code> when using
<code>outputClass</code>. The default implementation will lower case the row
names and skip underscores, and dashes. For example <code>"CUST_ID"</code> is
mapped as <code>"custId"</code>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>useGetBytesForBlob</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> To read BLOB
columns as bytes instead of string data. This may be needed for certain
databases such as Oracle where you must read BLOB columns as
bytes.</td></tr></tbody></table></div></rich-text-body><h3 id="JDBC-Result">R
esult</h3><p>By default the result is returned in the OUT body as an
<code>ArrayList<HashMap<String, Object>></code>. The
<code>List</code> object contains the list of rows and the <code>Map</code>
objects contain each row with the <code>String</code> key as the column name.
You can use the option <code>outputType</code> to control the
result.</p><p><strong>Note:</strong> This component fetches
<code>ResultSetMetaData</code> to be able to return the column name as the key
in the <code>Map</code>.</p><h4 id="JDBC-MessageHeaders">Message
Headers</h4><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>CamelJdbcRowCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the query is a
<code>SELECT</code>, query the row count is returned in
this OUT header.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelJdbcUpdateCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the query is an
<code>UPDATE</code>, query the update count is returned in this OUT
header.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelGeneratedKeysRows</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Rows that contains the generated keys.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelGeneratedKeysRowCount</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
The number of rows in the header that contains generated
keys.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelJdbcColumnNames</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11.1:</strong>
The column names from the ResultSe
t as a <code>java.util.Set</code> type.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>CamelJdbcParameters</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> A
<code>java.util.Map</code> which has the headers to be used if
<code>useHeadersAsParameters</code> has been
enabled.</p></td></tr></tbody></table></div><h3
id="JDBC-Generatedkeys">Generated keys</h3><p><strong>Available as of Camel
2.10</strong></p><p>If you insert data using SQL INSERT, then the RDBMS may
support auto generated keys. You can instruct the <a shape="rect"
href="jdbc.html">JDBC</a> producer to return the generated keys in headers.<br
clear="none"> To do that set the header
<code>CamelRetrieveGeneratedKeys=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="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/comp
onents/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcGeneratedKeysTest.java">unit
test</a>.</p><rich-text-body><p>Using generated keys does not work with
together with named parameters.</p></rich-text-body><h3
id="JDBC-Usingnamedparameters">Using named parameters</h3><p><strong>Available
as of Camel 2.12</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 these
parameters from the message headers. Notice in the example above we set two
headers with constant value<br clear="none"> for the named
parameters:</p><plain-text-body> from("direct:projects")
+ .setHeader("lic", constant("ASF"))
+ .setHeader("min", constant(123))
+ .setBody("select * from projects where license = :?lic and id > :?min
order by id")
+ .to("jdbc:myDataSource?useHeadersAsParameters=true")
+</plain-text-body><p>You can also store the header values in a
<code>java.util.Map</code> and store the map on the headers with the key
<code>CamelJdbcParameters</code>.</p><h3 id="JDBC-Samples">Samples</h3><p>In
the following example, we fetch the rows from the customer table.</p><p>First
we register our datasource in the Camel registry as
<code>testdb</code>:<plain-text-body>{snippet:id=register|lang=java|url=camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java}</plain-text-body>Then
we configure a route that routes to the JDBC component, so the SQL will be
executed. Note how we refer to the <code>testdb</code> datasource that was
bound in the previous
step:<plain-text-body>{snippet:id=route|lang=java|url=camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteTest.java}</plain-text-body>Or
you can create a <code>DataSource</code> in Spring like
this:<plain-text-body>{snippet:id=example|lang=j
ava|url=camel/trunk/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml}</plain-text-body>We
create an endpoint, add the SQL query to the body of the IN message, and then
send the exchange. The result of the query is returned in the OUT
body:<plain-text-body>{snippet:id=invoke|lang=java|url=camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteTest.java}</plain-text-body>If
you want to work on the rows one by one instead of the entire ResultSet at
once you need to use the <a shape="rect" href="splitter.html">Splitter</a> EIP
such as:</p><p>In Camel 2.13.x or
older<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteSplitTest.java}</plain-text-body>In
Camel 2.14.x or newer</p><plain-text-body>from("direct:hello")
// here we split the data from the testdb into new messages one by one
// so the mock endpoint will receive a message per row in the table
// the StreamList option allows to stream the result of the query without
creating a List of rows
// and notice we also enable streaming mode on the splitter
-.to("jdbc:testdb?outputType=StreamList")
+.to("jdbc:testdb?outputType=StreamList")
.split(body()).streaming()
- .to("mock:result");]]></script>
-</div></div><h3 id="JDBC-Sample-Pollingthedatabaseeveryminute"><br
clear="none"><span style="font-size: 16.0px;line-height: 1.5625;">Sample -
Polling the database every minute</span></h3><p>If we want to poll a database
using the JDBC component, we need to combine it with a polling scheduler such
as the <a shape="rect" href="timer.html">Timer</a> or <a shape="rect"
href="quartz.html">Quartz</a> etc. In the following example, we retrieve data
from the database every 60 seconds:</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("timer://foo?period=60000").setBody(constant("select
* from
customer")).to("jdbc:testdb").to("activemq:queue:customers");
-]]></script>
-</div></div><h3 id="JDBC-Sample-MoveDataBetweenDataSources"><span>Sample -
Move Data Between Data Sources<br clear="none"></span></h3><p>A common use case
is to query for data, process it and move it to another data source (ETL
operations). In the following example, we retrieve new customer records from
the source table every hour, filter/transform them and move them to a
destination table:</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("timer://MoveNewCustomersEveryHour?period=3600000")
- .setBody(constant("select * from customer where create_time >
(sysdate-1/24)"))
- .to("jdbc:testdb")
+ .to("mock:result");</plain-text-body><h3
id="JDBC-Sample-Pollingthedatabaseeveryminute"><br clear="none"><span
style="font-size: 16.0px;line-height: 1.5625;">Sample - Polling the database
every minute</span></h3><p>If we want to poll a database using the JDBC
component, we need to combine it with a polling scheduler such as the <a
shape="rect" href="timer.html">Timer</a> or <a shape="rect"
href="quartz.html">Quartz</a> etc. In the following example, we retrieve data
from the database every 60 seconds:</p><parameter
ac:name="">java</parameter><plain-text-body>from("timer://foo?period=60000").setBody(constant("select
* from customer")).to("jdbc:testdb").to("activemq:queue:customers");
+</plain-text-body><h3 id="JDBC-Sample-MoveDataBetweenDataSources"><span>Sample
- Move Data Between Data Sources<br clear="none"></span></h3><p>A common use
case is to query for data, process it and move it to another data source (ETL
operations). In the following example, we retrieve new customer records from
the source table every hour, filter/transform them and move them to a
destination table:</p><parameter
ac:name="">java</parameter><plain-text-body>from("timer://MoveNewCustomersEveryHour?period=3600000")
+ .setBody(constant("select * from customer where create_time >
(sysdate-1/24)"))
+ .to("jdbc:testdb")
.split(body())
.process(new MyCustomerProcessor()) //filter/transform results
as needed
- .setBody(simple("insert into processed_customer
values('${body[ID]}','${body[NAME]}')"))
- .to("jdbc:testdb");
-]]></script>
-</div></div><p> </p><p></p><h3 id="JDBC-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul><ul
class="alternate"><li><a shape="rect" href="sql.html">SQL</a></li></ul></div>
+ .setBody(simple("insert into processed_customer
values('${body[ID]}','${body[NAME]}')"))
+ .to("jdbc:testdb");
+</plain-text-body><p> </p><p><parameter ac:name=""><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></parameter></p><ul
class="alternate"><li><a shape="rect" href="sql.html">SQL</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">