Implementation of DynaClass for DynaBeans that wrap the
java.sql.Row objects of a java.sql.ResultSet .
The normal usage pattern is something like:
ResultSet rs = ...;
ResultSetDynaClass rsdc = new ResultSetDynaClass(rs);
Iterator rows = rsdc.iterator();
while (rows.hasNext()) {
DynaBean row = (DynaBean) rows.next();
... process this row ...
}
rs.close();
Each column in the result set will be represented as a DynaBean
property of the corresponding name (optionally forced to lower case
for portability).
WARNING - Any
DynaBean instance returned by
this class, or from the Iterator returned by the
iterator() method, is directly linked to the row that the
underlying result set is currently positioned at. This has the following
implications:
- Once you retrieve a different
DynaBean instance, you should
no longer use any previous instance.
- Changing the position of the underlying result set will change the
data that the
DynaBean references.
- Once the underlying result set is closed, the
DynaBean instance may no longer be used.
Any database data that you wish to utilize outside the context of the
current row of an open result set must be copied. For example, you could
use the following code to create standalone copies of the information in
a result set:
ArrayList results = new ArrayList(); // To hold copied list
ResultSetDynaClass rsdc = ...;
DynaProperty[] properties = rsdc.getDynaProperties();
BasicDynaClass bdc =
new BasicDynaClass("foo", BasicDynaBean.class,
rsdc.getDynaProperties());
Iterator rows = rsdc.iterator();
while (rows.hasNext()) {
DynaBean oldRow = (DynaBean) rows.next();
DynaBean newRow = bdc.newInstance();
PropertyUtils.copyProperties(newRow, oldRow);
results.add(newRow);
}
author: Craig R. McClanahan version: $Revision: 556229 $ $Date: 2007-07-14 07:11:19 +0100 (Sat, 14 Jul 2007) $ |