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 MockResultSet.java
Date Fri, 24 Oct 2003 02:21:11 GMT
dgraham     2003/10/23 19:21:11

  Modified:    dbutils/src/test/org/apache/commons/dbutils
                        MockResultSet.java
  Log:
  Added getString() implementations.
  
  Revision  Changes    Path
  1.6       +34 -9     jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/MockResultSet.java
  
  Index: MockResultSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/MockResultSet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MockResultSet.java	23 Oct 2003 04:50:05 -0000	1.5
  +++ MockResultSet.java	24 Oct 2003 02:21:11 -0000	1.6
  @@ -142,6 +142,16 @@
   				return this.getObject((String) args[0]);
   			}
   
  +		} else if (methodName.equals("getString")) {
  +
  +			if (args[0] instanceof Integer) {
  +				int col = ((Integer) args[0]).intValue();
  +				return this.getString(col);
  +
  +			} else if (args[0] instanceof String) {
  +				return this.getString((String) args[0]);
  +			}
  +
   		} else if (methodName.equals("wasNull")) {
   			return this.wasNull();
   
  @@ -156,11 +166,11 @@
   		return this.iter.hasNext() ? Boolean.FALSE : Boolean.TRUE;
   	}
   
  -    /**
  -     * Gets the object at the given column index.
  -     * @param columnIndex A 1 based index.
  -     * @throws SQLException
  -     */
  +	/**
  +	 * Gets the object at the given column index.
  +	 * @param columnIndex A 1 based index.
  +	 * @throws SQLException
  +	 */
   	protected Object getObject(int columnIndex) throws SQLException {
   		Object obj = this.currentRow[columnIndex - 1];
   		if (obj == null) {
  @@ -176,7 +186,7 @@
   
   	/**
   	 * Returns the column index for the given column name.
  -     * @return A 1 based index
  +	 * @return A 1 based index
   	 * @throws SQLException if the column name is invalid
   	 */
   	private int findColumnIndex(String columnName) throws SQLException {
  @@ -188,6 +198,21 @@
   		}
   
   		throw new SQLException(columnName + " is not a valid column name.");
  +	}
  +
  +	/**
  +	 * Gets the String at the given column index.
  +	 * @param columnIndex A 1 based index.
  +	 * @throws SQLException
  +	 */
  +	protected String getString(int columnIndex) throws SQLException {
  +		Object obj = this.getObject(columnIndex);
  +		return (obj == null) ? null : obj.toString();
  +	}
  +
  +	protected String getString(String columnName) throws SQLException {
  +		Object obj = this.getObject(this.findColumnIndex(columnName));
  +		return (obj == null) ? null : obj.toString();
   	}
   
   	protected Boolean next() throws SQLException {
  
  
  

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