Content starts here Add a Library Function or Procedure
This page last changed on Mar 11, 2008.

eDocs Home > BEA AquaLogic Data Services Platform Documentation > Data Services Developer's Guide > Contents

How To Add a Library Function or Procedure

This topic describes how to add a library function or procedure to a data service.

Overview

Library functions and procedures are utility operations that you can add to any service, physical, logical, or library. Library functions and procedures:

  • Have a kind of library
  • Are not marked as primary or non-primary
  • Have a visibility of public, protected or private

A library function can return values, but has no side effects. A library procedure can return values and can have side effects.

You can declare a library function or procedure visually in Studio, but you must still write the function body in the Source tab using XQuery. Alternatively, you can write the entire function or procedure and its pragma statement in XQuery.

You can call a library function or procedure from the service, the dataspace project, or from a client application, depending on the visibility level you set.

Add the Function or Procedure

The example in this section is a library function that casts a value from xs:integer to xs:string. 

  1. Open the service and click the Overview tab.
  2. Right-click at the left, right, or top, and choose Add Operation.
  3. Select a value at Visibility (public = call from anywhere; protected = from the same dataspace; private = from the same data service).
  4. At Kind, choose libraryFunction or libraryProcedure.
     

  5. Give your function or procedure a name.
  6. At Return Type, click Edit and choose a simple or complex return type. Click OK.
  7. At Parameters, click Edit. Enter a parameter name, and choose a simple or complex return type. Click OK.
  8. Click Empty Function Body, then OK.
  9. Click the Source tab.
    ALDSP has generated a pragma statement and an empty function or procedure body, like this:
    (::pragma  function <f:function kind="library" visibility="public" isPrimary="false" xmlns:f="urn:annotations.ld.bea.com"/>::)
    
    declare function cus2:integerToString($theInt as xs:positiveInteger) as xs:string* {
        $var-bea:tbd
    };
  10. In the function body, delete $var-bea:tbd and add your own XQuery code, for example:
     
    declare function cus2:integerToString($theInt as xs:positiveInteger) as xs:string* {
    		xs:string($theInt)
    };

Test in Studio

You can test the library function or procedure directly in Studio, before you use it from a client application.

  1. Open the service, and click the Test tab.
  2. At Select Operation, choose the library function or procedure you want to test.
  3. Enter a value in the Parameters box.
  4. (Optional) Expand Settings and enter new values for results, transactions, and authentication.
  5. Click Run.
    If the function or procedure works, you see valid results.
     

    If not, you see an exception message that provides details, so that you can correct the error.

How Tos
Reference



Document generated by Confluence on Apr 28, 2008 15:54