Source:
protected void processStreamList(Exchange exchange, PreparedStatementCreator statementCreator, String sql, String preparedQuery) throws Exception { log.trace("processStreamList: {}", preparedQuery); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = jdbcTemplate.getDataSource().getConnection(); ps = statementCreator.createPreparedStatement(con); int expected = parametersCount > 0 ? parametersCount : ps.getParameterMetaData().getParameterCount(); if (alwaysPopulateStatement || expected > 0) { if (batch) { Iterator<?> iterator; if (useMessageBodyForSql) { iterator = exchange.getIn().getHeader(SqlConstants.SQL_PARAMETERS, Iterator.class); } else { iterator = exchange.getIn().getBody(Iterator.class); } while (iterator != null && iterator.hasNext()) { Object value = iterator.next(); Iterator<?> i = sqlPrepareStatementStrategy.createPopulateIterator(sql, preparedQuery, expected, exchange, value); sqlPrepareStatementStrategy.populateStatement(ps, i, expected); ps.addBatch(); } } else { Object value; if (useMessageBodyForSql) { value = exchange.getIn().getHeader(SqlConstants.SQL_PARAMETERS); } else { value = exchange.getIn().getBody(); } Iterator<?> i = sqlPrepareStatementStrategy.createPopulateIterator(sql, preparedQuery, expected, exchange, value); sqlPrepareStatementStrategy.populateStatement(ps, i, expected); } } boolean isResultSet = ps.execute(); exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); if (isResultSet) { rs = ps.getResultSet(); ResultSetIterator iterator = getEndpoint().queryForStreamList(con, ps, rs); if (getEndpoint().isNoop()) { exchange.getOut().setBody(exchange.getIn().getBody()); } else if (getEndpoint().getOutputHeader() != null) { exchange.getOut().setBody(exchange.getIn().getBody()); exchange.getOut().setHeader(getEndpoint().getOutputHeader(), iterator); } else { exchange.getOut().setBody(iterator); } exchange.addOnCompletion(new ResultSetIteratorCompletion(iterator)); } } catch (Exception e) { closeConnection(con); closeStatement(ps); closeResultSet(rs); throw e; } }

Target:
protected void processStreamList(Exchange exchange, PreparedStatementCreator statementCreator, String sql, String preparedQuery) throws Exception { log.trace("processStreamList: {}", preparedQuery); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = jdbcTemplate.getDataSource().getConnection(); ps = statementCreator.createPreparedStatement(con); int expected = parametersCount > 0 ? parametersCount : ps.getParameterMetaData().getParameterCount(); if (alwaysPopulateStatement || expected > 0) { if (batch) { Iterator<?> iterator; if (useMessageBodyForSql) { iterator = exchange.getIn().getHeader(SqlConstants.SQL_PARAMETERS, Iterator.class); } else { iterator = exchange.getIn().getBody(Iterator.class); } while (iterator != null && iterator.hasNext()) { Object value = iterator.next(); Iterator<?> i = sqlPrepareStatementStrategy.createPopulateIterator(sql, preparedQuery, expected, exchange, value); sqlPrepareStatementStrategy.populateStatement(ps, i, expected); ps.addBatch(); } } else { Object value; if (useMessageBodyForSql) { value = exchange.getIn().getHeader(SqlConstants.SQL_PARAMETERS); } else { value = exchange.getIn().getBody(); } Iterator<?> i = sqlPrepareStatementStrategy.createPopulateIterator(sql, preparedQuery, expected, exchange, value); sqlPrepareStatementStrategy.populateStatement(ps, i, expected); } } boolean isResultSet = ps.execute(); if (isResultSet) { rs = ps.getResultSet(); ResultSetIterator iterator = getEndpoint().queryForStreamList(con, ps, rs); exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); if (getEndpoint().isNoop()) { exchange.getOut().setBody(exchange.getIn().getBody()); } else if (getEndpoint().getOutputHeader() != null) { exchange.getOut().setBody(exchange.getIn().getBody()); exchange.getOut().setHeader(getEndpoint().getOutputHeader(), iterator); } else { exchange.getOut().setBody(iterator); } exchange.addOnCompletion(new ResultSetIteratorCompletion(iterator)); } } catch (Exception e) { closeConnection(con); closeStatement(ps); closeResultSet(rs); throw e; } }