commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils BeanHandler.java
Date Thu, 16 Oct 2003 03:05:10 GMT
dgraham     2003/10/15 20:05:10

  Modified:    dbutils/src/java/org/apache/commons/dbutils BeanHandler.java
  Log:
  Added javadoc, use new version of DbUtils.resultSetToBean().
  
  Revision  Changes    Path
  1.3       +39 -29    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BeanHandler.java	15 Oct 2003 02:33:47 -0000	1.2
  +++ BeanHandler.java	16 Oct 2003 03:05:10 -0000	1.3
  @@ -57,41 +57,51 @@
    * 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;
  +
   /**
  - *
  - * @author  baliuka
  + * <code>ResultSetHandler</code> implementation that converts the first 
  + * <code>ResultSet</code> row into a JavaBean.
  + * 
  + * @see ResultSetHandler
  + * @author Juozas Baliuka
  + * @author David Graham
    */
   public class BeanHandler implements ResultSetHandler {
  -    
  -    private Class type;
  -    
  +
  +    /**
  +     * The Class of beans produced by this handler.
  +     */
  +    private Class type = null;
  +
       /** 
        * Creates a new instance of BeanHandler.
  +     * 
  +     * @param type The Class that objects returned from <code>handle()</code>
  +     * are created from.
        */
       public BeanHandler(Class type) {
           this.type = type;
       }
  -    
  -   public Object handle(java.sql.ResultSet rs, Object[] params, Object userObject) throws
java.sql.SQLException {
  -       Object bean;
  -        if(rs.next()){
  -            try{
  -             bean = type.newInstance();
  -            }catch(Exception e){
  -              throw new DbException(e);
  -            }
  -             DbUtils.resultSetToBean(rs, bean);
  -             if(rs.next()){
  -               throw new java.sql.SQLException();
  -             }
  -             return bean;
  -             
  -        }
  -        throw new java.sql.SQLException();
  -        
  -    }    
  -     
  +
  +    /**
  +     * Convert the first row of the <code>ResultSet</code> into a bean with
the
  +     * <code>Class</code> given in the constructor.
  +     * 
  +     * @return An initialized JavaBean or <code>null</code> if there were no

  +     * rows in the <code>ResultSet</code>.
  +     * 
  +     * @throws SQLException
  +     * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet, java.lang.Object[],
java.lang.Object)
  +     */
  +    public Object handle(ResultSet rs, Object[] params, Object userObject)
  +        throws SQLException {
  +
  +        return rs.next() ? DbUtils.resultSetToBean(rs, this.type) : null;
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
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