Issue Details (XML | Word | Printable)

Key: DBUTILS-37
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Dan Fabulich
Reporter: Julien Aymé
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

BeanListHandler#handle(ResultSet) is not optimal

Created: 09/May/07 10:50 AM   Updated: 07/Mar/09 06:09 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2

Time Tracking:
Not Specified

File Attachments:
  Size
Java Source File Licensed for inclusion in ASF works OptimalBeanListHandler.java 2007-05-09 11:07 AM Julien Aymé 3 kB
Text File Licensed for inclusion in ASF works OptimalBeanListHandler.patch 2007-05-09 11:07 AM Julien Aymé 2 kB

Resolution Date: 25/Feb/09 10:06 AM


 Description  « Hide
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).



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #743097 Tue Feb 10 20:52:10 UTC 2009 dfabulich [DBUTILS-37] BeanListHandler#handle(ResultSet) is not optimal
Submitted by: Julien Aymé

Julien's patch created a separate OptimalBeanListHandler to avoid breaking users who had extended BeanListHandler; I chose to just replace the existing one rather than clutter the API
Files Changed
MODIFY /commons/sandbox/dbutils/bugfixing/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java

Repository Revision Date User Message
ASF #747724 Wed Feb 25 10:01:31 UTC 2009 bayard Merging in Dab Fabulich's work on https://svn.apache.org/repos/asf/commons/sandbox/dbutils/bugfixing from -r741987:747723. Resolving DBUTILS-34 - DBUTILS-37 - DBUTILS-29 - DBUTILS-14 - DBUTILS-31 - DBUTILS-39 - DBUTILS-41 - DBUTILS-44 - DBUTILS-33 - DBUTILS-42 - DBUTILS-40
Files Changed
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/BasicRowProcessor.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/BeanProcessor.java
ADD /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java (from /commons/sandbox/dbutils/bugfixing/src/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java)
MODIFY /commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BaseTestCase.java
MODIFY /commons/proper/dbutils/trunk/pom.xml
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
DEL /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java
ADD /commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/QueryRunnerTest.java (from /commons/sandbox/dbutils/bugfixing/src/test/org/apache/commons/dbutils/QueryRunnerTest.java)
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/QueryRunner.java