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:
Setting up a datasource
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: Company
Create the Employee table:
Define a data service to insert records in batches
Let's create a data service using the Create Data Service wizard:
- Log in to the management console and click Create under Data Service.
- Add a name for the data service and select the Enable Batch Requests check box as shown below.
- Click Next and add a new datasource.
- Give an ID for the datasource, and create the connection to the Company database. Specifying the following details:
- Save the datasource details, and click Next to open the Queries screen.
Click Add New Query to specify the query details:
Enter addEmployeeQuery as the query ID.
Enter the following SQL dialect:
Click Generate Input Mapping and input mappings will be generated automatically for the EmployeeNumber, FirstName, LastName, Email, JobTitle, and OfficeCode fields.
Save the query, and click Next to open the Operations screen.
- Click Add New Operation, and create an operation for the addEmployeeQuery query as shown below.
- Save the operation.
- Click Finish to complete the data service creation process.
Invoking the 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 Try this Service to open the data service from the TryIt tool.
- Click Try this Service to open the data service from the TryIt tool. There will be a batch_request operation automatically generated.
- Select the batch operation.
Enter multiple transactions as shown below. In this example, we are sending two transactions with details of two employees.
- Execute the batch operation. You will find that all the records have been inserted into the database simultaneously.