I realise this is more a question on spring usage then on spring batch usage, but it is caused due to the way spring-batch works so bare with me...
One of our jobs is taking up way too much processing time, we have seen that a lot of time is lost in preparing the same statement over and over again. So I would like to created the prepared statement once and reuse it. Correct me if I'm wrong but using Spring's JdbcTemplate the only way to do this is to use a callback:
jdbcTemplate.execute("select count(*) from A where B = ?", new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
for (int i=0; i<listOfBs.length; i++) {
ps.setString(1, listOfBs[i]);
ResultSet rs = ps.executeQuery();
if rs.next()
listOfBCounts[i] = ps.getLong
}
return null;
}
});
This is fine if you can do all your processing inside a single callback. However, in spring batch typically the listOfBs is being provided by a reader and the execute is happening inside a processor. (Or more likely inside a dao called by the processor)
Obviously this means the preparedstatement can be reused multiple times for the same B (inside a single callback) but not for all B's. Is there another way to accomplish this?



Reply With Quote
