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/driver StringTrimmedResultSet.java
Date Fri, 17 Oct 2003 23:15:55 GMT
dgraham     2003/10/17 16:15:55

  Modified:    dbutils/src/java/org/apache/commons/dbutils/driver
                        StringTrimmedResultSet.java
  Log:
  Override getObject() methods and trim returned Strings.
  
  Revision  Changes    Path
  1.4       +74 -15    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringTrimmedResultSet.java	15 Oct 2003 02:26:41 -0000	1.3
  +++ StringTrimmedResultSet.java	17 Oct 2003 23:15:55 -0000	1.4
  @@ -63,12 +63,14 @@
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  +import java.util.Map;
   
   /**
    * Wraps a <code>ResultSet</code> to trim strings returned by the
  - * <code>getString</code> methods.
  + * <code>getString()</code> and <code>getObject()</code> methods.
    *
  - * @author  <a href="stevencaswell@apache.org">Steven Caswell</a>
  + * @author <a href="stevencaswell@apache.org">Steven Caswell</a>
  + * @author David Graham
    * @version $Id$
    */
   public class StringTrimmedResultSet extends ResultSetWrapper {
  @@ -89,8 +91,8 @@
        * Constructs a new instance of <code>StringTrimmedResultSet</code>
        * to wrap the specified <code>ResultSet</code> and <code>Statement</code>.
        */
  -    public StringTrimmedResultSet(ResultSet rs, Statement st) {
  -        super(rs, st);
  +    public StringTrimmedResultSet(ResultSet rs, Statement stmt) {
  +        super(rs, stmt);
           this.rs = rs;
       }
   
  @@ -100,13 +102,13 @@
        * language. Control characters, including whitespace, are removed from 
        * both ends of the string, handling null by returning null.
        *
  -     * @param column the SQL name of the column
  +     * @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 column) throws SQLException {
  -        String value = this.rs.getString(column);
  +    public String getString(String columnName) throws SQLException {
  +        String value = this.rs.getString(columnName);
           return (value == null) ? null : value.trim();
       }
       
  @@ -116,13 +118,70 @@
        * language. Control characters, including whitespace, are removed from 
        * both ends of the string, handling null by returning null.
        *
  -     * @param idx the first column is 1, the second is 2, ...
  -     * @return the column value; if the value is SQL NULL, the value returned 
  +     * @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
        */
  -    public String getString(int idx) throws SQLException {
  -        String value = this.rs.getString(idx);
  +    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;
  +    }
  +
  +    /**
  +     * If the object is a <code>String</code>, it is trimmed before returning
  +     * from this method.
  +     * @throws SQLException
  +     * @see java.sql.ResultSet#getObject(int)
  +     */
  +    public Object getObject(int columnIndex) throws SQLException {
  +        Object obj = this.rs.getObject(columnIndex);
  +        if (obj instanceof String) {
  +            obj = ((String) obj).trim();
  +        }
  +        return obj;
  +    }
  +
  +    /**
  +     * 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)
  +     */
  +    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;
  +    }
  +
  +    /**
  +     * 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();
  +        }
  +        return obj;
  +    }
  +
   }
  
  
  

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