You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/10/18 21:02:22 UTC

cvs commit: jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils BasicRowProcessor.java RowProcessor.java BeanHandler.java VectorHandler.java ResultSetIterator.java MapHandler.java CollectionHandler.java BeanListHandler.java ResultSetIteratorV1.java DbUtils.java

dgraham     2003/10/18 12:02:22

  Modified:    dbutils/src/java/org/apache/commons/dbutils BeanHandler.java
                        VectorHandler.java ResultSetIterator.java
                        MapHandler.java CollectionHandler.java
                        BeanListHandler.java ResultSetIteratorV1.java
                        DbUtils.java
  Added:       dbutils/src/java/org/apache/commons/dbutils
                        BasicRowProcessor.java RowProcessor.java
  Log:
  Renamed ResultSetConverter to RowProcessor and BasicResultSetConverter
  to BasicRowProcessor because the methods act on rows instead of
  a whole ResultSet.  toBeanList() is the exception.
  
  Revision  Changes    Path
  1.6       +7 -7      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BeanHandler.java	18 Oct 2003 01:07:25 -0000	1.5
  +++ BeanHandler.java	18 Oct 2003 19:02:22 -0000	1.6
  @@ -80,10 +80,10 @@
       private Class type = null;
       
       /**
  -     * The ResultSetConverter implementation to use when converting rows 
  +     * The RowProcessor implementation to use when converting rows 
        * into beans.
        */
  -    private ResultSetConverter convert = BasicResultSetConverter.instance();
  +    private RowProcessor convert = BasicRowProcessor.instance();
   
       /** 
        * Creates a new instance of BeanHandler.
  @@ -100,10 +100,10 @@
        * 
        * @param type The Class that objects returned from <code>handle()</code>
        * are created from.
  -     * @param convert The <code>ResultSetConverter</code> implementation 
  +     * @param convert The <code>RowProcessor</code> implementation 
        * to use when converting rows into beans.
        */
  -    public BeanHandler(Class type, ResultSetConverter convert) {
  +    public BeanHandler(Class type, RowProcessor convert) {
           this.type = type;
           this.convert = convert;
       }
  
  
  
  1.6       +4 -4      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/VectorHandler.java
  
  Index: VectorHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/VectorHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- VectorHandler.java	16 Oct 2003 04:21:11 -0000	1.5
  +++ VectorHandler.java	18 Oct 2003 19:02:22 -0000	1.6
  @@ -87,7 +87,7 @@
       public Object handle(ResultSet rs, Object[] params, Object userObject)
           throws SQLException {
   
  -        return rs.next() ? BasicResultSetConverter.instance().toArray(rs) : null;
  +        return rs.next() ? BasicRowProcessor.instance().toArray(rs) : null;
       }
   
   }
  
  
  
  1.7       +6 -6      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIterator.java
  
  Index: ResultSetIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIterator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ResultSetIterator.java	18 Oct 2003 00:11:52 -0000	1.6
  +++ ResultSetIterator.java	18 Oct 2003 19:02:22 -0000	1.7
  @@ -90,7 +90,7 @@
       /**
        * The processor to use when converting a row into an Object[].
        */
  -    private ResultSetConverter convert = BasicResultSetConverter.instance();
  +    private RowProcessor convert = BasicRowProcessor.instance();
   
       /**
        * Constructor for ResultSetIterator.
  @@ -105,9 +105,9 @@
        * @param rs Wrap this <code>ResultSet</code> in an <code>Iterator</code>.
        * @param convert The processor to use when converting a row into an 
        * <code>Object[]</code>.  Defaults to a 
  -     * <code>BasicResultSetConverter</code>.
  +     * <code>BasicRowProcessor</code>.
        */
  -    public ResultSetIterator(ResultSet rs, ResultSetConverter convert) {
  +    public ResultSetIterator(ResultSet rs, RowProcessor convert) {
           this.rs = rs;
           this.convert = convert;
       }
  
  
  
  1.5       +4 -4      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/MapHandler.java
  
  Index: MapHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/MapHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MapHandler.java	16 Oct 2003 04:21:11 -0000	1.4
  +++ MapHandler.java	18 Oct 2003 19:02:22 -0000	1.5
  @@ -88,7 +88,7 @@
       public Object handle(ResultSet rs, Object[] params, Object userObject)
           throws SQLException {
   
  -        return rs.next() ? BasicResultSetConverter.instance().toMap(rs) : null;
  +        return rs.next() ? BasicRowProcessor.instance().toMap(rs) : null;
       }
   
   }
  
  
  
  1.5       +7 -7      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CollectionHandler.java	18 Oct 2003 01:07:25 -0000	1.4
  +++ CollectionHandler.java	18 Oct 2003 19:02:22 -0000	1.5
  @@ -78,18 +78,18 @@
   public class CollectionHandler implements ResultSetHandler {
   
       /**
  -     * The ResultSetConverter implementation to use when converting rows 
  +     * The RowProcessor implementation to use when converting rows 
        * into Object[]s.
        */
  -    private ResultSetConverter convert = BasicResultSetConverter.instance();
  +    private RowProcessor convert = BasicRowProcessor.instance();
   
       /** 
        * Creates a new instance of CollectionHandler.
        * 
  -     * @param convert The <code>ResultSetConverter</code> implementation 
  +     * @param convert The <code>RowProcessor</code> implementation 
        * to use when converting rows into Object[]s.
        */
  -    public CollectionHandler(ResultSetConverter convert) {
  +    public CollectionHandler(RowProcessor convert) {
           this.convert = convert;
       }
   
  
  
  
  1.2       +7 -7      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BeanListHandler.java
  
  Index: BeanListHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BeanListHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BeanListHandler.java	18 Oct 2003 01:00:31 -0000	1.1
  +++ BeanListHandler.java	18 Oct 2003 19:02:22 -0000	1.2
  @@ -81,10 +81,10 @@
       private Class type = null;
       
       /**
  -     * The ResultSetConverter implementation to use when converting rows 
  +     * The RowProcessor implementation to use when converting rows 
        * into beans.
        */
  -    private ResultSetConverter convert = BasicResultSetConverter.instance();
  +    private RowProcessor convert = BasicRowProcessor.instance();
   
       /** 
        * Creates a new instance of BeanListHandler.
  @@ -101,10 +101,10 @@
        * 
        * @param type The Class that objects returned from <code>handle()</code>
        * are created from.
  -     * @param convert The <code>ResultSetConverter</code> implementation 
  +     * @param convert The <code>RowProcessor</code> implementation 
        * to use when converting rows into beans.
        */
  -    public BeanListHandler(Class type, ResultSetConverter convert) {
  +    public BeanListHandler(Class type, RowProcessor convert) {
           this.type = type;
           this.convert = convert;
       }
  
  
  
  1.7       +4 -4      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIteratorV1.java
  
  Index: ResultSetIteratorV1.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIteratorV1.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ResultSetIteratorV1.java	18 Oct 2003 00:11:52 -0000	1.6
  +++ ResultSetIteratorV1.java	18 Oct 2003 19:02:22 -0000	1.7
  @@ -103,7 +103,7 @@
       private void doNext() {
           try {
               rs.next();
  -            this.val = BasicResultSetConverter.instance().toArray(rs);
  +            this.val = BasicRowProcessor.instance().toArray(rs);
   
           } catch (SQLException sqle) {
               this.val = null;
  
  
  
  1.37      +4 -4      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java
  
  Index: DbUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- DbUtils.java	18 Oct 2003 00:11:52 -0000	1.36
  +++ DbUtils.java	18 Oct 2003 19:02:22 -0000	1.37
  @@ -277,7 +277,7 @@
           throws SQLException {
               
           ListAdapter la = new ListAdapter() {
  -            private ResultSetConverter convert = BasicResultSetConverter.instance();
  +            private RowProcessor convert = BasicRowProcessor.instance();
               
               public Object fetch(ResultSet rs) throws SQLException {
                   return convert.toArray(rs);
  
  
  
  1.1                  jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BasicRowProcessor.java
  
  Index: BasicRowProcessor.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BasicRowProcessor.java,v 1.1 2003/10/18 19:02:22 dgraham Exp $
   * $Revision: 1.1 $
   * $Date: 2003/10/18 19:02:22 $
   * 
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.dbutils;
  
  import java.beans.BeanInfo;
  import java.beans.IntrospectionException;
  import java.beans.Introspector;
  import java.beans.PropertyDescriptor;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  /**
   * Basic implementation of the <code>RowProcessor</code> interface.
   * This class is a thread-safe Singleton.
   * 
   * @see RowProcessor
   * 
   * @author Henri Yandell
   * @author Juozas Baliuka
   * @author David Graham
   */
  public class BasicRowProcessor implements RowProcessor {
      
      /**
       * Special array index that indicates there is no bean property that
       * matches a column from a ResultSet.
       */
      private static final int PROPERTY_NOT_FOUND = -1;
  
      /**
       * The Singleton instance of this class.
       */
      private static final BasicRowProcessor instance =
          new BasicRowProcessor();
     
      /**
       * Returns the Singleton instance of this class.
       */
      public static BasicRowProcessor instance(){
          return instance;
      }
  
      /**
       * Protected constructor for BasicRowProcessor subclasses only.
       */
      protected BasicRowProcessor() {
          super();
      }
  
      // See interface for javadoc.
      public Object[] toArray(ResultSet rs) throws SQLException {
          ResultSetMetaData meta = rs.getMetaData();
          int cols = meta.getColumnCount();
          Object[] objs = new Object[cols];
  
          for (int i = 0; i < cols; i++) {
              Object obj = rs.getObject(i + 1);
  
              objs[i] = rs.wasNull() ? null : obj;
          }
  
          return objs;
      }
  
      // See interface for javadoc.
      public Object toBean(ResultSet rs, Class type) throws SQLException {
          Object obj = newInstance(type);
  
          PropertyDescriptor[] pd = propertyDescriptors(type);
  
          ResultSetMetaData rsmd = rs.getMetaData();
          int cols = rsmd.getColumnCount();
          for (int i = 1; i <= cols; i++) {
              String columnName = rsmd.getColumnName(i);
  
              for (int j = 0; j < pd.length; j++) {
  
                  if (columnName.equalsIgnoreCase(pd[j].getName())) {
                      Object value = rs.getObject(i);
  
                      if (rs.wasNull() && pd[j].getPropertyType().isPrimitive()) {
                          continue;
                      }
  
                      callSetter(pd[j], obj, value);
                      break;
                  }
              }
          }
  
          return obj;
      }
  
      // See interface for javadoc.
      public List toBeanList(ResultSet rs, Class type) throws SQLException {
          List results = new ArrayList();
  
          if (!rs.next()) {
              return results;
          }
  
          PropertyDescriptor[] pd = propertyDescriptors(type);
          ResultSetMetaData rsmd = rs.getMetaData();
  
          int[] columnNameToIndex = this.mapColumnsToProperties(rsmd, pd);
  
          int cols = rsmd.getColumnCount();
  
          do {
              Object obj = newInstance(type);
  
              for (int i = 1; i <= cols; i++) {
                  Object value = rs.getObject(i);
                  if (rs.wasNull()) {
                      continue;
                  }
  
                  if (columnNameToIndex[i] != PROPERTY_NOT_FOUND) {
                      callSetter(pd[columnNameToIndex[i]], obj, value);
                  }
              }
  
              results.add(obj);
  
          } while (rs.next());
  
          return results;
      }
  
      /**
       * The positions in the returned array represent column numbers.  The values
       * stored at each position represent the index in the PropertyDescriptor[] 
       * for the bean property that matches the column name. 
       * 
       * @return An int[] with column index to property index mappings.  The 0th 
       * element is meaningless as column indexing starts at 1.
       * 
       * @throws SQLException
       */
      private int[] mapColumnsToProperties(
          ResultSetMetaData rsmd,
          PropertyDescriptor[] pd)
          throws SQLException {
  
          int cols = rsmd.getColumnCount();
          int columnNameToIndex[] = new int[cols + 1];
  
          for (int col = 1; col <= cols; col++) {
              String columnName = rsmd.getColumnName(col);
              for (int j = 0; j < pd.length; j++) {
  
                  if (columnName.equalsIgnoreCase(pd[j].getName())) {
                      columnNameToIndex[col] = j;
                      break;
  
                  } else {
                      columnNameToIndex[col] = PROPERTY_NOT_FOUND;
                  }
              }
          }
  
          return columnNameToIndex;
      }
  
      // See interface for javadoc.
      public Map toMap(ResultSet rs) throws SQLException {
          Map result = new CaseInsensitiveHashMap();
          ResultSetMetaData rsmd = rs.getMetaData();
          int cols = rsmd.getColumnCount();
  
          for (int i = 1; i <= cols; i++) {
              result.put(rsmd.getColumnName(i), rs.getObject(i));
          }
  
          return result;
      }
  
      /**
       * Calls the setter method on the target object for the given property.
       * If no setter method exists for the property, this method does nothing.
       * @param pd The property to set.
       * @param target The object to set the property on.
       * @param value The value to pass into the setter.
       * @throws DbException if an error occurs setting the property.
       */
      private void callSetter(PropertyDescriptor pd, Object target, Object value) {
          Method setter = pd.getWriteMethod();
  
          if (setter == null) {
              return;
          }
          
          Class[] params = setter.getParameterTypes();
  
          try {
              // Don't call setter if the value object isn't the right type 
              if (value == null || params[0].isInstance(value)) {
                  setter.invoke(target, new Object[] { value });
              }
  
          } catch (IllegalArgumentException e) {
              throw new DbException("Cannot set " + pd.getName(), e);
          } catch (IllegalAccessException e) {
              throw new DbException("Cannot set " + pd.getName(), e);
          } catch (InvocationTargetException e) {
              throw new DbException("Cannot set " + pd.getName(), e);
          }
      }
  
      /**
       * Returns a new instance of the given Class.
       * @param c The Class to create an object from.
       * @return A newly created object of the Class.
       * @throws DbException if creation failed.
       */
      private Object newInstance(Class c) {
          try {
              return c.newInstance();
  
          } catch (InstantiationException e) {
              throw new DbException("Cannot create " + c.getName(), e);
  
          } catch (IllegalAccessException e) {
              throw new DbException("Cannot create " + c.getName(), e);
          }
      }
  
      /**
       * Returns a PropertyDescriptor[] for the given Class.
       * @param c The Class to retrieve PropertyDescriptors for.
       * @return A PropertyDescriptor[] describing the Class.
       * @throws DbException if introspection failed.
       */
      private PropertyDescriptor[] propertyDescriptors(Class c) {
          // Introspector caches BeanInfo classes for better performance
          BeanInfo beanInfo = null;
          try {
              beanInfo = Introspector.getBeanInfo(c);
  
          } catch (IntrospectionException e) {
              throw new DbException(e);
          }
  
          return beanInfo.getPropertyDescriptors();
      }
      
      /**
       * A Map that converts all keys to lowercase Strings for case insensitive
       * lookups.  This is needed for the toMap() implementation because 
       * databases don't consistenly handle the casing of column names. 
       */
      private static class CaseInsensitiveHashMap extends HashMap {
  
          public boolean containsKey(Object key) {
              return super.containsKey(key.toString().toLowerCase());
          }
  
          public Object get(Object key) {
              return super.get(key.toString().toLowerCase());
          }
  
          public Object put(Object key, Object value) {
              return super.put(key.toString().toLowerCase(), value);
          }
  
          public void putAll(Map m) {
              Iterator iter = m.keySet().iterator();
              while (iter.hasNext()) {
                  Object key = iter.next();
                  Object value = m.get(key);
                  this.put(key, value);
              }
          }
  
          public Object remove(Object key) {
              return super.remove(key.toString().toLowerCase());
          }
  
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/RowProcessor.java
  
  Index: RowProcessor.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/RowProcessor.java,v 1.1 2003/10/18 19:02:22 dgraham Exp $
   * $Revision: 1.1 $
   * $Date: 2003/10/18 19:02:22 $
   * 
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.dbutils;
  
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.List;
  import java.util.Map;
  
  /**
   * <code>RowProcessor</code> implementations convert 
   * <code>ResultSet</code> rows into various other objects.  Implementations
   * can extend <code>BasicRowProcessor</code> to protect themselves
   * from changes to this interface. 
   * 
   * @see BasicRowProcessor
   * @author David Graham
   */
  public interface RowProcessor {
  
      /**
       * Create an <code>Object[]</code> from the column values in one 
       * <code>ResultSet</code> row.  The <code>ResultSet</code> should be 
       * positioned on a valid row before passing it to this method.  
       * Implementations of this method must not alter the row position of 
       * the <code>ResultSet</code>. 
       */
      public Object[] toArray(ResultSet rs) throws SQLException;
  
      /**
       * Create a JavaBean from the column values in one <code>ResultSet</code> 
       * row.  The <code>ResultSet</code> should be positioned on a valid row before
       * passing it to this method.  Implementations of this method must not
       * alter the row position of the <code>ResultSet</code>.
       */
      public Object toBean(ResultSet rs, Class type) throws SQLException;
  
      /**
       * Create a <code>List</code> of JavaBeans from the column values in all 
       * <code>ResultSet</code> rows.  <code>ResultSet.next()</code> should 
       * <strong>not</strong> be called before passing it to this method.
       * 
       * @return A <code>List</code> of beans with the given type in the order 
       * they were returned by the <code>ResultSet</code>.
       */
      public List toBeanList(ResultSet rs, Class type) throws SQLException;
  
      /**
       * Create a <code>Map</code> from the column values in one 
       * <code>ResultSet</code> row.  The <code>ResultSet</code> should be 
       * positioned on a valid row before
       * passing it to this method.  Implementations of this method must not
       * alter the row position of the <code>ResultSet</code>.
       */
      public Map toMap(ResultSet rs) throws SQLException;
  
  }
  
  
  

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