In this tutorial, we will run through the process of service enabling an RDBMS as a data service.
Step 1: Setting up an RDBMS
Follow the steps given below to set up a MySQL database for this tutorial.
- Install the MySQL server.
- Download the JDBC driver for MySQL from here and copy it to your
- Create the following database:
Create the following table:
Enter the following data into the table:
Step 2: Adding an RDBMS datasource
Follow the steps given below.
- Enter the URL to your MySQL database in the URL field.
- Enter the username and password to connect to your MySQL database. By default the username is root and the password is blank.
Step 3: Defining a query
Now let's start writing a query for getting data from the datasource. The query will specify the data that should be fetched and the format that should be used to display data when the query is invoked.
- Click Add New Query to open the Add New Query screen.
- Enter the following values:
- Query ID: Enter an ID for the query.
- Datasource: Select the datasource for which you are going to write a query. Select the RDBMS datasource that you created previously.
SQL: In this field, enter the SQL statement describing the data that should be retrieved from the RDBMS datasource.
Add input mappings: Click Generate Input Mapping to automatically create a mapping for the AccountID field in the database.
Input mappings allow you to add parameters to a query so that you can set the parameter value when executing the query. According to the above definition, you need to provide the account ID as an input in order to retrieve the data corresponding to the account ID.
Find out more about defining Input Mappings.
Add output mappings: Click Generate Response to automatically create mappings for the fields that should show in the output.
Output mapping is used to specify how the data that is fetched from your query will be shown in the response. Note that, by default, the output type is XML. Find out more about defining Output Mappings.
Step 4: Defining an operation to invoke the query
Data service operations are written to invoke queries.
- Click Add New Operation to open Add New Operation screen.
- Add a name for your operation in the Operation Name field.
- In the Query ID field, select the query that you defined previously.
- Save the operation.
Step 5: Finish creating the data service
Once you have defined the operation, click Finish to complete the data service creation process. You will now be taken to the Deployed Services screen, which shows all the data services deployed on the server.
Step 6: Invoking your data service
You can try the data service you created by using the TryIt tool that is in your product by default.
- Go to the Deployed Services screen.
- Click the Try this service link for the AccountDetailsService. The TryIt Tool will open with the data service.
- Select the operation you created earlier. You need to provide the account ID as an input. Enter '1'.
Click Send to see the details of the account.