Results 1 to 5 of 5

Thread: rowMapper or MappingSqlQuery?

  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Default rowMapper or MappingSqlQuery?

    Hello,

    I'm participating in the process of migrating existing DAOs of a web application to use Spring for database interaction.

    I am not sure which way is more efficient/fast: having an inner class inside the DAO which extends rowMapper for the SELECT statements, or perhaps having an inner class which extends MappingSqlQuery inside every method which executes a SELECT?

    From the amount of code point of view, the first option seems more attractive, because if I have five methods that all fetch the same information from the result set, then they can all use the same class. However, the manner in which I have to call the rowMapper in this case:

    List result = jt.query(SELECT_ACCOUNT_ON_ID, parms, parmsType, new AccountDAO().new ColumnRowMapper());

    seems too complex and maybe even improper, because such call is executed inside a static method.

    Any thoughts would be greatly appreciated.

    Thank you.

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Personally I tend to use the JdbcTemplate/callback approach most of the time, and the RdbmsObject approach mainly for stored procedures. I'd go for JdbcTemplate here. The method being static will only be a problem depending on what you do with the RowMapper--whether it's purely local to that method, in which case things will be fine.

    HTH,
    Rod
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    Since the RowMapper doesn't have any local state, you should create only one and use it upon each invocation of the query. Since you are using static methods, it would a static member.

    BTW, what does ColumnRowMapper do? ColumnMapRowMapper comes with Spring and creates a map with each column value using the actual name of the column.

  4. #4
    Join Date
    Jul 2005
    Posts
    3

    Default

    Thank you for your prompt replies!


    Quote Originally Posted by Rod Johnson
    The method being static will only be a problem depending on what you do with the RowMapper--whether it's purely local to that method, in which case things will be fine.
    The line of code that I included above is the only place where the rowMapper is used, after that I get a list and peacefully return it or convert to some other data structure.


    Quote Originally Posted by wpoitras
    BTW, what does ColumnRowMapper do?
    In my case ColumnRowMapper implements org.springframework.jdbc.core.RowMapper and has just one method, mapRow, which does exactly what its name implies, something like:

    public Object mapRow(ResultSet rs, int rowNum) throws SQLException
    {
    AccountVO vo = new AccountVO();
    vo.setName(rs.getString("NAME"));
    return vo;
    }

  5. #5
    Join Date
    Jul 2005
    Posts
    3

    Default

    Generally, what is the difference between the two? I know that one can use an inner class which extends MappingSqlQuery for dealing with complex SELECT statements, and JdbcTemplate.queryForObject for simple ones. So when would one use rowMapper?

Similar Threads

  1. Replies: 2
    Last Post: Sep 15th, 2005, 02:42 AM
  2. JDBC RowMapper and foreign keys
    By romanf in forum Data
    Replies: 2
    Last Post: Jul 6th, 2005, 12:42 AM
  3. Replies: 2
    Last Post: May 11th, 2005, 02:56 PM
  4. MappingSqlQuery
    By paulf in forum Data
    Replies: 1
    Last Post: Feb 12th, 2005, 01:12 PM
  5. Replies: 2
    Last Post: Dec 15th, 2004, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •