Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
XML
XML
<data baseURI="xs:anyURI" name="xs:NMTOKEN" enableBatchRequests="xs:BOOLEAN" enableBoxcarring="xs:BOOLEAN" txManagerJNDIName="xs:NMTOKEN" serviceNamespace="xs:anyURI" serviceGroup="xs:NMTOKEN" serviceStatus="active|inactive" transports="http https JMS local" >
    config+
    query+
    operation+
    resource+
    event-trigger+
</data>
AttributeDescription
baseURIa REQUIRED URI indicating the base URI for the operations and resources defined within the <data> element.
namea REQUIRED name of the data service.
enableBatchRequestan OPTIONAL boolean to enable the batch request feature.
enableBoxcarringan OPTIONAL boolean to enable the boxcarring feature.
txManagerJNDINamean OPTIONAL JNDI name for overriding the standard JNDI location for locating the JTA transaction manager
serviceNamespacean OPTIONAL URI to uniquely identify the web service.
serviceGroupan OPTIONAL name that is used to categorize data-services in different groups.
serviceStatusan OPTIONAL string to enable WIP (specifies weather the data service is deployed or work in progress) support.
transportsan OPTIONAL string to enable the transports required for the data service. The possible values are "http", "https", "JMS" and "local".

To create a data service using the management console, see Developing Data Services.

...

To create a datasource to connect to a database using the management console, see Creating Adding Datasources.

Defining queries

A query consists of parameters and it describes how to map the result to an XML element. It is similar to a function that maps some parameters to an XML element. A query definition does not indicate how the parameters are acquired. Instead, it just lists the parameters that are needed, assuming that the parameters will be provided. If the query is at a top level (i.e., direct child of <data>) then either an operation definition or a resource definition provides the context for the parameters. If the query is nested within a <result> element, then the parameter names refer to column names of the result table described in the <result> element of the XML.

...

AttributesSub-attributesSub-attributesDescription
id  an OPTIONAL XML ID identifying the query. If <query> is a direct child of <data> then this attribute is required.
useConfig  a REQUIRED reference to the datasource that is to be used for query.
returnGeneratedKeys  

an OPTIONAL boolean parameter to enable returnGeneratedKeys.

Set this attribute to true only in INSERT queries, where the query inserts to a table that has an auto incrementing key column. In such a case, an auto incremented key value is added to the results set.

Also see Returning Generated Keys.
param  a declaration of a parameter of the query
 name a REQUIRED name of the parameter.
 sqlType an OPTIONAL string containing a legal SQL type which defines the type of the parameter. If none is specified then defaults to string.
 paramType a REQUIRED parameter type. If none is specified then defaults to SCALAR.
 ordinal a  REQUIRED only for stored procedures which map the parameter positions with the query.
 defaultValue an OPTIONAL default value of the input parameter.
 validateCustomclassa REQUIRED custom validation class to validate the input parameter.
 validateLengthminimuma REQUIRED integer when specifying the minimum length of the parameter.
  maximuma REQUIRED integer when specifying the maximum length of the parameter.
 validatePatternpatterna REQUIRED string pattern to validate the string input parameter.
sql  a REQUIRED string containing the SQL query or SQL function to execute. See Calling an SQL Function in a Query.
 dialect an OPTIONAL string containing jdbc driver prefix when need to use sql-dialects.
sparql  a REQUIRED string containing the sparql query to execute when using RDF as datasource.
properties  an OPTIONAL XML to define advanced query properties. Each property is defined as a child element of this.
 name a REQUIRED name of the property.
result  a REQUIRED element descriibing how the table resulting from executing the query will be converted to an XML element. If any <column> or <query> child elements are present, then ONLY those are transferred as child elements of the result element (or elements, depending on whether result/@rowName is given or not). The order of the nested <column> or <query> elements defines the order of elements in the result element.
 element a REQUIRED QName which is the name of the element which will hold the results.
 rowName an OPTIONAL QName which is the name of the element wrapping each row of the result table if more than one element from the table is to be returned. If this attribute is not given, then only the first row is returned and hence no second level wrapper element is needed.
 defaultNamespace an OPTIONAL URI being the default namespace to use for the namespace name of elements and attributes that result columns are mapped to. Defaults to "" (meaning no namespace).
 call-query an OPTIONAL element (which may occur any number of times) which is used to execute a further query and produce an element which will be present in the parent element as a child. This is used primarily to use a value of a column as key to select data from a new table.
 element an OPTIONAL element (which may occur any number of times) indicating how a specific column in the result table is to be mapped into an element
  element/@namea REQUIRED QName giving the name of the element to put the column data into
  element/@columnan OPTIONAL string giving the name of the column whose value is to be copied into the element.
  element/@requiredRolesan OPTIONAL string giving the names of roles that who has permission to see the result element. By default it has set to all users.
  element/@exportan OPTIONAL name giving to the element that to be export outside of query. This feature is used with boxcarring support.
  element/@exportTypea REQUIRED parameter when using export option. Used to give the export element type whether scalar or array.
  element/@xsdTypean OPTIONAL indication of the XML Schema type of the element. If none is given defaults to the mapping of the SQL type of the result column named by @column to an XML Schema type as per [SQL XML Mapping]
 attribute an OPTIONAL element (which may occur any number of times) indicating how a specific column in the result table is to be mapped into an attribute of the element representing the current row
  attribute/@namea REQUIRED QName giving the name of the attribute to put the column data into
  attribute/@columnan OPTIONAL string giving the name of the column whose value is to be copied into the attribute. Either @column or @param is required.
  attribute/@paraman OPTIONAL string giving the name of the param whose value is to be copied into the attribute. Either @column or @param is required.
  attribute/@requiredRolesan OPTIONAL string giving the names of roles that who has permission to see the result attribute. By default it has set to all users.
  attribute/@exportan OPTIONAL name giving to the attribute that to be export outside of query. This feature is used with boxcarring support.
  attribute/@exportTypea REQUIRED parameter when using export option. Used to give the export element type whether scalar or array.
  attribute/@xsdTypean OPTIONAL indication of the XML Schema type of the attribute. If none is given defaults to the mapping of the SQL type of the result column named by @column to an XML Schema type as per [SQL XML Mapping]
 call-querry an OPTIONAL element (which may occur any number of times) indicating how a specific column in the result table is to be mapped into a query result.
  with-param/@namea REQUIRED name of the query to put the column data into
  with-param/@query-paraman OPTIONAL string giving the name of the column whose value is to be copied into the element.

...

Code Block
XML
XML
<data name="DSSample" enableBatchRequests="false" enableBoxcarring="true" serviceStatus="active" baseURI="http://ws.wso2.org/dataservice/samples/ds_sample" transports="http https JMS local">
   <config id="default">
      <property name="org.wso2.ws.dataservice.driver">org.h2.Driver</property>
      <property name="org.wso2.ws.dataservice.protocol">jdbc:h2:file:./samples/database/DATA_SERV_SAMP</property>
      <property name="org.wso2.ws.dataservice.user">wso2ds</property>
      <property name="org.wso2.ws.dataservice.password">wso2ds</property>
      <property name="org.wso2.ws.dataservice.minpoolsize">1</property>
      <property name="org.wso2.ws.dataservice.maxpoolsize">10</property>
      <property name="org.wso2.ws.dataservice.validation_query"></property>
   </config>
    <query id="employeesByNumberSQL" useConfig="default">
      <sql>select * from Employees where employeeNumber = ?</sql>
      <result element="employees" rowName="employee">
         <element name="last-name" column="lastName" />
         <element name="first-name" column="firstName" />
         <element name="email" column="email" />
         <element name="salary" column="salary" />
      </result>
       <param name="employeeNumber" paramType="SCALAR" sqlType="INTEGER" type="IN" ordinal="1" >
          <validateLength minimum="3" maximum="20" />
       </param>
   </query>
  <query id="updateProductQuantityQuery" useConfig="default" input-event-trigger="product_stock_low_trigger">
      <sql>update Products set quantityInStock=? where productCode=?</sql>
      <param name="productCode" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="2" />
      <param name="quantityInStock" paramType="SCALAR" sqlType="DOUBLE" type="IN" ordinal="1" />
   </query>
    <query id="createProductQuery" useConfig="default">
      <sql>insert into Products (productCode, productName, productLine, quantityInStock, buyPrice) values (?,?,?,?,?)</sql>
      <param name="productCode" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="1" />
      <param name="productName" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="2" />
      <param name="productLine" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="3" />
      <param name="quantityInStock" paramType="SCALAR" sqlType="INTEGER" type="IN" ordinal="4" />
      <param name="buyPrice" paramType="SCALAR" sqlType="DOUBLE" type="IN" ordinal="5" />
   </query>
  <operation name="employeesByNumber">
      <call-query href="employeesByNumberSQL"           >
         <with-param name="employeeNumber" query-param="employeeNumber" />
      </call-query>
   </operation>
   <event-trigger id="product_stock_low_trigger" language="XPath">
      <expression>/updateProductQuantityQuery/quantityInStock&lt;10</expression>
      <target-topic>product_stock_low_topic</target-topic>
      <subscriptions>
         <subscription>mailto:test@test.com</subscription>
      </subscriptions>
   </event-trigger>
    <resource path="product/{productCode}/{productName}/{productLine}/{quantityInStock}/{buyPrice}" method="POST">
      <call-query href="createProductQuery"          >
         <with-param name="productCode" query-param="productCode" />
         <with-param name="productName" query-param="productName" />
         <with-param name="productLine" query-param="productLine" />
         <with-param name="quantityInStock" query-param="quantityInStock" />
         <with-param name="buyPrice" query-param="buyPrice" />
      </call-query>
   </resource>
   <policy key="conf:repository/components/org.wso2.carbon.security.mgt/policy/scenario1"/>
   <enableSec/>
</data>