diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java
index c60c553a6dd..23e374d5502 100644
--- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java
+++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,10 +19,12 @@ package org.springframework.jdbc.support.rowset;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
+import java.util.HashMap;
import java.util.Map;
import org.springframework.jdbc.InvalidResultSetAccessException;
@@ -33,6 +35,14 @@ import org.springframework.jdbc.InvalidResultSetAccessException;
*
This implementation wraps a javax.sql.ResultSet,
* catching any SQLExceptions and translating them to the
* appropriate Spring {@link InvalidResultSetAccessException}.
+ *
+ *
Note: Since JDBC 4.0 it has been clarified that any methods using a String to identify the column should
+ * be using the column label. The column label is assigned using the ALIAS keyword in the SQL query string. When the
+ * query doesn't use an ALIAS the default label is the column name. Most JDBC ResultSet implementations follow this
+ * new pattern but there are some exceptions such as the com.sun.rowset.CachedRowSetImpl which only uses the column
+ * name ignoring any column labels. Since Spring 3.0.5 this class will translate column labels to the correct column
+ * index to provide better support for the com.sun.rowset.CachedRowSetImpl which is the default implementation used by
+ * the JdbcTemplate when working with RowSets.
*
*
The passed-in ResultSets should already be disconnected if the SqlRowSet
* is supposed to be usable in a disconnected fashion. This means that
@@ -59,6 +69,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
private final ResultSet resultSet;
private final SqlRowSetMetaData rowSetMetaData;
+
+ private final Map columnLabelMap;
/**
@@ -79,6 +91,22 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
catch (SQLException se) {
throw new InvalidResultSetAccessException(se);
}
+ try {
+ ResultSetMetaData rsmd = resultSet.getMetaData();
+ if (rsmd != null) {
+ int columnCount = rsmd.getColumnCount();
+ this.columnLabelMap = new HashMap(columnCount);
+ for (int i = 1; i <= columnCount; i++) {
+ columnLabelMap.put(rsmd.getColumnLabel(i), Integer.valueOf(i));
+ }
+ }
+ else {
+ this.columnLabelMap = new HashMap(0);
+ }
+ } catch (SQLException se) {
+ throw new InvalidResultSetAccessException(se);
+ }
+
}
@@ -101,13 +129,17 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#findColumn(String)
*/
- public int findColumn(String columnName) throws InvalidResultSetAccessException {
+ public int findColumn(String columnLabel) throws InvalidResultSetAccessException {
+ Integer columnIndex = columnLabelMap.get(columnLabel);
try {
- return this.resultSet.findColumn(columnName);
+ if (columnIndex == null) {
+ columnIndex = this.resultSet.findColumn(columnLabel);
+ }
}
catch (SQLException se) {
throw new InvalidResultSetAccessException(se);
}
+ return columnIndex.intValue();
}
@@ -128,13 +160,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getBigDecimal(String)
*/
- public BigDecimal getBigDecimal(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getBigDecimal(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException {
+ return getBigDecimal(findColumn(columnLabel));
}
/**
@@ -152,13 +179,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getBoolean(String)
*/
- public boolean getBoolean(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getBoolean(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public boolean getBoolean(String columnLabel) throws InvalidResultSetAccessException {
+ return getBoolean(findColumn(columnLabel));
}
/**
@@ -176,13 +198,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getByte(String)
*/
- public byte getByte(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getByte(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public byte getByte(String columnLabel) throws InvalidResultSetAccessException {
+ return getByte(findColumn(columnLabel));
}
/**
@@ -211,25 +228,15 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getDate(String, java.util.Calendar)
*/
- public Date getDate(String columnName, Calendar cal) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getDate(columnName, cal);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException {
+ return getDate(findColumn(columnLabel), cal);
}
/**
* @see java.sql.ResultSet#getDate(String)
*/
- public Date getDate(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getDate(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Date getDate(String columnLabel) throws InvalidResultSetAccessException {
+ return getDate(findColumn(columnLabel));
}
/**
@@ -247,13 +254,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getDouble(String)
*/
- public double getDouble(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getDouble(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public double getDouble(String columnLabel) throws InvalidResultSetAccessException {
+ return getDouble(findColumn(columnLabel));
}
/**
@@ -271,13 +273,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getFloat(String)
*/
- public float getFloat(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getFloat(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public float getFloat(String columnLabel) throws InvalidResultSetAccessException {
+ return getFloat(findColumn(columnLabel));
}
/**
* @see java.sql.ResultSet#getInt(int)
@@ -294,13 +291,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getInt(String)
*/
- public int getInt(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getInt(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public int getInt(String columnLabel) throws InvalidResultSetAccessException {
+ return getInt(findColumn(columnLabel));
}
/**
@@ -318,19 +310,14 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getLong(String)
*/
- public long getLong(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getLong(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public long getLong(String columnLabel) throws InvalidResultSetAccessException {
+ return getLong(findColumn(columnLabel));
}
/**
* @see java.sql.ResultSet#getObject(int, java.util.Map)
*/
- public Object getObject(int i, Map map) throws InvalidResultSetAccessException {
+ public Object getObject(int i, Map> map) throws InvalidResultSetAccessException {
try {
return this.resultSet.getObject(i, map);
}
@@ -354,25 +341,15 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getObject(String, java.util.Map)
*/
- public Object getObject(String columnName, Map map) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getObject(columnName, map);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Object getObject(String columnLabel, Map> map) throws InvalidResultSetAccessException {
+ return getObject(findColumn(columnLabel), map);
}
/**
* @see java.sql.ResultSet#getObject(String)
*/
- public Object getObject(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getObject(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Object getObject(String columnLabel) throws InvalidResultSetAccessException {
+ return getObject(findColumn(columnLabel));
}
/**
@@ -390,13 +367,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getShort(String)
*/
- public short getShort(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getShort(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public short getShort(String columnLabel) throws InvalidResultSetAccessException {
+ return getShort(findColumn(columnLabel));
}
/**
@@ -414,13 +386,8 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getString(String)
*/
- public String getString(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getString(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public String getString(String columnLabel) throws InvalidResultSetAccessException {
+ return getString(findColumn(columnLabel));
}
/**
@@ -450,25 +417,15 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getTime(String, java.util.Calendar)
*/
- public Time getTime(String columnName, Calendar cal) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getTime(columnName, cal);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException {
+ return getTime(findColumn(columnLabel), cal);
}
/**
* @see java.sql.ResultSet#getTime(String)
*/
- public Time getTime(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getTime(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Time getTime(String columnLabel) throws InvalidResultSetAccessException {
+ return getTime(findColumn(columnLabel));
}
/**
@@ -498,25 +455,15 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
/**
* @see java.sql.ResultSet#getTimestamp(String, java.util.Calendar)
*/
- public Timestamp getTimestamp(String columnName, Calendar cal) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getTimestamp(columnName, cal);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException {
+ return getTimestamp(findColumn(columnLabel), cal);
}
/**
* @see java.sql.ResultSet#getTimestamp(String)
*/
- public Timestamp getTimestamp(String columnName) throws InvalidResultSetAccessException {
- try {
- return this.resultSet.getTimestamp(columnName);
- }
- catch (SQLException se) {
- throw new InvalidResultSetAccessException(se);
- }
+ public Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException {
+ return getTimestamp(findColumn(columnLabel));
}
diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java
index c6f8111ef99..a88cd0e0e5a 100644
--- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java
+++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2005 the original author or authors.
+ * Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,12 +59,12 @@ public interface SqlRowSet extends Serializable {
SqlRowSetMetaData getMetaData();
/**
- * Maps the given column name to its column index.
- * @param columnName the name of the column
- * @return the column index for the given column name
+ * Maps the given column label to its column index.
+ * @param columnLabel the name of the column
+ * @return the column index for the given column label
* @see java.sql.ResultSet#findColumn(String)
*/
- int findColumn(String columnName) throws InvalidResultSetAccessException;
+ int findColumn(String columnLabel) throws InvalidResultSetAccessException;
// RowSet methods for extracting data values
@@ -81,11 +81,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* an BigDecimal object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return an BigDecimal object representing the column value
* @see java.sql.ResultSet#getBigDecimal(java.lang.String)
*/
- BigDecimal getBigDecimal(String columnName) throws InvalidResultSetAccessException;
+ BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -99,11 +99,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a boolean.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a boolean representing the column value
* @see java.sql.ResultSet#getBoolean(java.lang.String)
*/
- boolean getBoolean(String columnName) throws InvalidResultSetAccessException;
+ boolean getBoolean(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -117,11 +117,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a byte.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a byte representing the column value
* @see java.sql.ResultSet#getByte(java.lang.String)
*/
- byte getByte(String columnName) throws InvalidResultSetAccessException;
+ byte getByte(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -145,21 +145,21 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a Date object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @param cal the Calendar to use in constructing the Date
* @return a Date object representing the column value
* @see java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar)
*/
- Date getDate(String columnName, Calendar cal) throws InvalidResultSetAccessException;
+ Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
* a Date object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a Date object representing the column value
* @see java.sql.ResultSet#getDate(java.lang.String)
*/
- Date getDate(String columnName) throws InvalidResultSetAccessException;
+ Date getDate(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -173,11 +173,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a Double object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a Double object representing the column value
* @see java.sql.ResultSet#getDouble(java.lang.String)
*/
- double getDouble(String columnName) throws InvalidResultSetAccessException;
+ double getDouble(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -191,11 +191,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a float.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a float representing the column value
* @see java.sql.ResultSet#getFloat(java.lang.String)
*/
- float getFloat(String columnName) throws InvalidResultSetAccessException;
+ float getFloat(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -209,11 +209,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* an int.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return an int representing the column value
* @see java.sql.ResultSet#getInt(java.lang.String)
*/
- int getInt(String columnName) throws InvalidResultSetAccessException;
+ int getInt(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -227,11 +227,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a long.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a long representing the column value
* @see java.sql.ResultSet#getLong(java.lang.String)
*/
- long getLong(String columnName) throws InvalidResultSetAccessException;
+ long getLong(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -241,7 +241,7 @@ public interface SqlRowSet extends Serializable {
* @return a Object representing the column value
* @see java.sql.ResultSet#getObject(int, java.util.Map)
*/
- Object getObject(int columnIndex, Map map) throws InvalidResultSetAccessException;
+ Object getObject(int columnIndex, Map> map) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -255,21 +255,21 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* an Object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @param map a Map object containing the mapping from SQL types to Java types
* @return a Object representing the column value
* @see java.sql.ResultSet#getObject(java.lang.String, java.util.Map)
*/
- Object getObject(String columnName, Map map) throws InvalidResultSetAccessException;
+ Object getObject(String columnLabel, Map> map) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
* an Object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a Object representing the column value
* @see java.sql.ResultSet#getObject(java.lang.String)
*/
- Object getObject(String columnName) throws InvalidResultSetAccessException;
+ Object getObject(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -283,11 +283,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a short.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a short representing the column value
* @see java.sql.ResultSet#getShort(java.lang.String)
*/
- short getShort(String columnName) throws InvalidResultSetAccessException;
+ short getShort(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -301,11 +301,11 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a String.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a String representing the column value
* @see java.sql.ResultSet#getString(java.lang.String)
*/
- String getString(String columnName) throws InvalidResultSetAccessException;
+ String getString(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -329,21 +329,21 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a Time object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @param cal the Calendar to use in constructing the Date
* @return a Time object representing the column value
* @see java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar)
*/
- Time getTime(String columnName, Calendar cal) throws InvalidResultSetAccessException;
+ Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
* a Time object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a Time object representing the column value
* @see java.sql.ResultSet#getTime(java.lang.String)
*/
- Time getTime(String columnName) throws InvalidResultSetAccessException;
+ Time getTime(String columnLabel) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
@@ -367,21 +367,21 @@ public interface SqlRowSet extends Serializable {
/**
* Retrieves the value of the indicated column in the current row as
* a Timestamp object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @param cal the Calendar to use in constructing the Date
* @return a Timestamp object representing the column value
* @see java.sql.ResultSet#getTimestamp(java.lang.String, java.util.Calendar)
*/
- Timestamp getTimestamp(String columnName, Calendar cal) throws InvalidResultSetAccessException;
+ Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException;
/**
* Retrieves the value of the indicated column in the current row as
* a Timestamp object.
- * @param columnName the column name
+ * @param columnLabel the column label
* @return a Timestamp object representing the column value
* @see java.sql.ResultSet#getTimestamp(java.lang.String)
*/
- Timestamp getTimestamp(String columnName) throws InvalidResultSetAccessException;
+ Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException;
// RowSet navigation methods
diff --git a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java
index 489daa2ee1b..4c72a08876c 100644
--- a/org.springframework.jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java
+++ b/org.springframework.jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2006 the original author or authors.
+ * Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,8 @@ public class ResultSetWrappingRowSetTests extends TestCase {
rset = (ResultSet) rsetControl.getMock();
rset.getMetaData();
rsetControl.setReturnValue(null);
+ rset.getMetaData();
+ rsetControl.setReturnValue(null);
}
public void testGetBigDecimalInt() throws Exception {
@@ -53,7 +55,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetBigDecimalString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", new Class[] {String.class});
doTest(rset, rowset, "test", BigDecimal.valueOf(1));
}
@@ -65,7 +67,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetStringString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getString", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getString", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", new Class[] {String.class});
doTest(rset, rowset, "test", "test");
}
@@ -77,7 +79,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetTimestampString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", new Class[] {String.class});
doTest(rset, rowset, "test", new Timestamp(1234l));
}
@@ -89,7 +91,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetDateString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getDate", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getDate", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", new Class[] {String.class});
doTest(rset, rowset, "test", new Date(1234l));
}
@@ -101,7 +103,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetTimeString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getTime", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getTime", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", new Class[] {String.class});
doTest(rset, rowset, "test", new Time(1234l));
}
@@ -113,7 +115,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetObjectString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getObject", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getObject", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", new Class[] {String.class});
doTest(rset, rowset, "test", new Object());
}
@@ -125,7 +127,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetIntString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getInt", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getInt", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", new Class[] {String.class});
doTest(rset, rowset, "test", new Integer(1));
}
@@ -137,7 +139,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetFloatString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getFloat", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getFloat", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", new Class[] {String.class});
doTest(rset, rowset, "test", new Float(1));
}
@@ -149,7 +151,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetDoubleString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getDouble", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getDouble", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", new Class[] {String.class});
doTest(rset, rowset, "test", new Double(1));
}
@@ -161,7 +163,7 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetLongString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getLong", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getLong", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", new Class[] {String.class});
doTest(rset, rowset, "test", new Long(1));
}
@@ -173,13 +175,21 @@ public class ResultSetWrappingRowSetTests extends TestCase {
}
public void testGetBooleanString() throws Exception {
- Method rset = ResultSet.class.getDeclaredMethod("getBoolean", new Class[] {String.class});
+ Method rset = ResultSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class});
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", new Class[] {String.class});
doTest(rset, rowset, "test", new Boolean(true));
}
private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception {
- rsetMethod.invoke(rset, new Object[] {arg});
+ if (arg instanceof String) {
+ Method findMethod = ResultSet.class.getDeclaredMethod("findColumn", new Class[] {String.class});
+ findMethod.invoke(rset, new Object[] {arg});
+ rsetControl.setReturnValue(1);
+ rsetMethod.invoke(rset, new Object[] {1});
+ }
+ else {
+ rsetMethod.invoke(rset, new Object[] {arg});
+ }
if (ret instanceof Double) {
rsetControl.setReturnValue(((Double) ret).doubleValue());
}
@@ -204,7 +214,16 @@ public class ResultSetWrappingRowSetTests extends TestCase {
else {
rsetControl.setReturnValue(ret);
}
- rsetMethod.invoke(rset, new Object[] {arg});
+
+ if (arg instanceof String) {
+ Method findMethod = ResultSet.class.getDeclaredMethod("findColumn", new Class[] {String.class});
+ findMethod.invoke(rset, new Object[] {arg});
+ rsetControl.setReturnValue(1);
+ rsetMethod.invoke(rset, new Object[] {1});
+ }
+ else {
+ rsetMethod.invoke(rset, new Object[] {arg});
+ }
rsetControl.setThrowable(new SQLException("test"));
rsetControl.replay();