On Fri, Jan 3, 2014 at 6:24 PM, Christopher Gardner
<[email protected]> wrote:
> Here:
>
> http://camel.465427.n5.nabble.com/streaming-of-an-sql-resultset-td5547603.html
>
> 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.
Email: [email protected]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io

Reply via email to