dgraham 2003/10/17 18:07:25 Modified: dbutils/src/java/org/apache/commons/dbutils BeanHandler.java CollectionHandler.java Log: Added the ability to specify the processor to use when converting rows instead of always using the basic implementation. Revision Changes Path 1.5 +23 -6 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BeanHandler.java Index: BeanHandler.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BeanHandler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- BeanHandler.java 16 Oct 2003 04:21:11 -0000 1.4 +++ BeanHandler.java 18 Oct 2003 01:07:25 -0000 1.5 @@ -78,6 +78,12 @@ * The Class of beans produced by this handler. */ private Class type = null; + + /** + * The ResultSetConverter implementation to use when converting rows + * into beans. + */ + private ResultSetConverter convert = BasicResultSetConverter.instance(); /** * Creates a new instance of BeanHandler. @@ -88,6 +94,19 @@ public BeanHandler(Class type) { this.type = type; } + + /** + * Creates a new instance of BeanHandler. + * + * @param type The Class that objects returned from <code>handle()</code> + * are created from. + * @param convert The <code>ResultSetConverter</code> implementation + * to use when converting rows into beans. + */ + public BeanHandler(Class type, ResultSetConverter convert) { + this.type = type; + this.convert = convert; + } /** * Convert the first row of the <code>ResultSet</code> into a bean with the @@ -102,9 +121,7 @@ public Object handle(ResultSet rs, Object[] params, Object userObject) throws SQLException { - return rs.next() - ? BasicResultSetConverter.instance().toBean(rs, this.type) - : null; + return rs.next() ? this.convert.toBean(rs, this.type) : null; } } 1.4 +20 -5 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/CollectionHandler.java Index: CollectionHandler.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/CollectionHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CollectionHandler.java 16 Oct 2003 04:21:11 -0000 1.3 +++ CollectionHandler.java 18 Oct 2003 01:07:25 -0000 1.4 @@ -78,6 +78,22 @@ public class CollectionHandler implements ResultSetHandler { /** + * The ResultSetConverter implementation to use when converting rows + * into Object[]s. + */ + private ResultSetConverter convert = BasicResultSetConverter.instance(); + + /** + * Creates a new instance of CollectionHandler. + * + * @param convert The <code>ResultSetConverter</code> implementation + * to use when converting rows into Object[]s. + */ + public CollectionHandler(ResultSetConverter convert) { + this.convert = convert; + } + + /** * Convert each row's columns into an <code>Object[]</code> and store them * in a <code>List</code> in the same order they are returned from the * <code>ResultSet.next()</code> method. @@ -93,9 +109,8 @@ List result = new ArrayList(); - ResultSetConverter convert = BasicResultSetConverter.instance(); while (rs.next()) { - result.add(convert.toArray(rs)); + result.add(this.convert.toArray(rs)); } return result;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]