<!--
  ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<body>
<h1>Data Service Sample Guide</h1>

<h2>INTRODUCTION</h2>

<p>We will use this sample to demonstrate the data service features of WSO2
Web Services Application Server.
</p>

<p>Data service allows you to expose your data in relational databases in to XML
as a web service. WSAS uses a data service configuration file to define the SQL and
how to map the result in to xml elements. Data configuration is stored as an XML file
with the extension .dbs in the WSO2WSAS_HOME/repository/dataservices directory.
</p>

<p>In this sample we will expose the data in an Apache Derby embedded database
for the examples.</p>

<h2>HOW TO BUILD AND RUN THE SAMPLE</h2>

<p>To build the samples you need the <a href="http://ant.apache.org/">Apache
    Ant</a> build tool.</p>

<ol>
<li>
<p>Run WSO2 WSAS. See <a
            href="installation_guide.html">Installation Guide</a> for installation details.
</p>
</li>

<li>
<p>Switch to the sample DataService directory,<br/>
e.g. cd WSO2WSAS_HOME\samples\DataService<br/>
Note: $WSO2WSAS_HOME stands for the installation directory of WSO2 Web
Services Application Server.<br/>
</p>
</li>

<li>
<p>To  create the database and install the data service configuration type
&apos;ant deploy&apos;</p>

<pre>
wsasuser@wsasuser:~/apps/wso2wsas/samples/DataService$ ant deploy
Buildfile: build.xml

init:
    [mkdir] Created dir: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/database
    [mkdir] Created dir: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/classes

create-database:
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/CreateTables.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/Customers.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/Employees.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/Offices.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/OrderDetails.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/Orders.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/Payments.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/ProductLines.sql
      [sql] Executing file: /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/sql/Products.sql
      [sql] Executing commands
      [sql] 3881 of 3881 SQL statements executed successfully

deploy:
     [copy] Copying 1 file to /home/wsasuser/apps/wso2wsas-2.0/repository/dataservices
     [copy] Copying 1 file to /home/wsasuser/apps/wso2wsas-2.0/repository/dataservices

BUILD SUCCESSFUL
Total time: 16 seconds
</pre>
</li>

<li>
<p>To run the first web service client to access the data service type
&apos;ant run-client-1&apos;</p>

<pre>
wsasuser@wsasuser:~/apps/wso2wsas/samples/DataService$ ant run-client-1
Buildfile: build.xml

init:

compile-all:

run-client-1:


     [java] Requesting contact details of customers in Boston...

     [java] &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     [java] &lt;data:customers xmlns:data="http://ws.wso2.org/dataservice"&gt;
     [java]     &lt;customer&gt;
     [java]         &lt;customer-name&gt;Gifts4AllAges.com&lt;/customer-name&gt;
     [java]         &lt;contact-last-name&gt;Yoshido&lt;/contact-last-name&gt;
     [java]         &lt;contact-first-name&gt;Juri&lt;/contact-first-name&gt;
     [java]         &lt;phone&gt;6175559555&lt;/phone&gt;
     [java]         &lt;city&gt;Boston&lt;/city&gt;
     [java]         &lt;country&gt;USA&lt;/country&gt;
     [java]     &lt;/customer&gt;
     [java]     &lt;customer&gt;
     [java]         &lt;customer-name&gt;Diecast Collectables&lt;/customer-name&gt;
     [java]         &lt;contact-last-name&gt;Franco&lt;/contact-last-name&gt;
     [java]         &lt;contact-first-name&gt;Valarie&lt;/contact-first-name&gt;
     [java]         &lt;phone&gt;6175552555&lt;/phone&gt;
     [java]         &lt;city&gt;Boston&lt;/city&gt;
     [java]         &lt;country&gt;USA&lt;/country&gt;
     [java]     &lt;/customer&gt;
     [java] &lt;/data:customers&gt;


     [java] Requesting employee contact details for employee number 1002...

     [java] &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     [java] &lt;data:employees xmlns:data="http://ws.wso2.org/dataservice"&gt;
     [java]     &lt;employee&gt;
     [java]         &lt;last-name&gt;Murphy&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Diane&lt;/first-name&gt;
     [java]         &lt;email&gt;dmurphy@classicmodelcars.com&lt;/email&gt;
     [java]     &lt;/employee&gt;
     [java] &lt;/data:employees&gt;


     [java] Requestinng customer address for Jean King...

     [java] &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     [java] &lt;data:customer-addresses xmlns:data="http://ws.wso2.org/dataservice"&gt;
     [java]     &lt;customer-address&gt;
     [java]         &lt;customernumber&gt;112&lt;/customernumber&gt;
     [java]         &lt;contactlastname&gt;King&lt;/contactlastname&gt;
     [java]         &lt;contactfirstname&gt;Jean&lt;/contactfirstname&gt;
     [java]         &lt;addressline1&gt;8489 Strong St.&lt;/addressline1&gt;
     [java]         &lt;addressline2/&gt;
     [java]         &lt;city&gt;Las Vegas&lt;/city&gt;
     [java]         &lt;state&gt;NV&lt;/state&gt;
     [java]         &lt;postalcode&gt;83030&lt;/postalcode&gt;
     [java]         &lt;country&gt;USA&lt;/country&gt;
     [java]     &lt;/customer-address&gt;
     [java] &lt;/data:customer-addresses&gt;

BUILD SUCCESSFUL
Total time: 3 seconds
</pre>
</li>

<li>
<p>To run the second web service client to access the data service type
&apos;ant run-client-2&apos;</p>

<pre>
wsasuser@wsasuser:~/apps/wso2wsas/samples/DataService$ ant run-client-2
Buildfile: build.xml

init:

compile-all:
    [javac] Compiling 2 source files to /home/wsasuser/apps/wso2wsas-2.0-beta/samples/DataService/classes

run-client-2:


     [java] Requesting top customers in California...

     [java] &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     [java] &lt;data:top-customers xmlns:data="http://ws.wso2.org/dataservice"&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;124&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Nelson&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Susan&lt;/first-name&gt;
     [java]         &lt;telephone&gt;4155551450&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;129&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Murphy&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Julie&lt;/first-name&gt;
     [java]         &lt;telephone&gt;6505555787&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;161&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Hashimoto&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Juri&lt;/first-name&gt;
     [java]         &lt;telephone&gt;6505556809&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;205&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Young&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Julie&lt;/first-name&gt;
     [java]         &lt;telephone&gt;6265557265&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;239&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Thompson&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Valarie&lt;/first-name&gt;
     [java]         &lt;telephone&gt;7605558146&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;321&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Brown&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Julie&lt;/first-name&gt;
     [java]         &lt;telephone&gt;6505551386&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java]     &lt;customer-info&gt;
     [java]         &lt;customer-number&gt;450&lt;/customer-number&gt;
     [java]         &lt;last-name&gt;Frick&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Sue&lt;/first-name&gt;
     [java]         &lt;telephone&gt;4085553659&lt;/telephone&gt;
     [java]     &lt;/customer-info&gt;
     [java] &lt;/data:top-customers&gt;


     [java] Requesting top employees in MA...

     [java] &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     [java] &lt;data:top-employees xmlns:data="http://ws.wso2.org/dataservice"&gt;
     [java]     &lt;employee&gt;
     [java]         &lt;emp-no&gt;1188&lt;/emp-no&gt;
     [java]         &lt;last-name&gt;Firrelli&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Julie&lt;/first-name&gt;
     [java]         &lt;job-title&gt;Sales Rep&lt;/job-title&gt;
     [java]     &lt;/employee&gt;
     [java]     &lt;employee&gt;
     [java]         &lt;emp-no&gt;1216&lt;/emp-no&gt;
     [java]         &lt;last-name&gt;Patterson&lt;/last-name&gt;
     [java]         &lt;first-name&gt;Steve&lt;/first-name&gt;
     [java]         &lt;job-title&gt;Sales Rep&lt;/job-title&gt;
     [java]     &lt;/employee&gt;
     [java] &lt;/data:top-employees&gt;

BUILD SUCCESSFUL
Total time: 4 seconds
</pre>
</li>

<li>
<p>To delete all the generated artifacts, including the database, type
&apos;ant clean&apos;</p>

<pre>
wsasuser@wsasuser:~/apps/wso2wsas/samples/DataService$ ant clean
Buildfile: build.xml

clean:
   [delete] Deleting directory /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/database
   [delete] Deleting directory /home/wsasuser/apps/wso2wsas-2.0/samples/DataService/classes
   [delete] Deleting: /home/wsasuser/apps/wso2wsas-2.0/repository/dataservices/DataServiceSample1.dbs
   [delete] Deleting: /home/wsasuser/apps/wso2wsas-2.0/repository/dataservices/DataServiceSample2.dbs

BUILD SUCCESSFUL
Total time: 0 seconds
</pre>
</li>

</ol>

</body>
</html>