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 dj...@apache.org on 2004/11/29 18:35:57 UTC

svn commit: r106931 - in incubator/derby/code/trunk/java: engine/org/apache/derby/iapi/services/info engine/org/apache/derby/iapi/types testing/org/apache/derbyTesting/functionTests/master testing/org/apache/derbyTesting/functionTests/tests/lang

Author: djd
Date: Mon Nov 29 09:35:55 2004
New Revision: 106931

URL: http://svn.apache.org/viewcvs?view=rev&rev=106931
Log:
Fix Derby 83

Patch which makes SQLDecimal use BigDecimal.toPlainString() on JDK1.5 so that generated text is the same as in prior versions.

This uses reflection to invoke toPlainString() allowing the code to be compiled on earlier VMs.

Fix contributed by Jeremy Boynes <jb...@apache.org>
Test case contributed by Dan Debrunner djd@debrunners.com


Modified:
   incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
   incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out
   incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java?view=diff&rev=106931&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java&r1=106930&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java&r2=106931
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java	Mon Nov 29 09:35:55 2004
@@ -33,6 +33,7 @@
 		<LI> 2 - JDK 1.2, 1.3
 		<LI> 4 - JDK 1.4.0 or 1.4.1
 		<LI> 5 - JDK 1.4.2
+		<LI> 6 - JDK 1.5
 		</UL>
 		@return The JVM's runtime environment.
 	*/
@@ -82,6 +83,10 @@
 			else
 				id = 5;
 		}
+        else if (javaVersion.equals("1.5"))
+        {
+            id = 6;
+        }
 		else
 		{
 			// aussme our lowest support unless the java spec

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java?view=diff&rev=106931&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java&r1=106930&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java&r2=106931
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java	(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java	Mon Nov 29 09:35:55 2004
@@ -32,10 +32,13 @@
 import org.apache.derby.iapi.error.StandardException;
 
 import org.apache.derby.iapi.services.cache.ClassSize;
+import org.apache.derby.iapi.services.info.JVMInfo;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.lang.Math;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 import java.io.ObjectOutput;
 import java.io.ObjectInput;
 import java.io.IOException;
@@ -130,7 +133,7 @@
 		value = val;
 	}
 
-	public SQLDecimal(BigDecimal val, int precision, int scale) 
+	public SQLDecimal(BigDecimal val, int nprecision, int scale)
 			throws StandardException
 	{
 		
@@ -309,9 +312,41 @@
 		BigDecimal localValue = getBigDecimal();
 		if (localValue == null)
 			return null;
-		else
+		else if (JVMInfo.JDK_ID < 6)
 			return localValue.toString();
-	}
+        else
+        {
+            // use reflection so we can still compile using JDK1.4
+            // if we are prepared to require 1.5 to compile then this can be a direct call
+            try {
+                return (String) toPlainString.invoke(localValue, null);
+            } catch (IllegalAccessException e) {
+                // can't happen based on the JDK spec
+                throw new IllegalAccessError("toPlainString");
+            } catch (InvocationTargetException e) {
+                Throwable t = e.getTargetException();
+                if (t instanceof RuntimeException) {
+                    throw (RuntimeException) t;
+                } else if (t instanceof Error) {
+                    throw (Error) t;
+                } else {
+                    // can't happen
+                    throw new IncompatibleClassChangeError("toPlainString");
+                }
+            }
+        }
+	}
+
+    private static final Method toPlainString;
+    static {
+        Method m;
+        try {
+            m = BigDecimal.class.getMethod("toPlainString", null);
+        } catch (NoSuchMethodException e) {
+            m = null;
+        }
+        toPlainString = m;
+    }
 
 	public Object	getObject()
 	{

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out?view=diff&rev=106931&p1=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out&r1=106930&p2=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out&r2=106931
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out	(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/floattypes.out	Mon Nov 29 09:35:55 2004
@@ -2419,4 +2419,42 @@
 1                               
 --------------------------------
 ERROR 22003: The resulting value is outside the range for the data type DECIMAL/NUMERIC(31,0).
+ij> create table tiger(d decimal(12,11));
+0 rows inserted/updated/deleted
+ij> insert into tiger values (1.234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.1234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.01234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.0001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.00001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.000001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.0000001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.00000001234);
+1 row inserted/updated/deleted
+ij> insert into tiger values (0.00000001234);
+1 row inserted/updated/deleted
+ij> select d from tiger order by 1;
+D              
+---------------
+0.00000001234  
+0.00000001234  
+0.00000012340  
+0.00000123400  
+0.00001234000  
+0.00012340000  
+0.00123400000  
+0.00123400000  
+0.01234000000  
+0.12340000000  
+1.23400000000  
 ij> 

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql?view=diff&rev=106931&p1=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql&r1=106930&p2=incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql&r2=106931
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql	(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/floattypes.sql	Mon Nov 29 09:35:55 2004
@@ -1182,4 +1182,21 @@
 values cast('1e30' as decimal(31))*cast('1e30' as decimal(31));
 
 
+create table tiger(d decimal(12,11));
+
+insert into tiger values (1.234);
+insert into tiger values (0.1234);
+insert into tiger values (0.01234);
+insert into tiger values (0.001234);
+insert into tiger values (0.001234);
+insert into tiger values (0.0001234);
+insert into tiger values (0.00001234);
+insert into tiger values (0.000001234);
+insert into tiger values (0.0000001234);
+insert into tiger values (0.00000001234);
+insert into tiger values (0.00000001234);
+
+select d from tiger order by 1;
+
+