Friday, July 23, 2010

Storing integer values in Cordys

 
Cordys offers out of the box functionality to generate web methods to store data in existing database tables. Persisting business objects is facilitated nicely this way.

The standard functionality works all fine, until integer values are used.
If the process is using an XSD having integer fields, mapping them upon an integer field in a database table should not be much of an issue, one might think. In case using plain static values the functionality works fine indeed.

However: When XPath functionality are used to set the integer values in the BPM (e.g. via a function or operator) the result is that to all integer values are provided with an additional decimal point and a zero!

Hence: In case the XML value ./value has the value 1, the XPath operation ./value + 1 does not result (as one might think) simply in 2: The value is converted to 2.0

The actual reason is not in Cordys, however in XML/XPath. XML/XPath does not really support integer values: They are just floating point values, having 0 as decimal fraction.
This “feature” is pretty innocent when just using XPath in the BPM. However when this value has to be made persistent in a database in our case MySQL 5.0) there is in issue: The query to insert the value 2.0 in an integer field the database table results in error because of this format.

This issues cannot be solved in XPath by using the round() function: It does add the .0 itself too.

Fortunatly there is a rather inexpensive solution to the problem: use the string() function.

The XPath spec describes:
if the number is an integer, the number is represented in decimal form as a
Number <http://www.w3.org/TR/xpath#NT-Number> with no decimal point and no
leading zeros, preceded by a minus sign (-) if the number is negative

Hence: Replacing ./value + 1 by string(./value + 1) will leave you with an value without decimal point.

Regards,

Harald van der Weel