db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1571938 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
Date Wed, 26 Feb 2014 07:07:24 GMT
Author: kahatlen
Date: Wed Feb 26 07:07:24 2014
New Revision: 1571938

URL: http://svn.apache.org/r1571938
Log:
DERBY-6213: Deprecate support for Java 5 and CDC

Remove reflection code in SQLDecimal.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java?rev=1571938&r1=1571937&r2=1571938&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java Wed Feb 26
07:07:24 2014
@@ -34,8 +34,6 @@ import org.apache.derby.iapi.services.ca
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
 import java.io.ObjectOutput;
 import java.io.ObjectInput;
 import java.io.IOException;
@@ -304,51 +302,9 @@ public final class SQLDecimal extends Nu
 	public String	getString()
 	{
 		BigDecimal localValue = getBigDecimal();
-		if (localValue == null)
-			return null;
-		else if (toPlainString == null)
-			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");
-                }
-            }
-        }
+        return (localValue == null) ? null : localValue.toPlainString();
 	}
 
-    private static final Method toPlainString;
-    private static final Method bdPrecision;
-    static {
-        Method m;
-        try {
-            m = BigDecimal.class.getMethod("toPlainString", null);
-        } catch (NoSuchMethodException e) {
-            m = null;
-        }
-        toPlainString = m;
-        try {
-            m = BigDecimal.class.getMethod("precision", null);
-        } catch (NoSuchMethodException e) {
-            m = null;
-        }
-        bdPrecision = m;
-    }
-
 	public Object	getObject()
 	{
 		/*
@@ -1121,37 +1077,10 @@ public final class SQLDecimal extends Nu
         {
             return 0;
         }
-        
-        if (bdPrecision != null)
-		{
-	        // 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 {
-				// precision is the number of digits in the unscaled value,
-				// subtracting the scale (positive or negative) will give the
-				// number of whole digits.
-				int precision = ((Integer) bdPrecision.invoke(decimalValue,
-						null)).intValue();
-				return precision - decimalValue.scale();
-			} catch (IllegalAccessException e) {
-				// can't happen based on the JDK spec
-				throw new IllegalAccessError("precision");
-			} 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("precision");
-				}
-			}
-            
-		}
-   
-		String s = decimalValue.toString();
-        return (decimalValue.scale() == 0) ? s.length() : s.indexOf('.');
+
+        // precision is the number of digits in the unscaled value,
+        // subtracting the scale (positive or negative) will give the
+        // number of whole digits.
+        return decimalValue.precision() - decimalValue.scale();
 	}
 }



Mime
View raw message