2. Test an Update Map Cast This page last changed on Nov 28, 2008. .stickable, h1, h2, h3, h4, h5 false true Show Sticky notes Hide Sticky notes Save Cancel Oracle Data Service Integrator Documentation > Data Services Developer's Guide # How To Test an Update Map Cast This topic describes how to test a cast between elements of different data types in an update map. Example See Also ## Example The easiest way to test an update map cast function is to use Read-Edit-Submit from the Test tab in Workshop for WebLogic. Suppose you are casting from xs:integer to xs:string. To test the cast function, you need to retrieve data from the data source as xs:string and display it in the Test tab as xs:integer, so you also need to cast in the reverse direction. The primitive types casting chart in the XQuery 1.0 specification shows that you can always cast from xs:integer to xs:string, but you can only cast from xs:string to xs:integer in some cases. To test an update map cast using Read-Edit-Submit, you first edit the source code of the primary Read function to do a comparable cast when the data is read from the data source. For example, suppose you want to cast from dateTime to date during an update. To test, you must first cast the date value to dateTime when you read it from the data source. Before you use this test method, check the casting chart in the XQuery specification to make sure the XQuery cast you want to perform works in both directions. In the example given here, the cast is from xs:dateTime to xs:date in the update map and from xs:date to xs:dateTime in the primary Read function. Both casts must be valid in XQuery. Click the Source tab. Locate the primary Read function, which looks something like this:
       declare function tns:read() as element(cus:CUSTOMER)*{
       for $CUSTOMER in cus1:CUSTOMER()
       return
               <cus:CUSTOMER>
                   <CUSTOMER_ID>{fn:data($CUSTOMER/CUSTOMER_ID)}</CUSTOMER_ID>
                   <FIRST_NAME>{fn:data($CUSTOMER/FIRST_NAME)}</FIRST_NAME>
                   <LAST_NAME>{fn:data($CUSTOMER/LAST_NAME)}</LAST_NAME>
                   <CUSTOMER_SINCE>{fn:data($CUSTOMER/CUSTOMER_SINCE}</CUSTOMER_SINCE>
                   <EMAIL_ADDRESS>{fn:data($CUSTOMER/EMAIL_ADDRESS)}</EMAIL_ADDRESS>
                   <TELEPHONE_NUMBER>{fn:data($CUSTOMER/TELEPHONE_NUMBER)}</TELEPHONE_NUMBER>
                   <SSN?>{fn:data($CUSTOMER/SSN)}</SSN>
                   <BIRTH_DAY?>{fn:data($CUSTOMER/BIRTH_DAY)}</BIRTH_DAY>
                   <DEFAULT_SHIP_METHOD?>{fn:data($CUSTOMER/DEFAULT_SHIP_METHOD)}</DEFAULT_SHIP_METHOD>
                   <EMAIL_NOTIFICATION?>{fn:data($CUSTOMER/EMAIL_NOTIFICATION)}</EMAIL_NOTIFICATION>
                   <NEWS_LETTTER?>{fn:data($CUSTOMER/NEWS_LETTTER)}</NEWS_LETTTER>
                   <ONLINE_STATEMENT?>{fn:data($CUSTOMER/ONLINE_STATEMENT)}</ONLINE_STATEMENT>
                   <LOGIN_ID?>{fn:data($CUSTOMER/LOGIN_ID)}</LOGIN_ID>
               </cus:CUSTOMER>
       };
3. Locate the element you want to cast and add a XQuery cast expression to it. For example, this casts an xs:date to an xs:dateTime in the CUSTOMER_SINCE element:
       <CUSTOMER_SINCE>{ xs:dateTime(fn:data($CUSTOMER/CUSTOMER_SINCE)) }</CUSTOMER_SINCE>
   To cast an xs:string to an xs:integer in TELEPHONE_NUMBER, enter this:
       <TELEPHONE_NUMBER>{xs:integer(  fn:data($CUSTOMER/TELEPHONE_NUMBER)) }</TELEPHONE_NUMBER>
8. Click the Test tab. At Select Operation, choose the service's primary Read function and click Run. In the Result pane, you might see that the values have been cast, if the new type looks different. Click a customer record, then Edit. Change one of the values you have just cast. If you are working with xs:date and xs:dateTime, change the date portion of the value, rather than the time. The time is truncated when you store the value in the data source as an xs:date. When you read it back as an xs:dateTime, it looks like 00:00:00. Click Submit. You should see this message:
       Data has been submitted
Click Run again to verify the change. ## See Also ##### How To Cast Using a Built-In XQuery Function Cast Using a Custom XQuery Function ##### Other Resources XQuery 1.0 Specification

Document generated by Confluence on Jan 13, 2009 15:57