...
- Install the MySQL server.
- Download the JDBC driver for MySQL from here and copy it to your
<EI_HOME>/lib
directory. - Create the following database: Company
Create the Employee EMPLOYEES 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:
- Log into 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 Next and add a new datasource.
- Connect Give an ID for the datasource, and create the connection to the Company database that you defined above.Click . 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:
Code Block insert into Employees (employeeNumberEmployeeNumber, FirstName, lastNameLastName, firstNameEmail, emailJobTitle, salaryOfficeCode) values(:employeeNumber,'test','test',:email,:officecodeEmployeeNumber,:FirstName,:LastName,:Email,:JobTitle,:Officecode)
Click Generate Input Mapping and input mappings will be generated automatically for the employeeNumber, email, and officecode field.
Create 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 navigate to the Deployed Services window, from where you can manage data servicescomplete the data service creation process.
Invoking the data service
...
- 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 a batch_request operation automatically 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.
Code Block <p:addEmployeeQueryOPaddEmployeeOp_batch_req xmlns:p="http://ws.wso2.org/dataservice"> <!--1 or more occurrences--> <addEmployeeQueryOP<addEmployeeOp xmlns="http://ws.wso2.org/dataservice"> <!--Exactly 1 occurrence--> <xs:employeeNumber:EmployeeNumber xmlns:xs="http://ws.wso2.org/dataservice">1002</xs:EmployeeNumber> <!--Exactly 1 occurrence--> <xs:FirstName xmlns:xs="http://ws.wso2.org/dataservice">John</xs:FirstName> <!--Exactly 1 occurrence--> <xs:LastName xmlns:xs="http://ws.wso2.org/dataservice">100<>Doe</xs:employeeNumber>LastName> <!--Exactly 1 occurrence--> <xs:emailEmail xmlns:xs="http://ws.wso2.org/dataservice">abc@email>johnd@wso2.com</xs:Email> <!--Exactly 1 occurrence--> <xs:JobTitle xmlns:xs:email>="http://ws.wso2.org/dataservice">Consultant</xs:JobTitle> <!--Exactly 1 occurrence--> <xs:officecodeOfficecode xmlns:xs="http://ws.wso2.org/dataservice">1<>01</xs:officecode>Officecode> </addEmployeeQueryOP>addEmployeeOp> <addEmployeeQueryOP<addEmployeeOp xmlns="http://ws.wso2.org/dataservice"> <!--Exactly 1 occurrence--> <xs:employeeNumber:EmployeeNumber xmlns:xs="http://ws.wso2.org/dataservice">1004</xs:EmployeeNumber> <!--Exactly 1 occurrence--> <xs:FirstName xmlns:xs="http://ws.wso2.org/dataservice">Peter</xs:FirstName> <!--Exactly 1 occurrence--> <xs:LastName xmlns:xs="http://ws.wso2.org/dataservice">101<>Parker</xs:employeeNumber>LastName> <!--Exactly 1 occurrence--> <xs:emailEmail xmlns:xs="http://ws.wso2.org/dataservice">abd@email>peterp@wso2.com</xs:email>:Email> <!--Exactly 1 occurrence--> <xs:JobTitle xmlns:xs="http://ws.wso2.org/dataservice">Consultant</xs:JobTitle> <!--Exactly 1 occurrence--> <xs:officecodeOfficecode xmlns:xs="http://ws.wso2.org/dataservice">2<>01</xs:officecode>Officecode> </addEmployeeQueryOP>addEmployeeOp> </p:addEmployeeQueryOPaddEmployeeOp_batch_req>
- Execute the batch operation. You will find that all the records have been inserted into the database simultaneously.