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 ka...@apache.org on 2013/05/10 22:59:52 UTC
svn commit: r1481187 - in
/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types:
SqlXmlUtil.java build.xml
Author: kahatlen
Date: Fri May 10 20:59:51 2013
New Revision: 1481187
URL: http://svn.apache.org/r1481187
Log:
DERBY-6213: Deprecate support for Java 5 and CDC
- Revive build target for SqlXmlUtil to ensure that it always includes
the org.w3c.dom.xpath interfaces on the compile classpath.
- Update SqlXmlUtil.java so that no warnings are printed during
compilation.
- Remove code that's only used on Java 1.4 and CDC.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/build.xml
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java?rev=1481187&r1=1481186&r2=1481187&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java Fri May 10 20:59:51 2013
@@ -33,8 +33,6 @@ import java.util.List;
import java.io.IOException;
import java.io.StringReader;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.math.BigDecimal;
// -- JDBC 3.0 JAXP API classes.
@@ -128,40 +126,6 @@ public class SqlXmlUtil
private boolean recompileQuery;
/**
- * <p>
- * An object representing the {@code BigDecimal.toPlainString()} method
- * if it's available on the platform. If it's not available, this field
- * will be initialized to {@code null}, and in that case the
- * {@code BigDecimal.toString()} method should be used instead without
- * reflection.
- * </p>
- *
- * <p>
- * The behaviour of the {@code toString()} method changed when
- * {@code toPlainString()} was introduced in Java SE 5. On older
- * platforms, it behaves just like {@code toPlainString()} does on
- * newer platforms. So when {@code toPlainString()} is not
- * available, it is safe to fall back to {@code toString()}. It
- * behaves differently on newer platforms, so we need to use
- * {@code toPlainString()} when it is available in order to get
- * consistent behaviour across all platforms.
- * </p>
- *
- * @see #numberToString(double)
- */
- private static final Method TO_PLAIN_STRING;
- static {
- Method m = null;
- try {
- m = BigDecimal.class.getMethod("toPlainString", new Class[0]);
- } catch (NoSuchMethodException nsme) {
- // Couldn't find the method, so we'll just fall back to toString()
- // on this platform.
- }
- TO_PLAIN_STRING = m;
- }
-
- /**
* Constructor: Initializes objects required for parsing
* and serializing XML values. Since most XML operations
* that require XML-specific classes perform both parsing
@@ -335,7 +299,7 @@ public class SqlXmlUtil
protected String serializeToString(String xmlAsText)
throws Exception
{
- ArrayList aList = new ArrayList();
+ ArrayList<Document> aList = new ArrayList<Document>();
/* The call to dBuilder.parse() is a call to an external
* (w.r.t. to Derby) JAXP parser. If the received XML
@@ -349,9 +313,9 @@ public class SqlXmlUtil
final InputSource is = new InputSource(new StringReader(xmlAsText));
aList.add(java.security.AccessController.doPrivileged(
- new java.security.PrivilegedExceptionAction()
+ new java.security.PrivilegedExceptionAction<Document>()
{
- public Object run() throws IOException, SAXException
+ public Document run() throws IOException, SAXException
{
return dBuilder.parse(is);
}
@@ -423,9 +387,6 @@ public class SqlXmlUtil
"Tried to serialize with uninitialized XML serializer.");
}
- int sz = items.size();
- Object obj = null;
-
/* Step 1: Empty sequence. If we have an empty sequence then we
* won't ever enter the for loop and the call to sWriter.toString()
* at the end of this method will return an empty string, as
@@ -435,9 +396,8 @@ public class SqlXmlUtil
// Iterate through the list and serialize each item.
boolean lastItemWasString = false;
- for (int i = 0; i < sz; i++)
+ for (Object obj : items)
{
- obj = items.get(i);
// if it's a string, then this corresponds to some atomic
// value, so just echo the string as it is.
if (obj instanceof String)
@@ -663,11 +623,12 @@ public class SqlXmlUtil
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
// We have a sequence. Get all nodes.
- itemRefs = new ArrayList();
+ ArrayList<Node> nodes = new ArrayList<Node>();
Node node;
while ((node = result.iterateNext()) != null) {
- itemRefs.add(node);
+ nodes.add(node);
}
+ itemRefs = nodes;
break;
default:
if (SanityManager.DEBUG) {
@@ -754,8 +715,7 @@ public class SqlXmlUtil
* @param d {@code double} representation of the number
* @return {@code String} representation of the number
*/
- private static String numberToString(double d)
- throws IllegalAccessException, InvocationTargetException {
+ private static String numberToString(double d) {
if (Double.isNaN(d) || Double.isInfinite(d)) {
// BigDecimal doesn't know how to handle NaN or +/- infinity, so
// use Double to handle those cases.
@@ -783,17 +743,8 @@ public class SqlXmlUtil
}
// Finally, convert the value to a string. The method
- // BigDecimal.toPlainString() formats the number the way we want
- // it, but it's only available on Java 5 and later. Luckily, on
- // older platforms, BigDecimal.toString() is defined the same way
- // as toPlainString(), so we can fall back to that method if
- // toPlainString() isn't available. toString() was redefined in
- // Java 5, so we cannot use toString() unconditionally, however.
- if (TO_PLAIN_STRING == null) {
- return dec.toString();
- } else {
- return (String) TO_PLAIN_STRING.invoke(dec, (Object[]) null);
- }
+ // BigDecimal.toPlainString() formats the number the way we want.
+ return dec.toPlainString();
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/build.xml?rev=1481187&r1=1481186&r2=1481187&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/build.xml Fri May 10 20:59:51 2013
@@ -35,6 +35,30 @@
<!-- Targets -->
<target name="compile_types">
+ <!--
+ Compile SqlXmlUtil separately because it uses some XML
+ interfaces that are not part of the Java SE specification, and
+ requires xml-apis.jar on the compile classpath.
+ -->
+ <javac
+ source="1.6"
+ target="1.6"
+ bootclasspath="${empty}"
+ nowarn="on"
+ debug="${debug}"
+ depend="${depend}"
+ deprecation="${deprecation}"
+ optimize="${optimize}"
+ proceed="${proceed}"
+ verbose="${verbose}"
+ srcdir="${derby.engine.src.dir}"
+ destdir="${out.dir}">
+ <classpath>
+ <pathelement path="${xmlApis};${java16compile.classpath}"/>
+ </classpath>
+ <include name="${derby.dir}/iapi/types/SqlXmlUtil.java"/>
+ </javac>
+
<javac
source="1.6"
target="1.6"
@@ -52,6 +76,7 @@
<pathelement path="${java16compile.classpath}"/>
</classpath>
<include name="${derby.dir}/iapi/types/*.java"/>
+ <exclude name="${derby.dir}/iapi/types/SqlXmlUtil.java"/>
<!-- <compilerarg value="-Xlint:unchecked"/> -->
</javac>
</target>