db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1197264 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Thu, 03 Nov 2011 18:43:43 GMT
Author: rhillegas
Date: Thu Nov  3 18:43:42 2011
New Revision: 1197264

URL: http://svn.apache.org/viewvc?rev=1197264&view=rev
Log:
DERBY-5488: Move BigDecimal getters/setters from JDBC 2.0 implementation into JSR 169 implementation.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.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/CallableTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java?rev=1197264&r1=1197263&r2=1197264&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
Thu Nov  3 18:43:42 2011
@@ -31,6 +31,7 @@ import org.apache.derby.iapi.services.sa
 import org.apache.derby.iapi.reference.JDBC30Translation;
 import org.apache.derby.iapi.reference.SQLState;
 
+import java.math.BigDecimal;
 import java.net.URL;
 import java.sql.Blob;
 import java.sql.CallableStatement;
@@ -346,6 +347,49 @@ public abstract class EmbedCallableState
 
 	}
 
+	/*
+	** Methods using BigDecimal, moved back into EmbedCallableStatement
+    ** because our small device implementation now requires CDC/FP 1.1.
+	*/
+    /**
+     * JDBC 2.0
+     *
+     * Get the value of a NUMERIC parameter as a java.math.BigDecimal object.
+     *
+     * @param parameterIndex the first parameter is 1, the second is 2, ...
+     * @return the parameter value (full precision); if the value is SQL NULL, 
+     * the result is null 
+     * @exception SQLException if a database-access error occurs.
+     */
+    public final BigDecimal getBigDecimal(int parameterIndex) throws SQLException 
+	{
+		checkStatus();
+		try {
+			DataValueDescriptor dvd = getParms().getParameterForGet(parameterIndex-1);
+			if (wasNull = dvd.isNull())
+				return null;
+			
+			return org.apache.derby.iapi.types.SQLDecimal.getBigDecimal(dvd);
+			
+		} catch (StandardException e)
+		{
+			throw EmbedResultSet.noStateChangeException(e);
+		}
+	}
+
+    /**
+	 * @see CallableStatement#getBigDecimal
+     * @exception SQLException NoOutputParameters thrown.
+     * @deprecated
+     */
+    public final BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException
+	{
+    	BigDecimal v = getBigDecimal(parameterIndex);
+    	if (v != null)
+    		v = v.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
+    	return v;
+	}
+
     /**
 	 * @see CallableStatement#getFloat
      * @exception SQLException NoOutputParameters thrown.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java?rev=1197264&r1=1197263&r2=1197264&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
Thu Nov  3 18:43:42 2011
@@ -91,32 +91,6 @@ public abstract class EmbedCallableState
 	//
 	/////////////////////////////////////////////////////////////////////////
 
-    /**
-     * JDBC 2.0
-     *
-     * Get the value of a NUMERIC parameter as a java.math.BigDecimal object.
-     *
-     * @param parameterIndex the first parameter is 1, the second is 2, ...
-     * @return the parameter value (full precision); if the value is SQL NULL, 
-     * the result is null 
-     * @exception SQLException if a database-access error occurs.
-     */
-    public BigDecimal getBigDecimal(int parameterIndex) throws SQLException 
-	{
-		checkStatus();
-		try {
-			DataValueDescriptor dvd = getParms().getParameterForGet(parameterIndex-1);
-			if (wasNull = dvd.isNull())
-				return null;
-			
-			return org.apache.derby.iapi.types.SQLDecimal.getBigDecimal(dvd);
-			
-		} catch (StandardException e)
-		{
-			throw EmbedResultSet.noStateChangeException(e);
-		}
-	}
-
 
     /**
      * JDBC 2.0
@@ -1032,58 +1006,6 @@ public abstract class EmbedCallableState
 		throw Util.notImplemented();
 	}
 
-	/*
-	** Methods using BigDecimal, moved out of EmbedPreparedStatement
-	** to allow that class to support JSR169.
-	*/
-	/**
-     * Set a parameter to a java.lang.BigDecimal value.  
-     * The driver converts this to a SQL NUMERIC value when
-     * it sends it to the database.
-     *
-     * @param parameterIndex the first parameter is 1, the second is 2, ...
-     * @param x the parameter value
-	 * @exception SQLException thrown on failure.
-     */
-    public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
-		checkStatus();
-		try {
-			/* JDBC is one-based, DBMS is zero-based */
-			getParms().getParameterForSet(parameterIndex - 1).setBigDecimal(x);
-
-		} catch (Throwable t) {
-			throw EmbedResultSet.noStateChangeException(t);
-		}
-	}
-    /**
-	 * @see CallableStatement#getBigDecimal
-     * @exception SQLException NoOutputParameters thrown.
-     * @deprecated
-     */
-    public final BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException
-	{
-    	BigDecimal v = getBigDecimal(parameterIndex);
-    	if (v != null)
-    		v = v.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
-    	return v;
-	}
-	/**
-		Allow explict setObject conversions by sub-classes for classes
-		not supported by this variant. In this case handle BigDecimal.
-		@return true if the object was set successfully, false if no valid
-		conversion exists.
-
-		@exception SQLException value could not be set.
-	*/
-	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException
-	{
-		if (x instanceof BigDecimal) {
-			setBigDecimal(parameterIndex, (BigDecimal) x);
-			return true;
-		}
-		return false;
-	}
-
     /////////////////////////////////////////////////////////////////////////
     //
     //	JDBC 4.0	-	New public methods

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=1197264&r1=1197263&r2=1197264&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 18:43:42 2011
@@ -40,6 +40,8 @@ import org.apache.derby.iapi.error.Stand
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.reference.JDBC40Translation;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.Calendar;
 import java.util.Vector;
 
@@ -444,6 +446,31 @@ public abstract class EmbedPreparedState
 
 	}
 
+	/*
+	** Methods using BigDecimal, moved back into EmbedPreparedStatement
+	** since our small device implementation now requires CDC/FP 1.1, which
+    ** supports BigDecimal.
+	*/
+	/**
+     * Set a parameter to a java.lang.BigDecimal value.  
+     * The driver converts this to a SQL NUMERIC value when
+     * it sends it to the database.
+     *
+     * @param parameterIndex the first parameter is 1, the second is 2, ...
+     * @param x the parameter value
+	 * @exception SQLException thrown on failure.
+     */
+    public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
+		checkStatus();
+		try {
+			/* JDBC is one-based, DBMS is zero-based */
+			getParms().getParameterForSet(parameterIndex - 1).setBigDecimal(x);
+
+		} catch (Throwable t) {
+			throw EmbedResultSet.noStateChangeException(t);
+		}
+	}
+
     /**
      * Set a parameter to a Java float value.  The driver converts this
      * to a SQL FLOAT value when it sends it to the database.
@@ -1321,28 +1348,16 @@ public abstract class EmbedPreparedState
 			setTimestamp(parameterIndex, new Timestamp(  ((java.util.Calendar) x).getTime().getTime()
) );
 			return;
 		}
-
-		if (setObjectConvert(parameterIndex, x))
+		if (x instanceof BigDecimal) {
+			setBigDecimal(parameterIndex, (BigDecimal) x);
+			return;
+		}
+		if (x instanceof BigInteger) {
+			setBigDecimal(parameterIndex, new BigDecimal( (BigInteger) x ) );
 			return;
+        }
 
-		
 		throw dataTypeConversion(parameterIndex, x.getClass().getName());
-
-	}
-
-	/**
-		Allow explict setObject conversions by sub-classes for classes
-		not supported by this variant. E.g. BigDecimal
-		This top-level implementation always returns false.
-
-		@return true if the object was set successfully, false if no valid
-		conversion exists.
-
-		@exception SQLException value could not be set.
-	*/
-	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException
-	{
-		return false;
 	}
 
     /**

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=1197264&r1=1197263&r2=1197264&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 18:43:42 2011
@@ -113,49 +113,5 @@ public abstract class EmbedPreparedState
 		throw Util.notImplemented();
 	}
 
-	/*
-	** Methods using BigDecimal, moved out of EmbedPreparedStatement
-	** to allow that class to support JSR169.
-	*/
-	/**
-     * Set a parameter to a java.lang.BigDecimal value.  
-     * The driver converts this to a SQL NUMERIC value when
-     * it sends it to the database.
-     *
-     * @param parameterIndex the first parameter is 1, the second is 2, ...
-     * @param x the parameter value
-	 * @exception SQLException thrown on failure.
-     */
-    public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
-		checkStatus();
-		try {
-			/* JDBC is one-based, DBMS is zero-based */
-			getParms().getParameterForSet(parameterIndex - 1).setBigDecimal(x);
-
-		} catch (Throwable t) {
-			throw EmbedResultSet.noStateChangeException(t);
-		}
-	}
-
-	/**
-		Allow explict setObject conversions by sub-classes for classes
-		not supported by this variant. In this case handle BigDecimal.
-		@return true if the object was set successfully, false if no valid
-		conversion exists.
-
-		@exception SQLException value could not be set.
-	*/
-	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException
-	{
-		if (x instanceof BigDecimal) {
-			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/CallableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java?rev=1197264&r1=1197263&r2=1197264&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java
Thu Nov  3 18:43:42 2011
@@ -21,6 +21,7 @@
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.sql.Date;
 import java.sql.Time;
 import java.sql.Timestamp;
@@ -351,6 +352,16 @@ public class CallableTest extends BaseJD
         assertEquals("OUT float" , (float) 6.0, cs.getFloat(10), .0001);
         assertEquals("OUT double" , 7.0, cs.getDouble(11), .0001);
         assertDecimalSameValue("OUT decimal", "88.88", cs.getBigDecimal(12));
+
+        // test that setObject() does the right thing for BigDecimal. see derby-5488.
+        cs.setObject(3, new BigDecimal( "10" ) );
+        cs.execute();
+        assertEquals("OUT long" , 10, cs.getLong(9));
+
+        // test that setObject() does the right thing for BigInteger. see derby-5488.
+        cs.setObject(3, new BigInteger( "11" ) );
+        cs.execute();
+        assertEquals("OUT long" , 11, cs.getLong(9));
     }
 
     /**



Mime
View raw message