camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Streaming ResultSet Revisted
Date Sat, 04 Jan 2014 08:46:34 GMT
On Fri, Jan 3, 2014 at 6:24 PM, Christopher Gardner
<> wrote:
> Here:
> Claus recommends using "... a custom expression that returns an Iterator,
> the the
> splitter will use the iterator to read in a one row at a time."
> I'm using groovy to do something like this.  Instead of a custom
> expression, I'm using a processor.  The code does this:
> 1.  Processor creates a Query object.
> 2.  Processor passes a Closure to the Query object.
> 3.  Query object uses Spring's JDBCTemplate to execute the query.  It uses
> passes the Closure to an implementation of Spring's ResultSetExtractor.
> 4.  ResultSetExtractor implementation constructs a ResultSet iterator with
> the ResultSet and passes the iterator to the Closure.
> 5.  Closure calls the streaming/splitting route via a producer template.
> I took this approach to ensure that the connection is automatically closed,
> SQLExceptions are handled, etc.
> If you used a custom expression, where would you clean up your JDBC
> resources?

When the iterator reaches the end (hasNext returns false). And you can
add a UoW to the exchange to close it as well when its done, to ensure
they are closed as fallback in case the iterator do not reach the end
for some reason (eg maybe due to an exception happening prior in the
routing or something).

Claus Ibsen
Red Hat, Inc.
Twitter: davsclaus
Author of Camel in Action:
Make your Camel applications look hawt, try:

View raw message