It is possible to do, but you would have to design for it, and be willing to sacrifice clarity and maintainability of your code in some respects.
What you could do, is create a FieldSetMapper that returns a list, rather than using a domain object (again, probably sacrificing a bit of maintainability/clarity here), and create a Dao that accepted an injected sql statement, and generated it's arguments list (Object [] as part of JdbcTemplate) by turning the list into an array and passing it to JdbcTemplate along with the injected Sql statement. Something like:
Code:
public class JdbcTradeDao extends JdbcDaoSupport{
private final String sql;
public JdbcTradeDao(String sql){
this.sql = sql;
}
public void writeTrade(List trade){
jdbcTemplate.update(sql, trade.toArray());
}
}
The FieldSetMapper would have to look something like:
Code:
public class tradeMapper implements FieldSetMapper{
public Object mapLine(FieldSet fs){
return fs.getValues();
}
}
(Please note that I typed this out by hand quickly without doing any compile checking, it's just a rough sketch)
The FieldSet values should return in the same order every-time, since fieldSet.get*(#) always returns the same value.
Personally, I would prefer an approach that used a domain object, since it feels more natural to me. If you used Hibernate to write the objects out, you would only need to update an hbm. You can also use the BeanWrapperFieldSetMapper to wire columns into a domain object using the JavaBean spec. However, it would still require that you update your domain object to include a new field. With all that being said, I can understand the appeal of a configuration only file load as well, and the above approach should work for that scenario.