We are trying to make our spring batch jobs more generic. In this process, we want to make the model object that gets passed between reader, processor and writer generic/dynamic too. If we store the table-name, column-name, type-name in the database, and fetch this info at run time, will we be able to create a model class on the fly, map the data read in the reader and pass it along to the writer?
Is it possible to create MyClass at runtime and do the mappings based on the configuration? RowMapper doesnt accept generic ? So, how do we specify it in the code without actually having an already compiled class at run time?
public class MyRowMapper implements RowMapper {
@Override
public MyClass mapRow(ResultSet rs, int rowNum) throws SQLException {
MyClass myClass= new MyClass();
myClass.setName(rs.getString("Name"));
myClass.setNumber(rs.getLong("Number"));
return myClass;
}
}
Aucun commentaire:
Enregistrer un commentaire