This documentation is for WSO2 Data Services Server 3.0.1. View documentation for the latest release.

Nested Queries

When writing a data service query, we may need to use the result of one query as an input parameter of another. This can be achieved as follows:

1. First add the query with an input parameter, which is evaluated as the result of another query. In this example, the 'customerNumber' input maping will be the result of another query.

2. Next, add the query ('customerOrderSQL' in this example) which generates the 'customerNumber'.

3. Select the "Add New Output Mapping" option of the above query, and define the mappings as below.

In this case, 'query' should be selected as the mapping type, which allows to select the query name and define query parameter mapping. As shown below, the query 'customerNameSQL' will be invoked with 'customerNumber' parameter, which is a result of 'customerOrderSQL'.

Invoke the Query

4. In order to test the nested query, add an operation to the query "customerOrderSQL" as follows

5. When the operation is invoked, results will contain the nested result element 'Customer', which returns from 'customerNameSQL' query.

5. As described, nested queries can be configured and invoked in data services. In the configuration syntax, this is achieved by defining 'call-query' element as a result element of a query as follows.

Description of the child elements and attributes of the call-query are as follows.

  • call-query/@href : Name of the nested query
  • call-query/with-param : Define the input parameter to be passed to nested query
  • call-query/with-param/@name : name of the parameter as defined in the nested query
  • call-query/with-param/@query-param : name of the parameter as returned from this query
  • call-query/with-param/@column : name of the parameter as returned from the immediate parent result element

From "call-query/with-param/@query-param" and "call-query/with-param/@column" attributes, only one is used in a single "call-query/with-param" element.

For a sample guide of nested queries, refer to Nested Query Sample.

Copyright © WSO2 Inc. 2005-2013