LibraryToggle FramesPrintFeedback

The ibatis: component allows you to query, poll, insert, update and delete data in a relational database using Apache iBATIS.

Maven users will need to add the following dependency to their pom.xml for this component:

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

Option Type Default Description
consumer.onConsume String null Statements to run after consuming. Can be used, for example, to update rows after they have been consumed and processed in Apache Camel. See sample later. Multiple statements can be separated with comma.
consumer.useIterator boolean true If true each row returned when polling will be processed individually. If false the entire List of data is set as the IN body.
consumer.routeEmptyResultSet boolean false Apache Camel 2.0: Sets whether empty result set should be routed or not. By default, empty result sets are not routed.
statementType StatementType null Apache Camel 1.6.1/2.0: Mandatory to specify for IbatisProducer to control which iBatis SqlMapClient method to invoke. The enum values are: QueryForObject, QueryForList, Insert, Update, Delete.
maxMessagesPerPoll int 0 Apache Camel 2.0: 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.

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

Header Type Description
org.apache.camel.ibatis.queryName String Apache Camel 1.x: The statementName used (for example: insertAccount).
CamelIBatisStatementName String Apache Camel 2.0: The statementName used (for example: insertAccount).
CamelIBatisResult Object Apache Camel 1.6.2/2.0: The response returned from iBatis in any of the operations. For instance an INSERT could return the auto-generated key, or number of rows etc.

Since this component does not support scheduled polling, you need to use another mechanism for triggering the scheduled polls, such as the Timer or Quartz components.

In the sample below we poll the database, every 30 seconds using the Timer component and send the data to the JMS queue:

from("timer://pollTheDatabase?delay=30000").to("ibatis:selectAllAccounts?statementType=QueryForList").to("activemq:queue:allAccounts");

And the iBatis SQL map file used:

  <!-- Select with no parameters using the result map for Account class. -->
  <select id="selectAllAccounts" resultMap="AccountResult">
    select * from ACCOUNT
  </select>
Comments powered by Disqus