Author: rhillegas
Date: Wed Dec 22 19:36:04 2010
New Revision: 1052044
URL: http://svn.apache.org/viewvc?rev=1052044&view=rev
Log:
DERBY-4869: Correct error messages returned by ResultSet.getObject(int,Class).
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet40.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java?rev=1052044&r1=1052043&r2=1052044&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java Wed Dec
22 19:36:04 2010
@@ -275,11 +275,11 @@ public class NetResultSet40 extends NetR
if ( type == null )
{
- throw new SQLException( "NULL", SQLState.LANG_DATA_TYPE_GET_MISMATCH );
+ throw mismatchException( "NULL", columnIndex, null );
}
Exception ex = null;
-
+
try {
if ( String.class.equals( type ) ) { return (T) getString( columnIndex ); }
else if ( BigDecimal.class.equals( type ) ) { return (T) getBigDecimal( columnIndex
); }
@@ -296,11 +296,25 @@ public class NetResultSet40 extends NetR
else if ( Blob.class.equals( type ) ) { return (T) getBlob( columnIndex ); }
else if ( Clob.class.equals( type ) ) { return (T) getClob( columnIndex ); }
else if ( type.isArray() && type.getComponentType().equals( byte.class
) ) { return (T) getBytes( columnIndex ); }
- else { return (T) getObject( columnIndex ); }
+ else
+ {
+ Object result = getObject( columnIndex );
+ if ( !type.isInstance( result ) ) { throw new ClassCastException( type.getName()
); }
+ return (T) result;
+ }
}
- catch (ClassCastException e) {}
+ catch (Exception e) { ex = e; }
- throw new SQLException( type.getName(), SQLState.LANG_DATA_TYPE_GET_MISMATCH, ex
);
+ throw mismatchException( type.getName(), columnIndex, ex );
+ }
+ private SQLException mismatchException( String targetTypeName, int columnIndex, Throwable
t )
+ throws SQLException
+ {
+ String sourceTypeName = getMetaData().getColumnTypeName( columnIndex );
+ ClientMessageId cmi = new ClientMessageId( SQLState.LANG_DATA_TYPE_GET_MISMATCH );
+ SqlException se = new SqlException( agent_.logWriter_, cmi, targetTypeName, sourceTypeName,
t );
+
+ return se.getSQLException();
}
public <T> T getObject( String columnName, Class<T> type )
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet40.java?rev=1052044&r1=1052043&r2=1052044&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet40.java Wed Dec
22 19:36:04 2010
@@ -258,11 +258,9 @@ public class EmbedResultSet40 extends or
if ( type == null )
{
- throw new SQLException( "NULL", SQLState.LANG_DATA_TYPE_GET_MISMATCH );
+ throw mismatchException( "NULL", columnIndex );
}
- Exception ex = null;
-
try {
if ( String.class.equals( type ) ) { return (T) getString( columnIndex ); }
else if ( BigDecimal.class.equals( type ) ) { return (T) getBigDecimal( columnIndex
); }
@@ -279,11 +277,24 @@ public class EmbedResultSet40 extends or
else if ( Blob.class.equals( type ) ) { return (T) getBlob( columnIndex ); }
else if ( Clob.class.equals( type ) ) { return (T) getClob( columnIndex ); }
else if ( type.isArray() && type.getComponentType().equals( byte.class
) ) { return (T) getBytes( columnIndex ); }
- else { return (T) getObject( columnIndex ); }
+ else
+ {
+ Object result = getObject( columnIndex );
+ if ( !type.isInstance( result ) ) { throw new ClassCastException( type.getName()
); }
+ return (T) result;
+ }
}
- catch (ClassCastException e) { ex = e; }
+ catch (ClassCastException e) {}
- throw new SQLException( type.getName(), SQLState.LANG_DATA_TYPE_GET_MISMATCH, ex
);
+ throw mismatchException( type.getName(), columnIndex );
+ }
+ private SQLException mismatchException( String targetTypeName, int columnIndex )
+ throws SQLException
+ {
+ String sourceTypeName = getMetaData().getColumnTypeName( columnIndex );
+ SQLException se = newSQLException( SQLState.LANG_DATA_TYPE_GET_MISMATCH, targetTypeName,
sourceTypeName );
+
+ return se;
}
public <T> T getObject( String columnName, Class<T> type )
|