Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Div
classconfluenceTableSmall

Option

Type

Default

Description

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

batch

boolean

false

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

dataSource

String

null

Reference to a DataSource to look up in the registry.

template.<xxx>

 

null

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

consumer.delay

long

500

Delay in milliseconds between each poll.

consumer.initialDelay

long

1000

Milliseconds before polling starts.

consumer.useFixedDelay

boolean

false

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

maxMessagesPerPoll

int

0

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

consumer.useIterator

boolean

true

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

consumer.routeEmptyResultSet

boolean

false

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

consumer.onConsume

String

null

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

consumer.onConsumeFailed

String

null

After processing each row then this query can be executed, if the Exchange failed, for example to mark the row as failed. The query can have parameter.

consumer.onConsumeBatchComplete

String

null

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

consumer.breakBatchOnConsumeFail

boolean

false

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

outputType

String

SelectList

Make the output of consumer or producer to SelectList as List of Map, or SelectOne as single Java object in the following way:
a) If the query has only single column, then that JDBC Column object is returned. (such as SELECT COUNT( * ) FROM PROJECT will return a Long object.
b) If the query has more than one column, then it will return a Map of that result.
c) If the outputClass is set, then it will convert the query result into an Java bean object by calling all the setters that match the column names. It will assume your class has a default constructor to create instance with.
d) If the query resulted in more than one rows, it throws an non-unique result exception.

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

From Camel 2.18 onwards there is a new StreamList outputType that streams the result of the query using an Iterator. It can be used with the Splitter 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.

outputClass

String

null

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

outputHeader

Stringnull

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

noop

boolean

false

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

transactedbooleanfalseCamel 2.16.2: SQL consumer only:Enables or disables transaction. If enabled then if processing an exchange failed then the consumer break out processing any further exchanges to cause a rollback eager

...

Header

Description

CamelSqlUpdateCount

The number of rows updated for update operations, returned as an Integer object. This header is not provided when using outputType=StreamList.

CamelSqlRowCount

The number of rows returned for select operations, returned as an Integer object. This header is not provided when using outputType=StreamList.

Sample

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

...

Code Block
languagejava
   from("direct:projects")
     .setHeader("lic", constant("ASF"))
     .setHeader("min", constant(123))
     .to("elsql:projects:com/foo/ordersprojects.elsql")

And the elsql mapping file

...

Code Block
languagejava
   from("direct:projects")
     .to("elsql:projects:com/foo/ordersprojects.elsql")

 

In from Camel 2.16.1 onwards you can use Simple expressions as well, which allows to use an OGNL like notation on the message body, where it assumes to have getLicense and getMinimum methods:

Code Block
@NAME(projects)
  SELECT *
  FROM projects
  WHERE license = :${body.license} AND id > :${body.minimum}
  ORDER BY id

Using StreamList

From Camel 2.18 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 Splitter EIP to process each row one at a time, and load data from the database as needed.

Code Block
java
java
from("direct:withSplitModel")
    .to("elsql:allProjects:com/foo/projects.elsql?outputType=StreamList&outputClass=org.apache.camel.component.elsql.Project")
    .to("log:stream")
    .split(body()).streaming()
        .to("log:row")
        .to("mock:result")
    .end();

And the elsql mapping for allProjects

Code Block
@NAME(allProjects)
  SELECT *
  FROM projects
  ORDER BY id

 

Include Page
Endpoint See Also
Endpoint See Also

...