I have this stored procedure call in Java:
@Autowired
public ScoreDao(DataSource dataSource) {
setDataSource(dataSource);
mScoreStoredProcedure = new ScoreStoredProcedure(dataSource);
}
public List<Score> loadAllScore(String pUsername, String pUUID, int pLimit) {
return mScoreStoredProcedure.execute(pUsername, pUUID, pLimit);
}
private class ScoreStoredProcedure extends StoredProcedure {
private static final String SPROC_NAME = "loadUserScore";
public ScoreStoredProcedure(DataSource datasource) {
super(datasource, SPROC_NAME);
declareParameter(new SqlReturnResultSet("#result-set-2", mScoreMapper));
declareParameter(new SqlParameter("vusername", Types.VARCHAR));
declareParameter(new SqlParameter("vuuid", Types.VARCHAR));
declareParameter(new SqlParameter("vlimit", Types.INTEGER));
compile();
}
@SuppressWarnings("unchecked")
public List<Score> execute(String pUsername, String pUUID, int pLimit){
Map<String,Object> lAllScoreResult = super.execute(pUsername, pUUID, pLimit);
List<Score> lAllScore = ((List<Score>)lAllScoreResult.get("#result-set-2"));
return lAllScore;
}
}
and this mapper class:
public class ScoreMapper implements RowMapper<Score> {
private String suffix = "";
@Autowired
private ScoreCreator scoreCreator;
@Autowired
private QuestionMapper questionMapper;
public ScoreMapper(String pSuffix) {
suffix = pSuffix;
}
public Score mapRow(ResultSet rs, int rowNum) throws SQLException {
Score lScore = scoreCreator.createScore(rs.getLong(suffix+"id"),
rs.getTimestamp(suffix+"stempel"), rs.getString(suffix+"username"),
rs.getInt(suffix+"points"), rs.getInt(suffix+"level"),
rs.getString(suffix+"comment"),
questionMapper.mapRow(rs, rowNum), rs.getString(suffix+"uuid"));
return lScore;
}
}
The problem I have is that the result of my StoredProcedure
is never cast to List<Score>
.
Instead it contains a List of LinkedCaseInsensitiveMap<V>
. Each entry covers a value from the database.
The mapper is correctly wired via Spring.
Briefly: I expect as result a List<Score>
. I thought I handle this with the methods shown in the code. How can I cast the result directly to my List<Score>
?
I followed this tutorial http://www.jtmelton.com/2007/10/30/using-springs-storedprocedure-and-rowmapper-mechanisms/
Could you help me find the problem?