Table of Contents |
---|
Introduction
This sample demonstrates how to expose some data stored in a database created via WSO2 storage server.
Prerequisites
- Java Development Kit / JRE version 1.6.* or 1.7.*
- Apache Ant 1.7.0 or later
- Download WSO2 DSS.
- Download WSO2 Developer Studio
Creating a data service
- Create a Database, a privilege template and a database user using WSO2SS and attach the created user to the database,
Use WSO2 Developer Studio and create a data service using the following values.
Field Example Description Driver Class com.mysql.jdbc.Driver This is the driver class of the database created via WSO2 SS. JDBC URL jdbc:mysql://localhost:3306/wso2DB_wso2_com This is the url received from WSO2 SS after successful creation of a database. User Name user1_aJLNWWiS The user name of a user created in WSO2 SS, and attached to the database created. Password user1 The password of the above user created in WSO2 SS, and attached to the database created.
...
Code Block | ||
---|---|---|
| ||
<data enableBoxcarring="true" name="RDBMSSample" serviceNamespace="http://ws.wso2.org/dataservice/samples/rdbms_sample"> <config id="default"> // add the database driver of the relevant db instance created. <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property> //add the database url recieved from Storage server. <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/wso2DB_wso2_com</property> //add a user to connecto to the database, which is already attached to the afore mentioned database via Storage Server. <property name="org.wso2.ws.dataservice.user">user1_aJLNWWiS</property> //use the aforementioned users password. <property name="org.wso2.ws.dataservice.password">user1</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.autocommit">false</property> <property name="org.wso2.ws.dataservice.validation_query"/> </config> //The sample Query. <query id="customersInBostonSQL" useConfig="default"> <sql>select * from Customers where city = 'Boston' and country = 'USA'</sql> <result element="customers" rowName="customer"> <element column="customerName" name="customer-name" xsdType="string"/> <element column="contactLastName" name="contact-last-name" xsdType="string"/> <element column="contactFirstName" name="contact-first-name" xsdType="string"/> <element column="phone" name="phone" xsdType="string"/> <element column="city" name="city" xsdType="string"/> <element column="country" name="country" xsdType="string"/> </result> </query> //The sample dataservice. <operation name="customersInBoston"> <call-query href="customersInBostonSQL"/> </operation> </data> |
Executing the sample
- Group the created data service with a Carbon Application Project and create the Carbon Application Archive [CAR] and deploy in to the WSO2 Data Services Server.
...