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/test/org/apache/commons/dbutils/driver StringTrimmedResultSetTestCase.java SqlNullCheckedResultSetTestCase.java
Date Wed, 22 Oct 2003 02:10:23 GMT
dgraham     2003/10/21 19:10:23

  Modified:    dbutils/src/java/org/apache/commons/dbutils/driver
                        SqlNullCheckedResultSet.java
                        StringTrimmedResultSet.java
               dbutils/src/java/org/apache/commons/dbutils QueryRunner.java
               dbutils/src/test/org/apache/commons/dbutils/driver
                        StringTrimmedResultSetTestCase.java
                        SqlNullCheckedResultSetTestCase.java
  Added:       dbutils/src/java/org/apache/commons/dbutils
                        ProxyFactory.java
  Log:
  Added the beginnings of a proxy solution to the incompatible JDBC API
  versions.  We can create dynamic proxies instead of implementing the
  various JDBC interfaces directly.  The correct interface will be implemented
  at runtime.
  
  Revision  Changes    Path
  1.5       +80 -446   jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/driver/SqlNullCheckedResultSet.java
  
  Index: SqlNullCheckedResultSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/driver/SqlNullCheckedResultSet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlNullCheckedResultSet.java	19 Oct 2003 20:32:09 -0000	1.4
  +++ SqlNullCheckedResultSet.java	22 Oct 2003 02:10:23 -0000	1.5
  @@ -62,19 +62,21 @@
   
   import java.io.InputStream;
   import java.io.Reader;
  +import java.lang.reflect.InvocationHandler;
  +import java.lang.reflect.Method;
   import java.math.BigDecimal;
   import java.sql.Blob;
   import java.sql.Clob;
   import java.sql.Date;
   import java.sql.Ref;
   import java.sql.ResultSet;
  -import java.sql.SQLException;
  -import java.sql.Statement;
   import java.sql.Time;
   import java.sql.Timestamp;
  -import java.util.Calendar;
  +import java.util.HashMap;
   import java.util.Map;
   
  +import org.apache.commons.dbutils.ProxyFactory;
  +
   /**
    * Decorates a <code>ResultSet</code> with checks for a SQL NULL value on each
    * <code>getXXX</code> method. If a column value obtained by a 
  @@ -107,475 +109,87 @@
    * </p>
    *
    * @author  <a href="stevencaswell@apache.org">Steven Caswell</a>
  + * @author David Graham
    * @version $Id$
    */
  -public class SqlNullCheckedResultSet extends ResultSetWrapper {
  -    private ResultSet rs = null;
  +public class SqlNullCheckedResultSet implements InvocationHandler {
  +
  +    /**
  +     * Maps normal method names (ie. "getBigDecimal") to the corresponding null
  +     * Method object (ie. getNullBigDecimal).
  +     */
  +    private static final Map nullMethods = new HashMap();
  +
  +    static {
  +        Method[] methods = SqlNullCheckedResultSet.class.getMethods();
  +        for (int i = 0; i < methods.length; i++) {
  +            String methodName = methods[i].getName();
  +
  +            if (methodName.indexOf("getNull") == 0) {
  +                String normalName =
  +                    methodName.substring(0, 3) + methodName.substring(7);
  +
  +                nullMethods.put(normalName, methods[i]);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * The factory to create proxies with.
  +     */
  +    private static final ProxyFactory factory = ProxyFactory.instance();
  +
  +    /**
  +     * Wraps the <code>ResultSet</code> in an instance of this class.  This is
  +     * equivalent to:
  +     * <pre>
  +     * ProxyFactory.instance().createResultSet(new SqlNullCheckedResultSet(rs));
  +     * </pre>
  +     * 
  +     * @param rs The <code>ResultSet</code> to wrap.
  +     */
  +    public static ResultSet wrap(ResultSet rs) {
  +        return factory.createResultSet(new SqlNullCheckedResultSet(rs));
  +    }
  +
       private InputStream nullAsciiStream = null;
       private BigDecimal nullBigDecimal = null;
       private InputStream nullBinaryStream = null;
       private Blob nullBlob = null;
       private boolean nullBoolean = false;
  -    private byte nullByte = (byte) 0;
  +    private byte nullByte = 0;
       private byte[] nullBytes = null;
       private Reader nullCharacterStream = null;
       private Clob nullClob = null;
       private Date nullDate = null;
  -    private double nullDouble = (double) 0.0;
  -    private float nullFloat = (float) 0.0;
  -    private int nullInt = (int) 0;
  +    private double nullDouble = 0.0;
  +    private float nullFloat = 0.0f;
  +    private int nullInt = 0;
       private long nullLong = 0;
       private Object nullObject = null;
       private Ref nullRef = null;
  -    private short nullShort = (short) 0;
  +    private short nullShort = 0;
       private String nullString = null;
       private Time nullTime = null;
       private Timestamp nullTimestamp = null;
       private InputStream nullUnicodeStream = null;
   
       /**
  -     * Constructs a new instance of
  -     * <code>SqlNullCheckedResultSet</code>
  -     * to wrap the specified <code>ResultSet</code>.
  +     * The wrapped result. 
        */
  -    public SqlNullCheckedResultSet(ResultSet rs) {
  -        super(rs);
  -        this.rs = rs;
  -    }
  +    private final ResultSet rs;
   
       /**
        * Constructs a new instance of
        * <code>SqlNullCheckedResultSet</code>
  -     * to wrap the specified <code>ResultSet</code> and <code>Statement</code>.
  +     * to wrap the specified <code>ResultSet</code>.
        */
  -    public SqlNullCheckedResultSet(ResultSet rs, Statement st) {
  -        super(rs, st);
  +    public SqlNullCheckedResultSet(ResultSet rs) {
  +        super();
           this.rs = rs;
       }
   
       /**
  -     * @see ResultSet#getAsciiStream(int param)
  -     */
  -    public InputStream getAsciiStream(int param) throws SQLException {
  -        InputStream stream = rs.getAsciiStream(param);
  -        return rs.wasNull() ? getNullAsciiStream() : stream;
  -    }
  -
  -    /**
  -     * @see ResultSet#getAsciiStream(String str)
  -     */
  -    public InputStream getAsciiStream(String str) throws SQLException {
  -        InputStream stream = rs.getAsciiStream(str);
  -        return rs.wasNull() ? getNullAsciiStream() : stream;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBigDecimal(String str)
  -     */
  -    public BigDecimal getBigDecimal(String str) throws SQLException {
  -        BigDecimal bg = rs.getBigDecimal(str);
  -        return rs.wasNull() ? getNullBigDecimal() : bg;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBigDecimal(int param)
  -     */
  -    public BigDecimal getBigDecimal(int param) throws SQLException {
  -        BigDecimal bg = rs.getBigDecimal(param);
  -        return rs.wasNull() ? getNullBigDecimal() : bg;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBigDecimal(int param, int param1)
  -     * @deprecated
  -     */
  -    public BigDecimal getBigDecimal(int param, int param1) throws SQLException {
  -        BigDecimal bg = rs.getBigDecimal(param, param1);
  -        return rs.wasNull() ? getNullBigDecimal() : bg;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBigDecimal(String str, int param)
  -     * @deprecated
  -     */
  -    public BigDecimal getBigDecimal(String str, int param) throws SQLException {
  -        BigDecimal bg = rs.getBigDecimal(str, param);
  -        return rs.wasNull() ? getNullBigDecimal() : bg;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBinaryStream(int param)
  -     */
  -    public InputStream getBinaryStream(int param) throws SQLException {
  -        InputStream stream = rs.getBinaryStream(param);
  -        return rs.wasNull() ? getNullBinaryStream() : stream;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBinaryStream(String str)
  -     */
  -    public InputStream getBinaryStream(String str) throws SQLException {
  -        InputStream stream = rs.getBinaryStream(str);
  -        return rs.wasNull() ? getNullBinaryStream() : stream;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBlob(String str)
  -     */
  -    public Blob getBlob(String str) throws SQLException {
  -        Blob blob = rs.getBlob(str);
  -        return rs.wasNull() ? getNullBlob() : blob;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBlob(int param)
  -     */
  -    public Blob getBlob(int param) throws SQLException {
  -        Blob blob = rs.getBlob(param);
  -        return rs.wasNull() ? getNullBlob() : blob;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBoolean(String str)
  -     */
  -    public boolean getBoolean(String str) throws SQLException {
  -        boolean bool = rs.getBoolean(str);
  -        return rs.wasNull() ? getNullBoolean() : bool;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBoolean(int param)
  -     */
  -    public boolean getBoolean(int param) throws SQLException {
  -        boolean bool = rs.getBoolean(param);
  -        return rs.wasNull() ? getNullBoolean() : bool;
  -    }
  -
  -    /**
  -     * @see ResultSet#getByte(int param)
  -     */
  -    public byte getByte(int param) throws SQLException {
  -        byte aByte = rs.getByte(param);
  -        return rs.wasNull() ? getNullByte() : aByte;
  -    }
  -
  -    /** 
  -     * @see ResultSet#getByte(String str)
  -     */
  -    public byte getByte(String str) throws SQLException {
  -        byte aByte = rs.getByte(str);
  -        return rs.wasNull() ? getNullByte() : aByte;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBytes(int param)
  -     */
  -    public byte[] getBytes(int param) throws SQLException {
  -        byte[] bytes = rs.getBytes(param);
  -        return rs.wasNull() ? getNullBytes() : bytes;
  -    }
  -
  -    /**
  -     * @see ResultSet#getBytes(String str)
  -     */
  -    public byte[] getBytes(String str) throws SQLException {
  -        byte[] bytes = rs.getBytes(str);
  -        return rs.wasNull() ? getNullBytes() : bytes;
  -    }
  -
  -    /**
  -     * @see ResultSet#getCharacterStream(int param)
  -     */
  -    public Reader getCharacterStream(int param) throws SQLException {
  -        Reader reader = rs.getCharacterStream(param);
  -        return rs.wasNull() ? getNullCharacterStream() : reader;
  -    }
  -
  -    /**
  -     * @see ResultSet#getCharacterStream(String str)
  -     */
  -    public Reader getCharacterStream(String str) throws SQLException {
  -        Reader reader = rs.getCharacterStream(str);
  -        return rs.wasNull() ? getNullCharacterStream() : reader;
  -    }
  -
  -    /**
  -     * @see ResultSet#getClob(String str)
  -     */
  -    public Clob getClob(String str) throws SQLException {
  -        Clob clob = rs.getClob(str);
  -        return rs.wasNull() ? getNullClob() : clob;
  -    }
  -
  -    /**
  -     * @see ResultSet#getClob(int param)
  -     */
  -    public Clob getClob(int param) throws SQLException {
  -        Clob clob = rs.getClob(param);
  -        return rs.wasNull() ? getNullClob() : clob;
  -    }
  -
  -    /**
  -     * @see ResultSet#getDate(int param)
  -     */
  -    public Date getDate(int param) throws SQLException {
  -        Date date = rs.getDate(param);
  -        return rs.wasNull() ? getNullDate() : date;
  -    }
  -
  -    /**
  -     * @see ResultSet#getDate(String str)
  -     */
  -    public Date getDate(String str) throws SQLException {
  -        Date date = rs.getDate(str);
  -        return rs.wasNull() ? getNullDate() : date;
  -    }
  -
  -    /**
  -     * @see ResultSet#getDate(String str, Calendar calendar)
  -     */
  -    public Date getDate(String str, Calendar calendar) throws SQLException {
  -        Date date = rs.getDate(str, calendar);
  -        return rs.wasNull() ? getNullDate() : date;
  -    }
  -
  -    /**
  -     * @see ResultSet#getDate(int param, Calendar calendar)
  -     */
  -    public Date getDate(int param, Calendar calendar) throws SQLException {
  -        Date date = rs.getDate(param, calendar);
  -        return rs.wasNull() ? getNullDate() : date;
  -    }
  -
  -    /**
  -     * @see ResultSet#getDouble(String str)
  -     */
  -    public double getDouble(String str) throws SQLException {
  -        double aDouble = rs.getDouble(str);
  -        return rs.wasNull() ? getNullDouble() : aDouble;
  -    }
  -
  -    /**
  -     * @see ResultSet#getDouble(int param)
  -     */
  -    public double getDouble(int param) throws SQLException {
  -        double aDouble = rs.getDouble(param);
  -        return rs.wasNull() ? getNullDouble() : aDouble;
  -    }
  -
  -    /**
  -     * @see ResultSet#getFloat(int param)
  -     */
  -    public float getFloat(int param) throws SQLException {
  -        float aFloat = rs.getFloat(param);
  -        return rs.wasNull() ? getNullFloat() : aFloat;
  -    }
  -
  -    /**
  -     * @see ResultSet#getFloat(String str)
  -     */
  -    public float getFloat(String str) throws SQLException {
  -        float aFloat = rs.getFloat(str);
  -        return rs.wasNull() ? getNullFloat() : aFloat;
  -    }
  -
  -    /**
  -     * @see ResultSet#getInt(int param)
  -     */
  -    public int getInt(int param) throws SQLException {
  -        int aInt = rs.getInt(param);
  -        return rs.wasNull() ? getNullInt() : aInt;
  -    }
  -
  -    /**
  -     * @see ResultSet#getInt(String str)
  -     */
  -    public int getInt(String str) throws SQLException {
  -        int aInt = rs.getInt(str);
  -        return rs.wasNull() ? getNullInt() : aInt;
  -    }
  -
  -    /**
  -     * @see ResultSet#getLong(int param)
  -     */
  -    public long getLong(int param) throws SQLException {
  -        long aLong = rs.getLong(param);
  -        return rs.wasNull() ? getNullLong() : aLong;
  -    }
  -
  -    /**
  -     * @see ResultSet#getLong(String str)
  -     */
  -    public long getLong(String str) throws SQLException {
  -        long aLong = rs.getLong(str);
  -        return rs.wasNull() ? getNullLong() : aLong;
  -    }
  -
  -    /**
  -     * @see ResultSet#getObject(String str)
  -     */
  -    public Object getObject(String str) throws SQLException {
  -        Object aObject = rs.getObject(str);
  -        return rs.wasNull() ? getNullObject() : aObject;
  -    }
  -
  -    /**
  -     * @see ResultSet#getObject(int param)
  -     */
  -    public Object getObject(int param) throws SQLException {
  -        Object aObject = rs.getObject(param);
  -        return rs.wasNull() ? getNullObject() : aObject;
  -    }
  -
  -    /**
  -     * @see ResultSet#getObject(String str, Map map)
  -     */
  -    public Object getObject(String str, Map map) throws SQLException {
  -        Object aObject = rs.getObject(str, map);
  -        return rs.wasNull() ? getNullObject() : aObject;
  -    }
  -
  -    /**
  -     * @see ResultSet#getObject(int param, Map map)
  -     */
  -    public Object getObject(int param, Map map) throws SQLException {
  -        Object aObject = rs.getObject(param, map);
  -        return rs.wasNull() ? getNullObject() : aObject;
  -    }
  -
  -    /**
  -     * @see ResultSet#getRef(String str)
  -     */
  -    public Ref getRef(String str) throws SQLException {
  -        Ref ref = rs.getRef(str);
  -        return rs.wasNull() ? getNullRef() : ref;
  -    }
  -
  -    /**
  -     * @see ResultSet#getRef(int param)
  -     */
  -    public Ref getRef(int param) throws SQLException {
  -        Ref ref = rs.getRef(param);
  -        return rs.wasNull() ? getNullRef() : ref;
  -    }
  -
  -    /**
  -     * @see ResultSet#getShort(int param)
  -     */
  -    public short getShort(int param) throws SQLException {
  -        short aShort = rs.getShort(param);
  -        return rs.wasNull() ? getNullShort() : aShort;
  -    }
  -
  -    /**
  -     * @see ResultSet#getShort(String str)
  -     */
  -    public short getShort(String str) throws SQLException {
  -        short aShort = rs.getShort(str);
  -        return rs.wasNull() ? getNullShort() : aShort;
  -    }
  -
  -    /**
  -     * @see ResultSet#getString(String str)
  -     */
  -    public String getString(String str) throws SQLException {
  -        String string = rs.getString(str);
  -        return rs.wasNull() ? getNullString() : string;
  -    }
  -
  -    /**
  -     * @see ResultSet#getString(int param)
  -     */
  -    public String getString(int param) throws SQLException {
  -        String string = rs.getString(param);
  -        return rs.wasNull() ? getNullString() : string;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTime(int param)
  -     */
  -    public Time getTime(int param) throws SQLException {
  -        Time time = rs.getTime(param);
  -        return rs.wasNull() ? getNullTime() : time;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTime(String str)
  -     */
  -    public Time getTime(String str) throws SQLException {
  -        Time time = rs.getTime(str);
  -        return rs.wasNull() ? getNullTime() : time;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTime(String str, Calendar calendar)
  -     */
  -    public Time getTime(String str, Calendar calendar) throws SQLException {
  -        Time time = rs.getTime(str, calendar);
  -        return rs.wasNull() ? getNullTime() : time;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTime(int param, Calendar calendar)
  -     */
  -    public Time getTime(int param, Calendar calendar) throws SQLException {
  -        Time time = rs.getTime(param, calendar);
  -        return rs.wasNull() ? getNullTime() : time;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTimestamp(String str)
  -     */
  -    public Timestamp getTimestamp(String str) throws SQLException {
  -        Timestamp timestamp = rs.getTimestamp(str);
  -        return rs.wasNull() ? getNullTimestamp() : timestamp;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTimestamp(int param)
  -     */
  -    public Timestamp getTimestamp(int param) throws SQLException {
  -        Timestamp timestamp = rs.getTimestamp(param);
  -        return rs.wasNull() ? getNullTimestamp() : timestamp;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTimestamp(int param, Calendar calendar)
  -     */
  -    public Timestamp getTimestamp(int param, Calendar calendar)
  -        throws SQLException {
  -        Timestamp timestamp = rs.getTimestamp(param, calendar);
  -        return rs.wasNull() ? getNullTimestamp() : timestamp;
  -    }
  -
  -    /**
  -     * @see ResultSet#getTimestamp(String str, Calendar calendar)
  -     */
  -    public Timestamp getTimestamp(String str, Calendar calendar)
  -        throws SQLException {
  -        Timestamp timestamp = rs.getTimestamp(str, calendar);
  -        return rs.wasNull() ? getNullTimestamp() : timestamp;
  -    }
  -
  -    /**
  -     * @see ResultSet#getUnicodeStream(int param)
  -     * @deprecated
  -     */
  -    public InputStream getUnicodeStream(int param) throws SQLException {
  -        InputStream stream = rs.getUnicodeStream(param);
  -        return rs.wasNull() ? getNullUnicodeStream() : stream;
  -    }
  -
  -    /**
  -     * @see ResultSet#getUnicodeStream(String str)
  -     * @deprecated
  -     */
  -    public InputStream getUnicodeStream(String str) throws SQLException {
  -        InputStream stream = rs.getUnicodeStream(str);
  -        return rs.wasNull() ? getNullUnicodeStream() : stream;
  -    }
  -
  -    /**
        * Returns the value when a SQL null is encountered as the result of
        * invoking a <code>getAsciiStream</code> method.
        *
  @@ -783,6 +397,26 @@
        */
       public InputStream getNullUnicodeStream() {
           return this.nullUnicodeStream;
  +    }
  +
  +    /**
  +     * Intercepts calls to <code>get*</code> methods and calls the appropriate
  +     * <code>getNull*</code> method if the <code>ResultSet</code> returned
  +     * <code>null</code>.
  +     * 
  +     * @throws Throwable
  +     * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
  +     */
  +    public Object invoke(Object proxy, Method method, Object[] args)
  +        throws Throwable {
  +
  +        Object result = method.invoke(this.rs, args);
  +
  +        Method nullMethod = (Method) nullMethods.get(method.getName());
  +
  +        return (this.rs.wasNull() && nullMethod != null)
  +            ? nullMethod.invoke(this, null)
  +            : result;
       }
   
       /**
  
  
  
  1.5       +64 -99    jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/driver/StringTrimmedResultSet.java
  
  Index: StringTrimmedResultSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/driver/StringTrimmedResultSet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StringTrimmedResultSet.java	17 Oct 2003 23:15:55 -0000	1.4
  +++ StringTrimmedResultSet.java	22 Oct 2003 02:10:23 -0000	1.5
  @@ -60,128 +60,93 @@
   
   package org.apache.commons.dbutils.driver;
   
  +import java.lang.reflect.InvocationHandler;
  +import java.lang.reflect.Method;
   import java.sql.ResultSet;
  -import java.sql.SQLException;
  -import java.sql.Statement;
  -import java.util.Map;
  +
  +import org.apache.commons.dbutils.ProxyFactory;
   
   /**
    * Wraps a <code>ResultSet</code> to trim strings returned by the
    * <code>getString()</code> and <code>getObject()</code> methods.
  + * 
  + * <p>
  + * Usage Example:
  + * This example shows how to decorate ResultSets so processing continues as 
  + * normal but all Strings are trimmed before being returned from the 
  + * <code>ResultSet</code>.
  + * </p>
  + * 
  + * <pre>
  + * ResultSet rs = // somehow get a ResultSet;
  + * 
  + * // Substitute wrapped ResultSet with additional behavior for real ResultSet
  + * rs = StringTrimmedResultSet.wrap(rs);
  + * 
  + * // Pass wrapped ResultSet to processor
  + * List list = BasicRowProcessor.instance().toBeanList(rs);
  + * </pre>
    *
    * @author <a href="stevencaswell@apache.org">Steven Caswell</a>
    * @author David Graham
    * @version $Id$
    */
  -public class StringTrimmedResultSet extends ResultSetWrapper {
  -    
  -    private ResultSet rs = null;
  -    
  -    /**
  -     * Constructs a new instance of
  -     * <code>StringTrimmedResultSet</code>.
  -     * to wrap the specified <code>ResultSet</code>.
  -     */
  -    public StringTrimmedResultSet(ResultSet rs) {
  -        super(rs);
  -        this.rs = rs;
  -    }
  +public class StringTrimmedResultSet implements InvocationHandler {
   
       /**
  -     * Constructs a new instance of <code>StringTrimmedResultSet</code>
  -     * to wrap the specified <code>ResultSet</code> and <code>Statement</code>.
  +     * The factory to create proxies with.
        */
  -    public StringTrimmedResultSet(ResultSet rs, Statement stmt) {
  -        super(rs, stmt);
  -        this.rs = rs;
  -    }
  +    private static final ProxyFactory factory = ProxyFactory.instance();
   
       /**
  -     * Gets the value of the designated column in the current row of this 
  -     * <code>ResultSet</code> object as a String in the Java programming 
  -     * language. Control characters, including whitespace, are removed from 
  -     * both ends of the string, handling null by returning null.
  -     *
  -     * @param columnName the SQL name of the column
  -     * @return the column value; if the value is SQL NULL, the value returned 
  -     * is <code>null</code>
  -     * @throws SQLException if a database access error occurs
  -     */
  -    public String getString(String columnName) throws SQLException {
  -        String value = this.rs.getString(columnName);
  -        return (value == null) ? null : value.trim();
  -    }
  -    
  -    /**
  -     * Gets the value of the designated column in the current row of this 
  -     * <code>ResultSet</code> object as a String in the Java programming 
  -     * language. Control characters, including whitespace, are removed from 
  -     * both ends of the string, handling null by returning null.
  -     *
  -     * @param columnIndex The first column is 1, the second is 2, ...
  -     * @return The column value; if the value is SQL NULL, the value returned 
  -     * is <code>null</code>
  -     * @throws SQLException if a database access error occurs
  +     * Wraps the <code>ResultSet</code> in an instance of this class.  This is
  +     * equivalent to:
  +     * <pre>
  +     * ProxyFactory.instance().createResultSet(new StringTrimmedResultSet(rs));
  +     * </pre>
  +     * 
  +     * @param rs The <code>ResultSet</code> to wrap.
        */
  -    public String getString(int columnIndex) throws SQLException {
  -        String value = this.rs.getString(columnIndex);
  -        return (value == null) ? null : value.trim();
  -    }
  -    
  -    /**
  -     * If the object is a <code>String</code>, it is trimmed before returning
  -     * from this method.
  -     * @throws SQLException
  -     * @see java.sql.ResultSet#getObject(int, java.util.Map)
  -     */
  -    public Object getObject(int columnIndex, Map map) throws SQLException {
  -        Object obj = this.rs.getObject(columnIndex, map);
  -        if (obj instanceof String) {
  -            obj = ((String) obj).trim();
  -        }
  -        return obj;
  +    public static ResultSet wrap(ResultSet rs) {
  +        return factory.createResultSet(new StringTrimmedResultSet(rs));
       }
   
       /**
  -     * If the object is a <code>String</code>, it is trimmed before returning
  -     * from this method.
  -     * @throws SQLException
  -     * @see java.sql.ResultSet#getObject(int)
  +     * The wrapped result. 
        */
  -    public Object getObject(int columnIndex) throws SQLException {
  -        Object obj = this.rs.getObject(columnIndex);
  -        if (obj instanceof String) {
  -            obj = ((String) obj).trim();
  -        }
  -        return obj;
  -    }
  +    private final ResultSet rs;
   
       /**
  -     * If the object is a <code>String</code>, it is trimmed before returning
  -     * from this method.
  -     * @throws SQLException
  -     * @see java.sql.ResultSet#getObject(java.lang.String, java.util.Map)
  +     * Constructs a new instance of <code>StringTrimmedResultSet</code>
  +     * to wrap the specified <code>ResultSet</code>.
        */
  -    public Object getObject(String columnName, Map map) throws SQLException {
  -        Object obj = this.rs.getObject(columnName, map);
  -        if (obj instanceof String) {
  -            obj = ((String) obj).trim();
  -        }
  -        return obj;
  +    public StringTrimmedResultSet(ResultSet rs) {
  +        super();
  +        this.rs = rs;
       }
   
       /**
  -     * If the object is a <code>String</code>, it is trimmed before returning
  -     * from this method.
  -     * @throws SQLException
  -     * @see java.sql.ResultSet#getObject(java.lang.String)
  -     */
  -    public Object getObject(String columnName) throws SQLException {
  -        Object obj = this.rs.getObject(columnName);
  -        if (obj instanceof String) {
  -            obj = ((String) obj).trim();
  +     * Intercept calls to the <code>getString()</code> and 
  +     * <code>getObject()</code> methods and trim any Strings before they're
  +     * returned.
  +     * 
  +     * @throws Throwable
  +     * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
  +     */
  +    public Object invoke(Object proxy, Method method, Object[] args)
  +        throws Throwable {
  +
  +        Object result = method.invoke(this.rs, args);
  +
  +        if (method.getName().equals("getObject")
  +            || method.getName().equals("getString")) {
  +
  +            if (result instanceof String) {
  +                result = ((String) result).trim();
  +            }
           }
  -        return obj;
  +
  +        return result;
       }
   
   }
  
  
  
  1.7       +16 -3     jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java
  
  Index: QueryRunner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- QueryRunner.java	21 Oct 2003 00:12:58 -0000	1.6
  +++ QueryRunner.java	22 Oct 2003 02:10:23 -0000	1.7
  @@ -581,6 +581,19 @@
        * Wrap the <code>ResultSet</code> in a decorator before processing it.
        * This implementation returns the <code>ResultSet</code> it is given
        * without any decoration.
  +     *
  +     * <p>
  +     * Often, the implementation of this method can be done in an anonymous 
  +     * inner class like this:
  +     * </p>
  +     * <pre> 
  +     * QueryRunner run = new QueryRunner() {
  +     *     protected void wrap(ResultSet rs) {
  +     *         return StringTrimmedResultSet.wrap(rs);
  +     *     }
  +     * };
  +     * </pre>
  +     * 
        * @param rs The <code>ResultSet</code> to decorate; never 
        * <code>null</code>.
        * @return The <code>ResultSet</code> wrapped in some decorator. 
  
  
  
  1.1                  jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ProxyFactory.java
  
  Index: ProxyFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ProxyFactory.java,v 1.1 2003/10/22 02:10:23 dgraham Exp $
   * $Revision: 1.1 $
   * $Date: 2003/10/22 02:10:23 $
   * 
   * ====================================================================
   *
   * 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.lang.reflect.InvocationHandler;
  import java.lang.reflect.Proxy;
  import java.sql.Connection;
  import java.sql.Driver;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  /**
   * Creates proxy implementations of JDBC classes.  This avoids 
   * incompatibilities between the JDBC 2 and JDBC 3 interfaces.
   * 
   * @see java.lang.reflect.Proxy
   * @see java.lang.reflect.InvocationHandler
   * 
   * @author David Graham
   */
  public class ProxyFactory {
  
      /**
       * Class[] for Connection interface.
       */
      private static final Class[] connectionClass = new Class[] { Connection.class };
  
      /**
       * Class[] for Driver interface.
       */
      private static final Class[] driverClass = new Class[] { Driver.class };
  
      /**
       * The Singleton instance of this class.
       */
      private static final ProxyFactory instance = new ProxyFactory();
  
      /**
       * Class[] for PreparedStatement interface.
       */
      private static final Class[] preparedStatementClass =
          new Class[] { PreparedStatement.class };
  
      /**
       * Class[] for ResultSet interface.
       */
      private static final Class[] resultSetClass = new Class[] { ResultSet.class };
  
      /**
       * Class[] for Statement interface.
       */
      private static final Class[] statementClass = new Class[] { Statement.class };
  
      /**
       * Returns the Singleton instance of this class.
       */
      public static ProxyFactory instance() {
          return instance;
      }
  
      /**
       * Protected constructor for ProxyFactory subclasses to use.
       */
      protected ProxyFactory() {
          super();
      }
  
      /**
       * Creates a new proxy <code>Connection</code> object.
       * @param handler The handler that intercepts/overrides method calls.
       */
      public Connection createConnection(InvocationHandler handler) {
          return (Connection) Proxy.newProxyInstance(
              handler.getClass().getClassLoader(),
              connectionClass,
              handler);
      }
  
      /**
       * Creates a new proxy <code>Driver</code> object.
       * @param handler The handler that intercepts/overrides method calls.
       */
      public Driver createDriver(InvocationHandler handler) {
          return (Driver) Proxy.newProxyInstance(
              handler.getClass().getClassLoader(),
              driverClass,
              handler);
      }
  
      /**
       * Creates a new proxy <code>PreparedStatement</code> object.
       * @param handler The handler that intercepts/overrides method calls.
       */
      public PreparedStatement createPreparedStatement(InvocationHandler handler) {
          return (PreparedStatement) Proxy.newProxyInstance(
              handler.getClass().getClassLoader(),
              preparedStatementClass,
              handler);
      }
  
      /**
       * Creates a new proxy <code>ResultSet</code> object.
       * @param handler The handler that intercepts/overrides method calls.
       */
      public ResultSet createResultSet(InvocationHandler handler) {
          return (ResultSet) Proxy.newProxyInstance(
              handler.getClass().getClassLoader(),
              resultSetClass,
              handler);
      }
  
      /**
       * Creates a new proxy <code>Statement</code> object.
       * @param handler The handler that intercepts/overrides method calls.
       */
      public Statement createStatement(InvocationHandler handler) {
          return (Statement) Proxy.newProxyInstance(
              handler.getClass().getClassLoader(),
              statementClass,
              handler);
      }
  
  }
  
  
  
  1.3       +6 -6      jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver/StringTrimmedResultSetTestCase.java
  
  Index: StringTrimmedResultSetTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver/StringTrimmedResultSetTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringTrimmedResultSetTestCase.java	19 Oct 2003 20:23:28 -0000	1.2
  +++ StringTrimmedResultSetTestCase.java	22 Oct 2003 02:10:23 -0000	1.3
  @@ -127,7 +127,7 @@
                   "  untrimmed string 1 ",
                   rs.getString(1));
               rs =
  -                new StringTrimmedResultSet(
  +                StringTrimmedResultSet.wrap(
                       new StringUntrimmedMockResultSet(statement));
               assertEquals(
                   "untrimmed string from index",
  @@ -140,7 +140,7 @@
                   "  untrimmed string column ",
                   rs.getString("column"));
               rs =
  -                new StringTrimmedResultSet(
  +                StringTrimmedResultSet.wrap(
                       new StringUntrimmedMockResultSet(statement));
               assertEquals(
                   "untrimmed string from index",
  
  
  
  1.4       +78 -74    jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver/SqlNullCheckedResultSetTestCase.java
  
  Index: SqlNullCheckedResultSetTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/driver/SqlNullCheckedResultSetTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SqlNullCheckedResultSetTestCase.java	19 Oct 2003 20:23:28 -0000	1.3
  +++ SqlNullCheckedResultSetTestCase.java	22 Oct 2003 02:10:23 -0000	1.4
  @@ -70,6 +70,7 @@
   import java.sql.Blob;
   import java.sql.Clob;
   import java.sql.Ref;
  +import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
   import java.sql.Time;
  @@ -81,6 +82,7 @@
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  +import org.apache.commons.dbutils.ProxyFactory;
   import org.apache.commons.dbutils.mockdriver.MockConnection;
   import org.apache.commons.dbutils.mockdriver.MockResultSet;
   import org.apache.commons.dbutils.mockdriver.MockStatement;
  @@ -93,8 +95,10 @@
    * @version $Id$
    */
   public class SqlNullCheckedResultSetTestCase extends junit.framework.TestCase {
  -    
  -    protected SqlNullCheckedResultSet rs = null;
  +
  +    private ResultSet rs = null;
  +
  +    private SqlNullCheckedResultSet rs2 = null;
   
       /**
        * Constructs a new instance of
  @@ -111,11 +115,11 @@
        * Sets up instance variables required by this test case.
        */
       public void setUp() {
  -        MockConnection connection = new MockConnection();
  -        MockStatement statement = new MockStatement(connection);
  -        rs =
  -            new SqlNullCheckedResultSet(
  -                new SqlNullUncheckedMockResultSet(statement));
  +        MockConnection conn = new MockConnection();
  +        MockStatement stmt = new MockStatement(conn);
  +    
  +        rs2 = new SqlNullCheckedResultSet(new SqlNullUncheckedMockResultSet(stmt));
  +        rs = ProxyFactory.instance().createResultSet(rs2);
       }
   
       /**
  @@ -146,7 +150,7 @@
               assertTrue("get ascii stream was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               InputStream stream = new ByteArrayInputStream(new byte[0]);
  -            rs.setNullAsciiStream(stream);
  +            rs2.setNullAsciiStream(stream);
               assertNotNull("get ascii stream index not null", rs.getAsciiStream(1));
               assertEquals(
                   "get ascii stream when SQL NULL",
  @@ -175,7 +179,7 @@
               assertTrue("get big decimal was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               BigDecimal bd = new BigDecimal(5.0);
  -            rs.setNullBigDecimal(bd);
  +            rs2.setNullBigDecimal(bd);
               assertNotNull("get big decimal index not null", rs.getBigDecimal(1));
               assertEquals("get big decimal when SQL NULL", bd, rs.getBigDecimal(1));
               assertNotNull(
  @@ -203,7 +207,7 @@
               assertTrue("get binary stream was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               InputStream stream = new ByteArrayInputStream(new byte[0]);
  -            rs.setNullBinaryStream(stream);
  +            rs2.setNullBinaryStream(stream);
               assertNotNull("get binary stream index not null", rs.getBinaryStream(1));
               assertEquals(
                   "get binary stream when SQL NULL",
  @@ -232,7 +236,7 @@
               assertTrue("get blob was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Blob blob = new SqlNullCheckedResultSetMockBlob();
  -            rs.setNullBlob(blob);
  +            rs2.setNullBlob(blob);
               assertNotNull("get blob index not null", rs.getBlob(1));
               assertEquals("get blob when SQL NULL", blob, rs.getBlob(1));
               assertNotNull("get blob column not null", rs.getBlob("column"));
  @@ -252,7 +256,7 @@
               assertEquals("get boolean column", false, rs.getBoolean("column"));
               assertTrue("get boolean was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
  -            rs.setNullBoolean(true);
  +            rs2.setNullBoolean(true);
               assertEquals("get boolean when SQL NULL", true, rs.getBoolean(1));
               assertEquals("get boolean when SQL NULL", true, rs.getBoolean("column"));
           } catch (Exception e) {
  @@ -271,7 +275,7 @@
               assertTrue("get byte was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               byte b = (byte) 10;
  -            rs.setNullByte(b);
  +            rs2.setNullByte(b);
               assertEquals("get byte when SQL NULL", b, rs.getByte(1));
               assertEquals("get byte when SQL NULL", b, rs.getByte("column"));
           } catch (Exception e) {
  @@ -293,7 +297,7 @@
               for (int i = 0; i < 5; i++) {
                   b[0] = (byte) i;
               }
  -            rs.setNullBytes(b);
  +            rs2.setNullBytes(b);
               assertNotNull("get bytes index not null", rs.getBytes(1));
               assertEquals("get bytes when SQL NULL", b, rs.getBytes(1));
               assertNotNull("get bytes column not null", rs.getBytes("column"));
  @@ -318,7 +322,7 @@
               assertTrue("get character stream was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Reader reader = new CharArrayReader("this is a string".toCharArray());
  -            rs.setNullCharacterStream(reader);
  +            rs2.setNullCharacterStream(reader);
               assertNotNull(
                   "get character stream index not null",
                   rs.getCharacterStream(1));
  @@ -349,7 +353,7 @@
               assertTrue("get clob was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Clob clob = new SqlNullCheckedResultSetMockClob();
  -            rs.setNullClob(clob);
  +            rs2.setNullClob(clob);
               assertNotNull("get clob index not null", rs.getClob(1));
               assertEquals("get clob when SQL NULL", clob, rs.getClob(1));
               assertNotNull("get clob column not null", rs.getClob("column"));
  @@ -378,7 +382,7 @@
               assertTrue("get date was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
  -            rs.setNullDate(date);
  +            rs2.setNullDate(date);
               assertNotNull("get date index not null", rs.getDate(1));
               assertEquals("get date when SQL NULL", date, rs.getDate(1));
               assertNotNull("get date column not null", rs.getDate("column"));
  @@ -417,7 +421,7 @@
               assertTrue("get double was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               double d = (double) 10.0;
  -            rs.setNullDouble(d);
  +            rs2.setNullDouble(d);
               assertEquals("get double when SQL NULL", d, rs.getDouble(1), 0.0);
               assertEquals("get double when SQL NULL", d, rs.getDouble("column"), 0.0);
           } catch (Exception e) {
  @@ -436,7 +440,7 @@
               assertTrue("get float was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               float f = (float) 10.0;
  -            rs.setNullFloat(f);
  +            rs2.setNullFloat(f);
               assertEquals("get float when SQL NULL", f, rs.getFloat(1), 0.0);
               assertEquals("get float when SQL NULL", f, rs.getFloat("column"), 0.0);
           } catch (Exception e) {
  @@ -455,7 +459,7 @@
               assertTrue("get int was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               int i = (int) 10;
  -            rs.setNullInt(i);
  +            rs2.setNullInt(i);
               assertEquals("get int when SQL NULL", i, rs.getInt(1));
               assertEquals("get int when SQL NULL", i, rs.getInt("column"));
           } catch (Exception e) {
  @@ -474,7 +478,7 @@
               assertTrue("get long was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               long l = (long) 10;
  -            rs.setNullLong(l);
  +            rs2.setNullLong(l);
               assertEquals("get long when SQL NULL", l, rs.getLong(1));
               assertEquals("get long when SQL NULL", l, rs.getLong("column"));
           } catch (Exception e) {
  @@ -499,7 +503,7 @@
               assertTrue("get object was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Object o = new Object();
  -            rs.setNullObject(o);
  +            rs2.setNullObject(o);
               assertNotNull("get object index not null", rs.getObject(1));
               assertEquals("get object when SQL NULL", o, rs.getObject(1));
               assertNotNull("get object column not null", rs.getObject("column"));
  @@ -531,7 +535,7 @@
               assertTrue("get ref was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Ref ref = new SqlNullCheckedResultSetMockRef();
  -            rs.setNullRef(ref);
  +            rs2.setNullRef(ref);
               assertNotNull("get ref index not null", rs.getRef(1));
               assertEquals("get ref when SQL NULL", ref, rs.getRef(1));
               assertNotNull("get ref column not null", rs.getRef("column"));
  @@ -552,7 +556,7 @@
               assertTrue("get short was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               short s = (short) 10;
  -            rs.setNullShort(s);
  +            rs2.setNullShort(s);
               assertEquals("get short when SQL NULL", s, rs.getShort(1));
               assertEquals("get short when SQL NULL", s, rs.getShort("column"));
           } catch (Exception e) {
  @@ -571,7 +575,7 @@
               assertTrue("get string was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               String s = "hello, world";
  -            rs.setNullString(s);
  +            rs2.setNullString(s);
               assertEquals("get string when SQL NULL", s, rs.getString(1));
               assertEquals("get string when SQL NULL", s, rs.getString("column"));
           } catch (Exception e) {
  @@ -598,7 +602,7 @@
               assertTrue("get time was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Time time = new Time(new java.util.Date().getTime());
  -            rs.setNullTime(time);
  +            rs2.setNullTime(time);
               assertNotNull("get time index not null", rs.getTime(1));
               assertEquals("get time when SQL NULL", time, rs.getTime(1));
               assertNotNull("get time column not null", rs.getTime("column"));
  @@ -641,7 +645,7 @@
               assertTrue("get timestamp was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               Timestamp ts = new Timestamp(new java.util.Date().getTime());
  -            rs.setNullTimestamp(ts);
  +            rs2.setNullTimestamp(ts);
               assertNotNull("get timestamp index not null", rs.getTimestamp(1));
               assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp(1));
               assertNotNull(
  @@ -683,7 +687,7 @@
               assertTrue("get unicode stream was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               InputStream stream = new ByteArrayInputStream(new byte[0]);
  -            rs.setNullUnicodeStream(stream);
  +            rs2.setNullUnicodeStream(stream);
               assertNotNull(
                   "get unicode stream index not null",
                   rs.getUnicodeStream(1));
  @@ -708,10 +712,10 @@
        */
       public void testSetNullAsciiStream() {
           try {
  -            assertNull("null ascii stream", rs.getNullAsciiStream());
  +            assertNull("null ascii stream", rs2.getNullAsciiStream());
               // Set what gets returned to something other than the default
               InputStream stream = new ByteArrayInputStream(new byte[0]);
  -            rs.setNullAsciiStream(stream);
  +            rs2.setNullAsciiStream(stream);
               assertNotNull("get ascii stream index not null", rs.getAsciiStream(1));
               assertEquals(
                   "get ascii stream when SQL NULL",
  @@ -734,10 +738,10 @@
        */
       public void testSetNullBigDecimal() {
           try {
  -            assertNull("null big decimal", rs.getNullBigDecimal());
  +            assertNull("null big decimal", rs2.getNullBigDecimal());
               // Set what gets returned to something other than the default
               BigDecimal bd = new BigDecimal(5.0);
  -            rs.setNullBigDecimal(bd);
  +            rs2.setNullBigDecimal(bd);
               assertNotNull("get big decimal index not null", rs.getBigDecimal(1));
               assertEquals("get big decimal when SQL NULL", bd, rs.getBigDecimal(1));
               assertNotNull(
  @@ -757,10 +761,10 @@
        */
       public void testSetNullBinaryStream() {
           try {
  -            assertNull("null binary stream", rs.getNullBinaryStream());
  +            assertNull("null binary stream", rs2.getNullBinaryStream());
               // Set what gets returned to something other than the default
               InputStream stream = new ByteArrayInputStream(new byte[0]);
  -            rs.setNullBinaryStream(stream);
  +            rs2.setNullBinaryStream(stream);
               assertNotNull("get binary stream index not null", rs.getBinaryStream(1));
               assertEquals(
                   "get binary stream when SQL NULL",
  @@ -783,10 +787,10 @@
        */
       public void testSetNullBlob() {
           try {
  -            assertNull("null blob", rs.getNullBlob());
  +            assertNull("null blob", rs2.getNullBlob());
               // Set what gets returned to something other than the default
               Blob blob = new SqlNullCheckedResultSetMockBlob();
  -            rs.setNullBlob(blob);
  +            rs2.setNullBlob(blob);
               assertNotNull("get blob index not null", rs.getBlob(1));
               assertEquals("get blob when SQL NULL", blob, rs.getBlob(1));
               assertNotNull("get blob column not null", rs.getBlob("column"));
  @@ -801,9 +805,9 @@
        */
       public void testSetNullBoolean() {
           try {
  -            assertEquals("null boolean", false, rs.getNullBoolean());
  +            assertEquals("null boolean", false, rs2.getNullBoolean());
               // Set what gets returned to something other than the default
  -            rs.setNullBoolean(true);
  +            rs2.setNullBoolean(true);
               assertEquals("get boolean when SQL NULL", true, rs.getBoolean(1));
               assertEquals("get boolean when SQL NULL", true, rs.getBoolean("column"));
           } catch (Exception e) {
  @@ -816,10 +820,10 @@
        */
       public void testSetNullByte() {
           try {
  -            assertEquals("null byte", (byte) 0, rs.getNullByte());
  +            assertEquals("null byte", (byte) 0, rs2.getNullByte());
               // Set what gets returned to something other than the default
               byte b = (byte) 10;
  -            rs.setNullByte(b);
  +            rs2.setNullByte(b);
               assertEquals("get byte when SQL NULL", b, rs.getByte(1));
               assertEquals("get byte when SQL NULL", b, rs.getByte("column"));
           } catch (Exception e) {
  @@ -832,13 +836,13 @@
        */
       public void testSetNullBytes() {
           try {
  -            assertNull("null bytes", rs.getNullBytes());
  +            assertNull("null bytes", rs2.getNullBytes());
               // Set what gets returned to something other than the default
               byte[] b = new byte[5];
               for (int i = 0; i < 5; i++) {
                   b[0] = (byte) i;
               }
  -            rs.setNullBytes(b);
  +            rs2.setNullBytes(b);
               assertNotNull("get bytes index not null", rs.getBytes(1));
               assertEquals("get bytes when SQL NULL", b, rs.getBytes(1));
               assertNotNull("get bytes column not null", rs.getBytes("column"));
  @@ -853,10 +857,10 @@
        */
       public void testSetNullCharacterStream() {
           try {
  -            assertNull("null character tream", rs.getNullCharacterStream());
  +            assertNull("null character tream", rs2.getNullCharacterStream());
               // Set what gets returned to something other than the default
               Reader reader = new CharArrayReader("this is a string".toCharArray());
  -            rs.setNullCharacterStream(reader);
  +            rs2.setNullCharacterStream(reader);
               assertNotNull(
                   "get character stream index not null",
                   rs.getCharacterStream(1));
  @@ -881,10 +885,10 @@
        */
       public void testSetNullClob() {
           try {
  -            assertNull("null clob", rs.getNullClob());
  +            assertNull("null clob", rs2.getNullClob());
               // Set what gets returned to something other than the default
               Clob clob = new SqlNullCheckedResultSetMockClob();
  -            rs.setNullClob(clob);
  +            rs2.setNullClob(clob);
               assertNotNull("get clob index not null", rs.getClob(1));
               assertEquals("get clob when SQL NULL", clob, rs.getClob(1));
               assertNotNull("get clob column not null", rs.getClob("column"));
  @@ -899,10 +903,10 @@
        */
       public void testSetNullDate() {
           try {
  -            assertNull("null date", rs.getNullDate());
  +            assertNull("null date", rs2.getNullDate());
               // Set what gets returned to something other than the default
               java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
  -            rs.setNullDate(date);
  +            rs2.setNullDate(date);
               assertNotNull("get date index not null", rs.getDate(1));
               assertEquals("get date when SQL NULL", date, rs.getDate(1));
               assertNotNull("get date column not null", rs.getDate("column"));
  @@ -931,10 +935,10 @@
        */
       public void testSetNullDouble() {
           try {
  -            assertEquals("null double", (double) 0.0, rs.getNullDouble(), 0.0);
  +            assertEquals("null double", (double) 0.0, rs2.getNullDouble(), 0.0);
               // Set what gets returned to something other than the default
               double d = (double) 10.0;
  -            rs.setNullDouble(d);
  +            rs2.setNullDouble(d);
               assertEquals("get double when SQL NULL", d, rs.getDouble(1), 0.0);
               assertEquals("get double when SQL NULL", d, rs.getDouble("column"), 0.0);
           } catch (Exception e) {
  @@ -947,10 +951,10 @@
        */
       public void testSetNullFloat() {
           try {
  -            assertEquals("null float", (float) 0.0, rs.getNullFloat(), 0.0);
  +            assertEquals("null float", (float) 0.0, rs2.getNullFloat(), 0.0);
               // Set what gets returned to something other than the default
               float f = (float) 10.0;
  -            rs.setNullFloat(f);
  +            rs2.setNullFloat(f);
               assertEquals("get float when SQL NULL", f, rs.getFloat(1), 0.0);
               assertEquals("get float when SQL NULL", f, rs.getFloat("column"), 0.0);
           } catch (Exception e) {
  @@ -963,14 +967,14 @@
        */
       public void testSetNullInt() {
           try {
  -            assertEquals("null int", 0, rs.getNullInt());
  +            assertEquals("null int", 0, rs2.getNullInt());
               assertEquals("get int index", (int) 0, rs.getInt(1));
               assertTrue("get int was SQL NULL", rs.wasNull());
               assertEquals("get int column", (int) 0, rs.getInt("column"));
               assertTrue("get int was SQL NULL", rs.wasNull());
               // Set what gets returned to something other than the default
               int i = (int) 10;
  -            rs.setNullInt(i);
  +            rs2.setNullInt(i);
               assertEquals("get int when SQL NULL", i, rs.getInt(1));
               assertEquals("get int when SQL NULL", i, rs.getInt("column"));
           } catch (Exception e) {
  @@ -983,10 +987,10 @@
        */
       public void testSetNullLong() {
           try {
  -            assertEquals("null long", (long) 0, rs.getNullLong());
  +            assertEquals("null long", (long) 0, rs2.getNullLong());
               // Set what gets returned to something other than the default
               long l = (long) 10;
  -            rs.setNullLong(l);
  +            rs2.setNullLong(l);
               assertEquals("get long when SQL NULL", l, rs.getLong(1));
               assertEquals("get long when SQL NULL", l, rs.getLong("column"));
           } catch (Exception e) {
  @@ -999,10 +1003,10 @@
        */
       public void testSetNullObject() {
           try {
  -            assertNull("null object", rs.getNullObject());
  +            assertNull("null object", rs2.getNullObject());
               // Set what gets returned to something other than the default
               Object o = new Object();
  -            rs.setNullObject(o);
  +            rs2.setNullObject(o);
               assertNotNull("get object index not null", rs.getObject(1));
               assertEquals("get object when SQL NULL", o, rs.getObject(1));
               assertNotNull("get object column not null", rs.getObject("column"));
  @@ -1028,10 +1032,10 @@
        */
       public void testSetNullRef() {
           try {
  -            assertNull("null ref", rs.getNullRef());
  +            assertNull("null ref", rs2.getNullRef());
               // Set what gets returned to something other than the default
               Ref ref = new SqlNullCheckedResultSetMockRef();
  -            rs.setNullRef(ref);
  +            rs2.setNullRef(ref);
               assertNotNull("get ref index not null", rs.getRef(1));
               assertEquals("get ref when SQL NULL", ref, rs.getRef(1));
               assertNotNull("get ref column not null", rs.getRef("column"));
  @@ -1046,10 +1050,10 @@
        */
       public void testSetNullShort() {
           try {
  -            assertEquals("null short", (short) 0, rs.getNullShort());
  +            assertEquals("null short", (short) 0, rs2.getNullShort());
               // Set what gets returned to something other than the default
               short s = (short) 10;
  -            rs.setNullShort(s);
  +            rs2.setNullShort(s);
               assertEquals("get short when SQL NULL", s, rs.getShort(1));
               assertEquals("get short when SQL NULL", s, rs.getShort("column"));
           } catch (Exception e) {
  @@ -1062,10 +1066,10 @@
        */
       public void testSetNullString() {
           try {
  -            assertEquals("null string", null, rs.getNullString());
  +            assertEquals("null string", null, rs2.getNullString());
               // Set what gets returned to something other than the default
               String s = "hello, world";
  -            rs.setNullString(s);
  +            rs2.setNullString(s);
               assertEquals("get string when SQL NULL", s, rs.getString(1));
               assertEquals("get string when SQL NULL", s, rs.getString("column"));
           } catch (Exception e) {
  @@ -1078,10 +1082,10 @@
        */
       public void testSetNullTime() {
           try {
  -            assertEquals("null time", null, rs.getNullTime());
  +            assertEquals("null time", null, rs2.getNullTime());
               // Set what gets returned to something other than the default
               Time time = new Time(new java.util.Date().getTime());
  -            rs.setNullTime(time);
  +            rs2.setNullTime(time);
               assertNotNull("get time index not null", rs.getTime(1));
               assertEquals("get time when SQL NULL", time, rs.getTime(1));
               assertNotNull("get time column not null", rs.getTime("column"));
  @@ -1110,10 +1114,10 @@
        */
       public void testSetNullTimestamp() {
           try {
  -            assertEquals("null timestamp", null, rs.getNullTimestamp());
  +            assertEquals("null timestamp", null, rs2.getNullTimestamp());
               // Set what gets returned to something other than the default
               Timestamp ts = new Timestamp(new java.util.Date().getTime());
  -            rs.setNullTimestamp(ts);
  +            rs2.setNullTimestamp(ts);
               assertNotNull("get timestamp index not null", rs.getTimestamp(1));
               assertEquals("get timestamp when SQL NULL", ts, rs.getTimestamp(1));
               assertNotNull(
  @@ -1147,10 +1151,10 @@
        */
       public void testSetNullUnicodeStream() {
           try {
  -            assertEquals("null unicode stream", null, rs.getNullUnicodeStream());
  +            assertEquals("null unicode stream", null, rs2.getNullUnicodeStream());
               // Set what gets returned to something other than the default
               InputStream stream = new ByteArrayInputStream(new byte[0]);
  -            rs.setNullUnicodeStream(stream);
  +            rs2.setNullUnicodeStream(stream);
               assertNotNull(
                   "get unicode stream index not null",
                   rs.getUnicodeStream(1));
  
  
  

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