
|
If you were logged in you would be able to see more operations.
|
|
|
| Resolution Date: |
25/Feb/09 10:06 AM
|
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).
|
|
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). |
Show » |
made changes - 16/Mar/08 09:42 PM
|
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).
|
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:
{code}
PropertyDescriptor[] props = this.propertyDescriptors(type);
ResultSetMetaData rsmd = rs.getMetaData();
int[] columnToProperty = this.mapColumnsToProperties(rsmd, props);
{code}
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:
{code}
public Object handle(ResultSet rs) throws SQLException {
return this.convert.toBeanList(rs, type);
}
{code}
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).
|
made changes - 25/Feb/09 10:06 AM
|
Resolution
|
|
Fixed
[ 1
]
|
|
Fix Version/s
|
|
1.2
[ 12312139
]
|
|
Status
|
Open
[ 1
]
|
Closed
[ 6
]
|
made changes - 07/Mar/09 06:09 AM
|
Assignee
|
|
Dan Fabulich
[ dfabulich
]
|
|
With the change I propose, the BeanListHandler#handleRow(ResultSet) method is never called anymore. So, any subclass of BeanListHandler which would override this method would not work properly anymore.
In order to prevent this from happening, I preferred to create a new class (named OptimalBeanListHandler - created from BeanListHandler with svn copy), which would implements ResultSetHandler directly rather than extends GenericListHandler.