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 ResultSetIterator.java ResultSetIteratorV1.java DbUtils.java
Date Sat, 18 Oct 2003 00:11:52 GMT
dgraham     2003/10/17 17:11:52

  Modified:    dbutils/src/java/org/apache/commons/dbutils
                        ResultSetIterator.java ResultSetIteratorV1.java
                        DbUtils.java
  Log:
  Removed the DbUtils.iterateResultSet() methods and made the 
  ResultSetIterator classes public for clients to use directly.  Clients
  shouldn't have to ask DbUtils for an iterator when this is easier:
  Iterator i = new ResultSetIterator(rs);
  
  Added javadoc to ResultSetIterator as well as the ability to specify 
  the processor used to convert rows into Object[]s.
  
  Revision  Changes    Path
  1.6       +51 -10    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ResultSetIterator.java	16 Oct 2003 04:21:11 -0000	1.5
  +++ ResultSetIterator.java	18 Oct 2003 00:11:52 -0000	1.6
  @@ -66,19 +66,51 @@
   import java.util.Iterator;
   
   /**
  - * A version of ResultSetIterator that is simpler, but needs isLast which 
  - * Oracle fails to offer. As such this is sidelined until Oracle adds 
  - * features.
  + * <p>
  + * Wraps a <code>ResultSet</code> in an <code>Iterator</code>.
 This is useful
  + * when you want to present a non-database application layer with domain
  + * neutral data.
  + * </p>
  + * 
  + * <p>
  + * This implementation requires the <code>ResultSet.isLast()</code> method
  + * to be implemented.
  + * </p>
    * 
    * @author Henri Yandell
  + * @author David Graham
    */
  -class ResultSetIterator implements Iterator {
  +public class ResultSetIterator implements Iterator {
   
  +    /**
  +     * The wrapped <code>ResultSet</code>.
  +     */
       private ResultSet rs = null;
  -
  +    
  +    /**
  +     * The processor to use when converting a row into an Object[].
  +     */
  +    private ResultSetConverter convert = BasicResultSetConverter.instance();
  +
  +    /**
  +     * Constructor for ResultSetIterator.
  +     * @param rs Wrap this <code>ResultSet</code> in an <code>Iterator</code>.
  +     */
       public ResultSetIterator(ResultSet rs) {
           this.rs = rs;
       }
  +    
  +    /**
  +     * Constructor for ResultSetIterator.
  +     * @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>.
  +     */
  +    public ResultSetIterator(ResultSet rs, ResultSetConverter convert) {
  +        this.rs = rs;
  +        this.convert = convert;
  +    }
   
       public boolean hasNext() {
           try {
  @@ -91,10 +123,16 @@
           }
       }
   
  +    /**
  +     * Returns the next row as an <code>Object[]</code>.
  +     * @return An <code>Object[]</code> with the same number of elements as
  +     * columns in the <code>ResultSet</code>. 
  +     * @see java.util.Iterator#next()
  +     */
       public Object next() {
           try {
               rs.next();
  -            return BasicResultSetConverter.instance().toArray(rs);
  +            return this.convert.toArray(rs);
   
           } catch (SQLException e) {
               // TODO Logging?
  @@ -103,8 +141,11 @@
           }
       }
   
  +    /**
  +     * Deletes the current row from the <code>ResultSet</code>.
  +     * @see java.util.Iterator#remove()
  +     */
       public void remove() {
  -
           try {
               this.rs.deleteRow();
   
  
  
  
  1.6       +14 -5     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ResultSetIteratorV1.java	16 Oct 2003 04:21:11 -0000	1.5
  +++ ResultSetIteratorV1.java	18 Oct 2003 00:11:52 -0000	1.6
  @@ -65,10 +65,19 @@
   import java.sql.SQLException;
   import java.util.Iterator;
   
  -class ResultSetIteratorV1 implements Iterator {
  +/**
  + * A version of ResultSetIterator that doesn't require isLast() which 
  + * Oracle fails to offer.
  + * 
  + * @author Henri Yandell
  + * @author David Graham
  + */
  +public class ResultSetIteratorV1 implements Iterator {
   
       private ResultSet rs;
  +
       private boolean hasNextCalledLast = false;
  +
       private Object val = null;
   
       public ResultSetIteratorV1(ResultSet rs) {
  @@ -95,7 +104,7 @@
           try {
               rs.next();
               this.val = BasicResultSetConverter.instance().toArray(rs);
  -            
  +
           } catch (SQLException sqle) {
               this.val = null;
           }
  
  
  
  1.36      +4 -23     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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- DbUtils.java	16 Oct 2003 04:21:11 -0000	1.35
  +++ DbUtils.java	18 Oct 2003 00:11:52 -0000	1.36
  @@ -342,26 +342,7 @@
               return false;
           }
       }
  -    
  -    /**
  -     * Iterate over a result set, getting an Object[] back
  -     * for each row of the result set.
  -     * This version uses JDBC-2 code, which Oracle 9i fails
  -     * to support.
  -     */
  -    public static Iterator iterateResultSet(ResultSet rs) {
  -        return new ResultSetIterator(rs);
  -    }
  -    
  -    /**
  -     * Iterate over a result set, getting an Object[] back
  -     * for each row of the result set.
  -     * This version uses JDBC-1 code.
  -     */
  -    public static Iterator iterateResultSetVersion1(ResultSet rs) {
  -        return new ResultSetIteratorV1(rs);
  -    }
  -    
  +       
       /**
        * Close a <code>Connection</code>, avoid closing if 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