Creating a Data Service

Follow the instructions given below to create a new data service artifact.

Tip

You can also use a sample template to create your data service.

  1. Open the Getting Started view of WSO2 Integration Studio (Menu -> Help -> Getting Started).
  2. In the Getting Started view, go to the Data Service tab and select the REST Data Service example.

Instructions

Create the data service artifact

Follow the steps given below to create the data service file:

  1. Right-click the Data Service Config module in the project explorer and go to New -> Data Service.

  2. In the New Data Service wizard that opens, select Create New Data Service and click Next.

  3. Enter a name for the data service and click Finish.

A data service file (DBS file) will now be created in your data service project as show below.

Adding a datasource

You can configure the datasource connection details using this section.

  1. Click Data Sources to expand the section.

  2. Click Add New to open the Create Datasource page.

  3. Enter the datasource connection details.

  4. Click Test Connection to expand the section.

  5. Click the Test Connection button to verify the connectivity between the MySQL datasource and the data service.

  6. Save the data service.

Creating a query

You can configure the main query details using this section.

  1. Click Queries to expand the section.

  2. Click Add New to open the Add Query page.

  3. Enter the following query details.

    Parameter Description
    Query ID Give a unique name to Identify the Query.
    Datasource All the datasources created for this data service are listed. Select the required datasource from the list.
    SQL Query You can enter the SQL query in this text box.

Input mapping

You can configure input parameters for the query using this section.

  1. Click Input Mappings to expand the section.

  2. There are two ways to create the mapping:

    • You can click Generate to automatically generate the input mappings from the SQL query.
    • If you want to add a new input mapping:

      1. Click Add New to open the Add Input Mapping page.

      2. Enter the following input mapping details:

        Parameter Description
        Mapping Name Give a name for the mapping.
        Parameter Type The parameter type.
        SQL Type The SQL type.

      3. Save the input mapping.

Shown below is an example query with input mapping:

Result (Output Mappings)

You can configure output result parameters for the query using this section.

  1. Click Result (Output Mappings) to expand the section.

  2. Enter the following details:

    Property Description
    Grouped by Element Employees

  3. There are two ways to create the output mapping:

    • You can click Generate to automatically generate the output mappings from the SQL query.
    • Alternatively, you can manually add the mappings:

      1. Click Add New to open the Add Output Mapping page.

      2. Enter the following output element details.

        Property Description
        Datasource Type column
        Output Field Name EmployeeNumber
        Datasource Column Name EmployeeNumber
        Schema Type String

      3. Save the element.

      4. Follow the same steps to create the remaining output elements.

Shown below is an example query with output mappings:

Advanced properties

Click Advanced Properties to expand the section and add the required parameter values.

The data service should now have the query element added.

Adding a SOAP operation

Use this section to configure a SOAP operation for invoking the data service.

  1. Click Operations to expand the section.

  2. Click Add New to add a SOAP Operation for your data service.

  3. Enter the following information:

    Parameter Description
    Operation Name Give a name to the SOAP Operation.
    Query ID Select the Query from the listed queries.
    Operation Parameters Click Add New to add new parameters to the operation.

Adding a Resource

Use this section to configure a REST resource for invoking the data service.

  1. Click Resources to expand the section.

  2. Click Add New to add a new resource.

  3. Give the following details to create the REST resource.

    Parameter Description
    Resource Path Give the HTTP REST resource path you need to expose.
    Query ID Select the Query ID from the drop down list that you need to expose as a REST resource.

  4. Click Save to add the resource to the data service.

The data service should now have the resource added.

Generate Data Service from a Datasource

Follow the steps given below to automatically create a data service using a given datasource structure. When generating a data service, the server takes its table structure according to the structure specified in the datasource and automatically creates the SELECT, INSERT, UPDATE, and DELETE operations.

  1. Create a datasource project and add a datasource in the current workspace. You can refer Creating a Datasource for more information.

  2. In the New Data Service wizard that opens, select Generate Data Service from Datasource and click Next.

  3. From the wizard, select the datasource that you have configured in step 1.

  4. Select the driver to connect to the datasource. There are two ways to select a driver:

    • You can use an existing driver from the Integration Studio. You can select the driver version from the drop down.

    • You can browse and upload a driver from your file system.

    Then click Fetch Table to list down all avaialble tables in the selected datasource.

  5. From the list of tables, select the tables and the REST resource methods that you want in the generated data service.

  6. You can select a service generation mode from the following two options:

    • Single Service: Creates a single data service for resources of all tables. If this option is selected, you need to provide a name for the Data Service you are creating.

    • Multiple Services: Creates a service per table, which will contain isolated resources for each table.

  7. Click Finish to generate the services and add to the dataservices project.

Examples

Tutorials

  • See the tutorial on data integration
  • Top