RDBMS
Follow the instructions below to create a data service using a relational database as the data source. We take MySQL ( http://dev.mysql.com/downloads ) as the example database here.
First, copy the JDBC driver to:
- <PRODUCT_HOME>/repository/components/lib directory
- <PRODUCT_HOME>/repository/components/dropins
For example, cp mysql-connector-java-5.XX-bin.jar /home/user/wso2ds/wso2-dataservices-XX/repository/components/lib.
1. Log on to the product's management console and select "Data Services -> Create" under the "Main" menu.
2. The "Create Data Service" page appears. Fill in the fields and click "Next" . The Data Service name is mandatory.
For more information on advanced configurations, refer to Advanced Data Service Configurations.
3. The "Data Sources" page appears. Click on the "Add New Data Source" link and add your Data Source details. Then click "Save" .
For a RDBMS data source, select the data source type as "RDBMS". We use a MySQL database in the example below.
For more information on "Use as Secret Alias" option, refer to Securing Passwords. For more information on configuration parameters and dynamic user authentication, refer to the following:
Before saving, you can test your connection using the 'Test Connection' button. If the database connection is successful, you will get the following message:
4. After saving, the added data source page appears. You can edit or delete the Data Source. To proceed click "Next ".
5. The "Queries" page appears.
Initially your service does not include any queries. Click on "Add New Query" to add a new query, input/output mappings, events etc. to your Data Service. Enter query details using which values will be extracted. Specify how the SQL response is mapped to output XML.
Example 1:
Query ID : customersInBostonSQL
SQL Statemen t : select *, from Customers where city = 'Boston' and country ='USA'
Example 2:
Query ID : customerAddressSQL
SQL Statemen t : select *, from Customers where contactLastName = ? and contactFirstName = ?
The following query needs two parameters for execution. The "Input Mapping" section is used to specify these input parameters.
For information on adding validations to your input mappings in the query, refer to section Input Validators. Also, detailed information on writing queries can be found in section Data Service Queries.
6. Once a new query is added, it will be listed in the "Queries" window. For example,
You can edit or delete your query. To continue, click "Next" .
7. The "Operations" page appear s. Click the "Add new operation" link to c reate an operation. Select a query to be executed when this operation is called.
Click "Save" once done. For example,
8. The operation will be listed in the "Operations" page. You can edit or delete your operation. To continue click "Next ".
9. The "Resources" page appears. Click "Add new resource" to provide resource details and " Save" once done. For example,
10. The resource will be listed in the "Resources" page. You can edit or delete your resource.
11. The Data Service configuration is done. Click "Finish" .
12. You will be navigated to the "Deployed Services" page .
From here, you can manage your data service . For instructions, refer to section Service Management .