Index: src/java/org/apache/commons/dbutils/BasicRowProcessor.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/BasicRowProcessor.java,v
retrieving revision 1.10
diff -u -r1.10 BasicRowProcessor.java
--- src/java/org/apache/commons/dbutils/BasicRowProcessor.java 14 Mar 2004 23:03:54 -0000 1.10
+++ src/java/org/apache/commons/dbutils/BasicRowProcessor.java 8 Nov 2004 21:35:43 -0000
@@ -20,7 +20,6 @@
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
/**
@@ -108,16 +107,6 @@
*/
public Object toBean(ResultSet rs, Class type) throws SQLException {
return this.convert.toBean(rs, type);
- }
-
- /**
- * Convert a ResultSet into a List of JavaBeans.
- * This implementation delegates to a BeanProcessor instance.
- * @see org.apache.commons.dbutils.BeanProcessor#toBeanList(java.sql.ResultSet, java.lang.Class)
- * @see org.apache.commons.dbutils.RowProcessor#toBeanList(java.sql.ResultSet, java.lang.Class)
- */
- public List toBeanList(ResultSet rs, Class type) throws SQLException {
- return this.convert.toBeanList(rs, type);
}
/**
Index: src/java/org/apache/commons/dbutils/BeanProcessor.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/BeanProcessor.java,v
retrieving revision 1.7
diff -u -r1.7 BeanProcessor.java
--- src/java/org/apache/commons/dbutils/BeanProcessor.java 2 Sep 2004 03:19:01 -0000 1.7
+++ src/java/org/apache/commons/dbutils/BeanProcessor.java 8 Nov 2004 21:35:44 -0000
@@ -26,10 +26,8 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -118,52 +116,6 @@
int[] columnToProperty = this.mapColumnsToProperties(rsmd, props);
return this.createBean(rs, type, props, columnToProperty);
- }
-
- /**
- * Convert a ResultSet into a List of JavaBeans.
- * This implementation uses reflection and BeanInfo classes to
- * match column names to bean property names. Properties are matched to
- * columns based on several factors:
- *
- *
- * Primitive bean properties are set to their defaults when SQL NULL is
- * returned from the ResultSet. Numeric fields are set to 0
- * and booleans are set to false. Object bean properties are set to
- * null when SQL NULL is returned. This is the same behavior
- * as the ResultSet get* methods.
- *
ResultSet.
*/
public Object toBean(ResultSet rs, Class type) throws SQLException;
-
- /**
- * Create a List of JavaBeans from the column values in all
- * ResultSet rows. ResultSet.next() should
- * not be called before passing it to this method.
- *
- * @return A List of beans with the given type in the order
- * they were returned by the ResultSet.
- */
- public List toBeanList(ResultSet rs, Class type) throws SQLException;
/**
* Create a Map from the column values in one
Index: src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java,v
retrieving revision 1.4
diff -u -r1.4 ArrayListHandler.java
--- src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java 28 Feb 2004 00:12:22 -0000 1.4
+++ src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java 8 Nov 2004 21:35:44 -0000
@@ -17,8 +17,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.RowProcessor;
@@ -30,7 +28,7 @@
*
* @see ResultSetHandler
*/
-public class ArrayListHandler implements ResultSetHandler {
+public class ArrayListHandler extends GenericListHandler {
/**
* The RowProcessor implementation to use when converting rows
@@ -57,26 +55,17 @@
this.convert = convert;
}
+
/**
- * Convert each row's columns into an Object[] and store them
- * in a List in the same order they are returned from the
- * ResultSet.next() method.
- *
- * @return A List of Object[]s, never
- * null.
- *
- * @throws SQLException
- * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
- */
- public Object handle(ResultSet rs) throws SQLException {
-
- List result = new ArrayList();
-
- while (rs.next()) {
- result.add(this.convert.toArray(rs));
- }
-
- return result;
- }
+ * Convert row's columns into an Object[].
+ *
+ * @return Object[], never null.
+ *
+ * @throws SQLException
+ * @see org.apache.commons.dbutils.handlers.GenericListHandler#handle(ResultSet)
+ */
+ protected Object handleRow(ResultSet rs) throws SQLException {
+ return this.convert.toArray(rs);
+ }
}
Index: src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java,v
retrieving revision 1.4
diff -u -r1.4 BeanListHandler.java
--- src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java 28 Feb 2004 00:12:22 -0000 1.4
+++ src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java 8 Nov 2004 21:35:44 -0000
@@ -28,7 +28,7 @@
*
* @see ResultSetHandler
*/
-public class BeanListHandler implements ResultSetHandler {
+public class BeanListHandler extends GenericListHandler {
/**
* The Class of beans produced by this handler.
@@ -65,17 +65,16 @@
}
/**
- * Convert the ResultSet rows into a List of
- * beans with the Class given in the constructor.
+ * Convert the ResultSet row into a bean with
+ * the Class given in the constructor.
*
- * @return A List of beans (one for each row), never
- * null.
+ * @return A bean, never null.
*
* @throws SQLException
- * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
+ * @see org.apache.commons.dbutils.handlers.GenericListHandler#handle(ResultSet)
*/
- public Object handle(ResultSet rs) throws SQLException {
- return this.convert.toBeanList(rs, type);
+ protected Object handleRow(ResultSet rs) throws SQLException {
+ return this.convert.toBean(rs, type);
}
}
Index: src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java,v
retrieving revision 1.1
diff -u -r1.1 ColumnListHandler.java
--- src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java 9 Mar 2004 03:05:51 -0000 1.1
+++ src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java 8 Nov 2004 21:35:45 -0000
@@ -18,8 +18,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
import org.apache.commons.dbutils.ResultSetHandler;
@@ -31,7 +29,7 @@
* @see ResultSetHandler
* @since DbUtils 1.1
*/
-public class ColumnListHandler implements ResultSetHandler {
+public class ColumnListHandler extends GenericListHandler {
/**
* The column number to retrieve.
@@ -73,28 +71,20 @@
}
/**
- * Returns one ResultSet column as a List of
- * Objects. The elements are added to the List via
- * the ResultSet.getObject() method.
+ * Returns one ResultSet column value as Object.
*
- * @return A List of Objects, never
- * null.
+ * @return Object, never null.
*
* @throws SQLException
*
- * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
+ * @see org.apache.commons.dbutils.handlers.GenericListHandler#handle(ResultSet)
*/
- public Object handle(ResultSet rs) throws SQLException {
-
- List result = new ArrayList();
-
- while (rs.next()) {
- if (this.columnName == null) {
- result.add(rs.getObject(this.columnIndex));
- } else {
- result.add(rs.getObject(this.columnName));
- }
+ protected Object handleRow(ResultSet rs) throws SQLException {
+ if (this.columnName == null) {
+ return rs.getObject(this.columnIndex);
+ } else {
+ return rs.getObject(this.columnName);
}
- return result;
- }
+ }
+
}
Index: src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java,v
retrieving revision 1.4
diff -u -r1.4 MapListHandler.java
--- src/java/org/apache/commons/dbutils/handlers/MapListHandler.java 28 Feb 2004 00:12:22 -0000 1.4
+++ src/java/org/apache/commons/dbutils/handlers/MapListHandler.java 8 Nov 2004 21:35:45 -0000
@@ -17,8 +17,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.RowProcessor;
@@ -30,7 +28,7 @@
*
* @see ResultSetHandler
*/
-public class MapListHandler implements ResultSetHandler {
+public class MapListHandler extends GenericListHandler {
/**
* The RowProcessor implementation to use when converting rows
@@ -58,24 +56,16 @@
}
/**
- * Converts the ResultSet rows into a List of
- * Map objects.
+ * Converts the ResultSet row into a Map object.
*
- * @return A List of Maps, never null.
+ * @return A Map, never null.
*
* @throws SQLException
*
- * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
+ * @see org.apache.commons.dbutils.handlers.GenericListHandler#handle(ResultSet)
*/
- public Object handle(ResultSet rs) throws SQLException {
-
- List results = new ArrayList();
-
- while (rs.next()) {
- results.add(this.convert.toMap(rs));
- }
-
- return results;
+ protected Object handleRow(ResultSet rs) throws SQLException {
+ return this.convert.toMap(rs);
}
}
Index: src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/dbutils/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java,v
retrieving revision 1.8
diff -u -r1.8 BasicRowProcessorTest.java
--- src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java 31 May 2004 12:54:01 -0000 1.8
+++ src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java 8 Nov 2004 21:35:45 -0000
@@ -86,28 +86,6 @@
datef.parse(b.getNotDate());
}
- public void testToBeanList() throws SQLException, ParseException {
-
- List list = processor.toBeanList(this.rs, TestBean.class);
- assertNotNull(list);
- assertEquals(ROWS, list.size());
-
- TestBean b = (TestBean) list.get(1);
-
- assertEquals("4", b.getOne());
- assertEquals("5", b.getTwo());
- assertEquals("6", b.getThree());
- assertEquals("not set", b.getDoNotSet());
- assertEquals(3, b.getIntTest());
- assertEquals(new Integer(4), b.getIntegerTest());
- assertEquals(null, b.getNullObjectTest());
- assertEquals(0, b.getNullPrimitiveTest());
- // test date -> string handling
- assertNotNull(b.getNotDate());
- assertTrue(!"not a date".equals(b.getNotDate()));
- datef.parse(b.getNotDate());
- }
-
public void testToMap() throws SQLException {
int rowCount = 0;
Index: src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java
===================================================================
RCS file: src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java
diff -N src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbutils.handlers;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.dbutils.ResultSetHandler;
+
+/**
+ * Abstract class that simplify development of ResultSetHandler
+ * classes that convert ResultSet into List.
+ */
+abstract class GenericListHandler implements ResultSetHandler {
+ /**
+ * Whole ResultSet handler. It produce List as
+ * result. To convert individual rows into Java objects it uses
+ * handleRow(ResultSet) method.
+ *
+ * @see #handleRow(ResultSet)
+ */
+ public Object handle(ResultSet rs) throws SQLException {
+ List rows = new ArrayList();
+ while (rs.next()) {
+ rows.add(this.handleRow(rs));
+ }
+ return rows;
+ }
+
+ /**
+ * Row handler. Method converts current row into some Java object.
+ *
+ * @param rs ResultSet to process.
+ * @return row processing result
+ * @throws SQLException error occurs
+ */
+ protected abstract Object handleRow(ResultSet rs) throws SQLException;
+}