commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r470975 - in /jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers: ArrayListHandler.java BeanListHandler.java ColumnListHandler.java MapListHandler.java
Date Fri, 03 Nov 2006 20:20:07 GMT
Author: bayard
Date: Fri Nov  3 12:20:06 2006
New Revision: 470975

URL: http://svn.apache.org/viewvc?view=rev&rev=470975
Log:
Applying the code refactoring in #DBUTILS-16 - the new abstract class is currently not public.
In a later release we can decide whether to make it public or not (this is recorded in #DBUTILS-33

Modified:
    jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
    jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
    jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
    jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java

Modified: jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java?view=diff&rev=470975&r1=470974&r2=470975
==============================================================================
--- jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
(original)
+++ jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
Fri Nov  3 12:20:06 2006
@@ -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 <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. 
-     * 
-     * @return A <code>List</code> of <code>Object[]</code>s, never

-     * <code>null</code>.
-     * 
-     * @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 <code>Object[]</code>.
+      * 
+      * @return <code>Object[]</code>, never <code>null</code>.
+      * 
+      * @throws SQLException
+      * @see org.apache.commons.dbutils.handlers.GenericListHandler#handle(ResultSet)
+      */
+     protected Object handleRow(ResultSet rs) throws SQLException {
+         return this.convert.toArray(rs);
+     }
 
 }

Modified: jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java?view=diff&rev=470975&r1=470974&r2=470975
==============================================================================
--- jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
(original)
+++ jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
Fri Nov  3 12:20:06 2006
@@ -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 <code>ResultSet</code> rows into a <code>List</code>
of 
-     * beans with the <code>Class</code> given in the constructor.
+     * Convert the <code>ResultSet</code> row into a bean with
+     * the <code>Class</code> given in the constructor.
      * 
-     * @return A <code>List</code> of beans (one for each row), never 
-     * <code>null</code>.
+     * @return A bean, never <code>null</code>.
      * 
      * @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);
     }
 
 }

Modified: jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java?view=diff&rev=470975&r1=470974&r2=470975
==============================================================================
--- jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
(original)
+++ jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
Fri Nov  3 12:20:06 2006
@@ -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 <code>ResultSet</code> column as a <code>List</code>
of
-     * <code>Object</code>s. The elements are added to the <code>List</code>
via
-     * the <code>ResultSet.getObject()</code> method.
+     * Returns one <code>ResultSet</code> column value as <code>Object</code>.
      * 
-     * @return A <code>List</code> of <code>Object</code>s, never
-     * <code>null</code>. 
+     * @return <code>Object</code>, never <code>null</code>.
      * 
      * @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;
-    }
+   }
+
 }

Modified: jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java?view=diff&rev=470975&r1=470974&r2=470975
==============================================================================
--- jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
(original)
+++ jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
Fri Nov  3 12:20:06 2006
@@ -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 <code>ResultSet</code> rows into a <code>List</code>
of 
-     * <code>Map</code> objects.
+     * Converts the <code>ResultSet</code> row into a <code>Map</code>
object.
      * 
-     * @return A <code>List</code> of <code>Map</code>s, never null.
 
+     * @return A <code>Map</code>, 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);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message