Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The batch requests feature allows you to send multiple (IN-Only) requests to a datasource using a single operation (batch operation). Follow the steps given below to define a data service that can invoke batch requests:

Table of Contents

...

Setting up a datasource

Follow the steps given below to set up a MySQL database for this tutorial.

  1. Install the MySQL server.
  2. Download the JDBC driver for MySQL from here and copy it to your <DSS<EI_HOME>/repository/components/lib directory.
  3. Create the following database: Company
  4. Create the Employee table:

    Code Block
    CREATE TABLE `EMPLOYEES` (`EmployeeNumber` int(11) NOT NULL, `FirstName` varchar(255) NOT NULL, `LastName` varchar(255) DEFAULT NULL, `Email` varchar(255) DEFAULT NULL, `JobTitle` varchar(255) DEFAULT NULL, `OfficeCode` int(11) NOT NULL, PRIMARY KEY (`EmployeeNumber`,`OfficeCode`), CONSTRAINT `employees_ibfk_1` FOREIGN KEY (`OfficeCode`) REFERENCES `OFFICES` (`OfficeCode`));

...

Define a data service to insert records in batches

Let's create a data service using the Create Data Service wizard:

  1. Log into the management console of WSO2 DSS and EI and click Create in the  under Data Service menu.
  2. Add a name for the data service and select the Enable Batch Requests check box as shown below.
  3. Click Next and add a new datasource.
  4. Connect to the Company database that you defined above.
  5. Click Next to open the Queries screen.
  6. Click Add New Query to specify the query details:

    1. Enter addEmployeeQuery as the query ID.

    2. Enter the following SQL dialect:

      Code Block
      insert into Employees (employeeNumber, lastName, firstName, email, salary) values(:employeeNumber,'test','test',:email,:officecode)
  7. Click Generate Input Mapping and an input mapping mappings will be generated automatically for the employeeNumberemail, and officecode field.

  8. Create an operation for the addEmployeeQuery query as shown below.

  9. Click Finish to navigate to the Deployed Services window, from where you can manage data services.

Invoking the data service 

You can try the data service you created by using the TryIt tool that is in your product by default. 

...