You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2011/11/03 16:03:54 UTC
svn commit: r1197172 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/ engine/org/apache/derby/impl/jdbc/
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Author: rhillegas
Date: Thu Nov 3 15:03:54 2011
New Revision: 1197172
URL: http://svn.apache.org/viewvc?rev=1197172&view=rev
Log:
DERBY-5488: Make setObject( int, BigInteger ) rely on the existing setObject( int, BigDecimal ) logic.
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java?rev=1197172&r1=1197171&r2=1197172&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java Thu Nov 3 15:03:54 2011
@@ -930,7 +930,7 @@ final class CrossConverters {
} else if (source instanceof Byte) {
return setObject(targetType, ((Byte) source).byteValue());
} else if (source instanceof java.math.BigInteger) {
- return setObject(targetType, ((java.math.BigInteger) source).longValue() );
+ return setObject(targetType, new java.math.BigDecimal( (java.math.BigInteger) source ) );
} else if (source instanceof java.util.Date) {
return setObject(targetType, new java.sql.Timestamp( ((java.util.Date) source).getTime() ) );
} else if (source instanceof java.util.Calendar) {
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=1197172&r1=1197171&r2=1197172&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Thu Nov 3 15:03:54 2011
@@ -1405,7 +1405,7 @@ public class PreparedStatement extends S
} else if (x instanceof Short) {
setShort(parameterIndex, ((Short) x).shortValue());
} else if (x instanceof java.math.BigInteger) {
- setLong(parameterIndex, ((java.math.BigInteger) x).longValue() );
+ setBigDecimal(parameterIndex, new java.math.BigDecimal( (java.math.BigInteger) x ) );
} else if (x instanceof java.util.Date) {
setTimestamp(parameterIndex, new Timestamp( ((java.util.Date) x).getTime() ) );
} else if (x instanceof java.util.Calendar) {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=1197172&r1=1197171&r2=1197172&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java Thu Nov 3 15:03:54 2011
@@ -1313,10 +1313,6 @@ public abstract class EmbedPreparedState
setClob(parameterIndex, (Clob) x);
return;
}
- if (x instanceof java.math.BigInteger) {
- setLong(parameterIndex, ((java.math.BigInteger) x).longValue() );
- return;
- }
if (x instanceof java.util.Date) {
setTimestamp(parameterIndex, new Timestamp( ((java.util.Date) x).getTime() ) );
return;
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java?rev=1197172&r1=1197171&r2=1197172&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java Thu Nov 3 15:03:54 2011
@@ -32,6 +32,7 @@ import org.apache.derby.iapi.reference.S
import java.io.InputStream;
import java.math.BigDecimal;
+import java.math.BigInteger;
import java.sql.SQLException;
import java.sql.SQLWarning;
@@ -150,6 +151,10 @@ public abstract class EmbedPreparedState
setBigDecimal(parameterIndex, (BigDecimal) x);
return true;
}
+ else if (x instanceof BigInteger) {
+ setBigDecimal(parameterIndex, new BigDecimal( (BigInteger) x ) );
+ return true;
+ }
return false;
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java?rev=1197172&r1=1197171&r2=1197172&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java Thu Nov 3 15:03:54 2011
@@ -41,6 +41,7 @@ import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
+import java.util.HashSet;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -68,6 +69,9 @@ public class ParameterMappingTest extend
private static final String DATE_METHOD_NAME = "setObject(java.util.Date)";
private static final String CALENDAR_METHOD_NAME = "setObject(java.util.Calendar)";
+ private static final String WONT_FIT = "22003";
+ private static final String TRUNCATED = "22001";
+
static {
if (JDBC.vmSupportsJSR169())
HAVE_BIG_DECIMAL = false;
@@ -981,6 +985,115 @@ public class ParameterMappingTest extend
return calendar;
}
+ /**
+ * Test setObject( int, BigInteger ) in JDBC 4.1. See
+ * DERBY-5488.
+ */
+ public void testBigInteger() throws Exception
+ {
+ Connection conn = getConnection();
+
+ Statement s = conn.createStatement();
+ try {
+ s.execute( "drop table t2_object_map" );
+ } catch (SQLException seq) {}
+ s.execute( "create table t2_object_map( smallint_col smallint, int_col int, bigint_col bigint, real_col real, float_col float, double_col double, decimal_col decimal( 31 ), numeric_col numeric( 31 ), char_col char( 10 ), varchar_col varchar( 10 ) )" );
+
+ String[] allColumns = new String[]
+ {
+ "smallint_col", "int_col", "bigint_col",
+ "real_col", "float_col", "double_col",
+ "decimal_col", "numeric_col",
+ "char_col", "varchar_col"
+ };
+
+ HashSet smallIntColumns = new HashSet();
+ for ( int i = 0; i < allColumns.length; i++ )
+ {
+ String colName = allColumns[ i ];
+ if ( colName.endsWith( "int_col" ) ) { smallIntColumns.add( colName ); }
+ }
+
+ HashSet smallCharColumns = new HashSet();
+ for ( int i = 0; i < allColumns.length; i++ )
+ {
+ String colName = allColumns[ i ];
+ if ( colName.endsWith( "char_col" ) ) { smallCharColumns.add( colName ); }
+ }
+
+ vetBigInteger
+ (
+ conn,
+ "1",
+ allColumns,
+ new HashSet(),
+ new HashSet()
+ );
+ vetBigInteger
+ (
+ conn,
+ "9223372036854775808", // Long.MAX_VALUE + 1
+ allColumns,
+ smallIntColumns,
+ smallCharColumns
+ );
+ vetBigInteger
+ (
+ conn,
+ "-9223372036854775809", // Long.MIN_VALUE - 1
+ allColumns,
+ smallIntColumns,
+ smallCharColumns
+ );
+ }
+ private void vetBigInteger
+ (
+ Connection conn,
+ String seed,
+ String[] allColumns,
+ HashSet undersizedIntColumns,
+ HashSet undersizedStringColumns
+ )
+ throws Exception
+ {
+ for ( int i = 0; i < allColumns.length; i++ )
+ {
+ String columnName = allColumns[ i ];
+ String errorState = null;
+ if ( undersizedIntColumns.contains( columnName ) ) { errorState = WONT_FIT; }
+ else if ( undersizedStringColumns.contains( columnName ) ) { errorState = TRUNCATED; }
+
+ vetBigInteger( conn, seed, columnName, errorState );
+ }
+ }
+ private void vetBigInteger
+ (
+ Connection conn,
+ String seed,
+ String columnName,
+ String errorState
+ )
+ throws Exception
+ {
+ PreparedStatement ps = conn.prepareStatement( "delete from t2_object_map" );
+ ps.executeUpdate();
+ ps.close();
+
+ String insertText = "insert into t2_object_map( " + columnName + " ) values ( ? )";
+ ps = conn.prepareStatement( insertText );
+
+ try {
+ ps.setObject( 1, new BigInteger( seed ) );
+ ps.executeUpdate();
+
+ if ( errorState != null ) { fail( "Expected '" + insertText + "' to fail for BigInteger( " + seed + " )." ); }
+ }
+ catch (SQLException se )
+ {
+ assertEquals( errorState, se.getSQLState() );
+ }
+ }
+
/*
* (non-Javadoc)
*