Subject:Problems with Java date parameters using DDTEK XQuery engine Author:David Isaac Date:29 Jun 2009 10:39 AM
Hello-
Has anyone successfully passed a date parameter from XQuery to Java using the ddtek XQuery engine?
With SAXON, I can successfully do the following:
declare namespace sdf = "java:java.text.SimpleDateFormat";
declare function local:toDate($stringDate as xs:string?) as xs:dateTime? {
let $format := sdf:new("MM/dd/yyyy")
return sdf:parse($format, $stringDate)
};
which nicely converts the returned Java Date to xs:dateTime.
With DDTEK, I tried unsuccessfully to do the following:
declare namespace sdf = "ddtekjava:java.text.SimpleDateFormat";
declare function sdf:SimpleDateFormat($format as xs:string) as ddtek:javaObject external;
declare function sdf:parse($this as ddtek:javaObject, $stringDate) as ddtek:javaObject external;
declare function local:convert($stringDate as xs:string as xs:date {
let $format := sdfSimpleDateFormat("MM/dd/yyyy")
return xs:dateTime(sdf:parse($format,$stringDate))
};
The ddtek:javaObject returned from parse is not automatically converted to xs:date and cannot be cast either. Any hints what I am doing wrong? I cannot find any default mapping of date types between Java and XQuery in the ddtek documentation, so perhaps it can't be done? Am I approaching this all wrong...is there really no better way to convert dates? Sometimes I am simply trying to process dates in mm/dd/yyyy hh:mm:ss format, and of course XQuery requires ISO yyyy-mm-dd etc. format...is there really no implicit conversion for this common format? Any help would be greatly appreciated!
Subject:Problems with Java date parameters using DDTEK XQuery engine Author:(Deleted User) Date:30 Jun 2009 12:05 PM
Hi David,
the table listing the mapping used by DDXQ to convert between Java and XQuery datatypes is Table 13-1 in chapter 13 of the User Guide (that can be found at <Stylus Studio Install>\Components\DataDirect XQuery\books\ddxquery\ddxqug\ddxqug.pdf).
Unfortunately the java.util.Date type is not automatically converted into xs:date, so you must do one extra step to convert it into a string suitable for constructing an xs:date item.
declare namespace sdf = "ddtekjava:java.text.SimpleDateFormat";
declare function sdf:SimpleDateFormat($format as xs:string) as ddtek:javaObject external;
declare function sdf:parse($this as ddtek:javaObject, $stringDate) as ddtek:javaObject external;
declare function sdf:format($this as ddtek:javaObject, $objDate) as xs:string external;
declare function local:convert($stringDate as xs:string) as xs:date {
let $format := sdf:SimpleDateFormat("MM/dd/yyyy")
let $formatISO := sdf:SimpleDateFormat("yyyy-MM-dd")
return xs:date(sdf:format($formatISO, sdf:parse($format,$stringDate)))
};