Fix for DDLUTILS-190: column.setSize needs to be a bit more robust when trying to convert numbers
git-svn-id: https://svn.apache.org/repos/asf/db/ddlutils/trunk@668049 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/ddlutils/io/DatabaseIO.java b/src/main/java/org/apache/ddlutils/io/DatabaseIO.java
index 662a901..e8f794a 100644
--- a/src/main/java/org/apache/ddlutils/io/DatabaseIO.java
+++ b/src/main/java/org/apache/ddlutils/io/DatabaseIO.java
@@ -469,7 +469,7 @@
}
else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
{
- column.setSize(xmlReader.getAttributeValue(idx));
+ column.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
}
else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT))
{
@@ -710,7 +710,7 @@
}
else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
{
- indexColumn.setSize(xmlReader.getAttributeValue(idx));
+ indexColumn.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
}
}
consumeRestOfElement(xmlReader);
@@ -739,6 +739,21 @@
}
/**
+ * Returns the value of the indicated attribute of the current element as a string.
+ * This method can handle "null" in which case it returns a null object.
+ *
+ * @param xmlReader The xml reader
+ * @param attributeIdx The index of the attribute
+ * @return The attribute's value
+ */
+ private String getAttributeValueBeingNullAware(XMLStreamReader xmlReader, int attributeIdx) throws DdlUtilsXMLException
+ {
+ String value = xmlReader.getAttributeValue(attributeIdx);
+
+ return "null".equalsIgnoreCase(value) ? null : value;
+ }
+
+ /**
* Returns the value of the indicated attribute of the current element as a boolean.
* If the value is not a valid boolean, then an exception is thrown.
*
diff --git a/src/main/java/org/apache/ddlutils/model/Column.java b/src/main/java/org/apache/ddlutils/model/Column.java
index 283e608..6554321 100644
--- a/src/main/java/org/apache/ddlutils/model/Column.java
+++ b/src/main/java/org/apache/ddlutils/model/Column.java
@@ -311,6 +311,7 @@
/**
* Sets the size of the column. This is either a simple integer value or
* a comma-separated pair of integer values specifying the size and scale.
+ * I.e. "size" or "precision,scale".
*
* @param size The size
*/
@@ -320,16 +321,16 @@
{
int pos = size.indexOf(",");
- _size = size;
+ _size = size;
if (pos < 0)
{
_scale = 0;
- _sizeAsInt = new Integer(_size);
+ _sizeAsInt = new Integer(_size.trim());
}
else
{
- _sizeAsInt = new Integer(size.substring(0, pos));
- _scale = Integer.parseInt(size.substring(pos + 1));
+ _sizeAsInt = new Integer(size.substring(0, pos).trim());
+ _scale = Integer.parseInt(size.substring(pos + 1).trim());
}
}
else