Hi,
Is it safe in a web based app (thread per request) to have static RowMappers mapping the resultset to a pojo?
e.g. within a class you have code such as..
Can I rely entirely on getSimpleJdbcTemplate() being thread-safe or is there an issue with this pattern of usage?Code:// Declare a rowmapper private static final CommentRowMapper commentRowMapper = new CommentRowMapper(); // sample code where the row mapper is being used List<Comment> foundComments = getSimpleJdbcTemplate().query(SELECT_COMMENTS_BY_REQUESTID_SQL, commentRowMapper, requestId); // row mapper defined within a top-level class private static final class CommentRowMapper implements ParameterizedRowMapper<Comment> { public Comment mapRow(ResultSet rs, int rowNum) throws SQLException { Comment commentRow = new Comment(); commentRow.setCommentText(rs.getString(Comment.COMMENT_TX)); commentRow.setCreatedByUserId(rs.getString(Comment.CREATED_BY_USER_CD)); return commentRow; } }
Cheers for your help.. :-)


Reply With Quote
