Author: tomdz Date: Sun Jun 15 20:38:45 2008 New Revision: 668049 URL: http://svn.apache.org/viewvc?rev=668049&view=rev Log: Fix for DDLUTILS-190: column.setSize needs to be a bit more robust when trying to convert numbers
Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/io/DatabaseIO.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/model/Column.java Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/io/DatabaseIO.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/io/DatabaseIO.java?rev=668049&r1=668048&r2=668049&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/io/DatabaseIO.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/io/DatabaseIO.java Sun Jun 15 20:38:45 2008 @@ -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. * Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/model/Column.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/model/Column.java?rev=668049&r1=668048&r2=668049&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/model/Column.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/model/Column.java Sun Jun 15 20:38:45 2008 @@ -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