Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-37

BeanListHandler#handle(ResultSet) is not optimal

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.2
    • None

    Description

      I use the BeanListHandler for huge ResultSets (about 1000000 rows), and I searched through the code to see if I could gain little time.

      It appeared to me that the following code - in BeanProcessor.class - was executed too many times:

              PropertyDescriptor[] props = this.propertyDescriptors(type);
              ResultSetMetaData rsmd = rs.getMetaData();
              int[] columnToProperty = this.mapColumnsToProperties(rsmd, props);
      

      for the following reason.
      Since BeanListHandler extends GenericListHandler, the method #handle(ResultSet) calls #handleRow(ResultSet) for each row in the ResultSet,
      which in the case of a BeanListHandler, calls RowProcessor#toBean(ResultSet, Class),
      which itself calls BeanProcessor#toBean(ResultSet, Class).

      A very simple way to make the BeanListHandler#handle(ResultSet) method faster is to override the GenericListHandler#handle(ResultSet) method by this code:

          public Object handle(ResultSet rs) throws SQLException {
              return this.convert.toBeanList(rs, type);
          }
      

      This way, the code I showed would be called only once, as it would not call BeanProcessor#toBean(ResultSet, Class) for each row but BeanProcessor#toBeanList(ResultSet, Class).

      Attachments

        1. OptimalBeanListHandler.java
          3 kB
          Julien Aymé
        2. OptimalBeanListHandler.patch
          2 kB
          Julien Aymé

        Activity

          People

            dfabulich Daniel Fabulich
            julien.ayme@gmail.com Julien Aymé
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: